Fix backstack of RP/RD/TD

This commit is contained in:
max-klaus 2019-08-03 13:56:03 +03:00
parent e34c7ba29b
commit 67ff4adf74
11 changed files with 212 additions and 98 deletions

View file

@ -362,7 +362,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
app.getMapMarkersHelper().getPlanRouteContext().setFragmentVisible(true); app.getMapMarkersHelper().getPlanRouteContext().setFragmentVisible(true);
} }
if (trackDetailsMenu.isVisible()) { if (trackDetailsMenu.isVisible()) {
trackDetailsMenu.dismiss(); trackDetailsMenu.dismiss(false);
} }
removeFragment(ImportGpxBottomSheetDialogFragment.TAG); removeFragment(ImportGpxBottomSheetDialogFragment.TAG);
removeFragment(AdditionalActionsBottomSheetDialogFragment.TAG); removeFragment(AdditionalActionsBottomSheetDialogFragment.TAG);
@ -606,7 +606,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return; return;
} }
if (trackDetailsMenu.isVisible()) { if (trackDetailsMenu.isVisible()) {
trackDetailsMenu.hide(); trackDetailsMenu.hide(true);
if (prevActivityIntent == null) { if (prevActivityIntent == null) {
return; return;
} }
@ -625,7 +625,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
ChooseRouteFragment chooseRouteFragment = getChooseRouteFragment(); ChooseRouteFragment chooseRouteFragment = getChooseRouteFragment();
if (chooseRouteFragment != null) { if (chooseRouteFragment != null) {
chooseRouteFragment.dismiss(); chooseRouteFragment.dismiss(true);
return; return;
} }
if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) { if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) {

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -41,9 +42,10 @@ public class DashNavigationFragment extends DashBaseFragment {
(view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() { (view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Activity activity = getActivity(); FragmentActivity activity = getActivity();
if (activity instanceof MapActivity) { if (activity != null) {
ChooseRouteFragment.showInstance(((MapActivity) activity).getSupportFragmentManager()); closeDashboard();
ChooseRouteFragment.showInstance(activity.getSupportFragmentManager());
} }
} }
}); });

View file

@ -1311,10 +1311,13 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
super.onResume(); super.onResume();
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
if (!menu.isActive() || (mapActivity.getMapRouteInfoMenu().isVisible()) || MapRouteInfoMenu.chooseRoutesVisible || MapRouteInfoMenu.waypointsVisible) { if (!menu.isActive() || (mapActivity.getMapRouteInfoMenu().isVisible()) || MapRouteInfoMenu.waypointsVisible) {
dismissMenu(); dismissMenu();
return; return;
} }
if (MapRouteInfoMenu.chooseRoutesVisible) {
mapActivity.getChooseRouteFragment().dismiss();
}
updateLocationViewCache = mapActivity.getMyApplication().getUIUtilities().getUpdateLocationViewCache(); updateLocationViewCache = mapActivity.getMyApplication().getUIUtilities().getUpdateLocationViewCache();
mapActivity.getMapViewTrackingUtilities().setContextMenu(menu); mapActivity.getMapViewTrackingUtilities().setContextMenu(menu);
mapActivity.getMapViewTrackingUtilities().setMapLinkedToLocation(false); mapActivity.getMapViewTrackingUtilities().setMapLinkedToLocation(false);
@ -1465,7 +1468,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
@Override @Override
public void onClick(View v) { public void onClick(View v) {
dismissMenu(); dismissMenu();
ChooseRouteFragment.showFromRouteInfo(requireMyActivity().getSupportFragmentManager(), ChooseRouteFragment.showInstance(requireMyActivity().getSupportFragmentManager(),
requireMyApplication().getRoutingHelper().getTransportRoutingHelper().getCurrentRoute(), requireMyApplication().getRoutingHelper().getTransportRoutingHelper().getCurrentRoute(),
ContextMenuFragment.MenuState.FULL_SCREEN); ContextMenuFragment.MenuState.FULL_SCREEN);
/* fit route segment on map /* fit route segment on map

View file

@ -104,18 +104,18 @@ public class TrackDetailsMenu {
} }
} }
public void dismiss() { public void dismiss(boolean backPressed) {
TrackDetailsMenuFragment fragment = getMenuFragment(); TrackDetailsMenuFragment fragment = getMenuFragment();
if (fragment != null) { if (fragment != null) {
fragment.dismiss(); fragment.dismiss(backPressed);
} }
} }
public void hide() { public void hide(boolean backPressed) {
TrackDetailsMenuFragment fragment = getMenuFragment(); TrackDetailsMenuFragment fragment = getMenuFragment();
if (fragment != null) { if (fragment != null) {
hidding = true; hidding = true;
fragment.dismiss(); fragment.dismiss(backPressed);
} else { } else {
segment = null; segment = null;
trackChartPoints = null; trackChartPoints = null;
@ -174,7 +174,7 @@ public class TrackDetailsMenu {
toolbarController.setOnCloseButtonClickListener(new View.OnClickListener() { toolbarController.setOnCloseButtonClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
hide(); hide(false);
} }
}); });
mapActivity.showTopToolbar(toolbarController); mapActivity.showTopToolbar(toolbarController);

View file

@ -82,7 +82,7 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment {
closeButton.setOnClickListener(new View.OnClickListener() { closeButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
menu.hide(); menu.hide(false);
} }
}); });
} }
@ -114,7 +114,7 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (menu == null || menu.getGpxItem() == null) { if (menu == null || menu.getGpxItem() == null) {
dismiss(); dismiss(false);
} else { } else {
menu.onShow(); menu.onShow();
} }
@ -172,11 +172,12 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment {
.commitAllowingStateLoss(); .commitAllowingStateLoss();
} }
public void dismiss() { public void dismiss(boolean backPressed) {
FragmentActivity activity = getActivity(); MapActivity mapActivity = getMapActivity();
if (activity != null) { if (mapActivity != null) {
try { try {
activity.getSupportFragmentManager().popBackStackImmediate(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); mapActivity.getSupportFragmentManager().popBackStackImmediate(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE);
mapActivity.getMapRouteInfoMenu().onDismiss(this, 0, null, backPressed);
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }

View file

@ -78,7 +78,6 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
public static final String ROUTE_INDEX_KEY = "route_index_key"; public static final String ROUTE_INDEX_KEY = "route_index_key";
public static final String ROUTE_INFO_STATE_KEY = "route_info_state_key"; public static final String ROUTE_INFO_STATE_KEY = "route_info_state_key";
public static final String INITIAL_MENU_STATE_KEY = "initial_menu_state_key"; public static final String INITIAL_MENU_STATE_KEY = "initial_menu_state_key";
public static final String USE_ROUTE_INFO_MENU_KEY = "use_route_info_menu_key";
public static final String ADJUST_MAP_KEY = "adjust_map_key"; public static final String ADJUST_MAP_KEY = "adjust_map_key";
@Nullable @Nullable
@ -102,8 +101,6 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
private int routesCount; private int routesCount;
private boolean publicTransportMode; private boolean publicTransportMode;
private boolean useRouteInfoMenu;
private boolean openingAnalyseOnMap = false;
private boolean needAdjustMap; private boolean needAdjustMap;
@Nullable @Nullable
@ -123,7 +120,6 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
} }
if (args != null) { if (args != null) {
routeIndex = args.getInt(ROUTE_INDEX_KEY); routeIndex = args.getInt(ROUTE_INDEX_KEY);
useRouteInfoMenu = args.getBoolean(USE_ROUTE_INFO_MENU_KEY, false);
needAdjustMap = args.getBoolean(ADJUST_MAP_KEY, false); needAdjustMap = args.getBoolean(ADJUST_MAP_KEY, false);
initialMenuState = args.getInt(INITIAL_MENU_STATE_KEY, initialMenuState); initialMenuState = args.getInt(INITIAL_MENU_STATE_KEY, initialMenuState);
} }
@ -221,7 +217,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
if (!wasDrawerDisabled) { if (!wasDrawerDisabled) {
mapActivity.disableDrawer(); mapActivity.disableDrawer();
} }
updateControlsVisibility(false, false); updateControlsVisibility(false);
} }
} }
@ -233,16 +229,10 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
if (!wasDrawerDisabled) { if (!wasDrawerDisabled) {
mapActivity.enableDrawer(); mapActivity.enableDrawer();
} }
updateControlsVisibility(true, useRouteInfoMenu); updateControlsVisibility(true);
} }
} }
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putBoolean(USE_ROUTE_INFO_MENU_KEY, useRouteInfoMenu);
super.onSaveInstanceState(outState);
}
@Override @Override
public int getStatusBarColorId() { public int getStatusBarColorId() {
View view = getView(); View view = getView();
@ -273,7 +263,6 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
} }
public void analyseOnMap(LatLon location, GpxDisplayItem gpxItem) { public void analyseOnMap(LatLon location, GpxDisplayItem gpxItem) {
openingAnalyseOnMap = true;
OsmandApplication app = requireMyApplication(); OsmandApplication app = requireMyApplication();
final OsmandSettings settings = app.getSettings(); final OsmandSettings settings = app.getSettings();
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
@ -287,13 +276,23 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
} }
public void dismiss() { public void dismiss() {
dismiss(false);
}
public void dismiss(boolean backPressed) {
try { try {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { LockableViewPager viewPager = this.viewPager;
if (mapActivity != null && viewPager != null) {
mapActivity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss(); mapActivity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss();
if (useRouteInfoMenu && !openingAnalyseOnMap) { Bundle args = getArguments();
mapActivity.getMapLayers().getMapControlsLayer().showRouteInfoControlDialog(); if (args == null) {
args = new Bundle();
} }
args.putInt(ROUTE_INDEX_KEY, viewPager.getCurrentItem());
args.putInt(INITIAL_MENU_STATE_KEY, currentMenuState);
args.putBoolean(ADJUST_MAP_KEY, false);
mapActivity.getMapRouteInfoMenu().onDismiss(this, currentMenuState, args, backPressed);
} }
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
@ -445,7 +444,8 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
private void updatePagesViewVisibility(int menuState) { private void updatePagesViewVisibility(int menuState) {
View pagesView = this.pagesView; View pagesView = this.pagesView;
if (portrait && routesCount > 1 && pagesView != null) { if (pagesView != null) {
if (portrait && routesCount > 1) {
if (menuState != MenuState.FULL_SCREEN) { if (menuState != MenuState.FULL_SCREEN) {
if (pagesView.getVisibility() != View.VISIBLE) { if (pagesView.getVisibility() != View.VISIBLE) {
pagesView.setVisibility(View.VISIBLE); pagesView.setVisibility(View.VISIBLE);
@ -455,6 +455,11 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
pagesView.setVisibility(View.INVISIBLE); pagesView.setVisibility(View.INVISIBLE);
} }
} }
} else {
if (pagesView.getVisibility() == View.VISIBLE) {
pagesView.setVisibility(View.INVISIBLE);
}
}
} }
} }
@ -474,7 +479,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
OnClickListener backOnClick = new OnClickListener() { OnClickListener backOnClick = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
dismiss(); dismiss(true);
} }
}; };
backButton.setOnClickListener(backOnClick); backButton.setOnClickListener(backOnClick);
@ -783,16 +788,16 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
} }
} }
public void updateControlsVisibility(boolean visible, boolean openingRouteInfo) { public void updateControlsVisibility(boolean visible) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
int visibility = visible ? View.VISIBLE : View.GONE; int visibility = visible ? View.VISIBLE : View.GONE;
mapActivity.findViewById(R.id.map_center_info).setVisibility(visibility); mapActivity.findViewById(R.id.map_center_info).setVisibility(visibility);
mapActivity.findViewById(R.id.map_left_widgets_panel).setVisibility(visibility); mapActivity.findViewById(R.id.map_left_widgets_panel).setVisibility(visibility);
if (!openingRouteInfo) { if (!visible) {
mapActivity.findViewById(R.id.map_right_widgets_panel).setVisibility(visibility); mapActivity.findViewById(R.id.map_right_widgets_panel).setVisibility(visibility);
if (!portrait) { if (!portrait) {
mapActivity.getMapView().setMapPositionX(visible ? 0 : 1); mapActivity.getMapView().setMapPositionX(1);
} }
} }
mapActivity.updateStatusBarColor(); mapActivity.updateStatusBarColor();
@ -861,14 +866,17 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
} }
} }
public static boolean showFromRouteInfo(FragmentManager fragmentManager, int routeIndex, int initialMenuState) { public static boolean showInstance(FragmentManager fragmentManager, int routeIndex, int initialMenuState) {
try {
ChooseRouteFragment fragment = new ChooseRouteFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt(ROUTE_INDEX_KEY, routeIndex); args.putInt(ROUTE_INDEX_KEY, routeIndex);
args.putBoolean(USE_ROUTE_INFO_MENU_KEY, true);
args.putInt(INITIAL_MENU_STATE_KEY, initialMenuState); args.putInt(INITIAL_MENU_STATE_KEY, initialMenuState);
args.putBoolean(ADJUST_MAP_KEY, initialMenuState != MenuState.FULL_SCREEN); args.putBoolean(ADJUST_MAP_KEY, initialMenuState != MenuState.FULL_SCREEN);
return showInstance(fragmentManager, args);
}
public static boolean showInstance(FragmentManager fragmentManager, Bundle args) {
try {
ChooseRouteFragment fragment = new ChooseRouteFragment();
fragment.setArguments(args); fragment.setArguments(args);
fragmentManager.beginTransaction() fragmentManager.beginTransaction()
.add(R.id.routeMenuContainer, fragment, TAG) .add(R.id.routeMenuContainer, fragment, TAG)
@ -883,8 +891,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
public void onNavigationRequested() { public void onNavigationRequested() {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
useRouteInfoMenu = false; dismiss(false);
dismiss();
if (!mapActivity.getMyApplication().getRoutingHelper().isPublicTransportMode()) { if (!mapActivity.getMyApplication().getRoutingHelper().isPublicTransportMode()) {
mapActivity.getMapLayers().getMapControlsLayer().startNavigation(); mapActivity.getMapLayers().getMapControlsLayer().startNavigation();
} }

View file

@ -7,6 +7,7 @@ import android.graphics.PointF;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Build.VERSION_CODES; import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
@ -62,6 +63,7 @@ import net.osmand.plus.base.ContextMenuFragment.MenuState;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment;
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment; import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment; import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment;
@ -109,6 +111,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Stack;
import java.util.TreeMap; import java.util.TreeMap;
public class MapRouteInfoMenu implements IRouteInformationListener, CardListener { public class MapRouteInfoMenu implements IRouteInformationListener, CardListener {
@ -123,6 +126,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
public static boolean chooseRoutesVisible = false; public static boolean chooseRoutesVisible = false;
public static boolean waypointsVisible = false; public static boolean waypointsVisible = false;
private Stack<MapRouteMenuStateHolder> menuBackStack = new Stack<>();
private boolean routeCalculationInProgress; private boolean routeCalculationInProgress;
private boolean selectFromMapTouch; private boolean selectFromMapTouch;
@ -132,7 +137,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
private boolean showMenu = false; private boolean showMenu = false;
private int showMenuState = DEFAULT_MENU_STATE; private int showMenuState = DEFAULT_MENU_STATE;
private int lastMenuState = MenuState.HEADER_ONLY;
@Nullable @Nullable
private MapActivity mapActivity; private MapActivity mapActivity;
@ -348,7 +352,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (fragmentRef != null) { if (fragmentRef != null) {
return fragmentRef.get().getCurrentMenuState(); return fragmentRef.get().getCurrentMenuState();
} }
return lastMenuState; return getInitialMenuState();
} }
public int getSupportedMenuStates() { public int getSupportedMenuStates() {
@ -368,15 +372,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} }
public void showHideMenu() { public void showHideMenu() {
showHideMenu(lastMenuState);
}
public void showHideMenu(int menuState) {
intermediateRequestsLatLon.clear(); intermediateRequestsLatLon.clear();
if (isVisible()) { if (isVisible()) {
hide(); hide();
} else { } else {
show(menuState); show();
} }
} }
@ -648,7 +648,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (mapActivity != null) { if (mapActivity != null) {
if (card instanceof SimpleRouteCard) { if (card instanceof SimpleRouteCard) {
hide(); hide();
ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), 0, MenuState.FULL_SCREEN); ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), 0, MenuState.FULL_SCREEN);
} }
} }
} }
@ -672,14 +672,14 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} else if (card instanceof PublicTransportCard) { } else if (card instanceof PublicTransportCard) {
if (buttonIndex == PublicTransportCard.DETAILS_BUTTON_INDEX) { if (buttonIndex == PublicTransportCard.DETAILS_BUTTON_INDEX) {
hide(); hide();
ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(),
((PublicTransportCard) card).getRouteId(), MenuState.FULL_SCREEN); ((PublicTransportCard) card).getRouteId(), MenuState.FULL_SCREEN);
} else if (buttonIndex == PublicTransportCard.SHOW_BUTTON_INDEX) { } else if (buttonIndex == PublicTransportCard.SHOW_BUTTON_INDEX) {
showRouteOnMap(mapActivity, ((PublicTransportCard) card).getRouteId()); showRouteOnMap(mapActivity, ((PublicTransportCard) card).getRouteId());
} }
} else if (card instanceof SimpleRouteCard) { } else if (card instanceof SimpleRouteCard) {
hide(); hide();
ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), 0, MenuState.FULL_SCREEN); ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), 0, MenuState.FULL_SCREEN);
} else if (card instanceof PublicTransportNotFoundWarningCard) { } else if (card instanceof PublicTransportNotFoundWarningCard) {
updateApplicationMode(null, ApplicationMode.PEDESTRIAN); updateApplicationMode(null, ApplicationMode.PEDESTRIAN);
} else if (card instanceof PublicTransportNotFoundSettingsWarningCard) { } else if (card instanceof PublicTransportNotFoundSettingsWarningCard) {
@ -1407,8 +1407,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (mapActivity.getPointToNavigate() != null) { if (mapActivity.getPointToNavigate() != null) {
hide(); hide();
} }
ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), routeIndex, MenuState.HEADER_ONLY);
routeIndex, MenuState.HEADER_ONLY);
} }
private void clickRouteCancel() { private void clickRouteCancel() {
@ -2042,11 +2041,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
public void routeWasFinished() { public void routeWasFinished() {
} }
public void onDismiss(int currentMenuState) { public void onDismiss(Fragment fragment, int currentMenuState, Bundle arguments, boolean backPressed) {
cancelButtonsAnimations();
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
lastMenuState = currentMenuState; if (fragment instanceof MapRouteInfoMenuFragment) {
cancelButtonsAnimations();
mapActivity.getMapView().setMapPositionX(0); mapActivity.getMapView().setMapPositionX(0);
mapActivity.getMapView().refreshMap(); mapActivity.getMapView().refreshMap();
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_route_land_left_margin), false); AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_route_land_left_margin), false);
@ -2058,18 +2057,56 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
mapActivity.getMapActions().stopNavigationWithoutConfirm(); mapActivity.getMapActions().stopNavigationWithoutConfirm();
} }
mapActivity.updateStatusBarColor(); mapActivity.updateStatusBarColor();
RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
menuBackStack.clear();
if (routingHelper.isRoutePlanningMode() || routingHelper.isFollowingMode()) {
menuBackStack.push(new MapRouteMenuStateHolder(MapRouteMenuType.ROUTE_INFO, currentMenuState, fragment.getArguments()));
} }
if (onDismissListener != null) { if (onDismissListener != null) {
onDismissListener.onDismiss(null); onDismissListener.onDismiss(null);
} }
removeTargetPointListener(); removeTargetPointListener();
} else if (fragment instanceof ChooseRouteFragment) {
MapRouteMenuStateHolder holder = new MapRouteMenuStateHolder(MapRouteMenuType.ROUTE_DETAILS, currentMenuState, fragment.getArguments());
if (!menuBackStack.empty() && menuBackStack.peek().type == holder.type) {
menuBackStack.pop();
}
if (backPressed) {
holder.onDismiss(onBackPressed());
} else {
menuBackStack.push(holder);
holder.onDismiss(null);
}
} else if (fragment instanceof TrackDetailsMenuFragment) {
if (backPressed) {
onBackPressed();
}
}
}
} }
public void show() { public void show() {
show(getInitialMenuState()); show(getInitialMenuState());
} }
public void show(int menuState) { private void show(int menuState) {
MapRouteMenuStateHolder holder = !menuBackStack.empty() ? menuBackStack.pop() : null;
if (holder != null) {
holder.showMenu();
} else {
showInternal(menuState);
}
}
public MapRouteMenuStateHolder onBackPressed() {
MapRouteMenuStateHolder holder = !menuBackStack.empty() ? menuBackStack.pop() : null;
if (holder != null) {
holder.showMenu();
}
return holder;
}
private void showInternal(int menuState) {
if (menuState == DEFAULT_MENU_STATE) { if (menuState == DEFAULT_MENU_STATE) {
menuState = getInitialMenuState(); menuState = getInitialMenuState();
} }
@ -2121,4 +2158,76 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
showMenu = true; showMenu = true;
showMenuState = menuState; showMenuState = menuState;
} }
@DrawableRes
public int getRoutePlanningBtnImage() {
return menuBackStack.empty() ? 0 : menuBackStack.peek().getButtonImage();
}
public enum MapRouteMenuType {
ROUTE_INFO,
ROUTE_DETAILS
}
private class MapRouteMenuStateHolder {
private MapRouteMenuType type;
private int menuState;
private Bundle arguments;
MapRouteMenuStateHolder(MapRouteMenuType type, int menuState, Bundle arguments) {
this.type = type;
this.menuState = menuState;
this.arguments = arguments;
}
@DrawableRes
int getButtonImage() {
OsmandApplication app = getApp();
switch (type) {
case ROUTE_INFO:
return 0;
case ROUTE_DETAILS:
return app != null ? app.getRoutingHelper().getAppMode().getMapIconRes() : R.drawable.map_directions;
default:
return 0;
}
}
void showMenu() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
switch (type) {
case ROUTE_INFO:
showInternal(menuState);
break;
case ROUTE_DETAILS:
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), arguments);
break;
}
}
}
void onDismiss(@Nullable MapRouteMenuStateHolder openingMenuStateHolder) {
boolean openingRouteInfo = openingMenuStateHolder != null && openingMenuStateHolder.type == MapRouteMenuType.ROUTE_INFO;
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (!openingRouteInfo) {
switch (type) {
case ROUTE_INFO:
break;
case ROUTE_DETAILS:
mapActivity.findViewById(R.id.map_right_widgets_panel).setVisibility(View.VISIBLE);
if (!portraitMode) {
mapActivity.getMapView().setMapPositionX(0);
}
break;
default:
break;
}
}
}
}
}
} }

View file

@ -169,7 +169,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
if (menu != null) { if (menu != null) {
menu.onDismiss(getCurrentMenuState()); menu.onDismiss(this, getCurrentMenuState(), null, false);
} }
} }

View file

@ -187,6 +187,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) cardsContainer.getLayoutParams(); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) cardsContainer.getLayoutParams();
layoutParams.setMargins(pageMarginPx, 0, pageMarginPx, 0); layoutParams.setMargins(pageMarginPx, 0, pageMarginPx, 0);
cardsContainer.setLayoutParams(layoutParams); cardsContainer.setLayoutParams(layoutParams);
updateCardsLayout();
} }
updateCards(); updateCards();
runLayoutListener(); runLayoutListener();

View file

@ -814,7 +814,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
} }
public boolean disableSingleTap() { public boolean disableSingleTap() {
if (activity.getMapRouteInfoMenu().isVisible() || MapRouteInfoMenu.chooseRoutesVisible || MapRouteInfoMenu.waypointsVisible) { if (activity.getMapRouteInfoMenu().isVisible() || MapRouteInfoMenu.waypointsVisible) {
return true; return true;
} }
boolean res = false; boolean res = false;
@ -831,7 +831,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
public boolean disableLongPressOnMap() { public boolean disableLongPressOnMap() {
if (mInChangeMarkerPositionMode || mInGpxDetailsMode || mInAddGpxPointMode || if (mInChangeMarkerPositionMode || mInGpxDetailsMode || mInAddGpxPointMode ||
activity.getMapRouteInfoMenu().isVisible() || MapRouteInfoMenu.chooseRoutesVisible || MapRouteInfoMenu.waypointsVisible) { activity.getMapRouteInfoMenu().isVisible() || MapRouteInfoMenu.waypointsVisible) {
return true; return true;
} }
boolean res = false; boolean res = false;

View file

@ -340,10 +340,6 @@ public class MapControlsLayer extends OsmandMapLayer {
mapRouteInfoMenu.showHideMenu(); mapRouteInfoMenu.showHideMenu();
} }
public void showRouteInfoControlDialog(int menuState) {
mapRouteInfoMenu.showHideMenu(menuState);
}
public void showRouteInfoMenu() { public void showRouteInfoMenu() {
mapRouteInfoMenu.setShowMenu(MapRouteInfoMenu.DEFAULT_MENU_STATE); mapRouteInfoMenu.setShowMenu(MapRouteInfoMenu.DEFAULT_MENU_STATE);
} }
@ -398,14 +394,8 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mapActivity.dismissCardDialog(); mapActivity.dismissCardDialog();
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
TransportRoutingHelper transportRoutingHelper = routingHelper.getTransportRoutingHelper();
if (transportRoutingHelper.hasActiveRoute()) {
ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), transportRoutingHelper.getCurrentRoute(), MenuState.FULL_SCREEN);
} else {
doRoute(false); doRoute(false);
} }
}
}); });
} }
@ -434,7 +424,7 @@ public class MapControlsLayer extends OsmandMapLayer {
mapActivity.getMapActions().enterRoutePlanningMode(null, null); mapActivity.getMapActions().enterRoutePlanningMode(null, null);
} }
} else { } else {
showRouteInfoControlDialog(MenuState.HEADER_ONLY); showRouteInfoControlDialog();
} }
hasTargets = false; hasTargets = false;
} }
@ -782,8 +772,9 @@ public class MapControlsLayer extends OsmandMapLayer {
boolean showButtons = (showRouteCalculationControls || !routeFollowingMode) boolean showButtons = (showRouteCalculationControls || !routeFollowingMode)
&& !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() && !isInPlanRouteMode() && !contextMenuOpened && !isInChoosingRoutesMode() && !isInWaypointsChoosingMode(); && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() && !isInPlanRouteMode() && !contextMenuOpened && !isInChoosingRoutesMode() && !isInWaypointsChoosingMode();
//routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions); //routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions);
if (trh.hasActiveRoute()) { int routePlanningBtnImage = mapRouteInfoMenu.getRoutePlanningBtnImage();
routePlanningBtn.setIconResId(R.drawable.map_action_bus_dark); if (routePlanningBtnImage != 0) {
routePlanningBtn.setIconResId(routePlanningBtnImage);
routePlanningBtn.setIconColorId(R.color.color_myloc_distance); routePlanningBtn.setIconColorId(R.color.color_myloc_distance);
} else if (rh.isFollowingMode()) { } else if (rh.isFollowingMode()) {
routePlanningBtn.setIconResId(R.drawable.map_start_navigation); routePlanningBtn.setIconResId(R.drawable.map_start_navigation);