diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index fb0780e3fa..a90bb180e8 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -718,10 +718,17 @@ void DrapeEngine::SetKineticScrollEnabled(bool enabled) MessagePriority::Normal); } -void DrapeEngine::SetTimeInBackground(double time) +void DrapeEngine::OnEnterForeground(double backgroundTime) { m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread, - make_unique_dp(time), + make_unique_dp(backgroundTime), + MessagePriority::High); +} + +void DrapeEngine::OnEnterBackground() +{ + m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread, + make_unique_dp(), MessagePriority::High); } diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index 6a69145eb2..a50f6e5c31 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -209,7 +209,8 @@ public: void SetKineticScrollEnabled(bool enabled); - void SetTimeInBackground(double time); + void OnEnterForeground(double backgroundTime); + void OnEnterBackground(); void SetDisplacementMode(int mode); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 4195c7cbdd..b690123d5a 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -829,10 +829,16 @@ void FrontendRenderer::AcceptMessage(ref_ptr message) break; } - case Message::Type::SetTimeInBackground: + case Message::Type::OnEnterForeground: { - ref_ptr msg = message; - m_myPositionController->SetTimeInBackground(msg->GetTime()); + ref_ptr msg = message; + m_myPositionController->OnEnterForeground(msg->GetTime()); + break; + } + + case Message::Type::OnEnterBackground: + { + m_myPositionController->OnEnterBackground(); break; } diff --git a/drape_frontend/message.cpp b/drape_frontend/message.cpp index 607221ac83..eeb9023a90 100644 --- a/drape_frontend/message.cpp +++ b/drape_frontend/message.cpp @@ -63,7 +63,7 @@ std::string DebugPrint(Message::Type msgType) case Message::Type::ShowChoosePositionMark: return "ShowChoosePositionMark"; case Message::Type::SetKineticScrollEnabled: return "SetKineticScrollEnabled"; case Message::Type::BlockTapEvents: return "BlockTapEvents"; - case Message::Type::SetTimeInBackground: return "SetTimeInBackground"; + case Message::Type::OnEnterForeground: return "OnEnterForeground"; case Message::Type::SetAddNewPlaceMode: return "SetAddNewPlaceMode"; case Message::Type::SetDisplacementMode: return "SetDisplacementMode"; case Message::Type::AllowAutoZoom: return "AllowAutoZoom"; @@ -103,6 +103,7 @@ std::string DebugPrint(Message::Type msgType) case Message::Type::NotifyGraphicsReady: return "NotifyGraphicsReady"; case Message::Type::EnableIsolines: return "EnableIsolines"; case Message::Type::EnableGuides: return "EnableGuides"; + case Message::Type::OnEnterBackground: return "OnEnterBackground"; } ASSERT(false, ("Unknown message type.")); return "Unknown type"; diff --git a/drape_frontend/message.hpp b/drape_frontend/message.hpp index 15bddf2c55..d9441c31bf 100644 --- a/drape_frontend/message.hpp +++ b/drape_frontend/message.hpp @@ -64,7 +64,7 @@ public: ShowChoosePositionMark, SetKineticScrollEnabled, BlockTapEvents, - SetTimeInBackground, + OnEnterForeground, SetAddNewPlaceMode, SetDisplacementMode, AllowAutoZoom, @@ -104,6 +104,7 @@ public: NotifyGraphicsReady, EnableIsolines, EnableGuides, + OnEnterBackground, }; virtual ~Message() = default; diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp index 00c34f0ffc..7d63e4fbe0 100644 --- a/drape_frontend/message_subclasses.hpp +++ b/drape_frontend/message_subclasses.hpp @@ -956,14 +956,14 @@ public: Type GetType() const override { return Type::ClearGpsTrackPoints; } }; -class SetTimeInBackgroundMessage : public Message +class OnEnterForegroundMessage : public Message { public: - explicit SetTimeInBackgroundMessage(double time) + explicit OnEnterForegroundMessage(double time) : m_time(time) {} - Type GetType() const override { return Type::SetTimeInBackground; } + Type GetType() const override { return Type::OnEnterForeground; } double GetTime() const { return m_time; } @@ -971,6 +971,12 @@ private: double m_time; }; +class OnEnterBackgroundMessage : public Message +{ +public: + Type GetType() const override { return Type::OnEnterBackground; } +}; + class SetDisplacementModeMessage : public Message { public: diff --git a/drape_frontend/my_position_controller.cpp b/drape_frontend/my_position_controller.cpp index 079001219b..88847eb773 100644 --- a/drape_frontend/my_position_controller.cpp +++ b/drape_frontend/my_position_controller.cpp @@ -29,7 +29,7 @@ int const kPositionRoutingOffsetY = 104; double const kMinSpeedThresholdMps = 2.8; // 10 km/h double const kGpsBearingLifetimeSec = 5.0; double const kMaxPendingLocationTimeSec = 60.0; -double const kMaxTimeInBackgroundSec = 60.0 * 60; +double const kMaxTimeInBackgroundSec = 60.0 * 60 * 8; // 8 hours double const kMaxNotFollowRoutingTimeSec = 20.0; double const kMaxUpdateLocationInvervalSec = 30.0; double const kMaxBlockAutoZoomTimeSec = 10.0; @@ -131,7 +131,7 @@ void ResetNotification(uint64_t & notifyId) MyPositionController::MyPositionController(Params && params, ref_ptr notifier) : m_notifier(notifier) - , m_mode(location::PendingPosition) + , m_mode(params.m_isRoutingActive ? location::PendingPosition : location::NotFollowNoPosition) , m_desiredInitMode(params.m_initMode) , m_modeChangeCallback(std::move(params.m_myPositionModeCallback)) , m_hints(params.m_hints) @@ -177,6 +177,7 @@ MyPositionController::MyPositionController(Params && params, ref_ptr= kMaxTimeInBackgroundSec) { + m_mode = location::PendingPosition; m_desiredInitMode = location::Follow; } @@ -709,15 +710,21 @@ void MyPositionController::StopLocationFollow() ResetRoutingNotFollowTimer(); } -void MyPositionController::SetTimeInBackground(double time) +void MyPositionController::OnEnterForeground(double backgroundTime) { - if (time >= kMaxTimeInBackgroundSec && m_mode == location::NotFollow) + if (backgroundTime >= kMaxTimeInBackgroundSec && m_mode == location::NotFollow) { ChangeMode(m_isInRouting ? location::FollowAndRotate : location::Follow); UpdateViewport(kDoNotChangeZoom); } } +void MyPositionController::OnEnterBackground() +{ + if (!m_isInRouting) + ChangeMode(location::NotFollowNoPosition); +} + void MyPositionController::OnCompassTapped() { alohalytics::LogEvent("$compassClicked", {{"mode", LocationModeStatisticsName(m_mode)}, diff --git a/drape_frontend/my_position_controller.hpp b/drape_frontend/my_position_controller.hpp index 9bfbb9e93b..458fe886f4 100644 --- a/drape_frontend/my_position_controller.hpp +++ b/drape_frontend/my_position_controller.hpp @@ -115,7 +115,8 @@ public: void NextMode(ScreenBase const & screen); void LoseLocation(); - void SetTimeInBackground(double time); + void OnEnterForeground(double backgroundTime); + void OnEnterBackground(); void OnCompassTapped(); void OnLocationUpdate(location::GpsInfo const & info, bool isNavigable, ScreenBase const & screen); diff --git a/map/framework.cpp b/map/framework.cpp index 337fedf840..42fe4e5b64 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1483,6 +1483,9 @@ void Framework::EnterBackground() m_startBackgroundTime = base::Timer::LocalTime(); settings::Set("LastEnterBackground", m_startBackgroundTime); + if (m_drapeEngine != nullptr) + m_drapeEngine->OnEnterBackground(); + SaveViewport(); m_trafficManager.OnEnterBackground(); @@ -1507,7 +1510,7 @@ void Framework::EnterForeground() if (m_drapeEngine != nullptr && m_startBackgroundTime != 0.0) { auto const secondsInBackground = m_startForegroundTime - m_startBackgroundTime; - m_drapeEngine->SetTimeInBackground(secondsInBackground); + m_drapeEngine->OnEnterForeground(secondsInBackground); if (m_guidesManager.IsEnabled() && secondsInBackground / 60 / 60 > kGuidesEnabledInBackgroundMaxHours)