From e4ce08e64e35f757f31d592350304a882101ef6e Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 5 Dec 2017 16:23:08 +0400 Subject: [PATCH] Show other shared media links in Saved Photos. --- .../info/media/info_media_inner_widget.cpp | 211 +++++++++--------- .../info/media/info_media_inner_widget.h | 16 +- .../info/media/info_media_widget.cpp | 4 + .../info/media/info_media_widget.h | 2 + 4 files changed, 122 insertions(+), 111 deletions(-) diff --git a/Telegram/SourceFiles/info/media/info_media_inner_widget.cpp b/Telegram/SourceFiles/info/media/info_media_inner_widget.cpp index 75c6b1c5b3..aa80465f94 100644 --- a/Telegram/SourceFiles/info/media/info_media_inner_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_inner_widget.cpp @@ -49,109 +49,106 @@ InnerWidget::InnerWidget( [this] { refreshHeight(); }, _empty->lifetime()); _list = setupList(); - // Allows showing additional shared media links and tabs. - // Was done for top level tabs support. - // - //setupOtherTypes(); } // Allows showing additional shared media links and tabs. // Was done for top level tabs support. -// -//void InnerWidget::setupOtherTypes() { -// _controller->wrapValue() -// | rpl::start_with_next([this](Wrap value) { -// if (value == Wrap::Side -// && !_controller->hasStackHistory() -// && TypeToTabIndex(type())) { -// createOtherTypes(); -// } else { -// _otherTabs = nullptr; -// _otherTypes.destroy(); -// refreshHeight(); -// } -// }, lifetime()); -// rpl::combine( -// _controller->wrapValue(), -// _controller->searchEnabledByContent()) -// | rpl::start_with_next([this](Wrap wrap, bool enabled) { -// _searchEnabled = enabled; -// refreshSearchField(); -// }, lifetime()); -//} -// -//void InnerWidget::createOtherTypes() { -// _otherTabsShadow.create(this); -// _otherTabsShadow->show(); -// -// _otherTabs = nullptr; -// _otherTypes.create(this); -// _otherTypes->show(); -// -// createTypeButtons(); -// _otherTypes->add(object_ptr(_otherTypes)); -// createTabs(); -// -// _otherTypes->heightValue() -// | rpl::start_with_next( -// [this] { refreshHeight(); }, -// _otherTypes->lifetime()); -//} -// -//void InnerWidget::createTypeButtons() { -// auto wrap = _otherTypes->add(object_ptr>( -// _otherTypes, -// object_ptr(_otherTypes))); -// auto content = wrap->entity(); -// content->add(object_ptr( -// content, -// st::infoProfileSkip)); -// -// auto tracker = Ui::MultiSlideTracker(); -// auto addMediaButton = [&]( -// Type type, -// const style::icon &icon) { -// auto result = AddButton( -// content, -// _controller, -// _controller->peer(), -// _controller->migrated(), -// type, -// tracker); -// object_ptr( -// result, -// icon, -// st::infoSharedMediaButtonIconPosition); -// }; -// auto addCommonGroupsButton = [&]( -// not_null user, -// const style::icon &icon) { -// auto result = AddCommonGroupsButton( -// content, -// _controller, -// user, -// tracker); -// object_ptr( -// result, -// icon, -// st::infoSharedMediaButtonIconPosition); -// }; -// -// addMediaButton(Type::MusicFile, st::infoIconMediaAudio); -// addMediaButton(Type::Link, st::infoIconMediaLink); -// if (auto user = _controller->peer()->asUser()) { +// Now used for shared media in Saved Messages. +void InnerWidget::setupOtherTypes() { + if (_controller->peer()->isSelf() && _isStackBottom) { + createOtherTypes(); + } else { + _otherTypes.destroy(); + refreshHeight(); + } + //rpl::combine( + // _controller->wrapValue(), + // _controller->searchEnabledByContent()) + // | rpl::start_with_next([this](Wrap wrap, bool enabled) { + // _searchEnabled = enabled; + // refreshSearchField(); + // }, lifetime()); +} + +void InnerWidget::createOtherTypes() { + //_otherTabsShadow.create(this); + //_otherTabsShadow->show(); + + //_otherTabs = nullptr; + _otherTypes.create(this); + _otherTypes->show(); + + createTypeButtons(); + _otherTypes->add(object_ptr(_otherTypes)); + //createTabs(); + + _otherTypes->resizeToWidth(width()); + _otherTypes->heightValue() + | rpl::start_with_next( + [this] { refreshHeight(); }, + _otherTypes->lifetime()); +} + +void InnerWidget::createTypeButtons() { + auto wrap = _otherTypes->add(object_ptr>( + _otherTypes, + object_ptr(_otherTypes))); + auto content = wrap->entity(); + content->add(object_ptr( + content, + st::infoProfileSkip)); + + auto tracker = Ui::MultiSlideTracker(); + auto addMediaButton = [&]( + Type buttonType, + const style::icon &icon) { + if (buttonType == type()) { + return; + } + auto result = AddButton( + content, + _controller, + _controller->peer(), + _controller->migrated(), + buttonType, + tracker); + object_ptr( + result, + icon, + st::infoSharedMediaButtonIconPosition)->show(); + }; + //auto addCommonGroupsButton = [&]( + // not_null user, + // const style::icon &icon) { + // auto result = AddCommonGroupsButton( + // content, + // _controller, + // user, + // tracker); + // object_ptr( + // result, + // icon, + // st::infoSharedMediaButtonIconPosition)->show(); + //}; + + addMediaButton(Type::Photo, st::infoIconMediaPhoto); + addMediaButton(Type::Video, st::infoIconMediaVideo); + addMediaButton(Type::File, st::infoIconMediaFile); + addMediaButton(Type::MusicFile, st::infoIconMediaAudio); + addMediaButton(Type::Link, st::infoIconMediaLink); + if (auto user = _controller->peer()->asUser()) { // addCommonGroupsButton(user, st::infoIconMediaGroup); -// } -// addMediaButton(Type::VoiceFile, st::infoIconMediaVoice); -//// addMediaButton(Type::RoundFile, st::infoIconMediaRound); -// -// content->add(object_ptr( -// content, -// st::infoProfileSkip)); -// wrap->toggleOn(tracker.atLeastOneShownValue()); -// wrap->finishAnimating(); -//} -// + } + addMediaButton(Type::VoiceFile, st::infoIconMediaVoice); +// addMediaButton(Type::RoundFile, st::infoIconMediaRound); + + content->add(object_ptr( + content, + st::infoProfileSkip)); + wrap->toggleOn(tracker.atLeastOneShownValue()); + wrap->finishAnimating(); +} + //void InnerWidget::createTabs() { // _otherTabs = _otherTypes->add(object_ptr( // this, @@ -305,10 +302,10 @@ int InnerWidget::resizeGetHeight(int newWidth) { _inResize = true; auto guard = gsl::finally([this] { _inResize = false; }); - //if (_otherTypes) { - // _otherTypes->resizeToWidth(newWidth); - // _otherTabsShadow->resizeToWidth(newWidth); - //} + if (_otherTypes) { + _otherTypes->resizeToWidth(newWidth); + //_otherTabsShadow->resizeToWidth(newWidth); + } //if (_searchField) { // _searchField->resizeToWidth(newWidth); //} @@ -326,11 +323,11 @@ void InnerWidget::refreshHeight() { int InnerWidget::recountHeight() { auto top = 0; - //if (_otherTypes) { - // _otherTypes->moveToLeft(0, top); - // top += _otherTypes->heightNoMargins() - st::lineWidth; - // _otherTabsShadow->moveToLeft(0, top); - //} + if (_otherTypes) { + _otherTypes->moveToLeft(0, top); + top += _otherTypes->heightNoMargins() - st::lineWidth; +// _otherTabsShadow->moveToLeft(0, top); + } //if (_searchField) { // _searchField->moveToLeft(0, top); // top += _searchField->heightNoMargins() - st::lineWidth; diff --git a/Telegram/SourceFiles/info/media/info_media_inner_widget.h b/Telegram/SourceFiles/info/media/info_media_inner_widget.h index d6f392ffbb..81c5d21b11 100644 --- a/Telegram/SourceFiles/info/media/info_media_inner_widget.h +++ b/Telegram/SourceFiles/info/media/info_media_inner_widget.h @@ -49,6 +49,10 @@ public: not_null controller); bool showInternal(not_null memento); + void setIsStackBottom(bool isStackBottom) { + _isStackBottom = isStackBottom; + setupOtherTypes(); + } void saveState(not_null memento); void restoreState(not_null memento); @@ -72,10 +76,13 @@ private: void refreshHeight(); // Allows showing additional shared media links and tabs. // Was done for top level tabs support. + // Now used for shared media in Saved Messages. + void setupOtherTypes(); + void createOtherTypes(); + void createTypeButtons(); + // Allows showing additional shared media links and tabs. + // Was done for top level tabs support. // - //void setupOtherTypes(); - //void createOtherTypes(); - //void createTypeButtons(); //void createTabs(); //void switchToTab(Memento &&memento); //void refreshSearchField(); @@ -88,7 +95,7 @@ private: const not_null _controller; //Ui::SettingsSlider *_otherTabs = nullptr; - //object_ptr _otherTypes = { nullptr }; + object_ptr _otherTypes = { nullptr }; //object_ptr _otherTabsShadow = { nullptr }; //base::unique_qptr _searchField = nullptr; object_ptr _list = { nullptr }; @@ -96,6 +103,7 @@ private: //bool _searchEnabled = false; bool _inResize = false; + bool _isStackBottom = false; rpl::event_stream _scrollToRequests; rpl::event_stream> _selectedLists; diff --git a/Telegram/SourceFiles/info/media/info_media_widget.cpp b/Telegram/SourceFiles/info/media/info_media_widget.cpp index 393fd5ee60..7a805bab86 100644 --- a/Telegram/SourceFiles/info/media/info_media_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_widget.cpp @@ -102,6 +102,10 @@ void Widget::cancelSelection() { _inner->cancelSelection(); } +void Widget::setIsStackBottom(bool isStackBottom) { + _inner->setIsStackBottom(isStackBottom); +} + bool Widget::showInternal(not_null memento) { if (!controller()->validateMementoPeer(memento)) { return false; diff --git a/Telegram/SourceFiles/info/media/info_media_widget.h b/Telegram/SourceFiles/info/media/info_media_widget.h index c5bbe0ca9e..edae6c4b57 100644 --- a/Telegram/SourceFiles/info/media/info_media_widget.h +++ b/Telegram/SourceFiles/info/media/info_media_widget.h @@ -100,6 +100,8 @@ public: QWidget *parent, not_null controller); + void setIsStackBottom(bool isStackBottom) override; + bool showInternal( not_null memento) override;