From 221f7e98b0017917c821c89e448437f8d215cd5d Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Mon, 8 Jun 2020 18:10:28 +0300 Subject: [PATCH] [drape] don't drag a user to his current position after acquiring coordinates (cold and hot start) within 8 hours after a user puts the app to background --- drape_frontend/my_position_controller.cpp | 35 +++++++---------------- drape_frontend/my_position_controller.hpp | 1 - 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/drape_frontend/my_position_controller.cpp b/drape_frontend/my_position_controller.cpp index 88847eb773..2336febe47 100644 --- a/drape_frontend/my_position_controller.cpp +++ b/drape_frontend/my_position_controller.cpp @@ -127,11 +127,18 @@ void ResetNotification(uint64_t & notifyId) { notifyId = DrapeNotifier::kInvalidId; } + +bool IsModeChangeViewport(location::EMyPositionMode mode) +{ + return mode == location::Follow || mode == location::FollowAndRotate; +} } // namespace MyPositionController::MyPositionController(Params && params, ref_ptr notifier) : m_notifier(notifier) - , m_mode(params.m_isRoutingActive ? location::PendingPosition : location::NotFollowNoPosition) + , m_mode(params.m_isRoutingActive || df::IsModeChangeViewport(params.m_initMode) + ? location::PendingPosition + : location::NotFollowNoPosition) , m_desiredInitMode(params.m_initMode) , m_modeChangeCallback(std::move(params.m_myPositionModeCallback)) , m_hints(params.m_hints) @@ -158,7 +165,6 @@ MyPositionController::MyPositionController(Params && params, ref_ptr= kMaxTimeInBackgroundSec) { @@ -224,7 +229,7 @@ double MyPositionController::GetHorizontalAccuracy() const bool MyPositionController::IsModeChangeViewport() const { - return m_mode == location::Follow || m_mode == location::FollowAndRotate; + return df::IsModeChangeViewport(m_mode); } bool MyPositionController::IsModeHasPosition() const @@ -236,7 +241,6 @@ void MyPositionController::DragStarted() { m_needBlockAnimation = true; - m_allowToFollowAfterObsoletePosition = false; if (m_mode == location::PendingPosition) ChangeMode(location::NotFollowNoPosition); } @@ -256,7 +260,6 @@ void MyPositionController::ScaleStarted() m_needBlockAnimation = true; ResetBlockAutoZoomTimer(); - m_allowToFollowAfterObsoletePosition = false; if (m_mode == location::PendingPosition) ChangeMode(location::NotFollowNoPosition); } @@ -276,8 +279,6 @@ void MyPositionController::ScaleEnded() void MyPositionController::Rotated() { - m_allowToFollowAfterObsoletePosition = false; - if (m_mode == location::PendingPosition) ChangeMode(location::NotFollowNoPosition); else if (m_mode == location::FollowAndRotate) @@ -444,7 +445,6 @@ void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool m_isDirtyViewport = true; } - auto const previousPositionIsObsolete = m_positionIsObsolete; using namespace std::chrono; auto const delta = duration_cast(system_clock::now().time_since_epoch()).count() - info.m_timestamp; @@ -514,19 +514,6 @@ void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool } } } - else if (m_mode == location::NotFollow) - { - // If we are on the start, the first known location is obsolete, the new one has come and - // we didn't touch the map. In this case we allow to go from NotFollow to Follow. - if (!m_hints.m_isFirstLaunch && m_allowToFollowAfterObsoletePosition && - previousPositionIsObsolete && !m_positionIsObsolete) - { - ChangeMode(location::Follow); - ChangeModelView(m_position, kDoNotChangeZoom); - - m_allowToFollowAfterObsoletePosition = false; - } - } else if (m_mode == location::NotFollowNoPosition) { if (m_isInRouting) @@ -705,8 +692,6 @@ void MyPositionController::StopLocationFollow() if (m_mode == location::PendingPosition) ChangeMode(location::NotFollowNoPosition); - m_allowToFollowAfterObsoletePosition = false; - ResetRoutingNotFollowTimer(); } @@ -721,7 +706,7 @@ void MyPositionController::OnEnterForeground(double backgroundTime) void MyPositionController::OnEnterBackground() { - if (!m_isInRouting) + if (!m_isInRouting && !df::IsModeChangeViewport(m_mode)) ChangeMode(location::NotFollowNoPosition); } diff --git a/drape_frontend/my_position_controller.hpp b/drape_frontend/my_position_controller.hpp index 458fe886f4..d30c288592 100644 --- a/drape_frontend/my_position_controller.hpp +++ b/drape_frontend/my_position_controller.hpp @@ -213,7 +213,6 @@ private: bool m_isCompassAvailable; bool m_positionIsObsolete; - bool m_allowToFollowAfterObsoletePosition; bool m_needBlockAutoZoom; uint64_t m_locationWaitingNotifyId;