mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to provide preloaded credits topup options to list.
This commit is contained in:
parent
e3f4f60e2d
commit
983c949e8c
4 changed files with 89 additions and 30 deletions
|
@ -124,7 +124,8 @@ void GiftCreditsBox(
|
||||||
peer,
|
peer,
|
||||||
0,
|
0,
|
||||||
[=] { gifted(); box->uiShow()->hideLayer(); },
|
[=] { gifted(); box->uiShow()->hideLayer(); },
|
||||||
tr::lng_credits_summary_options_subtitle());
|
tr::lng_credits_summary_options_subtitle(),
|
||||||
|
{});
|
||||||
|
|
||||||
box->setPinnedToBottomContent(
|
box->setPinnedToBottomContent(
|
||||||
object_ptr<Ui::VerticalLayout>(box));
|
object_ptr<Ui::VerticalLayout>(box));
|
||||||
|
|
|
@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_photo_media.h"
|
#include "data/data_photo_media.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
#include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget.
|
||||||
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
||||||
#include "info/statistics/info_statistics_list_controllers.h"
|
#include "info/statistics/info_statistics_list_controllers.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
@ -101,6 +102,13 @@ Credits::Credits(
|
||||||
, _star(Ui::GenerateStars(st::creditsTopupButton.height, 1))
|
, _star(Ui::GenerateStars(st::creditsTopupButton.height, 1))
|
||||||
, _balanceStar(Ui::GenerateStars(st::creditsBalanceStarHeight, 1)) {
|
, _balanceStar(Ui::GenerateStars(st::creditsBalanceStarHeight, 1)) {
|
||||||
setupContent();
|
setupContent();
|
||||||
|
|
||||||
|
_controller->session().premiumPossibleValue(
|
||||||
|
) | rpl::start_with_next([=](bool premiumPossible) {
|
||||||
|
if (!premiumPossible) {
|
||||||
|
_showBack.fire({});
|
||||||
|
}
|
||||||
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<QString> Credits::title() {
|
rpl::producer<QString> Credits::title() {
|
||||||
|
@ -387,34 +395,76 @@ void Credits::setupContent() {
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
|
|
||||||
|
struct State final {
|
||||||
|
rpl::variable<bool> confirmButtonBusy = false;
|
||||||
|
std::optional<Api::CreditsTopupOptions> api;
|
||||||
|
};
|
||||||
|
const auto state = content->lifetime().make_state<State>();
|
||||||
|
|
||||||
const auto button = content->add(
|
const auto button = content->add(
|
||||||
object_ptr<Ui::RoundButton>(
|
object_ptr<Ui::RoundButton>(
|
||||||
content,
|
content,
|
||||||
tr::lng_credits_buy_button(),
|
rpl::conditional(
|
||||||
|
state->confirmButtonBusy.value(),
|
||||||
|
rpl::single(QString()),
|
||||||
|
tr::lng_credits_buy_button()),
|
||||||
st::creditsSettingsBigBalanceButton),
|
st::creditsSettingsBigBalanceButton),
|
||||||
st::boxRowPadding);
|
st::boxRowPadding);
|
||||||
button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
|
button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
|
||||||
button->setClickedCallback([=, show = _controller->uiShow()] {
|
const auto show = _controller->uiShow();
|
||||||
show->show(Box([=](not_null<Ui::GenericBox*> box) {
|
const auto optionsBox = [=](not_null<Ui::GenericBox*> box) {
|
||||||
box->setStyle(st::giveawayGiftCodeBox);
|
box->setStyle(st::giveawayGiftCodeBox);
|
||||||
box->setWidth(st::boxWideWidth);
|
box->setWidth(st::boxWideWidth);
|
||||||
box->setTitle(tr::lng_credits_summary_options_subtitle());
|
box->setTitle(tr::lng_credits_summary_options_subtitle());
|
||||||
const auto inner = box->verticalLayout();
|
const auto inner = box->verticalLayout();
|
||||||
const auto self = show->session().user();
|
const auto self = show->session().user();
|
||||||
FillCreditOptions(show, inner, self, 0, paid, nullptr);
|
const auto options = state->api
|
||||||
|
? state->api->options()
|
||||||
|
: Data::CreditTopupOptions();
|
||||||
|
FillCreditOptions(show, inner, self, 0, paid, nullptr, options);
|
||||||
|
|
||||||
const auto button = box->addButton(tr::lng_close(), [=] {
|
const auto button = box->addButton(tr::lng_close(), [=] {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
});
|
});
|
||||||
const auto buttonWidth = st::boxWideWidth
|
const auto buttonWidth = st::boxWideWidth
|
||||||
- rect::m::sum::h(st::giveawayGiftCodeBox.buttonPadding);
|
- rect::m::sum::h(st::giveawayGiftCodeBox.buttonPadding);
|
||||||
button->widthValue() | rpl::filter([=] {
|
button->widthValue() | rpl::filter([=] {
|
||||||
return (button->widthNoMargins() != buttonWidth);
|
return (button->widthNoMargins() != buttonWidth);
|
||||||
}) | rpl::start_with_next([=] {
|
}) | rpl::start_with_next([=] {
|
||||||
button->resizeToWidth(buttonWidth);
|
button->resizeToWidth(buttonWidth);
|
||||||
}, button->lifetime());
|
}, button->lifetime());
|
||||||
}));
|
};
|
||||||
|
button->setClickedCallback([=] {
|
||||||
|
if (state->api && !state->api->options().empty()) {
|
||||||
|
state->confirmButtonBusy = false;
|
||||||
|
show->show(Box(optionsBox));
|
||||||
|
} else {
|
||||||
|
state->confirmButtonBusy = true;
|
||||||
|
state->api.emplace(show->session().user());
|
||||||
|
state->api->request(
|
||||||
|
) | rpl::start_with_error_done([=](const QString &error) {
|
||||||
|
state->confirmButtonBusy = false;
|
||||||
|
show->showToast(error);
|
||||||
|
}, [=] {
|
||||||
|
state->confirmButtonBusy = false;
|
||||||
|
show->show(Box(optionsBox));
|
||||||
|
}, content->lifetime());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
{
|
||||||
|
using namespace Info::Statistics;
|
||||||
|
const auto loadingAnimation = InfiniteRadialAnimationWidget(
|
||||||
|
button,
|
||||||
|
button->height() / 2);
|
||||||
|
AddChildToWidgetCenter(button, loadingAnimation);
|
||||||
|
loadingAnimation->showOn(state->confirmButtonBusy.value());
|
||||||
|
}
|
||||||
|
const auto paddings = rect::m::sum::h(st::boxRowPadding);
|
||||||
|
button->widthValue() | rpl::filter([=] {
|
||||||
|
return (button->widthNoMargins() != (content->width() - paddings));
|
||||||
|
}) | rpl::start_with_next([=] {
|
||||||
|
button->resizeToWidth(content->width() - paddings);
|
||||||
|
}, button->lifetime());
|
||||||
|
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
|
|
||||||
|
|
|
@ -399,7 +399,8 @@ void FillCreditOptions(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
int minimumCredits,
|
int minimumCredits,
|
||||||
Fn<void()> paid,
|
Fn<void()> paid,
|
||||||
rpl::producer<QString> subtitle) {
|
rpl::producer<QString> subtitle,
|
||||||
|
std::vector<Data::CreditTopupOption> preloadedTopupOptions) {
|
||||||
const auto options = container->add(
|
const auto options = container->add(
|
||||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
container,
|
container,
|
||||||
|
@ -552,12 +553,16 @@ void FillCreditOptions(
|
||||||
const auto apiCredits = content->lifetime().make_state<ApiOptions>(peer);
|
const auto apiCredits = content->lifetime().make_state<ApiOptions>(peer);
|
||||||
|
|
||||||
if (show->session().premiumPossible()) {
|
if (show->session().premiumPossible()) {
|
||||||
apiCredits->request(
|
if (preloadedTopupOptions.empty()) {
|
||||||
) | rpl::start_with_error_done([=](const QString &error) {
|
apiCredits->request(
|
||||||
show->showToast(error);
|
) | rpl::start_with_error_done([=](const QString &error) {
|
||||||
}, [=] {
|
show->showToast(error);
|
||||||
fill(apiCredits->options());
|
}, [=] {
|
||||||
}, content->lifetime());
|
fill(apiCredits->options());
|
||||||
|
}, content->lifetime());
|
||||||
|
} else {
|
||||||
|
fill(std::move(preloadedTopupOptions));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
show->session().premiumPossibleValue(
|
show->session().premiumPossibleValue(
|
||||||
|
@ -1711,7 +1716,8 @@ void SmallBalanceBox(
|
||||||
show->session().user(),
|
show->session().user(),
|
||||||
credits - show->session().credits().balance(),
|
credits - show->session().credits().balance(),
|
||||||
[=] { show->session().credits().load(true); },
|
[=] { show->session().credits().load(true); },
|
||||||
tr::lng_credits_summary_options_subtitle());
|
tr::lng_credits_summary_options_subtitle(),
|
||||||
|
{});
|
||||||
|
|
||||||
content->setMaximumHeight(st::creditsLowBalancePremiumCoverHeight);
|
content->setMaximumHeight(st::creditsLowBalancePremiumCoverHeight);
|
||||||
content->setMinimumHeight(st::infoLayerTopBarHeight);
|
content->setMinimumHeight(st::infoLayerTopBarHeight);
|
||||||
|
|
|
@ -21,6 +21,7 @@ struct Boost;
|
||||||
struct CreditsHistoryEntry;
|
struct CreditsHistoryEntry;
|
||||||
struct SubscriptionEntry;
|
struct SubscriptionEntry;
|
||||||
struct GiftCode;
|
struct GiftCode;
|
||||||
|
struct CreditTopupOption;
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
||||||
namespace Main {
|
namespace Main {
|
||||||
|
@ -59,7 +60,8 @@ void FillCreditOptions(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
int minCredits,
|
int minCredits,
|
||||||
Fn<void()> paid,
|
Fn<void()> paid,
|
||||||
rpl::producer<QString> subtitle);
|
rpl::producer<QString> subtitle,
|
||||||
|
std::vector<Data::CreditTopupOption> preloadedTopupOptions);
|
||||||
|
|
||||||
[[nodiscard]] not_null<Ui::RpWidget*> AddBalanceWidget(
|
[[nodiscard]] not_null<Ui::RpWidget*> AddBalanceWidget(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
|
|
Loading…
Add table
Reference in a new issue