diff --git a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp index bce9e702b..6304cba74 100644 --- a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp +++ b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp @@ -56,15 +56,18 @@ void CreateGiveawayBox( not_null box, not_null controller, not_null peer) { + box->setWidth(st::boxWideWidth); + + const auto bar = box->verticalLayout()->add( + object_ptr( + box, + st::giveawayGiftCodeCover, + nullptr, + tr::lng_giveaway_new_title(), + tr::lng_giveaway_new_about(Ui::Text::RichLangValue), + true)); { - const auto bar = box->verticalLayout()->add( - object_ptr( - box, - st::giveawayGiftCodeCover, - nullptr, - tr::lng_giveaway_new_title(), - tr::lng_giveaway_new_about(Ui::Text::RichLangValue), - true)); + bar->setPaused(true); bar->setMaximumHeight(st::giveawayGiftCodeTopHeight); bar->setMinimumHeight(st::infoLayerTopBarHeight); bar->resize(bar->width(), bar->maximumHeight()); @@ -109,10 +112,33 @@ void CreateGiveawayBox( const auto state = box->lifetime().make_state(peer); const auto typeGroup = std::make_shared(); - box->setWidth(st::boxWideWidth); + const auto loading = box->addRow( + object_ptr>( + box, + object_ptr(box))); + { + loading->toggle(true, anim::type::instant); + const auto container = loading->entity(); + Settings::AddSkip(container); + Settings::AddSkip(container); + container->add( + object_ptr>( + box, + object_ptr( + box, + tr::lng_contacts_loading(), + st::giveawayLoadingLabel))); + Settings::AddSkip(container); + Settings::AddSkip(container); + } + const auto contentWrap = box->verticalLayout()->add( + object_ptr>( + box, + object_ptr(box))); + contentWrap->toggle(false, anim::type::instant); { - const auto row = box->verticalLayout()->add( + const auto row = contentWrap->entity()->add( object_ptr( box, GiveawayType::Random, @@ -123,7 +149,7 @@ void CreateGiveawayBox( }); } { - const auto row = box->verticalLayout()->add( + const auto row = contentWrap->entity()->add( object_ptr( box, GiveawayType::SpecificUsers, @@ -170,13 +196,13 @@ void CreateGiveawayBox( }); } - Settings::AddSkip(box->verticalLayout()); - Settings::AddDivider(box->verticalLayout()); - Settings::AddSkip(box->verticalLayout()); + Settings::AddSkip(contentWrap->entity()); + Settings::AddDivider(contentWrap->entity()); + Settings::AddSkip(contentWrap->entity()); - const auto randomWrap = box->verticalLayout()->add( + const auto randomWrap = contentWrap->entity()->add( object_ptr>( - box, + contentWrap, object_ptr(box))); state->typeValue.value( ) | rpl::start_with_next([=](GiveawayType type) { @@ -186,9 +212,6 @@ void CreateGiveawayBox( const auto sliderContainer = randomWrap->entity()->add( object_ptr(randomWrap)); const auto fillSliderContainer = [=] { - if (sliderContainer->count()) { - return; - } const auto availablePresets = state->apiOptions.availablePresets(); if (availablePresets.empty()) { return; @@ -465,71 +488,56 @@ void CreateGiveawayBox( } const auto durationGroup = std::make_shared(0); + const auto listOptions = contentWrap->entity()->add( + object_ptr(box)); + const auto rebuildListOptions = [=](int amountUsers) { + while (listOptions->count()) { + delete listOptions->widgetAt(0); + } + Settings::AddSubsectionTitle( + listOptions, + tr::lng_giveaway_duration_title( + lt_count, + rpl::single(amountUsers) | tr::to_count())); + Ui::Premium::AddGiftOptions( + listOptions, + durationGroup, + state->apiOptions.options(amountUsers), + st::giveawayGiftCodeGiftOption, + true); + + auto terms = object_ptr( + listOptions, + tr::lng_premium_gift_terms( + lt_link, + tr::lng_premium_gift_terms_link( + ) | rpl::map([](const QString &t) { + return Ui::Text::Link(t, 1); + }), + Ui::Text::WithEntities), + st::boxDividerLabel); + terms->setLink(1, std::make_shared([=] { + box->closeBox(); + Settings::ShowPremium(&peer->session(), QString()); + })); + listOptions->add(object_ptr( + listOptions, + std::move(terms), + st::settingsDividerLabelPadding)); + + box->verticalLayout()->resizeToWidth(box->width()); + }; { - const auto listOptions = box->verticalLayout()->add( - object_ptr(box)); - const auto rebuildListOptions = [=](int amountUsers) { - fillSliderContainer(); - while (listOptions->count()) { - delete listOptions->widgetAt(0); - } - Settings::AddSubsectionTitle( - listOptions, - tr::lng_giveaway_duration_title( - lt_count, - rpl::single(amountUsers) | tr::to_count())); - Ui::Premium::AddGiftOptions( - listOptions, - durationGroup, - state->apiOptions.options(amountUsers), - st::giveawayGiftCodeGiftOption, - true); - - auto terms = object_ptr( - listOptions, - tr::lng_premium_gift_terms( - lt_link, - tr::lng_premium_gift_terms_link( - ) | rpl::map([](const QString &t) { - return Ui::Text::Link(t, 1); - }), - Ui::Text::WithEntities), - st::boxDividerLabel); - terms->setLink(1, std::make_shared([=] { - box->closeBox(); - Settings::ShowPremium(&peer->session(), QString()); - })); - listOptions->add(object_ptr( - listOptions, - std::move(terms), - st::settingsDividerLabelPadding)); - - box->verticalLayout()->resizeToWidth(box->width()); - }; rpl::combine( state->sliderValue.value(), state->typeValue.value() ) | rpl::start_with_next([=](int users, GiveawayType type) { typeGroup->setValue(type); - const auto rebuild = [=] { - rebuildListOptions((type == GiveawayType::SpecificUsers) - ? state->selectedToAward.size() - : users); - }; - if (!listOptions->count()) { - state->lifetimeApi = state->apiOptions.request( - ) | rpl::start_with_error_done([=](const QString &error) { - }, rebuild); - } else { - rebuild(); - } + rebuildListOptions((type == GiveawayType::SpecificUsers) + ? state->selectedToAward.size() + : users); }, box->lifetime()); - state->lifetimeApi = state->apiOptions.request( - ) | rpl::start_with_error_done([=](const QString &error) { - }, [=] { - rebuildListOptions(1); - }); } { // TODO mini-icon. @@ -603,4 +611,21 @@ void CreateGiveawayBox( box->addButton(std::move(button)); } state->typeValue.force_assign(GiveawayType::Random); + + box->setShowFinishedCallback([=] { + if (!loading->toggled()) { + return; + } + bar->setPaused(false); + state->lifetimeApi = state->apiOptions.request( + ) | rpl::start_with_error_done([=](const QString &error) { + }, [=] { + state->lifetimeApi.destroy(); + loading->toggle(false, anim::type::instant); + fillSliderContainer(); + rebuildListOptions(1); + contentWrap->toggle(true, anim::type::instant); + contentWrap->resizeToWidth(box->width()); + }); + }); } diff --git a/Telegram/SourceFiles/ui/effects/premium.style b/Telegram/SourceFiles/ui/effects/premium.style index 522661517..9d8736fde 100644 --- a/Telegram/SourceFiles/ui/effects/premium.style +++ b/Telegram/SourceFiles/ui/effects/premium.style @@ -277,6 +277,8 @@ boostReplaceIconOutline: 2px; boostReplaceIconAdd: point(4px, 2px); boostReplaceArrow: icon{{ "mediaview/next", windowSubTextFg }}; +giveawayLoadingLabel: FlatLabel(membersAbout) { +} giveawayGiftCodeTopHeight: 195px; giveawayGiftCodeLink: FlatLabel(defaultFlatLabel) { margin: margins(10px, 12px, 10px, 8px);