From 2c9095792b519cd9b5781dccd78a57315571bb84 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Mon, 18 May 2015 12:04:58 +0300 Subject: [PATCH] Added reactions to country status buttons --- drape_frontend/drape_engine.cpp | 21 +++++++++++++++ drape_frontend/map_data_provider.cpp | 23 ++++++++++++++++- drape_frontend/map_data_provider.hpp | 13 +++++++++- drape_gui/country_status_helper.cpp | 6 +++++ drape_gui/country_status_helper.hpp | 1 + map/framework.cpp | 38 +++++++++++++++++++++++++++- map/framework.hpp | 8 ++++++ 7 files changed, 107 insertions(+), 3 deletions(-) diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index 6df64faff9..cc37072280 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -14,6 +14,23 @@ namespace df { +namespace +{ + +void ConnectDownloadFn(gui::CountryStatusHelper::EButtonType buttonType, MapDataProvider::TDownloadFn downloadFn) +{ + gui::DrapeGui & guiSubsystem = gui::DrapeGui::Instance(); + guiSubsystem.ConnectOnButtonPressedHandler(buttonType, [downloadFn, &guiSubsystem]() + { + storage::TIndex countryIndex = guiSubsystem.GetCountryStatusHelper().GetCountryIndex(); + ASSERT(countryIndex != storage::TIndex::INVALID, ()); + if (downloadFn != nullptr) + downloadFn(countryIndex); + }); +} + +} + DrapeEngine::DrapeEngine(Params const & params) : m_viewport(params.m_viewport) { @@ -33,6 +50,10 @@ DrapeEngine::DrapeEngine(Params const & params) guiSubsystem.SetLocalizator(bind(&StringsBundle::GetString, params.m_stringsBundle.get(), _1)); guiSubsystem.SetStorageAccessor(params.m_storageAccessor); + ConnectDownloadFn(gui::CountryStatusHelper::BUTTON_TYPE_MAP, params.m_model.GetDownloadMapHandler()); + ConnectDownloadFn(gui::CountryStatusHelper::BUTTON_TYPE_MAP_ROUTING, params.m_model.GetDownloadMapRoutingHandler()); + ConnectDownloadFn(gui::CountryStatusHelper::BUTTON_TRY_AGAIN, params.m_model.GetDownloadRetryHandler()); + m_textureManager = make_unique_dp(); m_threadCommutator = make_unique_dp(); diff --git a/drape_frontend/map_data_provider.cpp b/drape_frontend/map_data_provider.cpp index 28d5a2280e..340095a4e3 100644 --- a/drape_frontend/map_data_provider.cpp +++ b/drape_frontend/map_data_provider.cpp @@ -6,11 +6,17 @@ namespace df MapDataProvider::MapDataProvider(TReadIDsFn const & idsReader, TReadFeaturesFn const & featureReader, TResolveCountryFn const & countryResolver, - TIsCountryLoadedFn const & isCountryLoadedFn) + TIsCountryLoadedFn const & isCountryLoadedFn, + TDownloadFn const & downloadMapHandler, + TDownloadFn const & downloadMapRoutingHandler, + TDownloadFn const & downloadRetryHandler) : m_featureReader(featureReader) , m_idsReader(idsReader) , m_countryResolver(countryResolver) , m_isCountryLoadedFn(isCountryLoadedFn) + , m_downloadMapHandler(downloadMapHandler) + , m_downloadMapRoutingHandler(downloadMapRoutingHandler) + , m_downloadRetryHandler(downloadRetryHandler) { } @@ -34,4 +40,19 @@ MapDataProvider::TIsCountryLoadedFn const & MapDataProvider::GetIsCountryLoadedF return m_isCountryLoadedFn; } +MapDataProvider::TDownloadFn const & MapDataProvider::GetDownloadMapHandler() const +{ + return m_downloadMapHandler; +} + +MapDataProvider::TDownloadFn const & MapDataProvider::GetDownloadMapRoutingHandler() const +{ + return m_downloadMapRoutingHandler; +} + +MapDataProvider::TDownloadFn const & MapDataProvider::GetDownloadRetryHandler() const +{ + return m_downloadRetryHandler; +} + } diff --git a/drape_frontend/map_data_provider.hpp b/drape_frontend/map_data_provider.hpp index 142ae7353c..ddd20f06cc 100644 --- a/drape_frontend/map_data_provider.hpp +++ b/drape_frontend/map_data_provider.hpp @@ -19,11 +19,15 @@ public: using TReadIDsFn = function const & , m2::RectD const &, int)>; using TResolveCountryFn = function; using TIsCountryLoadedFn = function; + using TDownloadFn = function; MapDataProvider(TReadIDsFn const & idsReader, TReadFeaturesFn const & featureReader, TResolveCountryFn const & countryResolver, - TIsCountryLoadedFn const & isCountryLoadedFn); + TIsCountryLoadedFn const & isCountryLoadedFn, + TDownloadFn const & downloadMapHandler, + TDownloadFn const & downloadMapRoutingHandler, + TDownloadFn const & downloadRetryHandler); void ReadFeaturesID(TReadCallback const & fn, m2::RectD const & r, int scale) const; void ReadFeatures(TReadCallback const & fn, vector const & ids) const; @@ -31,11 +35,18 @@ public: storage::TIndex FindCountry(m2::PointF const & pt); TIsCountryLoadedFn const & GetIsCountryLoadedFn() const; + TDownloadFn const & GetDownloadMapHandler() const; + TDownloadFn const & GetDownloadMapRoutingHandler() const; + TDownloadFn const & GetDownloadRetryHandler() const; + private: TReadFeaturesFn m_featureReader; TReadIDsFn m_idsReader; TResolveCountryFn m_countryResolver; TIsCountryLoadedFn m_isCountryLoadedFn; + TDownloadFn m_downloadMapHandler; + TDownloadFn m_downloadMapRoutingHandler; + TDownloadFn m_downloadRetryHandler; }; } diff --git a/drape_gui/country_status_helper.cpp b/drape_gui/country_status_helper.cpp index 328e8a0028..d3a26eb33e 100644 --- a/drape_gui/country_status_helper.cpp +++ b/drape_gui/country_status_helper.cpp @@ -105,6 +105,12 @@ void CountryStatusHelper::SetCountryIndex(storage::TIndex const & index) SetState(state); } +storage::TIndex CountryStatusHelper::GetCountryIndex() const +{ + ASSERT(m_accessor != nullptr, ()); + return m_accessor->GetCountryIndex(); +} + void CountryStatusHelper::SetState(ECountryState state) { m_state = state; diff --git a/drape_gui/country_status_helper.hpp b/drape_gui/country_status_helper.hpp index 945f600530..4a63549e53 100644 --- a/drape_gui/country_status_helper.hpp +++ b/drape_gui/country_status_helper.hpp @@ -52,6 +52,7 @@ public: void SetStorageAccessor(ref_ptr accessor); void SetCountryIndex(storage::TIndex const & index); + storage::TIndex GetCountryIndex() const; void SetState(ECountryState state); ECountryState GetState() const; diff --git a/map/framework.cpp b/map/framework.cpp index a71c7b4517..0604788130 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -858,6 +858,36 @@ void Framework::ClearAllCaches() m_searchEngine->ClearAllCaches(); } +void Framework::OnDownloadMapCallback(storage::TIndex const & countryIndex) +{ + m_activeMaps->DownloadMap(countryIndex, TMapOptions::EMapOnly); +} + +void Framework::OnDownloadMapCallbackUI(storage::TIndex const & countryIndex) +{ + GetPlatform().RunOnGuiThread(bind(&Framework::OnDownloadMapCallback, this, countryIndex)); +} + +void Framework::OnDownloadMapRoutingCallback(storage::TIndex const & countryIndex) +{ + m_activeMaps->DownloadMap(countryIndex, TMapOptions::EMapWithCarRouting); +} + +void Framework::OnDownloadMapRoutingCallbackUI(storage::TIndex const & countryIndex) +{ + GetPlatform().RunOnGuiThread(bind(&Framework::OnDownloadMapRoutingCallback, this, countryIndex)); +} + +void Framework::OnDownloadRetryCallback(storage::TIndex const & countryIndex) +{ + m_activeMaps->RetryDownloading(countryIndex); +} + +void Framework::OnDownloadRetryCallbackUI(storage::TIndex const & countryIndex) +{ + GetPlatform().RunOnGuiThread(bind(&Framework::OnDownloadRetryCallback, this, countryIndex)); +} + void Framework::MemoryWarning() { LOG(LINFO, ("MemoryWarning")); @@ -1273,6 +1303,7 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, using TReadFeaturesFn = df::MapDataProvider::TReadFeaturesFn; using TResolveCountryFn = df::MapDataProvider::TResolveCountryFn; using TIsCountryLoadedFn = df::MapDataProvider::TIsCountryLoadedFn; + using TDownloadFn = df::MapDataProvider::TDownloadFn; TReadIDsFn idReadFn = [this](df::MapDataProvider::TReadCallback const & fn, m2::RectD const & r, int scale) -> void { @@ -1291,11 +1322,16 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, TIsCountryLoadedFn isCountryLoadedFn = bind(&Framework::IsCountryLoaded, this, _1); + TDownloadFn downloadMapFn = bind(&Framework::OnDownloadMapCallbackUI, this, _1); + TDownloadFn downloadMapRoutingFn = bind(&Framework::OnDownloadMapRoutingCallbackUI, this, _1); + TDownloadFn downloadRetryFn = bind(&Framework::OnDownloadRetryCallbackUI, this, _1); + df::DrapeEngine::Params p(contextFactory, make_ref(&m_stringsBundle), make_ref(m_storageAccessor), df::Viewport(0, 0, w, h), - df::MapDataProvider(idReadFn, featureReadFn, resolveCountry,isCountryLoadedFn), + df::MapDataProvider(idReadFn, featureReadFn, resolveCountry, isCountryLoadedFn, + downloadMapFn, downloadMapRoutingFn, downloadRetryFn), vs); m_drapeEngine = make_unique_dp(p); diff --git a/map/framework.hpp b/map/framework.hpp index 47b4506583..7d88f4aa75 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -298,6 +298,14 @@ private: void FillSearchResultsMarks(search::Results const & results); + + void OnDownloadMapCallback(storage::TIndex const & countryIndex); + void OnDownloadMapCallbackUI(storage::TIndex const & countryIndex); + void OnDownloadMapRoutingCallback(storage::TIndex const & countryIndex); + void OnDownloadMapRoutingCallbackUI(storage::TIndex const & countryIndex); + void OnDownloadRetryCallback(storage::TIndex const & countryIndex); + void OnDownloadRetryCallbackUI(storage::TIndex const & countryIndex); + public: using TSearchRequest = search::QuerySaver::TSearchRequest;