From 79398fe6cf3992d4bc529e0bec3fa98214a02891 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 7 Dec 2017 19:01:41 +0400 Subject: [PATCH] Add call button to Info::Profile top bar. --- Telegram/SourceFiles/data/data_peer.cpp | 3 +- .../history/history_admin_log_section.cpp | 1 + .../SourceFiles/history/history_widget.cpp | 1 + Telegram/SourceFiles/info/info.style | 64 +++++++++++++++++++ Telegram/SourceFiles/info/info_top_bar.cpp | 3 + .../SourceFiles/info/info_wrap_widget.cpp | 37 ++++++++++- Telegram/SourceFiles/info/info_wrap_widget.h | 2 + Telegram/SourceFiles/profile/profile.style | 2 +- .../profile/profile_back_button.cpp | 1 + .../window/themes/window_theme_preview.cpp | 1 + Telegram/SourceFiles/window/window.style | 58 ----------------- 11 files changed, 112 insertions(+), 61 deletions(-) diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 3c92392da..f7c3b3470 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -524,7 +524,8 @@ void UserData::setCallsStatus(CallsStatus callsStatus) { } bool UserData::hasCalls() const { - return (callsStatus() != CallsStatus::Disabled) && (callsStatus() != CallsStatus::Unknown); + return (callsStatus() != CallsStatus::Disabled) + && (callsStatus() != CallsStatus::Unknown); } void ChatData::setPhoto(const MTPChatPhoto &photo) { diff --git a/Telegram/SourceFiles/history/history_admin_log_section.cpp b/Telegram/SourceFiles/history/history_admin_log_section.cpp index 6c8132497..a5ca7ac7d 100644 --- a/Telegram/SourceFiles/history/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/history_admin_log_section.cpp @@ -25,6 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "profile/profile_back_button.h" #include "styles/style_history.h" #include "styles/style_window.h" +#include "styles/style_info.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/shadow.h" #include "ui/widgets/buttons.h" diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 1e26f1383..3e384abb5 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -26,6 +26,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "styles/style_boxes.h" #include "styles/style_profile.h" #include "styles/style_chat_helpers.h" +#include "styles/style_info.h" #include "boxes/confirm_box.h" #include "boxes/send_files_box.h" #include "boxes/share_box.h" diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index b276e7f7b..36cdfd5e0 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -164,6 +164,10 @@ infoNotificationsActive: icon {{ "info_notifications", windowBgActive }}; +infoTopBarCall: IconButton(infoTopBarNotifications) { + icon: icon {{ "top_bar_call", boxTitleCloseFg }}; + iconOver: icon {{ "top_bar_call", boxTitleCloseFgOver }}; +} infoTopBarForward: IconButton(infoTopBarBack) { width: 46px; icon: icon {{ "info_media_forward", boxTitleCloseFg }}; @@ -227,6 +231,10 @@ infoLayerTopBarNotifications: IconButton(infoLayerTopBarMenu) { iconOver: icon {{ "info_notifications", boxTitleCloseFgOver }}; iconPosition: point(5px, 11px); } +infoLayerTopBarCall: IconButton(infoLayerTopBarNotifications) { + icon: icon {{ "top_bar_call", boxTitleCloseFg }}; + iconOver: icon {{ "top_bar_call", boxTitleCloseFgOver }}; +} infoLayerTopBarForward: IconButton(infoLayerTopBarBack) { width: 45px; icon: icon {{ "info_media_forward", boxTitleCloseFg }}; @@ -615,3 +623,59 @@ editPeerInvitesSkip: 10px; historyTopBarBack: IconButton(infoTopBarBack) { width: 52px; } +topBarHeight: 54px; +topBarMenuPosition: point(-2px, 35px); +topBarDuration: 200; +topBarBackward: icon {{ "title_back", menuIconFg }}; +topBarForwardAlpha: 0.6; +topBarBack: icon {{ "title_back", lightButtonFg }}; +topBarArrowPadding: margins(39px, 8px, 17px, 8px); +topBarMinPadding: 5px; +topBarButton: RoundButton(defaultLightButton) { + width: -18px; + padding: margins(0px, 10px, 12px, 10px); +} +topBarClearButton: RoundButton(defaultLightButton) { + width: -18px; +} +topBarSearch: IconButton { + width: 40px; + height: topBarHeight; + + icon: icon {{ "top_bar_search", menuIconFg }}; + iconOver: icon {{ "top_bar_search", menuIconFgOver }}; + iconPosition: point(4px, 11px); + + rippleAreaPosition: point(0px, 7px); + rippleAreaSize: 40px; + ripple: RippleAnimation(defaultRippleAnimation) { + color: windowBgOver; + } +} +topBarSkip: -2px; +topBarCallSkip: -1px; +topBarMenuToggle: IconButton(topBarSearch) { + width: 44px; + + icon: icon {{ "title_menu_dots", menuIconFg }}; + iconOver: icon {{ "title_menu_dots", menuIconFgOver }}; + iconPosition: point(16px, 17px); + + rippleAreaPosition: point(0px, 7px); +} +topBarCall: IconButton(topBarSearch) { + icon: icon {{ "top_bar_call", menuIconFg }}; + iconOver: icon {{ "top_bar_call", menuIconFgOver }}; +} +topBarInfo: IconButton(topBarSearch) { + icon: icon {{ "top_bar_profile", menuIconFg }}; + iconOver: icon {{ "top_bar_profile", menuIconFgOver }}; +} +topBarInfoActive: icon {{ "top_bar_profile", windowActiveTextFg }}; +topBarActionSkip: 10px; + +topBarInfoButton: UserpicButton(defaultUserpicButton) { + size: size(52px, topBarHeight); + photoSize: 42px; + photoPosition: point(2px, -1px); +} diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index a6c866f79..acbcd03e0 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -145,6 +145,9 @@ Ui::FadeWrap *TopBar::pushButton( return !selectionMode() && !_searchModeEnabled; }); + weak->toggle( + !selectionMode() && !_searchModeEnabled, + anim::type::instant); weak->widthValue() | rpl::start_with_next([this] { updateControlsGeometry(width()); diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 78890f858..d54001226 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "info/info_wrap_widget.h" #include +#include #include #include "info/profile/info_profile_widget.h" #include "info/profile/info_profile_members.h" @@ -36,6 +37,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/dropdown_menu.h" #include "ui/wrap/fade_wrap.h" #include "ui/search_field_controller.h" +#include "calls/calls_instance.h" #include "window/window_controller.h" #include "window/window_slide_animation.h" #include "window/window_peer_menu.h" @@ -303,7 +305,7 @@ void WrapWidget::setupTop() { } void WrapWidget::createTopBar() { - auto wrapValue = wrap(); + const auto wrapValue = wrap(); auto selectedItems = _topBar ? _topBar->takeSelectedItems() : SelectedItems(Section::MediaType::kCount); @@ -350,6 +352,7 @@ void WrapWidget::createTopBar() { if (_controller->section().type() == Section::Type::Profile && (wrapValue != Wrap::Side || hasStackHistory())) { addProfileMenuButton(); + addProfileCallsButton(); // addProfileNotificationsButton(); } @@ -373,6 +376,38 @@ void WrapWidget::addProfileMenuButton() { }); } +void WrapWidget::addProfileCallsButton() { + Expects(_topBar != nullptr); + + const auto user = _controller->peer()->asUser(); + if (!user || user->isSelf() || !Global::PhoneCallsEnabled()) { + return; + } + + Notify::PeerUpdateValue( + user, + Notify::PeerUpdate::Flag::UserHasCalls + ) | rpl::filter([=] { + return user->hasCalls(); + }) | rpl::take( + 1 + ) | rpl::start_with_next([=] { + _topBar->addButton( + base::make_unique_q( + _topBar, + (wrap() == Wrap::Layer + ? st::infoLayerTopBarCall + : st::infoTopBarCall)) + )->addClickHandler([=] { + Calls::Current().startOutgoingCall(user); + }); + }, _topBar->lifetime()); + + if (user && user->callsStatus() == UserData::CallsStatus::Unknown) { + user->updateFull(); + } +} + void WrapWidget::addProfileNotificationsButton() { Expects(_topBar != nullptr); diff --git a/Telegram/SourceFiles/info/info_wrap_widget.h b/Telegram/SourceFiles/info/info_wrap_widget.h index b11f793a0..0f0e7b6c3 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.h +++ b/Telegram/SourceFiles/info/info_wrap_widget.h @@ -192,6 +192,7 @@ private: bool requireTopBarSearch() const; void addProfileMenuButton(); + void addProfileCallsButton(); void addProfileNotificationsButton(); void showProfileMenu(); @@ -205,6 +206,7 @@ private: object_ptr _topBarSurrogate = { nullptr }; Animation _topBarOverrideAnimation; bool _topBarOverrideShown = false; + object_ptr _topShadow; base::unique_qptr _topBarMenuToggle; base::unique_qptr _topBarMenu; diff --git a/Telegram/SourceFiles/profile/profile.style b/Telegram/SourceFiles/profile/profile.style index 98afb49dc..7d013faf6 100644 --- a/Telegram/SourceFiles/profile/profile.style +++ b/Telegram/SourceFiles/profile/profile.style @@ -21,7 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org using "basic.style"; using "ui/widgets/widgets.style"; -using "window/window.style"; +using "info/info.style"; profileBg: windowBg; diff --git a/Telegram/SourceFiles/profile/profile_back_button.cpp b/Telegram/SourceFiles/profile/profile_back_button.cpp index 3d67b661f..3603cb625 100644 --- a/Telegram/SourceFiles/profile/profile_back_button.cpp +++ b/Telegram/SourceFiles/profile/profile_back_button.cpp @@ -24,6 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "styles/style_widgets.h" #include "styles/style_window.h" #include "styles/style_profile.h" +#include "styles/style_info.h" namespace Profile { diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp index ad81bc335..aa87b79bb 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp @@ -28,6 +28,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "styles/style_mediaview.h" #include "styles/style_history.h" #include "styles/style_dialogs.h" +#include "styles/style_info.h" namespace Window { namespace Theme { diff --git a/Telegram/SourceFiles/window/window.style b/Telegram/SourceFiles/window/window.style index 0b0865f68..26a882e8f 100644 --- a/Telegram/SourceFiles/window/window.style +++ b/Telegram/SourceFiles/window/window.style @@ -247,64 +247,6 @@ titleButtonCloseIconActiveOver: icon { { "title_button_close", titleButtonCloseFgActiveOver, point(5px, 4px) }, }; -// Legacy top bar. -topBarHeight: 54px; -topBarMenuPosition: point(-2px, 35px); -topBarDuration: 200; -topBarBackward: icon {{ "title_back", menuIconFg }}; -topBarForwardAlpha: 0.6; -topBarBack: icon {{ "title_back", lightButtonFg }}; -topBarArrowPadding: margins(39px, 8px, 17px, 8px); -topBarMinPadding: 5px; -topBarButton: RoundButton(defaultLightButton) { - width: -18px; - padding: margins(0px, 10px, 12px, 10px); -} -topBarClearButton: RoundButton(defaultLightButton) { - width: -18px; -} -topBarSearch: IconButton { - width: 40px; - height: topBarHeight; - - icon: icon {{ "top_bar_search", menuIconFg }}; - iconOver: icon {{ "top_bar_search", menuIconFgOver }}; - iconPosition: point(4px, 11px); - - rippleAreaPosition: point(0px, 7px); - rippleAreaSize: 40px; - ripple: RippleAnimation(defaultRippleAnimation) { - color: windowBgOver; - } -} -topBarCall: IconButton(topBarSearch) { - icon: icon {{ "top_bar_call", menuIconFg }}; - iconOver: icon {{ "top_bar_call", menuIconFgOver }}; -} -topBarInfo: IconButton(topBarSearch) { - icon: icon {{ "top_bar_profile", menuIconFg }}; - iconOver: icon {{ "top_bar_profile", menuIconFgOver }}; -} -topBarInfoActive: icon {{ "top_bar_profile", windowActiveTextFg }}; -topBarSkip: -2px; -topBarCallSkip: -1px; -topBarMenuToggle: IconButton(topBarSearch) { - width: 44px; - - icon: icon {{ "title_menu_dots", menuIconFg }}; - iconOver: icon {{ "title_menu_dots", menuIconFgOver }}; - iconPosition: point(16px, 17px); - - rippleAreaPosition: point(0px, 7px); -} -topBarActionSkip: 10px; - -topBarInfoButton: UserpicButton(defaultUserpicButton) { - size: size(52px, topBarHeight); - photoSize: 42px; - photoPosition: point(2px, -1px); -} - themeEditorSampleSize: size(90px, 51px); themeEditorMargin: margins(17px, 10px, 17px, 10px); themeEditorDescriptionSkip: 10px;