Improve scheduled messages top bar.

This commit is contained in:
John Preston 2019-08-09 13:15:57 +01:00
parent ea0a616453
commit 99037d3d46
6 changed files with 43 additions and 30 deletions

View file

@ -1259,6 +1259,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_saved_short" = "Save"; "lng_saved_short" = "Save";
"lng_saved_forward_here" = "Forward messages here for quick access"; "lng_saved_forward_here" = "Forward messages here for quick access";
"lng_scheduled_messages" = "Scheduled Messages";
"lng_archived_name" = "Archived chats"; "lng_archived_name" = "Archived chats";
"lng_archived_add" = "Archive"; "lng_archived_add" = "Archive";
"lng_archived_remove" = "Unarchive"; "lng_archived_remove" = "Unarchive";

View file

@ -444,7 +444,9 @@ void Widget::refreshFolderTopBar() {
_folderTopBar.create(this, controller()); _folderTopBar.create(this, controller());
updateControlsGeometry(); updateControlsGeometry();
} }
_folderTopBar->setActiveChat(_openedFolder); _folderTopBar->setActiveChat(
_openedFolder,
HistoryView::TopBarWidget::Section::History);
} else { } else {
_folderTopBar.destroy(); _folderTopBar.destroy();
} }

View file

@ -1761,7 +1761,9 @@ void HistoryWidget::showHistory(
_migrated->clear(History::ClearType::Unload); _migrated->clear(History::ClearType::Unload);
} }
_topBar->setActiveChat(_history); _topBar->setActiveChat(
_history,
HistoryView::TopBarWidget::Section::History);
updateTopBarSelection(); updateTopBarSelection();
if (_channel) { if (_channel) {
@ -1837,7 +1839,9 @@ void HistoryWidget::showHistory(
} }
unreadCountUpdated(); // set _historyDown badge. unreadCountUpdated(); // set _historyDown badge.
} else { } else {
_topBar->setActiveChat(Dialogs::Key()); _topBar->setActiveChat(
Dialogs::Key(),
HistoryView::TopBarWidget::Section::History);
updateTopBarSelection(); updateTopBarSelection();
clearFieldText(); clearFieldText();

View file

@ -50,7 +50,7 @@ ScheduledWidget::ScheduledWidget(
, _topBar(this, controller) , _topBar(this, controller)
, _topBarShadow(this) , _topBarShadow(this)
, _scrollDown(_scroll, st::historyToDown) { , _scrollDown(_scroll, st::historyToDown) {
_topBar->setActiveChat(_history); _topBar->setActiveChat(_history, TopBarWidget::Section::Scheduled);
_topBar->move(0, 0); _topBar->move(0, 0);
_topBar->resizeToWidth(width()); _topBar->resizeToWidth(width());
@ -200,6 +200,7 @@ Dialogs::RowDescriptor ScheduledWidget::activeChat() const {
} }
QPixmap ScheduledWidget::grabForShowAnimation(const Window::SectionSlideParams &params) { QPixmap ScheduledWidget::grabForShowAnimation(const Window::SectionSlideParams &params) {
_topBar->updateControlsVisibility();
if (params.withTopBarShadow) _topBarShadow->hide(); if (params.withTopBarShadow) _topBarShadow->hide();
auto result = Ui::GrabWidget(this); auto result = Ui::GrabWidget(this);
if (params.withTopBarShadow) _topBarShadow->show(); if (params.withTopBarShadow) _topBarShadow->show();
@ -315,7 +316,9 @@ void ScheduledWidget::updateInnerVisibleArea() {
void ScheduledWidget::showAnimatedHook( void ScheduledWidget::showAnimatedHook(
const Window::SectionSlideParams &params) { const Window::SectionSlideParams &params) {
_topBar->setAnimatingMode(true); _topBar->setAnimatingMode(true);
if (params.withTopBarShadow) _topBarShadow->show(); if (params.withTopBarShadow) {
_topBarShadow->show();
}
} }
void ScheduledWidget::showFinishedHook() { void ScheduledWidget::showFinishedHook() {

View file

@ -313,23 +313,17 @@ void TopBarWidget::paintTopBar(Painter &p) {
auto statustop = st::topBarHeight - st::topBarArrowPadding.bottom() - st::dialogsTextFont->height; auto statustop = st::topBarHeight - st::topBarArrowPadding.bottom() - st::dialogsTextFont->height;
auto availableWidth = width() - _rightTaken - nameleft; auto availableWidth = width() - _rightTaken - nameleft;
auto history = _activeChat.history(); const auto history = _activeChat.history();
const auto folder = _activeChat.folder();
if (const auto folder = _activeChat.folder()) { if (folder
auto text = folder->chatListName(); // TODO feed name emoji || history->peer->isSelf()
const auto textWidth = st::historySavedFont->width(text); || (_section == Section::Scheduled)) {
if (availableWidth < textWidth) { // #TODO feed name emoji.
text = st::historySavedFont->elided(text, availableWidth); auto text = (_section == Section::Scheduled)
} ? tr::lng_scheduled_messages(tr::now)
p.setPen(st::dialogsNameFg); : folder
p.setFont(st::historySavedFont); ? folder->chatListName()
p.drawTextLeft( : tr::lng_saved_messages(tr::now);
nameleft,
(height() - st::historySavedFont->height) / 2,
width(),
text);
} else if (_activeChat.peer()->isSelf()) {
auto text = tr::lng_saved_messages(tr::now);
const auto textWidth = st::historySavedFont->width(text); const auto textWidth = st::historySavedFont->width(text);
if (availableWidth < textWidth) { if (availableWidth < textWidth) {
text = st::historySavedFont->elided(text, availableWidth); text = st::historySavedFont->elided(text, availableWidth);
@ -468,11 +462,12 @@ void TopBarWidget::backClicked() {
} }
} }
void TopBarWidget::setActiveChat(Dialogs::Key chat) { void TopBarWidget::setActiveChat(Dialogs::Key chat, Section section) {
if (_activeChat == chat) { if (_activeChat == chat && _section == section) {
return; return;
} }
_activeChat = chat; _activeChat = chat;
_section = section;
_back->clearState(); _back->clearState();
update(); update();
@ -611,11 +606,13 @@ void TopBarWidget::updateControlsVisibility() {
if (_unreadBadge) { if (_unreadBadge) {
_unreadBadge->show(); _unreadBadge->show();
} }
const auto historyMode = (_section == Section::History);
const auto smallDialogsColumn = _activeChat.folder() const auto smallDialogsColumn = _activeChat.folder()
&& (width() < _back->width() + _search->width()); && (width() < _back->width() + _search->width());
_search->setVisible(!smallDialogsColumn); _search->setVisible(historyMode && !smallDialogsColumn);
_menuToggle->setVisible(!_activeChat.folder()); _menuToggle->setVisible(historyMode && !_activeChat.folder());
_infoToggle->setVisible(!_activeChat.folder() _infoToggle->setVisible(historyMode
&& !_activeChat.folder()
&& !Adaptive::OneColumn() && !Adaptive::OneColumn()
&& _controller->canShowThirdSection()); && _controller->canShowThirdSection());
const auto callsEnabled = [&] { const auto callsEnabled = [&] {
@ -626,7 +623,7 @@ void TopBarWidget::updateControlsVisibility() {
} }
return false; return false;
}(); }();
_call->setVisible(callsEnabled); _call->setVisible(historyMode && callsEnabled);
if (_membersShowArea) { if (_membersShowArea) {
_membersShowArea->show(); _membersShowArea->show();

View file

@ -39,6 +39,10 @@ public:
int canDeleteCount = 0; int canDeleteCount = 0;
int canForwardCount = 0; int canForwardCount = 0;
}; };
enum class Section {
History,
Scheduled,
};
TopBarWidget( TopBarWidget(
QWidget *parent, QWidget *parent,
@ -55,7 +59,7 @@ public:
} }
void setAnimatingMode(bool enabled); void setAnimatingMode(bool enabled);
void setActiveChat(Dialogs::Key chat); void setActiveChat(Dialogs::Key chat, Section section);
rpl::producer<> forwardSelectionRequest() const { rpl::producer<> forwardSelectionRequest() const {
return _forwardSelection.events(); return _forwardSelection.events();
@ -112,8 +116,9 @@ private:
void refreshUnreadBadge(); void refreshUnreadBadge();
void updateUnreadBadge(); void updateUnreadBadge();
not_null<Window::SessionController*> _controller; const not_null<Window::SessionController*> _controller;
Dialogs::Key _activeChat; Dialogs::Key _activeChat;
Section _section = Section::History;
int _selectedCount = 0; int _selectedCount = 0;
bool _canDelete = false; bool _canDelete = false;