Add starref entry point to my/bot stars page.

This commit is contained in:
John Preston 2024-11-29 12:05:21 +04:00
parent 0e866a0266
commit 46fcc695a5
11 changed files with 181 additions and 103 deletions

View file

@ -918,6 +918,8 @@ PRIVATE
info/bot/earn/info_bot_earn_list.h
info/bot/earn/info_bot_earn_widget.cpp
info/bot/earn/info_bot_earn_widget.h
info/bot/starref/info_bot_starref_common.cpp
info/bot/starref/info_bot_starref_common.h
info/bot/starref/info_bot_starref_join_widget.cpp
info/bot/starref/info_bot_starref_join_widget.h
info/bot/starref/info_bot_starref_setup_widget.cpp

View file

@ -16,8 +16,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h"
#include "data/stickers/data_custom_emoji.h"
#include "info/bot/earn/info_bot_earn_widget.h"
#include "info/bot/starref/info_bot_starref_common.h"
#include "info/bot/starref/info_bot_starref_join_widget.h"
#include "info/channel_statistics/earn/earn_format.h"
#include "info/info_controller.h"
#include "info/info_memento.h"
#include "info/statistics/info_statistics_inner_widget.h" // FillLoading.
#include "info/statistics/info_statistics_list_controllers.h"
#include "lang/lang_keys.h"
@ -250,7 +253,17 @@ void InnerWidget::fill() {
return v ? ToUsd(v, multiplier, kMinorLength) : QString();
}));
}
{
const auto button = BotStarRef::AddViewListButton(
container,
tr::lng_credits_summary_earn_title(),
tr::lng_credits_summary_earn_about());
button->setClickedCallback([=] {
_controller->showSection(BotStarRef::Join::Make(peer()));
});
Ui::AddSkip(container);
Ui::AddDivider(container);
}
fillHistory();
}

View file

@ -0,0 +1,115 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/bot/starref/info_bot_starref_common.h"
#include "settings/settings_common.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/text/text_utilities.h"
//#include "styles/style_info.h"
#include "styles/style_layers.h"
#include "styles/style_settings.h"
//#include "styles/style_premium.h"
namespace Info::BotStarRef {
not_null<Ui::AbstractButton*> AddViewListButton(
not_null<Ui::VerticalLayout*> parent,
rpl::producer<QString> title,
rpl::producer<QString> subtitle) {
const auto &stLabel = st::defaultFlatLabel;
const auto iconSize = st::settingsPremiumIconDouble.size();
const auto &titlePadding = st::settingsPremiumRowTitlePadding;
const auto &descriptionPadding = st::settingsPremiumRowAboutPadding;
const auto button = Ui::CreateChild<Ui::SettingsButton>(
parent,
rpl::single(QString()));
button->show();
const auto label = parent->add(
object_ptr<Ui::FlatLabel>(
parent,
std::move(title) | Ui::Text::ToBold(),
stLabel),
titlePadding);
label->setAttribute(Qt::WA_TransparentForMouseEvents);
const auto description = parent->add(
object_ptr<Ui::FlatLabel>(
parent,
std::move(subtitle),
st::boxDividerLabel),
descriptionPadding);
description->setAttribute(Qt::WA_TransparentForMouseEvents);
const auto dummy = Ui::CreateChild<Ui::AbstractButton>(parent);
dummy->setAttribute(Qt::WA_TransparentForMouseEvents);
dummy->show();
parent->sizeValue(
) | rpl::start_with_next([=](const QSize &s) {
dummy->resize(s.width(), iconSize.height());
}, dummy->lifetime());
button->geometryValue(
) | rpl::start_with_next([=](const QRect &r) {
dummy->moveToLeft(0, r.y() + (r.height() - iconSize.height()) / 2);
}, dummy->lifetime());
::Settings::AddButtonIcon(dummy, st::settingsButton, {
.icon = &st::settingsStarRefEarnStars,
.backgroundBrush = st::premiumIconBg3,
});
rpl::combine(
parent->widthValue(),
label->heightValue(),
description->heightValue()
) | rpl::start_with_next([=,
topPadding = titlePadding,
bottomPadding = descriptionPadding](
int width,
int topHeight,
int bottomHeight) {
button->resize(
width,
topPadding.top()
+ topHeight
+ topPadding.bottom()
+ bottomPadding.top()
+ bottomHeight
+ bottomPadding.bottom());
}, button->lifetime());
label->topValue(
) | rpl::start_with_next([=, padding = titlePadding.top()](int top) {
button->moveToLeft(0, top - padding);
}, button->lifetime());
const auto arrow = Ui::CreateChild<Ui::IconButton>(
button,
st::backButton);
arrow->setIconOverride(
&st::settingsPremiumArrow,
&st::settingsPremiumArrowOver);
arrow->setAttribute(Qt::WA_TransparentForMouseEvents);
button->sizeValue(
) | rpl::start_with_next([=](const QSize &s) {
const auto &point = st::settingsPremiumArrowShift;
arrow->moveToRight(
-point.x(),
point.y() + (s.height() - arrow->height()) / 2);
}, arrow->lifetime());
return button;
}
QString FormatStarRefCommission(ushort commission) {
return QString::number(commission / 10.) + '%';
}
} // namespace Info::BotStarRef

View file

@ -0,0 +1,24 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
namespace Ui {
class AbstractButton;
class VerticalLayout;
} // namespace Ui
namespace Info::BotStarRef {
[[nodiscard]] not_null<Ui::AbstractButton*> AddViewListButton(
not_null<Ui::VerticalLayout*> parent,
rpl::producer<QString> title,
rpl::producer<QString> subtitle);
[[nodiscard]] QString FormatStarRefCommission(ushort commission);
} // namespace Info::BotStarRef

View file

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/click_handler_types.h"
#include "data/data_session.h"
#include "data/data_user.h"
#include "info/bot/starref/info_bot_starref_common.h"
#include "info/profile/info_profile_icon.h"
#include "info/info_controller.h"
#include "info/info_memento.h"
@ -868,9 +869,5 @@ std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer) {
std::make_shared<Memento>(peer)));
}
QString FormatStarRefCommission(ushort commission) {
return QString::number(commission / 10.) + '%';
}
} // namespace Info::BotStarRef::Join

View file

@ -76,6 +76,4 @@ private:
[[nodiscard]] std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer);
[[nodiscard]] QString FormatStarRefCommission(ushort commission);
} // namespace Info::BotStarRef::Join

View file

@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/unixtime.h"
#include "core/click_handler_types.h"
#include "data/data_user.h"
#include "info/bot/starref/info_bot_starref_join_widget.h"
#include "info/bot/starref/info_bot_starref_common.h"
#include "info/profile/info_profile_icon.h"
#include "info/info_controller.h"
#include "info/info_memento.h"
@ -496,7 +496,7 @@ void InnerWidget::setupCommission() {
commission,
setCommission,
setCommission,
[=](int value) { return Join::FormatStarRefCommission(value); },
[=](int value) { return FormatStarRefCommission(value); },
_state.exists),
st::boxRowPadding);
@ -907,92 +907,5 @@ std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer) {
std::make_shared<Memento>(peer)));
}
not_null<Ui::AbstractButton*> AddViewListButton(
not_null<Ui::VerticalLayout*> parent,
rpl::producer<QString> title,
rpl::producer<QString> subtitle) {
const auto &stLabel = st::defaultFlatLabel;
const auto iconSize = st::settingsPremiumIconDouble.size();
const auto &titlePadding = st::settingsPremiumRowTitlePadding;
const auto &descriptionPadding = st::settingsPremiumRowAboutPadding;
const auto button = Ui::CreateChild<Ui::SettingsButton>(
parent,
rpl::single(QString()));
const auto label = parent->add(
object_ptr<Ui::FlatLabel>(
parent,
std::move(title) | Ui::Text::ToBold(),
stLabel),
titlePadding);
label->setAttribute(Qt::WA_TransparentForMouseEvents);
const auto description = parent->add(
object_ptr<Ui::FlatLabel>(
parent,
std::move(subtitle),
st::boxDividerLabel),
descriptionPadding);
description->setAttribute(Qt::WA_TransparentForMouseEvents);
const auto dummy = Ui::CreateChild<Ui::AbstractButton>(parent);
dummy->setAttribute(Qt::WA_TransparentForMouseEvents);
parent->sizeValue(
) | rpl::start_with_next([=](const QSize &s) {
dummy->resize(s.width(), iconSize.height());
}, dummy->lifetime());
button->geometryValue(
) | rpl::start_with_next([=](const QRect &r) {
dummy->moveToLeft(0, r.y() + (r.height() - iconSize.height()) / 2);
}, dummy->lifetime());
::Settings::AddButtonIcon(dummy, st::settingsButton, {
.icon = &st::settingsStarRefEarnStars,
.backgroundBrush = st::premiumIconBg3,
});
rpl::combine(
parent->widthValue(),
label->heightValue(),
description->heightValue()
) | rpl::start_with_next([=,
topPadding = titlePadding,
bottomPadding = descriptionPadding](
int width,
int topHeight,
int bottomHeight) {
button->resize(
width,
topPadding.top()
+ topHeight
+ topPadding.bottom()
+ bottomPadding.top()
+ bottomHeight
+ bottomPadding.bottom());
}, button->lifetime());
label->topValue(
) | rpl::start_with_next([=, padding = titlePadding.top()](int top) {
button->moveToLeft(0, top - padding);
}, button->lifetime());
const auto arrow = Ui::CreateChild<Ui::IconButton>(
button,
st::backButton);
arrow->setIconOverride(
&st::settingsPremiumArrow,
&st::settingsPremiumArrowOver);
arrow->setAttribute(Qt::WA_TransparentForMouseEvents);
button->sizeValue(
) | rpl::start_with_next([=](const QSize &s) {
const auto &point = st::settingsPremiumArrowShift;
arrow->moveToRight(
-point.x(),
point.y() + (s.height() - arrow->height()) / 2);
}, arrow->lifetime());
return button;
}
} // namespace Info::BotStarRef::Setup

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "info/info_content_widget.h"
#include "info/bot/starref/info_bot_starref_common.h"
namespace Ui::Premium {
class TopBarAbstract;
@ -81,9 +82,4 @@ private:
[[nodiscard]] std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer);
[[nodiscard]] not_null<Ui::AbstractButton*> AddViewListButton(
not_null<Ui::VerticalLayout*> parent,
rpl::producer<QString> title,
rpl::producer<QString> subtitle);
} // namespace Info::BotStarRef::Setup

View file

@ -963,7 +963,7 @@ void InnerWidget::fill() {
) | rpl::map(creditsToUsdMap));
}
const auto button = Info::BotStarRef::Setup::AddViewListButton(
const auto button = Info::BotStarRef::AddViewListButton(
container,
tr::lng_credits_summary_earn_title(),
tr::lng_credits_summary_earn_about());

View file

@ -89,6 +89,7 @@ void AddButtonIcon(
std::move(descriptor));
icon->widget.setAttribute(Qt::WA_TransparentForMouseEvents);
icon->widget.resize(icon->icon.size());
icon->widget.show();
button->sizeValue(
) | rpl::start_with_next([=, left = st.iconLeft](QSize size) {
icon->widget.moveToLeft(

View file

@ -17,9 +17,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_photo_media.h"
#include "data/data_session.h"
#include "data/data_user.h"
#include "info/bot/starref/info_bot_starref_common.h"
#include "info/bot/starref/info_bot_starref_join_widget.h"
#include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget.
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
#include "info/statistics/info_statistics_list_controllers.h"
#include "info/info_memento.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
#include "settings/settings_common_session.h"
@ -74,7 +77,7 @@ private:
void setupContent();
void setupHistory(not_null<Ui::VerticalLayout*> container);
void setupSubscriptions(not_null<Ui::VerticalLayout*> container);
void setupStarRefPromo(not_null<Ui::VerticalLayout*> container);
const not_null<Window::SessionController*> _controller;
QWidget *_parent = nullptr;
@ -206,6 +209,21 @@ void Credits::setupSubscriptions(not_null<Ui::VerticalLayout*> container) {
}
}
void Credits::setupStarRefPromo(not_null<Ui::VerticalLayout*> container) {
Ui::AddSkip(container);
const auto button = Info::BotStarRef::AddViewListButton(
container,
tr::lng_credits_summary_earn_title(),
tr::lng_credits_summary_earn_about());
button->setClickedCallback([=] {
const auto self = _controller->session().user();
_controller->showSection(Info::BotStarRef::Join::Make(self));
});
Ui::AddSkip(container);
Ui::AddDivider(container);
Ui::AddSkip(container);
}
void Credits::setupHistory(not_null<Ui::VerticalLayout*> container) {
const auto history = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
@ -493,6 +511,7 @@ void Credits::setupContent() {
Ui::AddSkip(content);
Ui::AddDivider(content);
setupStarRefPromo(content);
setupSubscriptions(content);
setupHistory(content);