Show "Unlock emoji" button for premium sets.

This commit is contained in:
John Preston 2022-07-18 17:15:27 +03:00
parent bb7249f280
commit bf286cf175
4 changed files with 70 additions and 35 deletions

View File

@ -1159,31 +1159,6 @@ void ReactionPreview::paintEffect(QPainter &p) {
return CreateGradientButton(parent, Ui::Premium::ButtonGradientStops());
}
[[nodiscard]] object_ptr<Ui::GradientButton> CreateUnlockButton(
QWidget *parent,
rpl::producer<QString> text) {
auto result = CreatePremiumButton(parent);
const auto &st = st::premiumPreviewBox.button;
result->resize(result->width(), st.height);
const auto label = Ui::CreateChild<Ui::FlatLabel>(
result.data(),
std::move(text),
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());
return result;
}
[[nodiscard]] object_ptr<Ui::RpWidget> CreateSwitch(
not_null<Ui::RpWidget*> parent,
not_null<rpl::variable<PremiumPreview>*> selected) {
@ -1793,3 +1768,28 @@ void DoubledLimitsPreviewBox(
});
Ui::Premium::ShowListBox(box, std::move(entries));
}
object_ptr<Ui::GradientButton> CreateUnlockButton(
QWidget *parent,
rpl::producer<QString> text) {
auto result = CreatePremiumButton(parent);
const auto &st = st::premiumPreviewBox.button;
result->resize(result->width(), st.height);
const auto label = Ui::CreateChild<Ui::FlatLabel>(
result.data(),
std::move(text),
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());
return result;
}

View File

@ -7,10 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/object_ptr.h"
class DocumentData;
namespace Ui {
class GenericBox;
class GradientButton;
} // namespace Ui
namespace Window {
@ -60,3 +63,7 @@ void ShowPremiumPreviewToBuy(
Fn<void()> hiddenCallback);
void PremiumUnavailableBox(not_null<Ui::GenericBox*> box);
[[nodiscard]] object_ptr<Ui::GradientButton> CreateUnlockButton(
QWidget *parent,
rpl::producer<QString> text);

View File

@ -15,12 +15,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "menu/menu_send.h"
#include "lang/lang_keys.h"
#include "ui/boxes/confirm_box.h"
#include "boxes/premium_preview_box.h"
#include "core/application.h"
#include "mtproto/sender.h"
#include "storage/storage_account.h"
#include "dialogs/ui/dialogs_layout.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/scroll_area.h"
#include "ui/widgets/gradient_round_button.h"
#include "ui/image/image.h"
#include "ui/image/image_location_factory.h"
#include "ui/text/text_utilities.h"
@ -35,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/clip/media_clip_reader.h"
#include "window/window_session_controller.h"
#include "window/window_controller.h"
#include "settings/settings_premium.h"
#include "base/unixtime.h"
#include "main/main_session.h"
#include "apiwrap.h"
@ -46,6 +49,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_chat_helpers.h"
#include "styles/style_info.h"
#include "styles/style_menu_icons.h"
#include "styles/style_premium.h"
#include <QtWidgets/QApplication>
#include <QtGui/QClipboard>
@ -113,9 +117,10 @@ public:
not_null<Window::SessionController*> controller,
const StickerSetIdentifier &set);
bool loaded() const;
bool notInstalled() const;
bool official() const;
[[nodiscard]] bool loaded() const;
[[nodiscard]] bool notInstalled() const;
[[nodiscard]] bool premiumEmojiSet() const;
[[nodiscard]] bool official() const;
[[nodiscard]] rpl::producer<TextWithEntities> title() const;
[[nodiscard]] QString shortName() const;
[[nodiscard]] bool isEmojiSet() const;
@ -379,13 +384,29 @@ void StickerSetBox::updateButtons() {
: tr::lng_stickers_copied(tr::now)));
};
if (_inner->notInstalled()) {
auto addText = (type == Data::StickersType::Emoji)
? tr::lng_stickers_add_emoji()
: (type == Data::StickersType::Masks)
? tr::lng_stickers_add_masks()
: tr::lng_stickers_add_pack();
addButton(std::move(addText), [=] { addStickers(); });
addButton(tr::lng_cancel(), [=] { closeBox(); });
if (!_controller->session().premium()
&& _controller->session().premiumPossible()
&& _inner->premiumEmojiSet()) {
setStyle(st::premiumPreviewBox);
auto button = CreateUnlockButton(
this,
tr::lng_premium_unlock_emoji());
button->resizeToWidth(st::boxWideWidth
- st::premiumPreviewBox.buttonPadding.left()
- st::premiumPreviewBox.buttonPadding.left());
button->setClickedCallback([=] {
Settings::ShowPremium(_controller, u"animated_emoji"_q);
});
addButton(std::move(button));
} else {
auto addText = (type == Data::StickersType::Emoji)
? tr::lng_stickers_add_emoji()
: (type == Data::StickersType::Masks)
? tr::lng_stickers_add_masks()
: tr::lng_stickers_add_pack();
addButton(std::move(addText), [=] { addStickers(); });
addButton(tr::lng_cancel(), [=] { closeBox(); });
}
if (!_inner->shortName().isEmpty()) {
const auto top = addTopButton(st::infoTopBarMenu);
@ -1119,6 +1140,12 @@ bool StickerSetBox::Inner::loaded() const {
return _loaded && !_pack.isEmpty();
}
bool StickerSetBox::Inner::premiumEmojiSet() const {
return (_setFlags & SetFlag::Emoji)
&& !_pack.empty()
&& _pack.front()->isPremiumEmoji();
}
bool StickerSetBox::Inner::notInstalled() const {
if (!_loaded) {
return false;

View File

@ -73,6 +73,7 @@ using Order = std::vector<QString>;
u"no_ads"_q,
u"unique_reactions"_q,
u"premium_stickers"_q,
u"animated_emoji"_q,
u"advanced_chat_management"_q,
u"profile_badge"_q,
u"animated_userpics"_q,