mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Removed unnecessary rebuild of chats filters strip when order is same.
This commit is contained in:
parent
71efd95136
commit
ec83f4ae72
3 changed files with 33 additions and 8 deletions
|
@ -57,6 +57,26 @@ ChatsFiltersTabs::ChatsFiltersTabs(
|
||||||
Ui::DiscreteSlider::setSelectOnPress(false);
|
Ui::DiscreteSlider::setSelectOnPress(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChatsFiltersTabs::setSectionsAndCheckChanged(
|
||||||
|
std::vector<QString> &§ions) {
|
||||||
|
const auto &was = sectionsRef();
|
||||||
|
const auto changed = [&] {
|
||||||
|
if (was.size() != sections.size()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (auto i = 0; i < sections.size(); i++) {
|
||||||
|
if (was[i].label.toString() != sections[i]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}();
|
||||||
|
if (changed) {
|
||||||
|
Ui::DiscreteSlider::setSections(std::move(sections));
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
int ChatsFiltersTabs::centerOfSection(int section) const {
|
int ChatsFiltersTabs::centerOfSection(int section) const {
|
||||||
const auto widths = countSectionsWidths(0);
|
const auto widths = countSectionsWidths(0);
|
||||||
auto result = 0;
|
auto result = 0;
|
||||||
|
|
|
@ -27,6 +27,8 @@ public:
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
const style::SettingsSlider &st);
|
const style::SettingsSlider &st);
|
||||||
|
|
||||||
|
bool setSectionsAndCheckChanged(std::vector<QString> &§ions);
|
||||||
|
|
||||||
[[nodiscard]] int centerOfSection(int section) const;
|
[[nodiscard]] int centerOfSection(int section) const;
|
||||||
void fitWidthToSections();
|
void fitWidthToSections();
|
||||||
void setUnreadCount(int index, int unreadCount, bool muted);
|
void setUnreadCount(int index, int unreadCount, bool muted);
|
||||||
|
|
|
@ -293,15 +293,18 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
|
||||||
if ((list.size() <= 1 && !slider->width()) || state->ignoreRefresh) {
|
if ((list.size() <= 1 && !slider->width()) || state->ignoreRefresh) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const auto sectionsChanged = slider->setSectionsAndCheckChanged(
|
||||||
|
ranges::views::all(
|
||||||
|
list
|
||||||
|
) | ranges::views::transform([](const Data::ChatFilter &filter) {
|
||||||
|
return filter.title().isEmpty()
|
||||||
|
? tr::lng_filters_all_short(tr::now)
|
||||||
|
: filter.title();
|
||||||
|
}) | ranges::to_vector);
|
||||||
|
if (!sectionsChanged) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
state->rebuildLifetime.destroy();
|
state->rebuildLifetime.destroy();
|
||||||
auto sections = ranges::views::all(
|
|
||||||
list
|
|
||||||
) | ranges::views::transform([](const Data::ChatFilter &filter) {
|
|
||||||
return filter.title().isEmpty()
|
|
||||||
? tr::lng_filters_all_short(tr::now)
|
|
||||||
: filter.title();
|
|
||||||
}) | ranges::to_vector;
|
|
||||||
slider->setSections(std::move(sections));
|
|
||||||
slider->fitWidthToSections();
|
slider->fitWidthToSections();
|
||||||
{
|
{
|
||||||
const auto reorderAll = session->user()->isPremium();
|
const auto reorderAll = session->user()->isPremium();
|
||||||
|
|
Loading…
Add table
Reference in a new issue