mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added vertical time picker for mute period.
This commit is contained in:
parent
209e09ab66
commit
511789d7af
3 changed files with 74 additions and 2 deletions
|
@ -15,9 +15,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/boxes/choose_time.h"
|
#include "ui/boxes/choose_time.h"
|
||||||
#include "ui/effects/animation_value.h"
|
#include "ui/effects/animation_value.h"
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
|
#include "ui/text/format_values.h"
|
||||||
#include "ui/widgets/checkbox.h"
|
#include "ui/widgets/checkbox.h"
|
||||||
#include "ui/widgets/menu/menu_action.h"
|
#include "ui/widgets/menu/menu_action.h"
|
||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
|
#include "ui/boxes/time_picker_box.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_info.h" // infoTopBarMenu
|
#include "styles/style_info.h" // infoTopBarMenu
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
|
@ -123,11 +125,72 @@ void MuteBox(not_null<Ui::GenericBox*> box, not_null<PeerData*> peer) {
|
||||||
peer->owner().notifySettings().updateNotifySettings(
|
peer->owner().notifySettings().updateNotifySettings(
|
||||||
peer,
|
peer,
|
||||||
state->lastSeconds);
|
state->lastSeconds);
|
||||||
box->closeBox();
|
box->getDelegate()->hideLayer();
|
||||||
});
|
});
|
||||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PickMuteBox(not_null<Ui::GenericBox*> box, not_null<PeerData*> peer) {
|
||||||
|
struct State {
|
||||||
|
base::unique_qptr<Ui::PopupMenu> menu;
|
||||||
|
};
|
||||||
|
const auto seconds = std::vector<TimeId>{
|
||||||
|
(60 * 15),
|
||||||
|
(60 * 30),
|
||||||
|
(3600 * 1),
|
||||||
|
(3600 * 2),
|
||||||
|
(3600 * 3),
|
||||||
|
(3600 * 4),
|
||||||
|
(3600 * 8),
|
||||||
|
(3600 * 12),
|
||||||
|
(84600 * 1),
|
||||||
|
(84600 * 2),
|
||||||
|
(84600 * 3),
|
||||||
|
(84600 * 7 * 1),
|
||||||
|
(84600 * 7 * 2),
|
||||||
|
(84600 * 30 * 1),
|
||||||
|
(84600 * 30 * 2),
|
||||||
|
(84600 * 30 * 3),
|
||||||
|
};
|
||||||
|
const auto phrases = ranges::views::all(
|
||||||
|
seconds
|
||||||
|
) | ranges::views::transform(Ui::FormatMuteFor) | ranges::to_vector;
|
||||||
|
|
||||||
|
const auto state = box->lifetime().make_state<State>();
|
||||||
|
|
||||||
|
const auto pickerCallback = TimePickerBox(box, seconds, phrases, 0);
|
||||||
|
|
||||||
|
box->addButton(tr::lng_mute_menu_mute(), [=] {
|
||||||
|
peer->owner().notifySettings().updateNotifySettings(
|
||||||
|
peer,
|
||||||
|
pickerCallback());
|
||||||
|
box->closeBox();
|
||||||
|
});
|
||||||
|
|
||||||
|
box->setTitle(tr::lng_mute_box_title());
|
||||||
|
|
||||||
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||||
|
|
||||||
|
const auto top = box->addTopButton(st::infoTopBarMenu);
|
||||||
|
top->setClickedCallback([=] {
|
||||||
|
if (state->menu) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
|
top,
|
||||||
|
st::popupMenuWithIcons);
|
||||||
|
state->menu->addAction(
|
||||||
|
tr::lng_manage_messages_ttl_after_custom(tr::now),
|
||||||
|
[=] { box->getDelegate()->show(Box(MuteBox, peer)); },
|
||||||
|
&st::menuIconCustomize);
|
||||||
|
state->menu->setDestroyedCallback(crl::guard(top, [=] {
|
||||||
|
top->setForceRippled(false);
|
||||||
|
}));
|
||||||
|
top->setForceRippled(true);
|
||||||
|
state->menu->popup(QCursor::pos());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void FillMuteMenu(
|
void FillMuteMenu(
|
||||||
|
@ -149,7 +212,7 @@ void FillMuteMenu(
|
||||||
|
|
||||||
menu->addAction(
|
menu->addAction(
|
||||||
tr::lng_mute_menu_duration(tr::now),
|
tr::lng_mute_menu_duration(tr::now),
|
||||||
[=, show = args.show] { show->showBox(Box(MuteBox, peer)); },
|
[=, show = args.show] { show->showBox(Box(PickMuteBox, peer)); },
|
||||||
&st::menuIconMuteFor);
|
&st::menuIconMuteFor);
|
||||||
|
|
||||||
menu->addAction(
|
menu->addAction(
|
||||||
|
|
|
@ -408,6 +408,14 @@ QString FormatTTLTiny(float64 ttl) {
|
||||||
: tr::lng_years_tiny({}, lt_count, std::ceil(ttl / (86400 * 360)));
|
: tr::lng_years_tiny({}, lt_count, std::ceil(ttl / (86400 * 360)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString FormatMuteFor(float64 sec) {
|
||||||
|
return (sec <= 60)
|
||||||
|
? tr::lng_seconds(tr::now, lt_count, sec)
|
||||||
|
: (sec <= 60 * 59)
|
||||||
|
? tr::lng_minutes(tr::now, lt_count, std::ceil(sec / 60))
|
||||||
|
: FormatTTL(sec);
|
||||||
|
}
|
||||||
|
|
||||||
QString FormatMuteForTiny(float64 sec) {
|
QString FormatMuteForTiny(float64 sec) {
|
||||||
return (sec <= 60)
|
return (sec <= 60)
|
||||||
? QString()
|
? QString()
|
||||||
|
|
|
@ -29,6 +29,7 @@ inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2;
|
||||||
[[nodiscard]] QString FormatPhone(const QString &phone);
|
[[nodiscard]] QString FormatPhone(const QString &phone);
|
||||||
[[nodiscard]] QString FormatTTL(float64 ttl);
|
[[nodiscard]] QString FormatTTL(float64 ttl);
|
||||||
[[nodiscard]] QString FormatTTLTiny(float64 ttl);
|
[[nodiscard]] QString FormatTTLTiny(float64 ttl);
|
||||||
|
[[nodiscard]] QString FormatMuteFor(float64 sec);
|
||||||
[[nodiscard]] QString FormatMuteForTiny(float64 sec);
|
[[nodiscard]] QString FormatMuteForTiny(float64 sec);
|
||||||
|
|
||||||
struct CurrencyRule {
|
struct CurrencyRule {
|
||||||
|
|
Loading…
Add table
Reference in a new issue