MyPosition startup refactoring.

This commit is contained in:
Viktor Govako 2022-04-26 23:35:21 +03:00
parent ef3d94a116
commit 3aa5151e62
12 changed files with 50 additions and 82 deletions

View file

@ -1658,12 +1658,6 @@ Java_com_mapswithme_maps_Framework_nativeIsRouteFinished(JNIEnv * env, jclass)
return frm()->GetRoutingManager().IsRouteFinished();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeRunFirstLaunchAnimation(JNIEnv * env, jclass)
{
frm()->RunFirstLaunchAnimation();
}
JNIEXPORT jint JNICALL
Java_com_mapswithme_maps_Framework_nativeOpenRoutePointsTransaction(JNIEnv * env, jclass)
{

View file

@ -361,8 +361,6 @@ public class Framework
// Navigation.
public static native boolean nativeIsRouteFinished();
public static native void nativeRunFirstLaunchAnimation();
public static native int nativeOpenRoutePointsTransaction();
public static native void nativeApplyRoutePointsTransaction(int transactionId);
public static native void nativeCancelRoutePointsTransaction(int transactionId);

View file

@ -606,16 +606,11 @@ public enum LocationHelper implements Initializable<Context>, AppBackgroundTrack
// If there is a location we need just to pass it to the listeners, so that
// my position state machine will be switched to the FOLLOW state.
// Otherwise, restart location service to show alert dialog if any location error.
if (mSavedLocation != null)
{
notifyLocationUpdated();
mLogger.d(TAG, "Current location is available, so play the nice zoom animation");
Framework.nativeRunFirstLaunchAnimation();
return;
}
// Restart location service to show alert dialog if any location error.
restart();
else
restart();
}
@Nullable

View file

@ -21,8 +21,20 @@ namespace
{
std::string const kLocationStateMode = "LastLocationStateMode";
std::string const kLastEnterBackground = "LastEnterBackground";
std::string const kLastViewport = "ScreenClipRect";
}
void SaveViewportSetting(m2::AnyRectD const & r)
{
settings::Set(kLastViewport, r);
}
bool LoadViewportSetting(m2::AnyRectD & r)
{
return settings::Get(kLastViewport, r) && GetWorldRect().IsRectInside(r.GetGlobalRect());
}
DrapeEngine::DrapeEngine(Params && params)
: m_myPositionModeChanged(std::move(params.m_myPositionModeChanged))
, m_viewport(std::move(params.m_viewport))
@ -46,8 +58,8 @@ DrapeEngine::DrapeEngine(Params && params)
{
// If the screen rect setting in follow and rotate mode is missing or invalid, it could cause
// invalid animations, so the follow and rotate mode should be discarded.
m2::AnyRectD rect;
if (!(settings::Get("ScreenClipRect", rect) && df::GetWorldRect().IsRectInside(rect.GetGlobalRect())))
m2::AnyRectD dummy;
if (!LoadViewportSetting(dummy))
mode = Follow;
}
@ -884,13 +896,6 @@ void DrapeEngine::SetPosteffectEnabled(PostprocessRenderer::Effect effect, bool
MessagePriority::Normal);
}
void DrapeEngine::RunFirstLaunchAnimation()
{
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<RunFirstLaunchAnimationMessage>(),
MessagePriority::Normal);
}
void DrapeEngine::ShowDebugInfo(bool shown)
{
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,

View file

@ -46,6 +46,9 @@ namespace df
class UserMarksProvider;
class MapDataProvider;
void SaveViewportSetting(m2::AnyRectD const & r);
bool LoadViewportSetting(m2::AnyRectD & r);
class DrapeEngine
{
public:
@ -241,8 +244,6 @@ public:
void SetPosteffectEnabled(PostprocessRenderer::Effect effect, bool enabled);
void EnableDebugRectRendering(bool enabled);
void RunFirstLaunchAnimation();
void ShowDebugInfo(bool shown);
void UpdateVisualScale(double vs, bool needStopRendering);

View file

@ -119,8 +119,9 @@ bool IsModeChangeViewport(location::EMyPositionMode mode)
MyPositionController::MyPositionController(Params && params, ref_ptr<DrapeNotifier> notifier)
: m_notifier(notifier)
, m_modeChangeCallback(std::move(params.m_myPositionModeCallback))
, m_hints(params.m_hints)
, m_isInRouting(params.m_isRoutingActive)
, m_screenshotMode(params.m_hints.m_screenshotMode)
, m_followZoomLevel(13) // is taken from FrontendRenderer::CheckAndRunFirstLaunchAnimation()
, m_needBlockAnimation(false)
, m_wasRotationInScaling(false)
, m_errorRadius(0.0)
@ -151,12 +152,12 @@ MyPositionController::MyPositionController(Params && params, ref_ptr<DrapeNotifi
{
using namespace location;
if (m_hints.m_isFirstLaunch)
if (params.m_hints.m_isFirstLaunch)
{
m_mode = PendingPosition;
m_desiredInitMode = Follow;
}
else if (m_hints.m_isLaunchByDeepLink)
else if (params.m_hints.m_isLaunchByDeepLink)
{
m_mode = NotFollowNoPosition;
m_desiredInitMode = NotFollow;
@ -173,6 +174,9 @@ MyPositionController::MyPositionController(Params && params, ref_ptr<DrapeNotifi
m_desiredInitMode = params.m_initMode;
m_mode = (params.m_isRoutingActive || df::IsModeChangeViewport(m_desiredInitMode)) ?
PendingPosition : NotFollowNoPosition;
// If we restored state, do not make auto-zoom until user will trigger the location.
m_followZoomLevel = kDoNotChangeZoom;
}
m_pendingStarted = (m_mode == PendingPosition);
@ -333,6 +337,7 @@ void MyPositionController::ResetRenderShape()
void MyPositionController::NextMode(ScreenBase const & screen)
{
m_followZoomLevel = kMaxScaleZoomLevel;
// Skip switching to next mode while we are waiting for position.
if (IsWaitingForLocation())
@ -341,7 +346,6 @@ void MyPositionController::NextMode(ScreenBase const & screen)
return;
}
// Start looking for location.
if (m_mode == location::NotFollowNoPosition)
{
@ -444,7 +448,7 @@ void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool
m_positionIsObsolete = false;
}
if (!m_isPositionAssigned)
if (m_followZoomLevel == kDoNotChangeZoom)
{
// If the position was never assigned, the new mode will be the desired one except next cases:
location::EMyPositionMode newMode = m_desiredInitMode;
@ -464,18 +468,15 @@ void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool
ChangeMode(newMode);
if (!m_hints.m_isFirstLaunch || !AnimationSystem::Instance().AnimationExists(Animation::Object::MapPlane))
if (m_mode == location::Follow)
{
if (m_mode == location::Follow)
{
ChangeModelView(m_position, kDoNotChangeZoom);
}
else if (m_mode == location::FollowAndRotate)
{
ChangeModelView(m_position, m_drawDirection,
m_isInRouting ? GetRoutingRotationPixelCenter() : m_visiblePixelRect.Center(),
kDoNotChangeZoom);
}
ChangeModelView(m_position, kDoNotChangeZoom);
}
else if (m_mode == location::FollowAndRotate)
{
ChangeModelView(m_position, m_drawDirection,
m_isInRouting ? GetRoutingRotationPixelCenter() : m_visiblePixelRect.Center(),
kDoNotChangeZoom);
}
}
else if (m_mode == location::PendingPosition)
@ -488,22 +489,15 @@ void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool
else
{
ChangeMode(location::Follow);
if (m_hints.m_isFirstLaunch)
if (GetZoomLevel(screen, m_position, m_errorRadius) <= m_followZoomLevel)
{
if (!AnimationSystem::Instance().AnimationExists(Animation::Object::MapPlane))
ChangeModelView(m_position, kDoNotChangeZoom);
m2::PointD const size(m_errorRadius, m_errorRadius);
ChangeModelView(m2::RectD(m_position - size, m_position + size));
}
else
{
if (GetZoomLevel(screen, m_position, m_errorRadius) <= kMaxScaleZoomLevel)
{
m2::PointD const size(m_errorRadius, m_errorRadius);
ChangeModelView(m2::RectD(m_position - size, m_position + size));
}
else
{
ChangeModelView(m_position, kMaxScaleZoomLevel);
}
ChangeModelView(m_position, m_followZoomLevel);
}
}
}
@ -614,7 +608,7 @@ void MyPositionController::Render(ref_ptr<dp::GraphicsContext> context, ref_ptr<
m_shape->SetAccuracy(static_cast<float>(m_errorRadius));
m_shape->SetRoutingMode(IsInRouting());
if (!m_hints.m_screenshotMode)
if (!m_screenshotMode)
{
m_shape->RenderAccuracy(context, mng, screen, zoomLevel, frameValues);
m_shape->RenderMyPosition(context, mng, screen, zoomLevel, frameValues);

View file

@ -167,10 +167,12 @@ private:
location::EMyPositionMode m_mode;
location::EMyPositionMode m_desiredInitMode;
location::TMyPositionModeChanged m_modeChangeCallback;
Hints m_hints;
bool m_isInRouting = false;
bool m_isArrowGluedInRouting = false;
bool m_screenshotMode = false;
int m_followZoomLevel;
bool m_needBlockAnimation;
bool m_wasRotationInScaling;

View file

@ -14,7 +14,6 @@ typedef void (^SearchInDownloaderCompletions)(NSArray<MWMMapSearchResult *> *res
NS_SWIFT_NAME(FrameworkHelper)
@interface MWMFrameworkHelper : NSObject
+ (void)processFirstLaunch:(BOOL)hasLocation;
+ (void)setVisibleViewport:(CGRect)rect scaleFactor:(CGFloat)scale;
+ (void)setTheme:(MWMTheme)theme;
+ (MWMDayTime)daytimeAtLocation:(nullable CLLocation *)location;

View file

@ -10,14 +10,6 @@
@implementation MWMFrameworkHelper
+ (void)processFirstLaunch:(BOOL)hasLocation {
auto &f = GetFramework();
if (!hasLocation)
f.SwitchMyPositionNextMode();
else
f.RunFirstLaunchAnimation();
}
+ (void)setVisibleViewport:(CGRect)rect scaleFactor:(CGFloat)scale {
CGFloat const x0 = rect.origin.x * scale;
CGFloat const y0 = rect.origin.y * scale;

View file

@ -324,9 +324,6 @@ NSString *const kPP2BookmarkEditingSegue = @"PP2BookmarkEditing";
if ([FirstSession isFirstSession])
{
[MWMLocationManager start];
dispatch_async(dispatch_get_main_queue(), ^{
[MWMFrameworkHelper processFirstLaunch:[MWMLocationManager isStarted]];
});
}
else
{

View file

@ -900,18 +900,17 @@ void Framework::SaveViewport()
rect = modelView.GlobalRect();
}
else
{
rect = m_currentModelView.GlobalRect();
}
settings::Set("ScreenClipRect", rect);
df::SaveViewportSetting(rect);
}
void Framework::LoadViewport()
{
m2::AnyRectD rect;
if (settings::Get("ScreenClipRect", rect) && df::GetWorldRect().IsRectInside(rect.GetGlobalRect()))
if (df::LoadViewportSetting(rect))
{
if (m_drapeEngine != nullptr)
if (m_drapeEngine)
m_drapeEngine->SetModelViewAnyRect(rect, false /* isAnim */, false /* useVisibleViewport */);
}
else
@ -1075,12 +1074,6 @@ int Framework::GetDrawScale() const
return 0;
}
void Framework::RunFirstLaunchAnimation()
{
if (m_drapeEngine != nullptr)
m_drapeEngine->RunFirstLaunchAnimation();
}
bool Framework::IsCountryLoaded(m2::PointD const & pt) const
{
// TODO (@gorshenin, @govako): the method's name is quite

View file

@ -560,8 +560,6 @@ public:
int GetDrawScale() const;
void RunFirstLaunchAnimation();
/// Set correct viewport, parse API, show balloon.
bool ShowMapForURL(std::string const & url);
url_scheme::ParsedMapApi::ParsingResult ParseAndSetApiURL(std::string const & url);