Improve premium preview boxes close buttons.

This commit is contained in:
John Preston 2022-06-14 16:03:13 +04:00
parent 629574685e
commit 6260f258bb
3 changed files with 91 additions and 68 deletions

View file

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_message_reactions.h" #include "data/data_message_reactions.h"
#include "data/data_document_media.h" #include "data/data_document_media.h"
#include "data/data_streaming.h" #include "data/data_streaming.h"
#include "data/data_peer_values.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_domain.h" // kMaxAccounts #include "main/main_domain.h" // kMaxAccounts
@ -42,6 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "apiwrap.h" #include "apiwrap.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
#include "styles/style_chat_helpers.h" #include "styles/style_chat_helpers.h"
#include "styles/style_settings.h"
#include <QSvgRenderer> #include <QSvgRenderer>
@ -1241,6 +1243,15 @@ void PreviewBox(
const auto outer = box->addRow( const auto outer = box->addRow(
ChatBackPreview(box, size.height(), back), ChatBackPreview(box, size.height(), back),
{}); {});
const auto close = Ui::CreateChild<Ui::IconButton>(
box->verticalLayout().get(),
st::settingsPremiumTopBarClose);
box->verticalLayout()->widthValue(
) | rpl::start_with_next([=](int width) {
close->moveToRight(0, 0, width);
}, close->lifetime());
close->setClickedCallback([=] { box->closeBox(); });
struct Hiding { struct Hiding {
not_null<Ui::RpWidget*> widget; not_null<Ui::RpWidget*> widget;
int leftFrom = 0; int leftFrom = 0;
@ -1304,16 +1315,8 @@ void PreviewBox(
switch (descriptor.section) { switch (descriptor.section) {
case PremiumPreview::Stickers: case PremiumPreview::Stickers:
state->content = media state->content = media
? StickerPreview( ? StickerPreview(outer, controller, media, state->preload)
outer, : StickersPreview(outer, controller, state->preload);
controller,
media,
state->preload)
: GenericPreview(
outer,
controller,
descriptor.section,
state->preload);
break; break;
case PremiumPreview::Reactions: case PremiumPreview::Reactions:
state->content = ReactionsPreview( state->content = ReactionsPreview(
@ -1437,40 +1440,52 @@ void PreviewBox(
box->addRow( box->addRow(
CreateSwitch(box->verticalLayout(), &state->selected), CreateSwitch(box->verticalLayout(), &state->selected),
st::premiumDotsMargin); st::premiumDotsMargin);
box->setStyle(st::premiumPreviewBox); if (descriptor.fromSettings && controller->session().premium()) {
const auto buttonPadding = st::premiumPreviewBox.buttonPadding; box->addButton(tr::lng_close(), [=] { box->closeBox(); });
const auto width = size.width() } else {
- buttonPadding.left() box->setStyle(st::premiumPreviewBox);
- buttonPadding.right(); const auto buttonPadding = st::premiumPreviewBox.buttonPadding;
const auto computeRef = [=] { const auto width = size.width()
return Settings::LookupPremiumRef(state->selected.current()); - buttonPadding.left()
}; - buttonPadding.right();
auto unlock = state->selected.value( const auto computeRef = [=] {
) | rpl::map([=](PremiumPreview section) { return Settings::LookupPremiumRef(state->selected.current());
return (section == PremiumPreview::Reactions) };
? tr::lng_premium_unlock_reactions() auto unlock = state->selected.value(
: (section == PremiumPreview::Stickers) ) | rpl::map([=](PremiumPreview section) {
? tr::lng_premium_unlock_stickers() return (section == PremiumPreview::Reactions)
: tr::lng_premium_more_about(); ? tr::lng_premium_unlock_reactions()
}) | rpl::flatten_latest(); : (section == PremiumPreview::Stickers)
auto button = descriptor.fromSettings ? tr::lng_premium_unlock_stickers()
? object_ptr<Ui::GradientButton>::fromRaw( : tr::lng_premium_more_about();
Settings::CreateSubscribeButton(controller, box, computeRef)) }) | rpl::flatten_latest();
: CreateUnlockButton(box, std::move(unlock)); auto button = descriptor.fromSettings
button->resizeToWidth(width); ? object_ptr<Ui::GradientButton>::fromRaw(
button->setClickedCallback([=] { Settings::CreateSubscribeButton(controller, box, computeRef))
Settings::ShowPremium( : CreateUnlockButton(box, std::move(unlock));
controller, button->resizeToWidth(width);
Settings::LookupPremiumRef(state->selected.current())); button->setClickedCallback([=] {
}); Settings::ShowPremium(
box->setShowFinishedCallback([=, raw = button.data()] { controller,
state->showFinished = true; Settings::LookupPremiumRef(state->selected.current()));
if (base::take(state->preloadScheduled)) { });
state->preload(); box->setShowFinishedCallback([=, raw = button.data()] {
} state->showFinished = true;
raw->startGlareAnimation(); if (base::take(state->preloadScheduled)) {
}); state->preload();
box->addButton(std::move(button)); }
raw->startGlareAnimation();
});
box->addButton(std::move(button));
}
if (descriptor.fromSettings) {
Data::AmPremiumValue(
&controller->session()
) | rpl::skip(1) | rpl::start_with_next([=](bool premium) {
box->closeBox();
}, box->lifetime());
}
if (const auto &hidden = descriptor.hiddenCallback) { if (const auto &hidden = descriptor.hiddenCallback) {
box->boxClosing() | rpl::start_with_next(hidden, box->lifetime()); box->boxClosing() | rpl::start_with_next(hidden, box->lifetime());

View file

@ -770,31 +770,39 @@ void Premium::setupContent() {
} }
controller->show(Box([=](not_null<Ui::GenericBox*> box) { controller->show(Box([=](not_null<Ui::GenericBox*> box) {
DoubledLimitsPreviewBox(box, &controller->session()); DoubledLimitsPreviewBox(box, &controller->session());
box->addTopButton(st::boxTitleClose, [=] {
const auto button = CreateSubscribeButton( box->closeBox();
controller,
box,
[] { return u"double_limits"_q; });
box->boxClosing(
) | rpl::start_with_next(hidden, box->lifetime());
box->setShowFinishedCallback([=] {
button->startGlareAnimation();
}); });
if (controller->session().premium()) {
box->addButton(tr::lng_close(), [=] {
box->closeBox();
});
} else {
const auto button = CreateSubscribeButton(
controller,
box,
[] { return u"double_limits"_q; });
box->setStyle(st::premiumPreviewDoubledLimitsBox); box->boxClosing(
box->widthValue( ) | rpl::start_with_next(hidden, box->lifetime());
) | rpl::start_with_next([=](int width) {
const auto &padding = box->setShowFinishedCallback([=] {
st::premiumPreviewDoubledLimitsBox.buttonPadding; button->startGlareAnimation();
button->resizeToWidth(width });
- padding.left()
- padding.right()); box->setStyle(st::premiumPreviewDoubledLimitsBox);
button->moveToLeft(padding.left(), padding.top()); box->widthValue(
}, button->lifetime()); ) | rpl::start_with_next([=](int width) {
box->addButton( const auto &padding =
object_ptr<Ui::AbstractButton>::fromRaw(button)); st::premiumPreviewDoubledLimitsBox.buttonPadding;
button->resizeToWidth(width
- padding.left()
- padding.right());
button->moveToLeft(padding.left(), padding.top());
}, button->lifetime());
box->addButton(
object_ptr<Ui::AbstractButton>::fromRaw(button));
}
})); }));
}); });

@ -1 +1 @@
Subproject commit 1679da738b2739820287fbf810981c91de48b73d Subproject commit 3aa78fb00043e83bb000cec091bdbd93a8233794