Handle last suggestion being added.

This commit is contained in:
John Preston 2020-03-10 16:51:23 +04:00
parent b8c11f3d8c
commit 2fb2fa9661
1 changed files with 44 additions and 30 deletions

View File

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/wrap/slide_wrap.h"
#include "settings/settings_common.h" #include "settings/settings_common.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "apiwrap.h" #include "apiwrap.h"
@ -297,7 +298,7 @@ void ManageFiltersPrepare::showBoxWithSuggested() {
void ManageFiltersPrepare::CreateBox( void ManageFiltersPrepare::CreateBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> window, not_null<Window::SessionController*> window,
const std::vector<Suggested> &suggested) { const std::vector<Suggested> &suggestions) {
struct FilterRow { struct FilterRow {
not_null<FilterRowButton*> button; not_null<FilterRowButton*> button;
Data::ChatFilter filter; Data::ChatFilter filter;
@ -349,19 +350,27 @@ void ManageFiltersPrepare::CreateBox(
tr::lng_filters_create() | Ui::Text::ToUpper(), tr::lng_filters_create() | Ui::Text::ToUpper(),
st::settingsUpdate); st::settingsUpdate);
Settings::AddSkip(content); Settings::AddSkip(content);
if (suggested.empty()) { const auto emptyAbout = content->add(
content->add( object_ptr<Ui::SlideWrap<Ui::FlatLabel>>(
content,
object_ptr<Ui::FlatLabel>( object_ptr<Ui::FlatLabel>(
content, content,
tr::lng_filters_about(), tr::lng_filters_about(),
st::boxDividerLabel), st::boxDividerLabel),
st::settingsDividerLabelPadding); st::settingsDividerLabelPadding)
} else { )->setDuration(0);
Settings::AddDividerText(content, tr::lng_filters_about()); const auto nonEmptyAbout = content->add(
Settings::AddSkip(content); object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
Settings::AddSubsectionTitle(content, tr::lng_filters_recommended()); content,
object_ptr<Ui::VerticalLayout>(content))
)->setDuration(0);
const auto aboutRows = nonEmptyAbout->entity();
Settings::AddDividerText(aboutRows, tr::lng_filters_about());
Settings::AddSkip(aboutRows);
Settings::AddSubsectionTitle(aboutRows, tr::lng_filters_recommended());
for (const auto &suggestion : suggested) { const auto suggested = box->lifetime().make_state<rpl::variable<int>>();
for (const auto &suggestion : suggestions) {
const auto filter = suggestion.filter; const auto filter = suggestion.filter;
const auto already = [&] { const auto already = [&] {
for (const auto &entry : list) { for (const auto &entry : list) {
@ -376,17 +385,22 @@ void ManageFiltersPrepare::CreateBox(
if (already) { if (already) {
continue; continue;
} }
const auto button = content->add(object_ptr<FilterRowButton>( *suggested = suggested->current() + 1;
content, const auto button = aboutRows->add(object_ptr<FilterRowButton>(
aboutRows,
filter, filter,
suggestion.description)); suggestion.description));
button->addRequests( button->addRequests(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
addFilter(filter); addFilter(filter);
*suggested = suggested->current() - 1;
delete button; delete button;
}, button->lifetime()); }, button->lifetime());
} }
}
using namespace rpl::mappers;
emptyAbout->toggleOn(suggested->value() | rpl::map(_1 == 0));
nonEmptyAbout->toggleOn(suggested->value() | rpl::map(_1 > 0));
const auto prepareGoodIdsForNewFilters = [=] { const auto prepareGoodIdsForNewFilters = [=] {
const auto &list = session->data().chatsFilters().list(); const auto &list = session->data().chatsFilters().list();