Added initial implementation of detailed mute menu.

This commit is contained in:
23rd 2022-03-27 13:08:47 +03:00 committed by John Preston
parent f32215f77d
commit 8b7ea09fa9
8 changed files with 169 additions and 0 deletions

View file

@ -894,6 +894,8 @@ PRIVATE
media/view/media_view_playback_progress.cpp
media/view/media_view_playback_progress.h
media/view/media_view_open_common.h
menu/menu_mute.cpp
menu/menu_mute.h
menu/menu_send.cpp
menu/menu_send.h
mtproto/config_loader.cpp

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,007 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -892,6 +892,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_change_phone_code_description" = "We've sent an SMS with a confirmation code to your phone {phone}.";
"lng_change_phone_success" = "Your phone number has been changed.";
"lng_mute_menu_mute" = "Mute";
"lng_mute_menu_unmute" = "Unmute";
"lng_mute_menu_duration_hours#one" = "Mute for {count} hour";
"lng_mute_menu_duration_hours#other" = "Mute for {count} hours";
"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_box_title" = "Mute notifications for...";
"lng_mute_box_no_notifications" = "No notifications";
"lng_mute_box_silent_notifications" = "Silent notifications";
"lng_mute_duration_hours#one" = "For {count} hour";
"lng_mute_duration_hours#other" = "For {count} hours";
"lng_mute_duration_days#one" = "For {count} day";

View file

@ -0,0 +1,125 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "menu/menu_mute.h"
#include "data/data_peer.h"
#include "data/data_session.h"
#include "info/profile/info_profile_values.h"
#include "lang/lang_keys.h"
#include "ui/effects/animation_value.h"
#include "ui/widgets/menu/menu_action.h"
#include "ui/widgets/popup_menu.h"
#include "styles/style_menu_icons.h"
namespace MuteMenu {
namespace {
class MuteItem final : public Ui::Menu::Action {
public:
MuteItem(
not_null<RpWidget*> parent,
const style::Menu &st,
not_null<PeerData*> peer);
protected:
void paintEvent(QPaintEvent *e) override;
private:
const QPoint _itemIconPosition;
Ui::Animations::Simple _animation;
bool _isMuted = false;
};
MuteItem::MuteItem(
not_null<RpWidget*> parent,
const style::Menu &st,
not_null<PeerData*> peer)
: Ui::Menu::Action(
parent,
st,
Ui::CreateChild<QAction>(parent.get()),
nullptr,
nullptr)
, _itemIconPosition(st.itemIconPosition)
, _isMuted(peer->owner().notifyIsMuted(peer)) {
Info::Profile::NotificationsEnabledValue(
peer
) | rpl::start_with_next([=](bool isUnmuted) {
const auto isMuted = !isUnmuted;
action()->setText(isMuted
? tr::lng_mute_menu_duration_unmute(tr::now)
: tr::lng_mute_menu_duration_forever(tr::now));
if (isMuted == _isMuted) {
return;
}
_isMuted = isMuted;
_animation.start(
[=] { update(); },
isMuted ? 0. : 1.,
isMuted ? 1. : 0.,
st::defaultPopupMenu.showDuration);
}, lifetime());
setClickedCallback([=] {
peer->owner().updateNotifySettings(
peer,
_isMuted ? 0 : Data::NotifySettings::kDefaultMutePeriod);
});
}
void MuteItem::paintEvent(QPaintEvent *e) {
Painter p(this);
const auto progress = _animation.value(_isMuted ? 1. : 0.);
const auto color = anim::color(
st::settingsIconBg1,
st::settingsIconBg2,
progress);
p.setPen(color);
Action::paintText(p);
const auto &icon = _isMuted ? st::menuIconUnmute : st::menuIconMute;
icon.paint(p, _itemIconPosition, width(), color);
}
} // namespace
void FillMuteMenu(
not_null<Ui::PopupMenu*> menu,
not_null<PeerData*> peer) {
menu->addAction(
base::make_unique_q<MuteItem>(menu, menu->st().menu, peer));
}
void SetupMuteMenu(
not_null<Ui::RpWidget*> parent,
rpl::producer<> triggers,
not_null<PeerData*> peer) {
struct State {
base::unique_qptr<Ui::PopupMenu> menu;
};
const auto state = parent->lifetime().make_state<State>();
std::move(
triggers
) | rpl::start_with_next([=] {
if (state->menu) {
return;
}
state->menu = base::make_unique_q<Ui::PopupMenu>(
parent,
st::popupMenuWithIcons);
FillMuteMenu(state->menu.get(), peer);
state->menu->popup(QCursor::pos());
}, parent->lifetime());
}
} // namespace MuteMenu

View file

@ -0,0 +1,28 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
class PeerData;
namespace Ui {
class PopupMenu;
class RpWidget;
} // namespace Ui
namespace MuteMenu {
void FillMuteMenu(
not_null<Ui::PopupMenu*> menu,
not_null<PeerData*> peer);
void SetupMuteMenu(
not_null<Ui::RpWidget*> parent,
rpl::producer<> triggers,
not_null<PeerData*> peer);
} // namespace MuteMenu

View file

@ -93,6 +93,7 @@ menuIconFake: icon {{ "menu/fake", menuIconColor }};
menuIconPersonal: icon {{ "menu/personal", menuIconColor }};
menuIconPorn: icon {{ "menu/porn", menuIconColor }};
menuIconViolence: icon {{ "menu/violence", menuIconColor }};
menuIconSilent: icon {{ "menu/silent", menuIconColor }};
mediaMenuIconStickers: icon {{ "menu/stickers", mediaviewMenuFg }};
mediaMenuIconCancel: icon {{ "menu/cancel", mediaviewMenuFg }};