From 538934a88a2ab4eba37c8ff4a7742151e518696b Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 21 Mar 2024 19:32:38 +0300 Subject: [PATCH] Added learn more box to channel earn info section. --- .../earn/channel_earn.style | 6 + .../earn/info_earn_inner_widget.cpp | 205 ++++++++++++++---- 2 files changed, 174 insertions(+), 37 deletions(-) diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style b/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style index 1dea3e14c6..653f3c87ba 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style +++ b/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style @@ -101,3 +101,9 @@ channelEarnBalanceMinorLabel: FlatLabel(channelEarnOverviewMinorLabel) { } } channelEarnBalanceMinorLabelSkip: 6px; + +channelEarnLearnDescription: FlatLabel(defaultFlatLabel) { + maxHeight: 0px; + minWidth: 280px; + align: align(top); +} diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp index bb354144de..189e566527 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp @@ -14,28 +14,20 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/ui_integration.h" // Core::MarkedTextContext. #include "data/data_peer.h" #include "data/data_session.h" -#include "data/data_session.h" #include "data/stickers/data_custom_emoji.h" #include "info/info_controller.h" #include "info/profile/info_profile_values.h" // Info::Profile::NameValue. #include "lang/lang_keys.h" #include "main/main_session.h" -#include "settings/settings_common.h" -#include "statistics/widgets/chart_header_widget.h" #include "ui/controls/userpic_button.h" -#include "ui/effects/animation_value.h" #include "ui/effects/animation_value_f.h" -#include "ui/effects/animations.h" #include "ui/layers/generic_box.h" #include "ui/painter.h" #include "ui/rect.h" #include "ui/text/text_utilities.h" #include "ui/vertical_list.h" -#include "ui/widgets/buttons.h" #include "ui/widgets/continuous_sliders.h" #include "ui/widgets/fields/input_field.h" -#include "ui/widgets/labels.h" -#include "ui/wrap/slide_wrap.h" #include "ui/wrap/slide_wrap.h" #include "styles/style_boxes.h" #include "styles/style_channel_earn.h" @@ -113,19 +105,6 @@ void AddRecipient(not_null box, const TextWithEntities &t) { return emoji; } -void AddEmojiToMajor( - not_null label, - not_null session, - float64 value) { - auto emoji = EmojiCurrency(session); - label->setMarkedText( - emoji.append(' ').append(QString::number(int64(value))), - Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [label] { label->update(); }, - }); -} - [[nodiscard]] QString FormatDate(TimeId date) { const auto parsedDate = base::unixtime::parse(date); return tr::lng_group_call_starts_short_date( @@ -160,13 +139,27 @@ void InnerWidget::fill() { const auto multiplier = 3.8; // Debug. const auto session = &_peer->session(); + const auto makeContext = [=](not_null l) { + return Core::MarkedTextContext{ + .session = session, + .customEmojiRepaint = [=] { l->update(); }, + }; + }; + const auto addEmojiToMajor = [=]( + not_null label, + float64 value) { + auto emoji = EmojiCurrency(session); + label->setMarkedText( + emoji.append(' ').append(QString::number(int64(value))), + makeContext(label)); + }; + const auto arrow = Ui::Text::SingleCustomEmoji( + session->data().customEmojiManager().registerInternalEmoji( + st::topicButtonArrow, + st::channelEarnLearnArrowMargins, + false)); const auto addAboutWithLearn = [&](const tr::phrase &text) { - const auto emoji = Ui::Text::SingleCustomEmoji( - session->data().customEmojiManager().registerInternalEmoji( - st::topicButtonArrow, - st::channelEarnLearnArrowMargins, - false)); auto label = object_ptr( container, st::boxDividerLabel); @@ -175,18 +168,159 @@ void InnerWidget::fill() { lt_link, tr::lng_channel_earn_about_link( lt_emoji, - rpl::single(emoji), + rpl::single(arrow), Ui::Text::RichLangValue ) | rpl::map([](TextWithEntities text) { return Ui::Text::Link(std::move(text), 1); }), Ui::Text::RichLangValue ) | rpl::start_with_next([=](const TextWithEntities &text) { - raw->setMarkedText( - text, - Core::MarkedTextContext{ .session = session }); + raw->setMarkedText(text, makeContext(raw)); }, label->lifetime()); label->setLink(1, std::make_shared([=] { + _show->showBox(Box([=](not_null box) { + box->setNoContentMargin(true); + + const auto content = box->verticalLayout().get(); + + Ui::AddSkip(content); + Ui::AddSkip(content); + Ui::AddSkip(content); + box->addRow(object_ptr>( + content, + object_ptr( + content, + tr::lng_channel_earn_learn_title(), + st::boxTitle))); + Ui::AddSkip(content); + Ui::AddSkip(content); + Ui::AddSkip(content); + Ui::AddSkip(content); + { + const auto padding = QMargins( + st::settingsButton.padding.left(), + st::boxRowPadding.top(), + st::boxRowPadding.right(), + st::boxRowPadding.bottom()); + const auto addEntry = [&]( + rpl::producer title, + rpl::producer about, + const style::icon &icon) { + const auto top = content->add( + object_ptr( + content, + std::move(title), + st::channelEarnSemiboldLabel), + padding); + Ui::AddSkip(content, st::channelEarnHistoryThreeSkip); + content->add( + object_ptr( + content, + std::move(about), + st::channelEarnHistoryRecipientLabel), + padding); + const auto left = Ui::CreateChild( + box->verticalLayout().get()); + left->paintRequest( + ) | rpl::start_with_next([=] { + auto p = Painter(left); + icon.paint(p, 0, 0, left->width()); + }, left->lifetime()); + left->resize(icon.size()); + top->geometryValue( + ) | rpl::start_with_next([=](const QRect &g) { + left->moveToLeft( + (g.left() - left->width()) / 2, + g.top() + st::channelEarnHistoryThreeSkip); + }, left->lifetime()); + }; + addEntry( + tr::lng_channel_earn_learn_in_subtitle(), + tr::lng_channel_earn_learn_in_about(), + st::getBoostsButtonIcon); + Ui::AddSkip(content); + Ui::AddSkip(content); + addEntry( + tr::lng_channel_earn_learn_split_subtitle(), + tr::lng_channel_earn_learn_split_about(), + st::getBoostsButtonIcon); + Ui::AddSkip(content); + Ui::AddSkip(content); + addEntry( + tr::lng_channel_earn_learn_out_subtitle(), + tr::lng_channel_earn_learn_out_about(), + st::getBoostsButtonIcon); + Ui::AddSkip(content); + Ui::AddSkip(content); + } + Ui::AddSkip(content); + Ui::AddSkip(content); + { + const auto l = box->addRow( + object_ptr>( + content, + object_ptr( + content, + st::boxTitle)))->entity(); + tr::lng_channel_earn_learn_coin_title( + lt_emoji, + rpl::single( + Ui::Text::Link(EmojiCurrency(session), 1)), + Ui::Text::RichLangValue + ) | rpl::start_with_next([=](TextWithEntities t) { + l->setMarkedText(std::move(t), makeContext(l)); + }, l->lifetime()); + const auto diamonds = l->lifetime().make_state(0); + l->setLink(1, std::make_shared([=] { + const auto count = (*diamonds); + box->showToast((count == 100) + ? u"You are rich now!"_q + : (u"You have earned "_q + + QString::number(++(*diamonds)) + + (!count + ? u" diamond!"_q + : u" diamonds!"_q))); + })); + } + Ui::AddSkip(content); + { + const auto label = box->addRow( + object_ptr( + content, + st::channelEarnLearnDescription)); + tr::lng_channel_earn_learn_coin_about( + lt_link, + tr::lng_channel_earn_about_link( + lt_emoji, + rpl::single(arrow), + Ui::Text::RichLangValue + ) | rpl::map([](TextWithEntities text) { + return Ui::Text::Link(std::move(text), 1); + }), + Ui::Text::RichLangValue + ) | rpl::start_with_next([=, l = label]( + TextWithEntities t) { + l->setMarkedText(std::move(t), makeContext(l)); + l->resizeToWidth(box->width() + - rect::m::sum::h(st::boxRowPadding)); + }, label->lifetime()); + } + Ui::AddSkip(content); + Ui::AddSkip(content); + { + const auto &st = st::premiumPreviewDoubledLimitsBox; + box->setStyle(st); + auto button = object_ptr( + container, + tr::lng_channel_earn_learn_close(), + st::defaultActiveButton); + button->resizeToWidth(box->width() + - st.buttonPadding.left() + - st.buttonPadding.left()); + button->setClickedCallback([=] { box->closeBox(); }); + box->addButton(std::move(button)); + } + })); })); container->add(object_ptr( container, @@ -210,7 +344,7 @@ void InnerWidget::fill() { const auto majorLabel = Ui::CreateChild( line, st::channelEarnOverviewMajorLabel); - AddEmojiToMajor(majorLabel, session, value); + addEmojiToMajor(majorLabel, value); const auto minorLabel = Ui::CreateChild( line, QString::number(value - int64(value)).mid(1), @@ -273,7 +407,7 @@ void InnerWidget::fill() { const auto majorLabel = Ui::CreateChild( labels, st::channelEarnBalanceMajorLabel); - AddEmojiToMajor(majorLabel, session, value); + addEmojiToMajor(majorLabel, value); majorLabel->setAttribute(Qt::WA_TransparentForMouseEvents); const auto minorLabel = Ui::CreateChild( labels, @@ -701,7 +835,7 @@ void InnerWidget::fill() { const auto right = Ui::CreateChild( line, st::defaultFlatLabel); - AddEmojiToMajor(right, session, kMaxCPM); + addEmojiToMajor(right, kMaxCPM); const auto slider = Ui::CreateChild( line, st::settingsScale); @@ -747,10 +881,7 @@ void InnerWidget::fill() { lt_emoji, EmojiCurrency(session), Ui::Text::RichLangValue), - Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [center] { center->update(); }, - }); + makeContext(center)); } else { center->setText({}); }