mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Simplified settings of notification sound.
This commit is contained in:
parent
93563358ca
commit
4dd5be9356
10 changed files with 21 additions and 93 deletions
BIN
Telegram/Resources/icons/menu/sound_disable.png
Normal file
BIN
Telegram/Resources/icons/menu/sound_disable.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 748 B |
BIN
Telegram/Resources/icons/menu/sound_disable@2x.png
Normal file
BIN
Telegram/Resources/icons/menu/sound_disable@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
Telegram/Resources/icons/menu/sound_disable@3x.png
Normal file
BIN
Telegram/Resources/icons/menu/sound_disable@3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
BIN
Telegram/Resources/icons/menu/sound_enable.png
Normal file
BIN
Telegram/Resources/icons/menu/sound_enable.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 585 B |
BIN
Telegram/Resources/icons/menu/sound_enable@2x.png
Normal file
BIN
Telegram/Resources/icons/menu/sound_enable@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1 KiB |
BIN
Telegram/Resources/icons/menu/sound_enable@3x.png
Normal file
BIN
Telegram/Resources/icons/menu/sound_enable@3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
|
@ -899,11 +899,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_mute_menu_duration" = "Mute for...";
|
||||
"lng_mute_menu_duration_forever" = "Mute forever";
|
||||
"lng_mute_menu_duration_unmute" = "Unmute";
|
||||
"lng_mute_menu_sound_on" = "Sound On";
|
||||
"lng_mute_menu_sound_off" = "Sound Off";
|
||||
"lng_mute_menu_sound_on" = "Enable sound";
|
||||
"lng_mute_menu_sound_off" = "Disable sound";
|
||||
"lng_mute_box_title" = "Mute notifications for...";
|
||||
"lng_mute_box_no_notifications" = "No notifications";
|
||||
"lng_mute_box_silent_notifications" = "Silent notifications";
|
||||
"lng_mute_box_days#one" = "{count} day";
|
||||
"lng_mute_box_days#other" = "{count} days";
|
||||
"lng_mute_box_hours#one" = "{count} hour";
|
||||
|
|
|
@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_session.h"
|
||||
#include "info/profile/info_profile_values.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "menu/menu_check_item.h"
|
||||
#include "ui/boxes/choose_time.h"
|
||||
#include "ui/effects/animation_value.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
|
@ -99,99 +98,28 @@ void MuteItem::paintEvent(QPaintEvent *e) {
|
|||
icon.paint(p, _itemIconPosition, width(), color);
|
||||
}
|
||||
|
||||
void FillSoundMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
not_null<PeerData*> peer,
|
||||
rpl::producer<QString> &&soundOnText,
|
||||
rpl::producer<QString> &&soundOffText,
|
||||
Fn<void(bool)> notifySound) {
|
||||
const auto createView = [&](rpl::producer<QString> &&text, bool checked) {
|
||||
auto item = base::make_unique_q<Menu::ItemWithCheck>(
|
||||
menu->menu(),
|
||||
st::popupMenuWithIcons.menu,
|
||||
new QAction(QString(), menu->menu()),
|
||||
nullptr,
|
||||
nullptr);
|
||||
std::move(
|
||||
text
|
||||
) | rpl::start_with_next([action = item->action()](QString text) {
|
||||
action->setText(text);
|
||||
}, item->lifetime());
|
||||
item->init(checked);
|
||||
const auto view = item->checkView();
|
||||
menu->addAction(std::move(item));
|
||||
return view;
|
||||
};
|
||||
|
||||
const auto soundIsNone = peer->owner().notifySoundIsNone(peer);
|
||||
const auto soundOn = createView(std::move(soundOnText), !soundIsNone);
|
||||
const auto soundOff = createView(std::move(soundOffText), soundIsNone);
|
||||
|
||||
soundOn->checkedChanges(
|
||||
) | rpl::start_with_next([=](bool checked) {
|
||||
soundOff->setChecked(!checked, anim::type::normal);
|
||||
notifySound(!checked);
|
||||
}, menu->lifetime());
|
||||
soundOff->checkedChanges(
|
||||
) | rpl::start_with_next([=](bool checked) {
|
||||
soundOn->setChecked(!checked, anim::type::normal);
|
||||
notifySound(checked);
|
||||
}, menu->lifetime());
|
||||
}
|
||||
|
||||
void MuteBox(not_null<Ui::GenericBox*> box, not_null<PeerData*> peer) {
|
||||
struct State {
|
||||
base::unique_qptr<Ui::PopupMenu> menu;
|
||||
rpl::variable<bool> noSoundChanges;
|
||||
int lastSeconds = 0;
|
||||
};
|
||||
|
||||
auto chooseTimeResult = ChooseTimeWidget(box, kMuteDurSecondsDefault);
|
||||
box->addRow(std::move(chooseTimeResult.widget));
|
||||
|
||||
const auto state = box->lifetime().make_state<State>(State{
|
||||
.noSoundChanges = false,
|
||||
});
|
||||
const auto state = box->lifetime().make_state<State>();
|
||||
|
||||
box->setTitle(tr::lng_mute_box_title());
|
||||
|
||||
const auto topButton = box->addTopButton(st::infoTopBarMenu);
|
||||
topButton->setClickedCallback([=] {
|
||||
if (state->menu) {
|
||||
return;
|
||||
}
|
||||
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
||||
topButton,
|
||||
st::popupMenuWithIcons);
|
||||
FillSoundMenu(
|
||||
state->menu.get(),
|
||||
peer,
|
||||
tr::lng_mute_box_no_notifications(),
|
||||
tr::lng_mute_box_silent_notifications(),
|
||||
[=](bool silent) {
|
||||
state->noSoundChanges = silent;
|
||||
});
|
||||
state->menu->popup(QCursor::pos());
|
||||
return;
|
||||
});
|
||||
|
||||
auto confirmText = rpl::combine(
|
||||
std::move(chooseTimeResult.secondsValue),
|
||||
state->noSoundChanges.value()
|
||||
) | rpl::map([=](int seconds, bool noSound) {
|
||||
auto confirmText = std::move(
|
||||
chooseTimeResult.secondsValue
|
||||
) | rpl::map([=](int seconds) {
|
||||
state->lastSeconds = seconds;
|
||||
return !seconds
|
||||
? tr::lng_mute_menu_unmute()
|
||||
: noSound
|
||||
? tr::lng_mute_box_silent_notifications()
|
||||
: tr::lng_mute_menu_mute();
|
||||
}) | rpl::flatten_latest();
|
||||
const auto confirm = box->addButton(std::move(confirmText), [=] {
|
||||
peer->owner().updateNotifySettings(
|
||||
peer,
|
||||
state->lastSeconds,
|
||||
std::nullopt,
|
||||
state->noSoundChanges.current());
|
||||
peer->owner().updateNotifySettings(peer, state->lastSeconds);
|
||||
box->closeBox();
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
|
@ -204,16 +132,16 @@ void FillMuteMenu(
|
|||
Args args) {
|
||||
const auto peer = args.peer;
|
||||
|
||||
FillSoundMenu(
|
||||
menu,
|
||||
peer,
|
||||
tr::lng_mute_menu_sound_on(),
|
||||
tr::lng_mute_menu_sound_off(),
|
||||
[peer](bool silent) {
|
||||
peer->owner().updateNotifySettings(peer, {}, {}, silent);
|
||||
});
|
||||
|
||||
menu->addSeparator();
|
||||
const auto soundIsNone = peer->owner().notifySoundIsNone(peer);
|
||||
menu->addAction(
|
||||
soundIsNone
|
||||
? tr::lng_mute_menu_sound_on(tr::now)
|
||||
: tr::lng_mute_menu_sound_off(tr::now),
|
||||
[=] {
|
||||
const auto soundIsNone = peer->owner().notifySoundIsNone(peer);
|
||||
peer->owner().updateNotifySettings(peer, {}, {}, !soundIsNone);
|
||||
},
|
||||
soundIsNone ? &st::menuIconSoundOn : &st::menuIconSoundOff);
|
||||
|
||||
menu->addAction(
|
||||
tr::lng_mute_menu_duration(tr::now),
|
||||
|
|
|
@ -97,6 +97,8 @@ menuIconViolence: icon {{ "menu/violence", menuIconColor }};
|
|||
menuIconMuteFor: icon {{ "menu/mute_for", menuIconColor }};
|
||||
menuIconSilent: icon {{ "menu/silent", menuIconColor }};
|
||||
menuIconCustomize: icon {{ "menu/customize", menuIconColor }};
|
||||
menuIconSoundOn: icon {{ "menu/sound_enable", menuIconColor }};
|
||||
menuIconSoundOff: icon {{ "menu/sound_disable", menuIconColor }};
|
||||
|
||||
menuIconTTLAny: icon {{ "menu/auto_delete_plain", menuIconColor }};
|
||||
menuIconTTLAnyTextPosition: point(11px, 22px);
|
||||
|
|
|
@ -133,7 +133,7 @@ void PeerMenuAddMuteSubmenuAction(
|
|||
peer->owner().requestNotifySettings(peer);
|
||||
const auto isMuted = peer->owner().notifyIsMuted(peer);
|
||||
if (isMuted) {
|
||||
const auto text = tr::lng_mute_menu_unmute(tr::now)
|
||||
const auto text = tr::lng_context_unmute(tr::now)
|
||||
+ '\t'
|
||||
+ Ui::FormatMuteForTiny(peer->notifyMuteUntil().value_or(0)
|
||||
- base::unixtime::now());
|
||||
|
@ -143,7 +143,7 @@ void PeerMenuAddMuteSubmenuAction(
|
|||
} else {
|
||||
const auto show = std::make_shared<Window::Show>(controller);
|
||||
addAction(PeerMenuCallback::Args{
|
||||
.text = tr::lng_mute_menu_mute(tr::now),
|
||||
.text = tr::lng_context_mute(tr::now),
|
||||
.handler = nullptr,
|
||||
.icon = peer->owner().notifySoundIsNone(peer)
|
||||
? &st::menuIconSilent
|
||||
|
|
Loading…
Add table
Reference in a new issue