From c7f5edca551a6487b35b88d005eaed96ec63f7f9 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 26 Jan 2021 17:59:47 +0200 Subject: [PATCH] Fix first map position adjusting --- .../osmand/plus/base/ContextMenuFragment.java | 7 ++++--- .../plus/base/ContextMenuScrollFragment.java | 2 +- .../ChooseRouteFragment.java | 2 +- .../osmand/plus/track/TrackMenuFragment.java | 19 +++++++------------ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java index 4f6097897f..4cc90afd96 100644 --- a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java @@ -103,7 +103,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment public interface ContextMenuFragmentListener { void onContextMenuYPosChanged(@NonNull ContextMenuFragment fragment, int y, boolean needMapAdjust, boolean animated); - void onContextMenuStateChanged(@NonNull ContextMenuFragment fragment, int menuState); + void onContextMenuStateChanged(@NonNull ContextMenuFragment fragment, int menuState, int previousMenuState); void onContextMenuDismiss(@NonNull ContextMenuFragment fragment); } @@ -815,7 +815,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment ContextMenuFragmentListener listener = this.listener; if (listener != null) { - listener.onContextMenuStateChanged(this, newMenuState); + listener.onContextMenuStateChanged(this, newMenuState, currentMenuState); } } @@ -971,7 +971,8 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment ContextMenuFragmentListener listener = ContextMenuFragment.this.listener; if (listener != null) { - listener.onContextMenuStateChanged(ContextMenuFragment.this, getCurrentMenuState()); + int menuState = getCurrentMenuState(); + listener.onContextMenuStateChanged(ContextMenuFragment.this, menuState, menuState); } } } diff --git a/OsmAnd/src/net/osmand/plus/base/ContextMenuScrollFragment.java b/OsmAnd/src/net/osmand/plus/base/ContextMenuScrollFragment.java index 51f4278948..5ba853e147 100644 --- a/OsmAnd/src/net/osmand/plus/base/ContextMenuScrollFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/ContextMenuScrollFragment.java @@ -82,7 +82,7 @@ public abstract class ContextMenuScrollFragment extends ContextMenuFragment impl } @Override - public void onContextMenuStateChanged(@NonNull ContextMenuFragment fragment, int menuState) { + public void onContextMenuStateChanged(@NonNull ContextMenuFragment fragment, int menuState, int previousMenuState) { updateMapControlsVisibility(menuState); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java index 5c283c670d..99d6a5c0cd 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java @@ -815,7 +815,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe } @Override - public void onContextMenuStateChanged(@NonNull ContextMenuFragment fragment, int menuState) { + public void onContextMenuStateChanged(@NonNull ContextMenuFragment fragment, int menuState, int previousMenuState) { LockableViewPager viewPager = this.viewPager; RouteDetailsFragment current = getCurrentFragment(); if (viewPager != null && fragment == current) { diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 8bcfb411ef..0e21879f85 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -152,6 +152,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private int menuTitleHeight; private int toolbarHeightPx; + private boolean mapPositionAdjusted; public enum TrackMenuType { OVERVIEW(R.id.action_overview, R.string.shared_string_overview), @@ -455,9 +456,11 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - adjustMapPosition(getHeight()); + public void onContextMenuStateChanged(@NonNull ContextMenuFragment fragment, int currentMenuState, int previousMenuState) { + super.onContextMenuStateChanged(fragment, currentMenuState, previousMenuState); + if (currentMenuState != MenuState.FULL_SCREEN && (currentMenuState != previousMenuState || !mapPositionAdjusted)) { + adjustMapPosition(getViewY()); + } } @Override @@ -760,15 +763,6 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } } - @Override - protected int applyPosY(int currentY, boolean needCloseMenu, boolean needMapAdjust, int previousMenuState, int newMenuState, int dZoom, boolean animated) { - int y = super.applyPosY(currentY, needCloseMenu, needMapAdjust, previousMenuState, newMenuState, dZoom, animated); - if (needMapAdjust) { - adjustMapPosition(y); - } - return y; - } - public void updateToolbar(int y, boolean animated) { final MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { @@ -821,6 +815,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (r.left != 0 && r.right != 0) { mapActivity.getMapView().fitRectToMap(r.left, r.right, r.top, r.bottom, tileBoxWidthPx, tileBoxHeightPx, 0); } + mapPositionAdjusted = true; } }