mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Redesign gift visibility toggle.
This commit is contained in:
parent
e92270a9ab
commit
c6cf8be8d4
4 changed files with 131 additions and 61 deletions
|
@ -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_visible_hint" = "This gift is visible to visitors of your page.";
|
||||||
"lng_gift_availability" = "Availability";
|
"lng_gift_availability" = "Availability";
|
||||||
"lng_gift_from_hidden" = "Hidden User";
|
"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#one" = "{count} of {amount} left";
|
||||||
"lng_gift_availability_left#other" = "{count} of {amount} left";
|
"lng_gift_availability_left#other" = "{count} of {amount} left";
|
||||||
"lng_gift_availability_none" = "None 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#one" = "Convert to {count} Star";
|
||||||
"lng_gift_convert_to_stars#other" = "Convert to {count} Stars";
|
"lng_gift_convert_to_stars#other" = "Convert to {count} Stars";
|
||||||
"lng_gift_convert_sure_title" = "Convert Gift to Stars";
|
"lng_gift_convert_sure_title" = "Convert Gift to Stars";
|
||||||
|
|
|
@ -237,7 +237,7 @@ void AddTableRow(
|
||||||
valueMargins);
|
valueMargins);
|
||||||
}
|
}
|
||||||
|
|
||||||
object_ptr<Ui::RpWidget> MakeStarGiftStarsValue(
|
[[nodiscard]] object_ptr<Ui::RpWidget> MakeStarGiftStarsValue(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
not_null<Window::SessionNavigation*> controller,
|
not_null<Window::SessionNavigation*> controller,
|
||||||
const Data::CreditsHistoryEntry &entry,
|
const Data::CreditsHistoryEntry &entry,
|
||||||
|
@ -302,6 +302,62 @@ object_ptr<Ui::RpWidget> MakeStarGiftStarsValue(
|
||||||
return result;
|
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::FlatLabel*> AddTableRow(
|
||||||
not_null<Ui::TableLayout*> table,
|
not_null<Ui::TableLayout*> table,
|
||||||
rpl::producer<QString> label,
|
rpl::producer<QString> label,
|
||||||
|
@ -1035,6 +1091,7 @@ void AddStarGiftTable(
|
||||||
not_null<Window::SessionNavigation*> controller,
|
not_null<Window::SessionNavigation*> controller,
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
const Data::CreditsHistoryEntry &entry,
|
const Data::CreditsHistoryEntry &entry,
|
||||||
|
Fn<void(bool)> toggleVisibility,
|
||||||
Fn<void()> convertToStars) {
|
Fn<void()> convertToStars) {
|
||||||
auto table = container->add(
|
auto table = container->add(
|
||||||
object_ptr<Ui::TableLayout>(
|
object_ptr<Ui::TableLayout>(
|
||||||
|
@ -1072,9 +1129,15 @@ void AddStarGiftTable(
|
||||||
rpl::single(Ui::Text::WithEntities(
|
rpl::single(Ui::Text::WithEntities(
|
||||||
langDateTime(entry.lastSaleDate))));
|
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(
|
AddTableRow(
|
||||||
table,
|
table,
|
||||||
tr::lng_gift_link_label_value(),
|
tr::lng_gift_link_label_value(),
|
||||||
|
@ -1083,13 +1146,18 @@ void AddStarGiftTable(
|
||||||
controller,
|
controller,
|
||||||
entry,
|
entry,
|
||||||
std::move(convertToStars)),
|
std::move(convertToStars)),
|
||||||
margin);
|
marginWithButton);
|
||||||
}
|
}
|
||||||
if (!entry.date.isNull()) {
|
if (toggleVisibility) {
|
||||||
AddTableRow(
|
AddTableRow(
|
||||||
table,
|
table,
|
||||||
tr::lng_gift_link_label_date(),
|
tr::lng_gift_visibility(),
|
||||||
rpl::single(Ui::Text::WithEntities(langDateTime(entry.date))));
|
MakeVisibilityTableValue(
|
||||||
|
table,
|
||||||
|
controller,
|
||||||
|
entry.savedToProfile,
|
||||||
|
std::move(toggleVisibility)),
|
||||||
|
marginWithButton);
|
||||||
}
|
}
|
||||||
if (entry.limitedCount > 0) {
|
if (entry.limitedCount > 0) {
|
||||||
auto amount = rpl::single(TextWithEntities{
|
auto amount = rpl::single(TextWithEntities{
|
||||||
|
|
|
@ -58,6 +58,7 @@ void AddStarGiftTable(
|
||||||
not_null<Window::SessionNavigation*> controller,
|
not_null<Window::SessionNavigation*> controller,
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
const Data::CreditsHistoryEntry &entry,
|
const Data::CreditsHistoryEntry &entry,
|
||||||
|
Fn<void(bool)> toggleVisibility,
|
||||||
Fn<void()> convertToStars);
|
Fn<void()> convertToStars);
|
||||||
void AddCreditsHistoryEntryTable(
|
void AddCreditsHistoryEntryTable(
|
||||||
not_null<Window::SessionNavigation*> controller,
|
not_null<Window::SessionNavigation*> controller,
|
||||||
|
|
|
@ -1244,6 +1244,49 @@ void ReceiptCreditsBox(
|
||||||
const auto state = box->lifetime().make_state<State>();
|
const auto state = box->lifetime().make_state<State>();
|
||||||
const auto weakWindow = base::make_weak(controller);
|
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()) {
|
if (isStarGift && e.id.isEmpty()) {
|
||||||
const auto convert = [=, weak = Ui::MakeWeak(box)] {
|
const auto convert = [=, weak = Ui::MakeWeak(box)] {
|
||||||
const auto stars = e.starsConverted;
|
const auto stars = e.starsConverted;
|
||||||
|
@ -1287,11 +1330,13 @@ void ReceiptCreditsBox(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const auto canToggle = canConvert || couldConvert || nonConvertible;
|
||||||
|
|
||||||
AddStarGiftTable(
|
AddStarGiftTable(
|
||||||
controller,
|
controller,
|
||||||
content,
|
content,
|
||||||
e,
|
e,
|
||||||
|
canToggle ? toggleVisibility : Fn<void(bool)>(),
|
||||||
canConvert ? convert : Fn<void()>());
|
canConvert ? convert : Fn<void()>());
|
||||||
} else {
|
} else {
|
||||||
AddCreditsHistoryEntryTable(controller, content, e);
|
AddCreditsHistoryEntryTable(controller, content, e);
|
||||||
|
@ -1339,7 +1384,7 @@ void ReceiptCreditsBox(
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
auto label = object_ptr<Ui::FlatLabel>(
|
auto label = object_ptr<Ui::FlatLabel>(
|
||||||
box,
|
box,
|
||||||
(s.cancelledByBot && bot)
|
((s.cancelledByBot && bot)
|
||||||
? tr::lng_credits_subscription_off_by_bot_about(
|
? tr::lng_credits_subscription_off_by_bot_about(
|
||||||
lt_bot,
|
lt_bot,
|
||||||
rpl::single(bot->name()))
|
rpl::single(bot->name()))
|
||||||
|
@ -1349,8 +1394,8 @@ void ReceiptCreditsBox(
|
||||||
? tr::lng_credits_subscription_off_about()
|
? tr::lng_credits_subscription_off_about()
|
||||||
: tr::lng_credits_subscription_on_about(
|
: tr::lng_credits_subscription_on_about(
|
||||||
lt_date,
|
lt_date,
|
||||||
rpl::single(langDayOfMonthFull(s.until.date()))),
|
rpl::single(langDayOfMonthFull(s.until.date())))),
|
||||||
st::creditsBoxAboutDivider);
|
st::creditsBoxAboutDivider);
|
||||||
if (toCancel) {
|
if (toCancel) {
|
||||||
label->setClickHandlerFilter([=](
|
label->setClickHandlerFilter([=](
|
||||||
const auto &,
|
const auto &,
|
||||||
|
@ -1402,54 +1447,9 @@ void ReceiptCreditsBox(
|
||||||
? tr::lng_credits_subscription_off_button()
|
? tr::lng_credits_subscription_off_button()
|
||||||
: toRejoin
|
: toRejoin
|
||||||
? tr::lng_credits_subscription_off_rejoin_button()
|
? 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()));
|
: tr::lng_box_ok()));
|
||||||
const auto send = [=, weak = Ui::MakeWeak(box)] {
|
const auto send = [=, weak = Ui::MakeWeak(box)] {
|
||||||
if (canConvert || couldConvert || nonConvertible) {
|
if (toRejoin) {
|
||||||
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 (const auto window = weakWindow.get()) {
|
if (const auto window = weakWindow.get()) {
|
||||||
const auto finish = [=](Payments::CheckoutResult&&) {
|
const auto finish = [=](Payments::CheckoutResult&&) {
|
||||||
ProcessReceivedSubscriptions(weak, session);
|
ProcessReceivedSubscriptions(weak, session);
|
||||||
|
@ -1480,9 +1480,7 @@ void ReceiptCreditsBox(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto willBusy = toRejoin
|
const auto willBusy = toRejoin || (peer && toRenew);
|
||||||
|| (peer
|
|
||||||
&& (toRenew || canConvert || couldConvert || nonConvertible));
|
|
||||||
if (willBusy) {
|
if (willBusy) {
|
||||||
const auto close = Ui::CreateChild<Ui::IconButton>(
|
const auto close = Ui::CreateChild<Ui::IconButton>(
|
||||||
content,
|
content,
|
||||||
|
|
Loading…
Add table
Reference in a new issue