From b6aa269e3ce9eae249a0881c22e43750d1156fba Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Thu, 30 Aug 2018 17:42:46 +0300 Subject: [PATCH] [tips] set delegate fix --- map/framework.cpp | 1 + map/tips_api.cpp | 16 ++++++---------- map/tips_api.hpp | 5 ++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index 44b35bd789..64c5dc8a74 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -389,6 +389,7 @@ Framework::Framework(FrameworkParams const & params) , m_lastReportedCountry(kInvalidCountryId) , m_popularityLoader(m_model.GetDataSource()) , m_subscription(std::make_unique()) + , m_tipsApi(static_cast(*this)) { m_startBackgroundTime = my::Timer::LocalTime(); diff --git a/map/tips_api.cpp b/map/tips_api.cpp index dadd2a6665..09ce43cf20 100644 --- a/map/tips_api.cpp +++ b/map/tips_api.cpp @@ -104,7 +104,8 @@ size_t TipsApi::GetGotitClicksCountToDisable() return kGotitClicksCountToDisable; } -TipsApi::TipsApi() +TipsApi::TipsApi(Delegate const & delegate) + : m_delegate(delegate) { m_conditions = {{ @@ -115,29 +116,24 @@ TipsApi::TipsApi() // Condition for Tips::Type::DiscoverButton type. [this] { - auto const pos = m_delegate->GetCurrentPosition(); + auto const pos = m_delegate.GetCurrentPosition(); if (!pos.is_initialized()) return false; - return m_delegate->IsCountryLoaded(pos.get()); + return m_delegate.IsCountryLoaded(pos.get()); }, // Condition for Tips::Type::MapsLayers type. [this] { - auto const pos = m_delegate->GetCurrentPosition(); + auto const pos = m_delegate.GetCurrentPosition(); if (!pos.is_initialized()) return false; - return m_delegate->HaveTransit(pos.get()); + return m_delegate.HaveTransit(pos.get()); } }}; } -void TipsApi::SetDelegate(std::unique_ptr delegate) -{ - m_delegate = std::move(delegate); -} - boost::optional TipsApi::GetTip() const { return GetTipImpl(GetShowAnyTipPeriod(), GetShowSameTipPeriod(), m_conditions); diff --git a/map/tips_api.hpp b/map/tips_api.hpp index e974be12d3..0eaec73eea 100644 --- a/map/tips_api.hpp +++ b/map/tips_api.hpp @@ -34,9 +34,8 @@ public: static size_t GetActionClicksCountToDisable(); static size_t GetGotitClicksCountToDisable(); - TipsApi(); + explicit TipsApi(Delegate const & delegate); - void SetDelegate(std::unique_ptr delegate); boost::optional GetTip() const; static boost::optional GetTipForTesting(Duration showAnyTipPeriod, @@ -44,6 +43,6 @@ public: Conditions const & triggers); private: - std::unique_ptr m_delegate; + Delegate const & m_delegate; Conditions m_conditions; };