From 62e0ced6a6afc41fd5ade0436ad5a43cfcb37fe2 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 6 Feb 2020 00:39:58 +0300 Subject: [PATCH] Imporved computing state of buttons in dictionaries manager. --- .../boxes/dictionaries_manager.cpp | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/boxes/dictionaries_manager.cpp b/Telegram/SourceFiles/boxes/dictionaries_manager.cpp index 2ab0dbe7a9..3d1cc444bf 100644 --- a/Telegram/SourceFiles/boxes/dictionaries_manager.cpp +++ b/Telegram/SourceFiles/boxes/dictionaries_manager.cpp @@ -80,11 +80,14 @@ MTP::DedicatedLoader::Location GetDownloadLocation(int id) { return MTP::DedicatedLoader::Location{ username, i->postId }; } -DictState ComputeState(int id) { - // if (id == CurrentSetId()) { - // return Active(); - if (Spellchecker::DictionaryExists(id)) { - return Ready(); +inline auto DictExists(int langId) { + return Spellchecker::DictionaryExists(langId); +} + +DictState ComputeState(int id, bool enabled) { + const auto result = enabled ? DictState(Active()) : DictState(Ready()); + if (DictExists(id)) { + return result; } return Available{ GetDownloadSize(id) }; } @@ -210,14 +213,7 @@ auto AddButtonWithLoader( ) | rpl::then( button->toggledValue() ) | rpl::map([=](auto enabled) { - const auto &state = buttonState->current(); - if (enabled && state.is()) { - return DictState(Active()); - } - if (!enabled && state.is()) { - return DictState(Ready()); - } - return ComputeState(id); + return ComputeState(id, enabled); }); }) | rpl::flatten_latest( ) | rpl::filter([=](const DictState &state) { @@ -255,7 +251,7 @@ void Inner::setupContent(Dictionaries enabledDictionaries) { ranges::contains(enabledDictionaries, set.id)); row->toggledValue( ) | rpl::start_with_next([=](auto enabled) { - if (enabled && Spellchecker::DictionaryExists(set.id)) { + if (enabled && DictExists(set.id)) { _enabledRows.push_back(set.id); } else { auto &rows = _enabledRows;