Slightly improved process of switching between chats filters view types.

This commit is contained in:
23rd 2024-11-04 16:28:06 +03:00
parent 81aef519d4
commit ba0da9f59e
10 changed files with 65 additions and 62 deletions

View file

@ -1640,8 +1640,8 @@ bool Settings::chatFiltersHorizontal() const {
return _chatFiltersHorizontal.current();
}
rpl::producer<bool> Settings::chatFiltersHorizontalValue() const {
return _chatFiltersHorizontal.value();
rpl::producer<bool> Settings::chatFiltersHorizontalChanges() const {
return _chatFiltersHorizontal.changes();
}
void Settings::setChatFiltersHorizontal(bool value) {

View file

@ -930,7 +930,7 @@ public:
void setIvZoom(int value);
[[nodiscard]] bool chatFiltersHorizontal() const;
[[nodiscard]] rpl::producer<bool> chatFiltersHorizontalValue() const;
[[nodiscard]] rpl::producer<bool> chatFiltersHorizontalChanges() const;
void setChatFiltersHorizontal(bool value);
[[nodiscard]] Media::VideoQuality videoQuality() const;

View file

@ -652,41 +652,10 @@ Widget::Widget(
setupDownloadBar();
}
session().data().chatsFilters().changed(
) | rpl::start_with_next([=] {
if (!session().data().chatsFilters().loaded()) {
return;
}
if (session().data().chatsFilters().has()) {
if (_chatFilters) {
return;
}
_chatFilters = Ui::AddChatFiltersTabsStrip(
this,
&session(),
rpl::single(0),
[=](int h) { updateControlsGeometry(); },
[=](FilterId id) { controller->setActiveChatsFilter(id); },
Core::App().settings().chatFiltersHorizontalValue(),
true);
_chatFilters->stackUnder(_scroll);
_chatFilters->resizeToWidth(width());
updateControlsGeometry();
const auto shadow = Ui::CreateChild<Ui::PlainShadow>(
_chatFilters);
shadow->show();
_chatFilters->sizeValue(
) | rpl::start_with_next([=](const QSize &size) {
shadow->setGeometry(
0,
size.height() - shadow->height(),
size.width(),
shadow->height());
}, lifetime());
} else {
_chatFilters = nullptr;
}
}, lifetime());
if (session().settings().dialogsFiltersEnabled()
&& Core::App().settings().chatFiltersHorizontal()) {
toggleFiltersMenu(true);
}
}
void Widget::chosenRow(const ChosenRow &row) {
@ -1331,6 +1300,42 @@ void Widget::updateHasFocus(not_null<QWidget*> focused) {
}
}
void Widget::toggleFiltersMenu(bool enabled) {
if (!enabled == !_chatFilters) {
return;
} else if (enabled) {
_chatFilters = base::make_unique_q<Ui::RpWidget>(this);
const auto raw = _chatFilters.get();
const auto inner = Ui::AddChatFiltersTabsStrip(
_chatFilters.get(),
&session(),
rpl::single(0),
[this](int h) { updateControlsGeometry(); },
[this](FilterId id) {
if (controller()->activeChatsFilterCurrent() != id) {
controller()->setActiveChatsFilter(id);
}
},
true);
raw->show();
raw->stackUnder(_scroll);
raw->resizeToWidth(width());
const auto shadow = Ui::CreateChild<Ui::PlainShadow>(raw);
shadow->show();
inner->sizeValue() | rpl::start_with_next([=](const QSize &s) {
raw->resize(s);
shadow->setGeometry(
0,
s.height() - shadow->height(),
s.width(),
shadow->height());
}, _chatFilters->lifetime());
updateControlsGeometry();
} else {
_chatFilters = nullptr;
}
}
bool Widget::cancelSearchByMouseBack() {
return _searchHasFocus
&& !_searchSuggestionsLocked

View file

@ -129,6 +129,7 @@ public:
[[nodiscard]] RowDescriptor resolveChatNext(RowDescriptor from = {}) const;
[[nodiscard]] RowDescriptor resolveChatPrevious(RowDescriptor from = {}) const;
void updateHasFocus(not_null<QWidget*> focused);
void toggleFiltersMenu(bool value);
// Float player interface.
bool floatPlayerHandleWheelEvent(QEvent *e) override;
@ -317,6 +318,8 @@ private:
std::unique_ptr<Ui::RequestsBar> _forumRequestsBar;
std::unique_ptr<HistoryView::ContactStatus> _forumReportBar;
base::unique_qptr<Ui::RpWidget> _chatFilters;
object_ptr<Ui::ElasticScroll> _scroll;
QPointer<InnerWidget> _inner;
std::unique_ptr<Suggestions> _suggestions;
@ -390,8 +393,6 @@ private:
QPixmap _widthAnimationCache;
Ui::RpWidget *_chatFilters = nullptr;
int _topDelta = 0;
std::unique_ptr<Widget> _childList;

View file

@ -1098,6 +1098,12 @@ void MainWidget::dialogsCancelled() {
_history->activate();
}
void MainWidget::toggleFiltersMenu(bool value) const {
if (_dialogs) {
_dialogs->toggleFiltersMenu(value);
}
}
void MainWidget::setChatBackground(
const Data::WallPaper &background,
QImage &&image) {

View file

@ -213,6 +213,7 @@ public:
void showNonPremiumLimitToast(bool download);
void dialogsCancelled();
void toggleFiltersMenu(bool value) const;
private:
void paintEvent(QPaintEvent *e) override;

View file

@ -40,7 +40,6 @@ struct State final {
std::optional<FilterId> lastFilterId = std::nullopt;
rpl::lifetime unreadLifetime;
base::unique_qptr<Ui::PopupMenu> menu;
rpl::variable<bool> additionalToggleOn;
Api::RemoveComplexChatFilter removeApi;
bool waitingSuggested = false;
@ -130,7 +129,6 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
rpl::producer<int> multiSelectHeightValue,
Fn<void(int)> setAddedTopScrollSkip,
Fn<void(FilterId)> choose,
rpl::producer<bool> additionalToggleOn,
bool trackActiveChatsFilter) {
const auto window = Core::App().findWindow(parent);
const auto controller = window ? window->sessionController() : nullptr;
@ -151,7 +149,6 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
object_ptr<Ui::ChatsFiltersTabs>(parent, st::dialogsSearchTabs),
QMargins(sliderPadding, 0, sliderPadding, 0)))->entity();
const auto state = wrap->lifetime().make_state<State>();
state->additionalToggleOn = std::move(additionalToggleOn);
wrap->toggle(false, anim::type::instant);
container->sizeValue() | rpl::start_with_next([=](const QSize &s) {
scroll->resize(s + QSize(0, scrollSt.deltax * 4));
@ -289,10 +286,7 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
slider->contextMenuRequested() | rpl::start_with_next([=](int index) {
ShowMenu(wrap, controller, state, index);
}, slider->lifetime());
state->additionalToggleOn.value(
) | rpl::start_with_next([=](bool enabled) {
wrap->toggle(enabled && (list.size() > 1), anim::type::instant);
}, wrap->lifetime());
wrap->toggle((list.size() > 1), anim::type::instant);
};
session->data().chatsFilters().changed(
) | rpl::start_with_next(rebuild, wrap->lifetime());

View file

@ -23,7 +23,6 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
rpl::producer<int> multiSelectHeightValue,
Fn<void(int)> setAddedTopScrollSkip,
Fn<void(FilterId)> choose,
rpl::producer<bool> additionalToggleOn = rpl::single(true),
bool trackActiveChatsFilter = false);
} // namespace Ui

View file

@ -1315,17 +1315,20 @@ SessionController::SessionController(
}, lifetime());
rpl::merge(
session->data().chatsFilters().changed() | rpl::filter([=] {
return session->data().chatsFilters().loaded();
}) | rpl::map([] {
return Core::App().settings().chatFiltersHorizontalValue(
) | rpl::to_empty;
}) | rpl::flatten_latest(),
Core::App().settings().chatFiltersHorizontalChanges() | rpl::to_empty,
session->data().chatsFilters().changed()
) | rpl::start_with_next([=] {
checkOpenedFilter();
crl::on_main(this, [=] {
refreshFiltersMenu();
crl::on_main(this, [this] {
if (SessionNavigation::session().data().chatsFilters().has()) {
const auto isHorizontal
= Core::App().settings().chatFiltersHorizontal();
content()->toggleFiltersMenu(isHorizontal);
toggleFiltersMenu(!isHorizontal);
} else {
content()->toggleFiltersMenu(false);
toggleFiltersMenu(false);
}
});
}, lifetime());
@ -1556,11 +1559,6 @@ void SessionController::toggleFiltersMenu(bool enabled) {
_filtersMenuChanged.fire({});
}
void SessionController::refreshFiltersMenu() {
toggleFiltersMenu(session().data().chatsFilters().has()
&& !Core::App().settings().chatFiltersHorizontal());
}
rpl::producer<> SessionController::filtersMenuChanged() const {
return _filtersMenuChanged.events();
}

View file

@ -630,7 +630,6 @@ private:
void init();
void setupShortcuts();
void refreshFiltersMenu();
void checkOpenedFilter();
void suggestArchiveAndMute();
void activateFirstChatsFilter();