diff --git a/map/framework.cpp b/map/framework.cpp index a3b0124706..cb7f97dffb 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -255,6 +255,11 @@ LocalAdsManager & Framework::GetLocalAdsManager() return m_localAdsManager; } +TransitReadManager & Framework::GetTransitManager() +{ + return m_transitManager; +} + void Framework::OnUserPositionChanged(m2::PointD const & position, bool hasPosition) { GetBookmarkManager().MyPositionMark().SetUserPosition(position, hasPosition); @@ -1775,6 +1780,9 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, InvalidateUserMarks(); + bool const transitSchemeEnabled = LoadTransitSchemeEnabled(); + m_transitManager.EnableTransitSchemeMode(transitSchemeEnabled); + benchmark::RunGraphicsBenchmark(this); } @@ -2538,15 +2546,13 @@ void Framework::SaveAutoZoom(bool allowAutoZoom) void Framework::EnableTransitScheme(bool enable) { m_transitManager.EnableTransitSchemeMode(enable); - if (m_drapeEngine != nullptr) - m_drapeEngine->EnableTransitScheme(enable); } bool Framework::LoadTransitSchemeEnabled() { bool enabled; if (!settings::Get(kTransitSchemeEnabledKey, enabled)) - enabled = true; + enabled = false; return enabled; } diff --git a/map/framework.hpp b/map/framework.hpp index 662a1ce512..24f6f0233c 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -747,13 +747,17 @@ public: LocalAdsManager & GetLocalAdsManager(); + TransitReadManager & GetTransitManager(); + bool LoadTrafficEnabled(); void SaveTrafficEnabled(bool trafficEnabled); bool LoadTrafficSimplifiedColors(); void SaveTrafficSimplifiedColors(bool simplified); + // TODO: Enable transit scheme via transit manager. void EnableTransitScheme(bool enable); + bool LoadTransitSchemeEnabled(); void SaveTransitSchemeEnabled(bool enabled); diff --git a/map/transit/transit_reader.cpp b/map/transit/transit_reader.cpp index 393c733e4a..6c039ca436 100644 --- a/map/transit/transit_reader.cpp +++ b/map/transit/transit_reader.cpp @@ -176,6 +176,7 @@ void TransitReadManager::SetDrapeEngine(ref_ptr engine) void TransitReadManager::EnableTransitSchemeMode(bool enable) { + ChangeState(enable ? TransitSchemeState::Enabled : TransitSchemeState::Disabled); if (m_isSchemeMode == enable) return; m_isSchemeMode = enable; @@ -190,6 +191,7 @@ void TransitReadManager::EnableTransitSchemeMode(bool enable) { Invalidate(); } + m_drapeEngine.SafeCall(&df::DrapeEngine::EnableTransitScheme, enable); } void TransitReadManager::UpdateViewport(ScreenBase const & screen) @@ -242,9 +244,19 @@ void TransitReadManager::UpdateViewport(ScreenBase const & screen) } } ShrinkCacheToAllowableSize(); - m_drapeEngine.SafeCall(&df::DrapeEngine::UpdateTransitScheme, - std::move(displayInfos), mwms); + m_drapeEngine.SafeCall(&df::DrapeEngine::UpdateTransitScheme, std::move(displayInfos), mwms); } + + bool hasData = false; + for (auto const & mwmId : m_lastActiveMwms) + { + if (m_mwmCache.at(mwmId).m_isLoaded) + { + hasData = true; + break; + } + } + ChangeState(hasData ? TransitSchemeState::Enabled : TransitSchemeState::NoData); } void TransitReadManager::ClearCache(MwmSet::MwmId const & mwmId) @@ -260,6 +272,7 @@ void TransitReadManager::ClearCache(MwmSet::MwmId const & mwmId) void TransitReadManager::OnMwmDeregistered(MwmSet::MwmId const & mwmId) { ClearCache(mwmId); + Invalidate(); } void TransitReadManager::Invalidate() @@ -343,3 +356,17 @@ void TransitReadManager::OnTaskCompleted(threads::IRoutine * task) if (--m_tasksGroups[t->GetId()] == 0) m_event.notify_all(); } + +void TransitReadManager::SetStateListener(TransitStateChangedFn const & onStateChangedFn) +{ + m_onStateChangedFn = onStateChangedFn; +} + +void TransitReadManager::ChangeState(TransitSchemeState newState) +{ + if (m_state == newState) + return; + m_state = newState; + if (m_onStateChangedFn) + m_onStateChangedFn(newState); +} diff --git a/map/transit/transit_reader.hpp b/map/transit/transit_reader.hpp index 5644763b58..2df70dda9d 100644 --- a/map/transit/transit_reader.hpp +++ b/map/transit/transit_reader.hpp @@ -80,8 +80,15 @@ private: class TransitReadManager { public: - using GetMwmsByRectFn = function(m2::RectD const &)>; + enum class TransitSchemeState + { + Disabled, + Enabled, + NoData, + }; + using GetMwmsByRectFn = function(m2::RectD const &)>; + using TransitStateChangedFn = function; TransitReadManager(DataSourceBase & dataSource, TReadFeaturesFn const & readFeaturesFn, GetMwmsByRectFn const & getMwmsByRectFn); @@ -91,6 +98,7 @@ public: void Stop(); void SetDrapeEngine(ref_ptr engine); + void SetStateListener(TransitStateChangedFn const & onStateChangedFn); bool GetTransitDisplayInfo(TransitDisplayInfos & transitDisplayInfos); @@ -102,6 +110,7 @@ public: private: void OnTaskCompleted(threads::IRoutine * task); + void ChangeState(TransitSchemeState newState); void ShrinkCacheToAllowableSize(); void ClearCache(MwmSet::MwmId const & mwmId); @@ -118,6 +127,9 @@ private: df::DrapeEngineSafePtr m_drapeEngine; + TransitSchemeState m_state = TransitSchemeState::Disabled; + TransitStateChangedFn m_onStateChangedFn; + struct CacheEntry { CacheEntry(std::chrono::time_point const & activeTime)