Fixed order of premium feature previews.
This commit is contained in:
		
							parent
							
								
									8296d72923
								
							
						
					
					
						commit
						cf4dfa55da
					
				
					 6 changed files with 67 additions and 20 deletions
				
			
		|  | @ -52,7 +52,6 @@ namespace { | ||||||
| constexpr auto kPremiumShift = 21. / 240; | constexpr auto kPremiumShift = 21. / 240; | ||||||
| constexpr auto kReactionsPerRow = 5; | constexpr auto kReactionsPerRow = 5; | ||||||
| constexpr auto kDisabledOpacity = 0.5; | constexpr auto kDisabledOpacity = 0.5; | ||||||
| constexpr auto kPreviewsCount = int(PremiumPreview::kCount); |  | ||||||
| constexpr auto kToggleStickerTimeout = 2 * crl::time(1000); | constexpr auto kToggleStickerTimeout = 2 * crl::time(1000); | ||||||
| constexpr auto kStarOpacityOff = 0.1; | constexpr auto kStarOpacityOff = 0.1; | ||||||
| constexpr auto kStarOpacityOn = 1.; | constexpr auto kStarOpacityOn = 1.; | ||||||
|  | @ -744,19 +743,21 @@ struct VideoPreviewDocument { | ||||||
| 
 | 
 | ||||||
| [[nodiscard]] object_ptr<Ui::RpWidget> CreateSwitch( | [[nodiscard]] object_ptr<Ui::RpWidget> CreateSwitch( | ||||||
| 		not_null<Ui::RpWidget*> parent, | 		not_null<Ui::RpWidget*> parent, | ||||||
| 		not_null<rpl::variable<PremiumPreview>*> selected) { | 		not_null<rpl::variable<PremiumPreview>*> selected, | ||||||
|  | 		std::vector<PremiumPreview> order) { | ||||||
| 	const auto padding = st::premiumDotPadding; | 	const auto padding = st::premiumDotPadding; | ||||||
| 	const auto width = padding.left() + st::premiumDot + padding.right(); | 	const auto width = padding.left() + st::premiumDot + padding.right(); | ||||||
| 	const auto height = padding.top() + st::premiumDot + padding.bottom(); | 	const auto height = padding.top() + st::premiumDot + padding.bottom(); | ||||||
| 	const auto stops = Ui::Premium::ButtonGradientStops(); | 	const auto stops = Ui::Premium::ButtonGradientStops(); | ||||||
| 	auto result = object_ptr<Ui::FixedHeightWidget>(parent.get(), height); | 	auto result = object_ptr<Ui::FixedHeightWidget>(parent.get(), height); | ||||||
| 	const auto raw = result.data(); | 	const auto raw = result.data(); | ||||||
| 	for (auto i = 0; i != kPreviewsCount; ++i) { | 	const auto count = order.size(); | ||||||
| 		const auto section = PremiumPreview(i); | 	for (auto i = 0; i != count; ++i) { | ||||||
|  | 		const auto section = order[i]; | ||||||
| 		const auto button = Ui::CreateChild<Ui::AbstractButton>(raw); | 		const auto button = Ui::CreateChild<Ui::AbstractButton>(raw); | ||||||
| 		parent->widthValue( | 		parent->widthValue( | ||||||
| 		) | rpl::start_with_next([=](int outer) { | 		) | rpl::start_with_next([=](int outer) { | ||||||
| 			const auto full = width * kPreviewsCount; | 			const auto full = width * count; | ||||||
| 			const auto left = (outer - full) / 2 + (i * width); | 			const auto left = (outer - full) / 2 + (i * width); | ||||||
| 			button->setGeometry(left, 0, width, height); | 			button->setGeometry(left, 0, width, height); | ||||||
| 		}, button->lifetime()); | 		}, button->lifetime()); | ||||||
|  | @ -770,7 +771,7 @@ struct VideoPreviewDocument { | ||||||
| 			p.setBrush((selected->current() == section) | 			p.setBrush((selected->current() == section) | ||||||
| 				? anim::gradient_color_at( | 				? anim::gradient_color_at( | ||||||
| 					stops, | 					stops, | ||||||
| 					float64(i) / (kPreviewsCount - 1)) | 					float64(i) / (count - 1)) | ||||||
| 				: st::windowBgRipple->c); | 				: st::windowBgRipple->c); | ||||||
| 			p.setPen(Qt::NoPen); | 			p.setPen(Qt::NoPen); | ||||||
| 			p.drawEllipse( | 			p.drawEllipse( | ||||||
|  | @ -815,15 +816,23 @@ void PreviewBox( | ||||||
| 		Fn<void()> preload; | 		Fn<void()> preload; | ||||||
| 		std::vector<Hiding> hiding; | 		std::vector<Hiding> hiding; | ||||||
| 		rpl::variable<PremiumPreview> selected; | 		rpl::variable<PremiumPreview> selected; | ||||||
|  | 		std::vector<PremiumPreview> order; | ||||||
| 	}; | 	}; | ||||||
| 	const auto state = outer->lifetime().make_state<State>(); | 	const auto state = outer->lifetime().make_state<State>(); | ||||||
| 	state->selected = descriptor.section; | 	state->selected = descriptor.section; | ||||||
|  | 	state->order = Settings::PremiumPreviewOrder(&controller->session()); | ||||||
|  | 
 | ||||||
|  | 	const auto index = [=](PremiumPreview section) { | ||||||
|  | 		const auto it = ranges::find(state->order, section); | ||||||
|  | 		return (it == end(state->order)) | ||||||
|  | 			? 0 | ||||||
|  | 			: std::distance(begin(state->order), it); | ||||||
|  | 	}; | ||||||
| 
 | 
 | ||||||
| 	const auto move = [=](int delta) { | 	const auto move = [=](int delta) { | ||||||
| 		using Type = PremiumPreview; | 		const auto count = int(state->order.size()); | ||||||
| 		const auto count = int(Type::kCount); |  | ||||||
| 		const auto now = state->selected.current(); | 		const auto now = state->selected.current(); | ||||||
| 		state->selected = Type((int(now) + count + delta) % count); | 		state->selected = state->order[(index(now) + count + delta) % count]; | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	const auto buttonsParent = box->verticalLayout().get(); | 	const auto buttonsParent = box->verticalLayout().get(); | ||||||
|  | @ -912,7 +921,7 @@ void PreviewBox( | ||||||
| 			} | 			} | ||||||
| 		}; | 		}; | ||||||
| 		animationCallback(); | 		animationCallback(); | ||||||
| 		const auto toLeft = int(now) > int(was); | 		const auto toLeft = index(now) > index(was); | ||||||
| 		auto start = state->content->x() + (toLeft ? single : -single); | 		auto start = state->content->x() + (toLeft ? single : -single); | ||||||
| 		for (const auto &hiding : state->hiding) { | 		for (const auto &hiding : state->hiding) { | ||||||
| 			const auto left = hiding.widget->x(); | 			const auto left = hiding.widget->x(); | ||||||
|  | @ -955,14 +964,10 @@ void PreviewBox( | ||||||
| 	}, outer->lifetime()); | 	}, outer->lifetime()); | ||||||
| 
 | 
 | ||||||
| 	auto title = state->selected.value( | 	auto title = state->selected.value( | ||||||
| 	) | rpl::map([=](PremiumPreview section) { | 	) | rpl::map(SectionTitle) | rpl::flatten_latest(); | ||||||
| 		return SectionTitle(section); |  | ||||||
| 	}) | rpl::flatten_latest(); |  | ||||||
| 
 | 
 | ||||||
| 	auto text = state->selected.value( | 	auto text = state->selected.value( | ||||||
| 	) | rpl::map([=](PremiumPreview section) { | 	) | rpl::map(SectionAbout) | rpl::flatten_latest(); | ||||||
| 		return SectionAbout(section); |  | ||||||
| 	}) | rpl::flatten_latest(); |  | ||||||
| 
 | 
 | ||||||
| 	const auto padding = st::premiumPreviewAboutPadding; | 	const auto padding = st::premiumPreviewAboutPadding; | ||||||
| 	const auto available = size.width() - padding.left() - padding.right(); | 	const auto available = size.width() - padding.left() - padding.right(); | ||||||
|  | @ -985,7 +990,7 @@ void PreviewBox( | ||||||
| 		object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(box, std::move(textLabel)), | 		object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(box, std::move(textLabel)), | ||||||
| 		padding); | 		padding); | ||||||
| 	box->addRow( | 	box->addRow( | ||||||
| 		CreateSwitch(box->verticalLayout(), &state->selected), | 		CreateSwitch(box->verticalLayout(), &state->selected, state->order), | ||||||
| 		st::premiumDotsMargin); | 		st::premiumDotsMargin); | ||||||
| 	const auto showFinished = [=] { | 	const auto showFinished = [=] { | ||||||
| 		state->showFinished = true; | 		state->showFinished = true; | ||||||
|  |  | ||||||
|  | @ -3910,7 +3910,8 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { | ||||||
| 		return result; | 		return result; | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	auto prepareAttachMenuBotAllowed = [this](const MTPDmessageActionAttachMenuBotAllowed &action) { | 	auto prepareAttachMenuBotAllowed = []( | ||||||
|  | 			const MTPDmessageActionAttachMenuBotAllowed &action) { | ||||||
| 		return PreparedServiceText{ { | 		return PreparedServiceText{ { | ||||||
| 			tr::lng_action_attach_menu_bot_allowed(tr::now) | 			tr::lng_action_attach_menu_bot_allowed(tr::now) | ||||||
| 		} }; | 		} }; | ||||||
|  |  | ||||||
|  | @ -1840,4 +1840,41 @@ not_null<Ui::GradientButton*> CreateSubscribeButton( | ||||||
| 	return result; | 	return result; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | [[nodiscard]] std::vector<PremiumPreview> PremiumPreviewOrder( | ||||||
|  | 		not_null<Main::Session*> session) { | ||||||
|  | 	const auto mtpOrder = session->account().appConfig().get<Order>( | ||||||
|  | 		"premium_promo_order", | ||||||
|  | 		FallbackOrder()); | ||||||
|  | 	return ranges::views::all( | ||||||
|  | 		mtpOrder | ||||||
|  | 	) | ranges::views::transform([](const QString &s) { | ||||||
|  | 		if (s == u"more_upload"_q) { | ||||||
|  | 			return PremiumPreview::MoreUpload; | ||||||
|  | 		} else if (s == u"faster_download"_q) { | ||||||
|  | 			return PremiumPreview::FasterDownload; | ||||||
|  | 		} else if (s == u"voice_to_text"_q) { | ||||||
|  | 			return PremiumPreview::VoiceToText; | ||||||
|  | 		} else if (s == u"no_ads"_q) { | ||||||
|  | 			return PremiumPreview::NoAds; | ||||||
|  | 		} else if (s == u"emoji_status"_q) { | ||||||
|  | 			return PremiumPreview::EmojiStatus; | ||||||
|  | 		} else if (s == u"infinite_reactions"_q) { | ||||||
|  | 			return PremiumPreview::InfiniteReactions; | ||||||
|  | 		} else if (s == u"premium_stickers"_q) { | ||||||
|  | 			return PremiumPreview::Stickers; | ||||||
|  | 		} else if (s == u"animated_emoji"_q) { | ||||||
|  | 			return PremiumPreview::AnimatedEmoji; | ||||||
|  | 		} else if (s == u"advanced_chat_management"_q) { | ||||||
|  | 			return PremiumPreview::AdvancedChatManagement; | ||||||
|  | 		} else if (s == u"profile_badge"_q) { | ||||||
|  | 			return PremiumPreview::ProfileBadge; | ||||||
|  | 		} else if (s == u"animated_userpics"_q) { | ||||||
|  | 			return PremiumPreview::AnimatedUserpics; | ||||||
|  | 		} | ||||||
|  | 		return PremiumPreview::kCount; | ||||||
|  | 	}) | ranges::views::filter([](PremiumPreview type) { | ||||||
|  | 		return (type != PremiumPreview::kCount); | ||||||
|  | 	}) | ranges::to_vector; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } // namespace Settings
 | } // namespace Settings
 | ||||||
|  |  | ||||||
|  | @ -59,6 +59,9 @@ struct SubscribeButtonArgs final { | ||||||
| [[nodiscard]] not_null<Ui::GradientButton*> CreateSubscribeButton( | [[nodiscard]] not_null<Ui::GradientButton*> CreateSubscribeButton( | ||||||
| 	SubscribeButtonArgs &&args); | 	SubscribeButtonArgs &&args); | ||||||
| 
 | 
 | ||||||
|  | [[nodiscard]] std::vector<PremiumPreview> PremiumPreviewOrder( | ||||||
|  | 	not_null<::Main::Session*> session); | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| } // namespace Settings
 | } // namespace Settings
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -921,7 +921,8 @@ QGradientStops FullHeightGradientStops() { | ||||||
| 		{ 0.0, st::premiumIconBg1->c }, | 		{ 0.0, st::premiumIconBg1->c }, | ||||||
| 		{ .28, st::premiumIconBg2->c }, | 		{ .28, st::premiumIconBg2->c }, | ||||||
| 		{ .55, st::premiumButtonBg2->c }, | 		{ .55, st::premiumButtonBg2->c }, | ||||||
| 		{ 1.0, st::premiumButtonBg1->c }, | 		{ .75, st::premiumButtonBg1->c }, | ||||||
|  | 		{ 1.0, st::premiumIconBg3->c }, | ||||||
| 	}; | 	}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1 +1 @@ | ||||||
| Subproject commit 9f5ddf3d8aaa95e0c32c187f7e8b6c3239953991 | Subproject commit fbdc6ed5ac791890d87ca7f22b668ceca47d7684 | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 23rd
						23rd