[tips] set delegate fix

This commit is contained in:
Arsentiy Milchakov 2018-08-30 17:42:46 +03:00 committed by Roman Kuznetsov
parent ae25bf71ca
commit b6aa269e3c
3 changed files with 9 additions and 13 deletions

View file

@ -389,6 +389,7 @@ Framework::Framework(FrameworkParams const & params)
, m_lastReportedCountry(kInvalidCountryId)
, m_popularityLoader(m_model.GetDataSource())
, m_subscription(std::make_unique<Subscription>())
, m_tipsApi(static_cast<TipsApi::Delegate &>(*this))
{
m_startBackgroundTime = my::Timer::LocalTime();

View file

@ -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> delegate)
{
m_delegate = std::move(delegate);
}
boost::optional<eye::Tip::Type> TipsApi::GetTip() const
{
return GetTipImpl(GetShowAnyTipPeriod(), GetShowSameTipPeriod(), m_conditions);

View file

@ -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> delegate);
boost::optional<eye::Tip::Type> GetTip() const;
static boost::optional<eye::Tip::Type> GetTipForTesting(Duration showAnyTipPeriod,
@ -44,6 +43,6 @@ public:
Conditions const & triggers);
private:
std::unique_ptr<Delegate> m_delegate;
Delegate const & m_delegate;
Conditions m_conditions;
};