2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Subscription status display.

This commit is contained in:
John Preston
2022-05-31 21:11:59 +04:00
parent 1d7e901b7a
commit de31c1cf0c
16 changed files with 221 additions and 43 deletions

View File

@@ -455,3 +455,4 @@ settingsPremiumAboutTextStyle: TextStyle(defaultTextStyle) {
font: font(12px);
lineHeight: 18px;
}
settingsPremiumStatusPadding: margins(22px, 8px, 22px, 2px);

View File

@@ -93,6 +93,9 @@ public:
virtual void setInnerFocus() {
setFocus();
}
[[nodiscard]] virtual const Ui::RoundRect *bottomSkipRounding() const {
return nullptr;
}
[[nodiscard]] virtual QPointer<Ui::RpWidget> createPinnedToTop(
not_null<QWidget*> parent) {
return nullptr;

View File

@@ -47,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_cloud_password.h"
#include "api/api_global_privacy.h"
#include "api/api_sensitive_content.h"
#include "api/api_premium.h"
#include "info/profile/info_profile_values.h"
#include "window/window_controller.h"
#include "window/window_session_controller.h"
@@ -558,6 +559,9 @@ Main::Main(
: Section(parent)
, _controller(controller) {
setupContent(controller);
if (_controller->session().premium()) {
_controller->session().api().premium().reload();
}
}
rpl::producer<QString> Main::title() {

View File

@@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_session_controller.h"
#include "base/unixtime.h"
#include "apiwrap.h"
#include "api/api_premium.h"
#include "styles/style_boxes.h"
#include "styles/style_chat_helpers.h"
#include "styles/style_info.h"
@@ -164,6 +165,43 @@ using Order = std::vector<QString>;
};
}
[[nodiscard]] not_null<Ui::RpWidget*> CreateSubscribeButton(
not_null<Ui::RpWidget*> parent,
Fn<void()> callback) {
const auto result = Ui::CreateChild<Ui::GradientButton>(
parent.get(),
Ui::Premium::ButtonGradientStops());
result->setClickedCallback(std::move(callback));
const auto &st = st::premiumPreviewBox.button;
result->resize(parent->width(), st.height);
const auto label = Ui::CreateChild<Ui::FlatLabel>(
result,
tr::lng_premium_summary_button(tr::now, lt_cost, "$5"),
st::premiumPreviewButtonLabel);
label->setAttribute(Qt::WA_TransparentForMouseEvents);
rpl::combine(
result->widthValue(),
label->widthValue()
) | rpl::start_with_next([=](int outer, int width) {
label->moveToLeft(
(outer - width) / 2,
st::premiumPreviewBox.button.textTop,
outer);
}, label->lifetime());
parent->widthValue(
) | rpl::start_with_next([=](int width) {
const auto padding = st::settingsPremiumButtonPadding;
result->resizeToWidth(width - padding.left() - padding.right());
result->moveToLeft(padding.left(), padding.top(), width);
}, result->lifetime());
return result;
}
void SendAppLog(
not_null<Main::Session*> session,
const QString &type,
@@ -583,6 +621,7 @@ public:
not_null<Ui::RpWidget*> parent) override;
[[nodiscard]] bool hasFlexibleTopBar() const override;
[[nodiscard]] const Ui::RoundRect *bottomSkipRounding() const override;
void setStepDataReference(std::any &data) override;
@@ -598,6 +637,7 @@ private:
base::unique_qptr<Ui::IconButton> _close;
rpl::variable<bool> _backToggles;
rpl::variable<Info::Wrap> _wrap;
std::optional<Ui::RoundRect> _bottomSkipRounding;
rpl::event_stream<> _showBack;
@@ -610,6 +650,7 @@ Premium::Premium(
, _controller(controller)
, _ref(ResolveRef(controller->premiumRef())) {
setupContent();
_controller->session().api().premium().reload();
}
rpl::producer<QString> Premium::title() {
@@ -620,6 +661,10 @@ bool Premium::hasFlexibleTopBar() const {
return true;
}
const Ui::RoundRect *Premium::bottomSkipRounding() const {
return _bottomSkipRounding ? &*_bottomSkipRounding : nullptr;
}
rpl::producer<> Premium::sectionShowBack() {
return _showBack.events();
}
@@ -763,8 +808,6 @@ void Premium::setupContent() {
st::aboutLabel),
st::boxRowPadding);
AddSkip(content, stDefault.padding.top() + stDefault.padding.bottom());
#else
AddSkip(content, stDefault.padding.bottom());
#endif
Ui::ResizeFitChild(this, content);
@@ -835,51 +878,51 @@ QPointer<Ui::RpWidget> Premium::createPinnedToBottom(
not_null<Ui::RpWidget*> parent) {
const auto content = Ui::CreateChild<Ui::RpWidget>(parent.get());
auto result = object_ptr<Ui::GradientButton>(
content,
Ui::Premium::ButtonGradientStops());
const auto raw = result.data();
raw->setClickedCallback([=] {
const auto button = CreateSubscribeButton(content, [=] {
SendScreenAccept(_controller);
StartPremiumPayment(_controller, _ref);
});
const auto &st = st::premiumPreviewBox.button;
raw->resize(content->width(), st.height);
const auto label = Ui::CreateChild<Ui::FlatLabel>(
raw,
tr::lng_premium_summary_button(tr::now, lt_cost, "$5"),
st::premiumPreviewButtonLabel);
label->setAttribute(Qt::WA_TransparentForMouseEvents);
rpl::combine(
raw->widthValue(),
label->widthValue()
) | rpl::start_with_next([=](int outer, int width) {
label->moveToLeft(
(outer - width) / 2,
st::premiumPreviewBox.button.textTop,
outer);
}, label->lifetime());
auto text = _controller->session().api().premium().statusTextValue();
const auto status = Ui::CreateChild<Ui::DividerLabel>(
content,
object_ptr<Ui::FlatLabel>(
content,
rpl::duplicate(text),
st::boxDividerLabel),
st::settingsPremiumStatusPadding,
RectPart::Top);
content->widthValue(
) | rpl::start_with_next([=](int width) {
const auto padding = st::settingsPremiumButtonPadding;
raw->resizeToWidth(width - padding.left() - padding.right());
}, raw->lifetime());
status->resizeToWidth(width);
}, status->lifetime());
rpl::combine(
raw->heightValue(),
button->heightValue(),
status->heightValue(),
std::move(text),
Data::AmPremiumValue(&_controller->session())
) | rpl::start_with_next([=](int height, bool premium) {
) | rpl::start_with_next([=](
int buttonHeight,
int statusHeight,
const TextWithEntities &text,
bool premium) {
const auto padding = st::settingsPremiumButtonPadding;
const auto finalHeight = premium
const auto finalHeight = !premium
? (padding.top() + buttonHeight + padding.bottom())
: text.text.isEmpty()
? 0
: (padding.top() + height + padding.bottom());
: statusHeight;
content->resize(content->width(), finalHeight);
raw->moveToLeft(padding.left(), padding.top());
}, raw->lifetime());
button->moveToLeft(padding.left(), padding.top());
status->moveToLeft(0, 0);
button->setVisible(!premium);
status->setVisible(premium && !text.text.isEmpty());
if (!premium || text.text.isEmpty()) {
_bottomSkipRounding.reset();
} else if (!_bottomSkipRounding) {
_bottomSkipRounding.emplace(st::boxRadius, st::boxDividerBg);
}
}, button->lifetime());
return Ui::MakeWeak(not_null<Ui::RpWidget*>{ content });
}