From e7b7a98266c61f62a542e02cf0ed95819c0f6ca7 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 4 Aug 2017 19:45:36 +0300 Subject: [PATCH] Fix transport context menu --- .../osmand/plus/activities/MapActivity.java | 4 +++ .../plus/mapcontextmenu/MapContextMenu.java | 10 ++---- .../MapContextMenuFragment.java | 8 +++-- .../controllers/TransportRouteController.java | 33 +++++++++++++------ 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 5d4d1cf404..94af799ba9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -498,6 +498,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return; } } + if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) { + mapContextMenu.close(); + return; + } if (prevActivityIntent != null && getSupportFragmentManager().getBackStackEntryCount() == 0) { prevActivityIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); LatLon loc = getMapLocation(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index a02acabfd1..d62cb251ff 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -379,15 +379,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL WeakReference fragmentRef = findMenuFragment(); init(latLon, pointDescription, object, true, false); if (fragmentRef != null) { - fragmentRef.get().rebuildMenu(); - } - } - - public void rebuildMenu() { - WeakReference fragmentRef = findMenuFragment(); - if (fragmentRef != null) { - fragmentRef.get().rebuildMenu(); + fragmentRef.get().rebuildMenu(centerMarker); } + centerMarker = false; } public void showOrUpdate(LatLon latLon, PointDescription pointDescription, Object object) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index f9f799b4b1..e34dea0ef1 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -792,7 +792,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { menu.setMapZoom(0); } - public void rebuildMenu() { + public void rebuildMenu(boolean centered) { OsmandApplication app = getMyApplication(); if (app != null && view != null) { IconsCache iconsCache = app.getIconsCache(); @@ -807,6 +807,10 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { bottomLayout.removeAllViews(); buildBottomView(); + if (centered) { + this.initLayout = true; + this.centered = true; + } runLayoutListener(); } } @@ -1284,7 +1288,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { public void downloadHasFinished() { updateOnDownload(); if (menu != null && menu.isVisible() && menu.isMapDownloaded()) { - rebuildMenu(); + rebuildMenu(false); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java index 9726df1a33..eb4311e2f9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java @@ -101,7 +101,13 @@ public class TransportRouteController extends MenuController { @Override public String getTypeStr() { - return getPointDescription().getTypeName(); + if (transportRoute.refStop != null) { + return transportRoute.refStop.getName(); + } else if (transportRoute.stop != null) { + return transportRoute.stop.getName(); + } else { + return getPointDescription().getTypeName(); + } } @Override @@ -159,16 +165,23 @@ public class TransportRouteController extends MenuController { @Override public void onClick(View arg0) { - MapContextMenu menu = getMapActivity().getContextMenu(); - PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_STOP, - getMapActivity().getString(R.string.transport_Stop), name); + if (mapContextMenu != null) { + transportRoute.stop = stop; + transportRoute.refStop = stop; + PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, + transportRoute.getDescription(getMapActivity().getMyApplication(), false)); - //resetRoute(); - LatLon stopLocation = stop.getLocation(); - getMapActivity().getMyApplication().getSettings() - .setMapLocationToShow(stopLocation.getLatitude(), stopLocation.getLongitude(), - 15, pd, false, stop); - MapActivity.launchMapActivityMoveToTop(getMapActivity()); + LatLon stopLocation = stop.getLocation(); + if (mapContextMenu.isVisible()) { + mapContextMenu.updateMapCenter(stopLocation); + } else { + mapContextMenu.setMapCenter(stopLocation); + mapContextMenu.setMapPosition(getMapActivity().getMapView().getMapPosition()); + } + mapContextMenu.setCenterMarker(true); + mapContextMenu.setMapZoom(15); + mapContextMenu.showOrUpdate(stopLocation, pd, transportRoute); + } } }); }