mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to provide custom text to subscribe button.
This commit is contained in:
parent
afb336ed41
commit
2a3d72ad2e
3 changed files with 36 additions and 19 deletions
|
@ -1482,7 +1482,11 @@ void PreviewBox(
|
||||||
}) | rpl::flatten_latest();
|
}) | rpl::flatten_latest();
|
||||||
auto button = descriptor.fromSettings
|
auto button = descriptor.fromSettings
|
||||||
? object_ptr<Ui::GradientButton>::fromRaw(
|
? object_ptr<Ui::GradientButton>::fromRaw(
|
||||||
Settings::CreateSubscribeButton(controller, box, computeRef))
|
Settings::CreateSubscribeButton({
|
||||||
|
controller,
|
||||||
|
box,
|
||||||
|
computeRef,
|
||||||
|
}))
|
||||||
: CreateUnlockButton(box, std::move(unlock));
|
: CreateUnlockButton(box, std::move(unlock));
|
||||||
button->resizeToWidth(width);
|
button->resizeToWidth(width);
|
||||||
if (!descriptor.fromSettings) {
|
if (!descriptor.fromSettings) {
|
||||||
|
|
|
@ -787,10 +787,11 @@ void Premium::setupContent() {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const auto button = CreateSubscribeButton(
|
const auto button = CreateSubscribeButton({
|
||||||
controller,
|
controller,
|
||||||
box,
|
box,
|
||||||
[] { return u"double_limits"_q; });
|
[] { return u"double_limits"_q; }
|
||||||
|
});
|
||||||
|
|
||||||
box->boxClosing(
|
box->boxClosing(
|
||||||
) | rpl::start_with_next(hidden, box->lifetime());
|
) | rpl::start_with_next(hidden, box->lifetime());
|
||||||
|
@ -986,8 +987,10 @@ QPointer<Ui::RpWidget> Premium::createPinnedToBottom(
|
||||||
not_null<Ui::RpWidget*> parent) {
|
not_null<Ui::RpWidget*> parent) {
|
||||||
const auto content = Ui::CreateChild<Ui::RpWidget>(parent.get());
|
const auto content = Ui::CreateChild<Ui::RpWidget>(parent.get());
|
||||||
|
|
||||||
_subscribe = CreateSubscribeButton(_controller, content, [=] {
|
_subscribe = CreateSubscribeButton({
|
||||||
return _ref;
|
_controller,
|
||||||
|
content,
|
||||||
|
[=] { return _ref; }
|
||||||
});
|
});
|
||||||
|
|
||||||
_showFinished.events(
|
_showFinished.events(
|
||||||
|
@ -1089,22 +1092,24 @@ QString LookupPremiumRef(PremiumPreview section) {
|
||||||
}
|
}
|
||||||
|
|
||||||
not_null<Ui::GradientButton*> CreateSubscribeButton(
|
not_null<Ui::GradientButton*> CreateSubscribeButton(
|
||||||
not_null<Window::SessionController*> controller,
|
SubscribeButtonArgs &&args) {
|
||||||
not_null<Ui::RpWidget*> parent,
|
|
||||||
Fn<QString()> computeRef) {
|
|
||||||
const auto result = Ui::CreateChild<Ui::GradientButton>(
|
const auto result = Ui::CreateChild<Ui::GradientButton>(
|
||||||
parent.get(),
|
args.parent.get(),
|
||||||
Ui::Premium::ButtonGradientStops());
|
args.gradientStops
|
||||||
|
? base::take(*args.gradientStops)
|
||||||
|
: Ui::Premium::ButtonGradientStops());
|
||||||
|
|
||||||
result->setClickedCallback([=] {
|
result->setClickedCallback([
|
||||||
|
controller = args.controller,
|
||||||
|
computeRef = args.computeRef] {
|
||||||
SendScreenAccept(controller);
|
SendScreenAccept(controller);
|
||||||
StartPremiumPayment(controller, computeRef());
|
StartPremiumPayment(controller, computeRef());
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto &st = st::premiumPreviewBox.button;
|
const auto &st = st::premiumPreviewBox.button;
|
||||||
result->resize(parent->width(), st.height);
|
result->resize(args.parent->width(), st.height);
|
||||||
|
|
||||||
const auto premium = &controller->session().api().premium();
|
const auto premium = &args.controller->session().api().premium();
|
||||||
premium->reload();
|
premium->reload();
|
||||||
const auto computeCost = [=] {
|
const auto computeCost = [=] {
|
||||||
const auto amount = premium->monthlyAmount();
|
const auto amount = premium->monthlyAmount();
|
||||||
|
@ -1117,9 +1122,11 @@ not_null<Ui::GradientButton*> CreateSubscribeButton(
|
||||||
|
|
||||||
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
result,
|
result,
|
||||||
tr::lng_premium_summary_button(
|
args.text
|
||||||
lt_cost,
|
? base::take(*args.text)
|
||||||
premium->statusTextValue() | rpl::map(computeCost)),
|
: tr::lng_premium_summary_button(
|
||||||
|
lt_cost,
|
||||||
|
premium->statusTextValue() | rpl::map(computeCost)),
|
||||||
st::premiumPreviewButtonLabel);
|
st::premiumPreviewButtonLabel);
|
||||||
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
|
|
|
@ -39,10 +39,16 @@ void StartPremiumPayment(
|
||||||
|
|
||||||
[[nodiscard]] QString LookupPremiumRef(PremiumPreview section);
|
[[nodiscard]] QString LookupPremiumRef(PremiumPreview section);
|
||||||
|
|
||||||
|
struct SubscribeButtonArgs final {
|
||||||
|
not_null<Window::SessionController*> controller;
|
||||||
|
not_null<Ui::RpWidget*> parent;
|
||||||
|
Fn<QString()> computeRef;
|
||||||
|
std::optional<rpl::producer<QString>> text;
|
||||||
|
std::optional<QGradientStops> gradientStops;
|
||||||
|
};
|
||||||
|
|
||||||
[[nodiscard]] not_null<Ui::GradientButton*> CreateSubscribeButton(
|
[[nodiscard]] not_null<Ui::GradientButton*> CreateSubscribeButton(
|
||||||
not_null<Window::SessionController*> controller,
|
SubscribeButtonArgs &&args);
|
||||||
not_null<Ui::RpWidget*> parent,
|
|
||||||
Fn<QString()> computeRef);
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
Loading…
Add table
Reference in a new issue