Return third section when returning in main section.

This commit is contained in:
John Preston 2017-10-03 19:13:36 +01:00
parent 76b8078bd9
commit c0bb8a8af7
2 changed files with 136 additions and 82 deletions

View File

@ -107,11 +107,104 @@ MTPMessagesFilter TypeToMediaFilter(MediaOverviewType &type) {
} // namespace } // namespace
StackItemSection::StackItemSection(std::unique_ptr<Window::SectionMemento> &&memento) : StackItem(nullptr) enum StackItemType {
, _memento(std::move(memento)) { HistoryStackItem,
SectionStackItem,
OverviewStackItem,
};
class StackItem {
public:
StackItem(PeerData *peer) : _peer(peer) {
} }
StackItemSection::~StackItemSection() { PeerData *peer() const {
return _peer;
}
void setThirdSectionMemento(
std::unique_ptr<Window::SectionMemento> &&memento);
Window::SectionMemento *thirdSectionMemento() const {
return _thirdSectionMemento.get();
}
virtual StackItemType type() const = 0;
virtual ~StackItem() = default;
private:
PeerData *_peer = nullptr;
std::unique_ptr<Window::SectionMemento> _thirdSectionMemento;
};
class StackItemHistory : public StackItem {
public:
StackItemHistory(
PeerData *peer,
MsgId msgId,
QList<MsgId> replyReturns)
: StackItem(peer)
, msgId(msgId)
, replyReturns(replyReturns) {
}
StackItemType type() const override {
return HistoryStackItem;
}
MsgId msgId;
QList<MsgId> replyReturns;
};
class StackItemSection : public StackItem {
public:
StackItemSection(
std::unique_ptr<Window::SectionMemento> &&memento);
StackItemType type() const override {
return SectionStackItem;
}
Window::SectionMemento *memento() const {
return _memento.get();
}
private:
std::unique_ptr<Window::SectionMemento> _memento;
};
class StackItemOverview : public StackItem {
public:
StackItemOverview(
PeerData *peer,
MediaOverviewType mediaType,
int32 lastWidth,
int32 lastScrollTop)
: StackItem(peer)
, mediaType(mediaType)
, lastWidth(lastWidth)
, lastScrollTop(lastScrollTop) {
}
StackItemType type() const {
return OverviewStackItem;
}
MediaOverviewType mediaType;
int32 lastWidth, lastScrollTop;
};
void StackItem::setThirdSectionMemento(
std::unique_ptr<Window::SectionMemento> &&memento) {
_thirdSectionMemento = std::move(memento);
}
StackItemSection::StackItemSection(
std::unique_ptr<Window::SectionMemento> &&memento)
: StackItem(nullptr)
, _memento(std::move(memento)) {
} }
template <typename ToggleCallback, typename DraggedCallback> template <typename ToggleCallback, typename DraggedCallback>
@ -2487,15 +2580,15 @@ void MainWidget::ui_showPeerHistory(
bool foundInStack = !peerId; bool foundInStack = !peerId;
if (foundInStack || (way == Way::ClearStack)) { if (foundInStack || (way == Way::ClearStack)) {
for_const (auto &item, _stack) { for_const (auto &item, _stack) {
clearBotStartToken(item->peer); clearBotStartToken(item->peer());
} }
_stack.clear(); _stack.clear();
} else { } else {
for (auto i = 0, s = int(_stack.size()); i < s; ++i) { for (auto i = 0, s = int(_stack.size()); i < s; ++i) {
if (_stack.at(i)->type() == HistoryStackItem && _stack.at(i)->peer->id == peerId) { if (_stack.at(i)->type() == HistoryStackItem && _stack.at(i)->peer()->id == peerId) {
foundInStack = true; foundInStack = true;
while (int(_stack.size()) > i + 1) { while (int(_stack.size()) > i + 1) {
clearBotStartToken(_stack.back()->peer); clearBotStartToken(_stack.back()->peer());
_stack.pop_back(); _stack.pop_back();
} }
_stack.pop_back(); _stack.pop_back();
@ -3095,7 +3188,7 @@ void MainWidget::showBackFromStack(
for (auto i = _stack.size(); i > 0;) { for (auto i = _stack.size(); i > 0;) {
if (_stack[--i]->type() == HistoryStackItem) { if (_stack[--i]->type() == HistoryStackItem) {
auto historyItem = static_cast<StackItemHistory*>(_stack[i].get()); auto historyItem = static_cast<StackItemHistory*>(_stack[i].get());
_peerInStack = historyItem->peer; _peerInStack = historyItem->peer();
_msgIdInStack = historyItem->msgId; _msgIdInStack = historyItem->msgId;
dlgUpdated(); dlgUpdated();
break; break;
@ -3103,10 +3196,10 @@ void MainWidget::showBackFromStack(
} }
auto historyItem = static_cast<StackItemHistory*>(item.get()); auto historyItem = static_cast<StackItemHistory*>(item.get());
_controller->showPeerHistory( _controller->showPeerHistory(
historyItem->peer->id, historyItem->peer()->id,
params.withWay(SectionShow::Way::Backward), params.withWay(SectionShow::Way::Backward),
ShowAtUnreadMsgId); ShowAtUnreadMsgId);
_history->setReplyReturns(historyItem->peer->id, historyItem->replyReturns); _history->setReplyReturns(historyItem->peer()->id, historyItem->replyReturns);
} else if (item->type() == SectionStackItem) { } else if (item->type() == SectionStackItem) {
auto sectionItem = static_cast<StackItemSection*>(item.get()); auto sectionItem = static_cast<StackItemSection*>(item.get());
showNewSection( showNewSection(
@ -3115,11 +3208,21 @@ void MainWidget::showBackFromStack(
} else if (item->type() == OverviewStackItem) { } else if (item->type() == OverviewStackItem) {
auto overviewItem = static_cast<StackItemOverview*>(item.get()); auto overviewItem = static_cast<StackItemOverview*>(item.get());
showMediaOverview( showMediaOverview(
overviewItem->peer, overviewItem->peer(),
overviewItem->mediaType, overviewItem->mediaType,
true, true,
overviewItem->lastScrollTop); overviewItem->lastScrollTop);
} }
if (auto memento = item->thirdSectionMemento()) {
if (_thirdSection) {
_controller->showSection(
std::move(*memento),
SectionShow(
SectionShow::Way::ClearStack,
anim::type::instant,
anim::activation::background));
}
}
} }
void MainWidget::orderWidgets() { void MainWidget::orderWidgets() {
@ -3560,21 +3663,35 @@ void MainWidget::updateDialogsWidthAnimated() {
void MainWidget::updateThirdColumnToCurrentPeer( void MainWidget::updateThirdColumnToCurrentPeer(
PeerData *peer, PeerData *peer,
bool canWrite) { bool canWrite) {
if (Adaptive::ThreeColumn() auto saveOldThirdSection = [&] {
&& Auth().data().tabbedSelectorSectionEnabled() if (!_stack.empty() && _thirdSection) {
&& peer) { _stack.back()->setThirdSectionMemento(
if (!canWrite) { _thirdSection->createMemento());
}
};
auto switchInfoFast = [&] {
saveOldThirdSection();
_controller->showPeerInfo( _controller->showPeerInfo(
peer, peer,
SectionShow( SectionShow(
SectionShow::Way::ClearStack, SectionShow::Way::ClearStack,
anim::type::instant, anim::type::instant,
anim::activation::background)); anim::activation::background));
};
auto switchTabbedFast = [&] {
saveOldThirdSection();
_history->pushTabbedSelectorToThirdSection();
};
if (Adaptive::ThreeColumn()
&& Auth().data().tabbedSelectorSectionEnabled()
&& peer) {
if (!canWrite) {
switchInfoFast();
Auth().data().setTabbedSelectorSectionEnabled(true); Auth().data().setTabbedSelectorSectionEnabled(true);
Auth().data().setTabbedReplacedWithInfo(true); Auth().data().setTabbedReplacedWithInfo(true);
} else if (Auth().data().tabbedReplacedWithInfo()) { } else if (Auth().data().tabbedReplacedWithInfo()) {
Auth().data().setTabbedReplacedWithInfo(false); Auth().data().setTabbedReplacedWithInfo(false);
_history->pushTabbedSelectorToThirdSection(); switchTabbedFast();
} }
} else { } else {
Auth().data().setTabbedReplacedWithInfo(false); Auth().data().setTabbedReplacedWithInfo(false);
@ -3583,12 +3700,7 @@ void MainWidget::updateThirdColumnToCurrentPeer(
_thirdShadow.destroy(); _thirdShadow.destroy();
} else if (Adaptive::ThreeColumn() } else if (Adaptive::ThreeColumn()
&& Auth().data().thirdSectionInfoEnabled()) { && Auth().data().thirdSectionInfoEnabled()) {
_controller->showPeerInfo( switchInfoFast();
peer,
SectionShow(
SectionShow::Way::ClearStack,
anim::type::instant,
anim::activation::background));
} }
} }
} }

View File

@ -74,65 +74,7 @@ class HistoryWidget;
class OverviewWidget; class OverviewWidget;
class HistoryHider; class HistoryHider;
enum StackItemType { class StackItem;
HistoryStackItem,
SectionStackItem,
OverviewStackItem,
};
class StackItem {
public:
StackItem(PeerData *peer) : peer(peer) {
}
virtual StackItemType type() const = 0;
virtual ~StackItem() {
}
PeerData *peer;
};
class StackItemHistory : public StackItem {
public:
StackItemHistory(PeerData *peer, MsgId msgId, QList<MsgId> replyReturns) : StackItem(peer)
, msgId(msgId)
, replyReturns(replyReturns) {
}
StackItemType type() const {
return HistoryStackItem;
}
MsgId msgId;
QList<MsgId> replyReturns;
};
class StackItemSection : public StackItem {
public:
StackItemSection(std::unique_ptr<Window::SectionMemento> &&memento);
~StackItemSection();
StackItemType type() const {
return SectionStackItem;
}
Window::SectionMemento *memento() const {
return _memento.get();
}
private:
std::unique_ptr<Window::SectionMemento> _memento;
};
class StackItemOverview : public StackItem {
public:
StackItemOverview(PeerData *peer, MediaOverviewType mediaType, int32 lastWidth, int32 lastScrollTop) : StackItem(peer)
, mediaType(mediaType)
, lastWidth(lastWidth)
, lastScrollTop(lastScrollTop) {
}
StackItemType type() const {
return OverviewStackItem;
}
MediaOverviewType mediaType;
int32 lastWidth, lastScrollTop;
};
enum SilentNotifiesStatus { enum SilentNotifiesStatus {
SilentNotifiesDontChange, SilentNotifiesDontChange,