diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp index ad1f896fc..03af31483 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp @@ -127,6 +127,7 @@ private: void setupHandler(); void load(); void radialAnimationCallback(crl::time now); + void updateLoadingToFinished(); int _id = 0; bool _switching = false; @@ -152,6 +153,12 @@ int GetDownloadSize(int id) { return ranges::find(sets, id, &Set::id)->size; } +[[nodiscard]] float64 CountProgress(not_null loading) { + return (loading->size > 0) + ? (loading->already / float64(loading->size)) + : 0.; +} + MTP::DedicatedLoader::Location GetDownloadLocation(int id) { constexpr auto kUsername = "tdhbcfiles"; const auto sets = Sets(); @@ -379,6 +386,9 @@ void Row::paintPreview(Painter &p) const { } void Row::paintRadio(Painter &p) { + if (_loading && !_loading->animating()) { + _loading = nullptr; + } const auto loading = _loading ? _loading->computeState() : Ui::RadialState{ 0., 0, FullArcLength }; @@ -580,14 +590,20 @@ void Row::setupPreview(const Set &set) { } } +void Row::updateLoadingToFinished() { + _loading->update( + _state.current().is() ? 0. : 1., + true, + crl::now()); +} + void Row::radialAnimationCallback(crl::time now) { const auto updated = [&] { const auto state = _state.current(); if (const auto loading = base::get_if(&state)) { - const auto progress = (loading->size > 0) - ? (loading->already / float64(loading->size)) - : 0.; - return _loading->update(progress, false, now); + return _loading->update(CountProgress(loading), false, now); + } else { + updateLoadingToFinished(); } return false; }(); @@ -636,15 +652,9 @@ void Row::setupAnimation() { if (loading && !_loading) { _loading = std::make_unique( [=](crl::time now) { radialAnimationCallback(now); }); - const auto progress = (loading->size > 0) - ? (loading->already / float64(loading->size)) - : 0.; - _loading->start(progress); + _loading->start(CountProgress(loading)); } else if (!loading && _loading) { - _loading->update( - _state.current().is() ? 0. : 1., - true, - crl::now()); + updateLoadingToFinished(); } }, lifetime());