Redesign gift visibility toggle.

This commit is contained in:
John Preston 2024-12-11 13:51:27 +04:00
parent e92270a9ab
commit c6cf8be8d4
4 changed files with 131 additions and 61 deletions

View file

@ -3192,11 +3192,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_gift_visible_hint" = "This gift is visible to visitors of your page.";
"lng_gift_availability" = "Availability";
"lng_gift_from_hidden" = "Hidden User";
"lng_gift_visibility" = "Visibility";
"lng_gift_visibility_shown" = "Visible on your page";
"lng_gift_visibility_hidden" = "Not visible on your page";
"lng_gift_visibility_show" = "show";
"lng_gift_visibility_hide" = "hide";
"lng_gift_availability_left#one" = "{count} of {amount} left";
"lng_gift_availability_left#other" = "{count} of {amount} left";
"lng_gift_availability_none" = "None of {amount} left";
"lng_gift_display_on_page" = "Display on my Page";
"lng_gift_display_on_page_hide" = "Hide from my Page";
"lng_gift_convert_to_stars#one" = "Convert to {count} Star";
"lng_gift_convert_to_stars#other" = "Convert to {count} Stars";
"lng_gift_convert_sure_title" = "Convert Gift to Stars";

View file

@ -237,7 +237,7 @@ void AddTableRow(
valueMargins);
}
object_ptr<Ui::RpWidget> MakeStarGiftStarsValue(
[[nodiscard]] object_ptr<Ui::RpWidget> MakeStarGiftStarsValue(
not_null<QWidget*> parent,
not_null<Window::SessionNavigation*> controller,
const Data::CreditsHistoryEntry &entry,
@ -302,6 +302,62 @@ object_ptr<Ui::RpWidget> MakeStarGiftStarsValue(
return result;
}
[[nodiscard]] object_ptr<Ui::RpWidget> MakeVisibilityTableValue(
not_null<QWidget*> parent,
not_null<Window::SessionNavigation*> controller,
bool savedToProfile,
Fn<void(bool)> toggleVisibility) {
auto result = object_ptr<Ui::RpWidget>(parent);
const auto raw = result.data();
const auto label = Ui::CreateChild<Ui::FlatLabel>(
raw,
(savedToProfile
? tr::lng_gift_visibility_shown()
: tr::lng_gift_visibility_hidden()),
st::giveawayGiftCodeValue,
st::defaultPopupMenu);
const auto toggle = Ui::CreateChild<Ui::RoundButton>(
raw,
(savedToProfile
? tr::lng_gift_visibility_hide()
: tr::lng_gift_visibility_show()),
st::starGiftSmallButton);
toggle->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
toggle->setClickedCallback([=] {
toggleVisibility(!savedToProfile);
});
rpl::combine(
raw->widthValue(),
toggle->widthValue()
) | rpl::start_with_next([=](int width, int toggleWidth) {
const auto toggleSkip = toggleWidth
? (st::normalFont->spacew + toggleWidth)
: 0;
label->resizeToNaturalWidth(width - toggleSkip);
label->moveToLeft(0, 0, width);
if (toggle) {
toggle->moveToLeft(
label->width() + st::normalFont->spacew,
(st::giveawayGiftCodeValue.style.font->ascent
- st::starGiftSmallButton.style.font->ascent),
width);
}
}, label->lifetime());
label->heightValue() | rpl::start_with_next([=](int height) {
raw->resize(
raw->width(),
height + st::giveawayGiftCodeValueMargin.bottom());
}, raw->lifetime());
label->setAttribute(Qt::WA_TransparentForMouseEvents);
return result;
}
not_null<Ui::FlatLabel*> AddTableRow(
not_null<Ui::TableLayout*> table,
rpl::producer<QString> label,
@ -1035,6 +1091,7 @@ void AddStarGiftTable(
not_null<Window::SessionNavigation*> controller,
not_null<Ui::VerticalLayout*> container,
const Data::CreditsHistoryEntry &entry,
Fn<void(bool)> toggleVisibility,
Fn<void()> convertToStars) {
auto table = container->add(
object_ptr<Ui::TableLayout>(
@ -1072,9 +1129,15 @@ void AddStarGiftTable(
rpl::single(Ui::Text::WithEntities(
langDateTime(entry.lastSaleDate))));
}
if (!entry.date.isNull()) {
AddTableRow(
table,
tr::lng_gift_link_label_date(),
rpl::single(Ui::Text::WithEntities(langDateTime(entry.date))));
}
const auto marginWithButton = st::giveawayGiftCodeValueMargin
- QMargins(0, 0, 0, st::giveawayGiftCodeValueMargin.bottom());
{
const auto margin = st::giveawayGiftCodeValueMargin
- QMargins(0, 0, 0, st::giveawayGiftCodeValueMargin.bottom());
AddTableRow(
table,
tr::lng_gift_link_label_value(),
@ -1083,13 +1146,18 @@ void AddStarGiftTable(
controller,
entry,
std::move(convertToStars)),
margin);
marginWithButton);
}
if (!entry.date.isNull()) {
if (toggleVisibility) {
AddTableRow(
table,
tr::lng_gift_link_label_date(),
rpl::single(Ui::Text::WithEntities(langDateTime(entry.date))));
tr::lng_gift_visibility(),
MakeVisibilityTableValue(
table,
controller,
entry.savedToProfile,
std::move(toggleVisibility)),
marginWithButton);
}
if (entry.limitedCount > 0) {
auto amount = rpl::single(TextWithEntities{

View file

@ -58,6 +58,7 @@ void AddStarGiftTable(
not_null<Window::SessionNavigation*> controller,
not_null<Ui::VerticalLayout*> container,
const Data::CreditsHistoryEntry &entry,
Fn<void(bool)> toggleVisibility,
Fn<void()> convertToStars);
void AddCreditsHistoryEntryTable(
not_null<Window::SessionNavigation*> controller,

View file

@ -1244,6 +1244,49 @@ void ReceiptCreditsBox(
const auto state = box->lifetime().make_state<State>();
const auto weakWindow = base::make_weak(controller);
const auto toggleVisibility = [=, weak = Ui::MakeWeak(box)](bool save) {
const auto window = weakWindow.get();
const auto showSection = !e.fromGiftsList;
const auto itemId = MsgId(e.bareMsgId);
if (!window) {
return;
}
const auto done = [=](bool ok) {
if (const auto window = weakWindow.get()) {
if (ok) {
using GiftAction = Data::GiftUpdate::Action;
window->session().data().notifyGiftUpdate({
.itemId = FullMsgId(
starGiftSender->id,
itemId),
.action = (save
? GiftAction::Save
: GiftAction::Unsave),
});
if (showSection) {
window->showSection(
std::make_shared<Info::Memento>(
window->session().user(),
Info::Section::Type::PeerGifts));
}
}
}
if (const auto strong = weak.data()) {
if (ok) {
strong->closeBox();
} else {
state->confirmButtonBusy = false;
}
}
};
ToggleStarGiftSaved(
window,
starGiftSender,
itemId,
save,
done);
};
if (isStarGift && e.id.isEmpty()) {
const auto convert = [=, weak = Ui::MakeWeak(box)] {
const auto stars = e.starsConverted;
@ -1287,11 +1330,13 @@ void ReceiptCreditsBox(
}
});
};
const auto canToggle = canConvert || couldConvert || nonConvertible;
AddStarGiftTable(
controller,
content,
e,
canToggle ? toggleVisibility : Fn<void(bool)>(),
canConvert ? convert : Fn<void()>());
} else {
AddCreditsHistoryEntryTable(controller, content, e);
@ -1339,7 +1384,7 @@ void ReceiptCreditsBox(
Ui::AddSkip(content);
auto label = object_ptr<Ui::FlatLabel>(
box,
(s.cancelledByBot && bot)
((s.cancelledByBot && bot)
? tr::lng_credits_subscription_off_by_bot_about(
lt_bot,
rpl::single(bot->name()))
@ -1349,8 +1394,8 @@ void ReceiptCreditsBox(
? tr::lng_credits_subscription_off_about()
: tr::lng_credits_subscription_on_about(
lt_date,
rpl::single(langDayOfMonthFull(s.until.date()))),
st::creditsBoxAboutDivider);
rpl::single(langDayOfMonthFull(s.until.date())))),
st::creditsBoxAboutDivider);
if (toCancel) {
label->setClickHandlerFilter([=](
const auto &,
@ -1402,54 +1447,9 @@ void ReceiptCreditsBox(
? tr::lng_credits_subscription_off_button()
: toRejoin
? tr::lng_credits_subscription_off_rejoin_button()
: (canConvert || couldConvert || nonConvertible)
? (e.savedToProfile
? tr::lng_gift_display_on_page_hide()
: tr::lng_gift_display_on_page())
: tr::lng_box_ok()));
const auto send = [=, weak = Ui::MakeWeak(box)] {
if (canConvert || couldConvert || nonConvertible) {
const auto save = !e.savedToProfile;
const auto window = weakWindow.get();
const auto showSection = !e.fromGiftsList;
const auto itemId = MsgId(e.bareMsgId);
if (window) {
const auto done = [=](bool ok) {
if (const auto window = weakWindow.get()) {
if (ok) {
using GiftAction = Data::GiftUpdate::Action;
window->session().data().notifyGiftUpdate({
.itemId = FullMsgId(
starGiftSender->id,
itemId),
.action = (save
? GiftAction::Save
: GiftAction::Unsave),
});
if (showSection) {
window->showSection(
std::make_shared<Info::Memento>(
window->session().user(),
Info::Section::Type::PeerGifts));
}
}
}
if (const auto strong = weak.data()) {
if (ok) {
strong->closeBox();
} else {
state->confirmButtonBusy = false;
}
}
};
ToggleStarGiftSaved(
window,
starGiftSender,
itemId,
save,
done);
}
} else if (toRejoin) {
if (toRejoin) {
if (const auto window = weakWindow.get()) {
const auto finish = [=](Payments::CheckoutResult&&) {
ProcessReceivedSubscriptions(weak, session);
@ -1480,9 +1480,7 @@ void ReceiptCreditsBox(
}
};
const auto willBusy = toRejoin
|| (peer
&& (toRenew || canConvert || couldConvert || nonConvertible));
const auto willBusy = toRejoin || (peer && toRenew);
if (willBusy) {
const auto close = Ui::CreateChild<Ui::IconButton>(
content,