From d60acbb34f33c9d0baa512ab82b661364b4db7a5 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Wed, 26 Oct 2016 12:49:52 +0300 Subject: [PATCH] Fix crash while dismissing search address dialog (add favorite) --- .../plus/mapcontextmenu/MapContextMenu.java | 38 +++++++++++++------ .../mapcontextmenu/MenuTitleController.java | 22 ++++++----- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index c475f38f93..55d47b2d56 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -151,6 +151,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL if (menuController != null) { menuController.addPlainMenuItems(typeStr, this.pointDescription, this.latLon); } + if (searchDoneAction != null && searchDoneAction.dlg != null && searchDoneAction.dlg.getOwnerActivity() != mapActivity) { + searchDoneAction.dlg = buildSearchActionDialog(); + searchDoneAction.dlg.show(); + } } else { menuController = null; } @@ -593,10 +597,15 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL fragmentRef.get().refreshTitle(); if (searchDoneAction != null) { - if (searchDoneAction.dlg != null) { - searchDoneAction.dlg.dismiss(); - searchDoneAction.dlg = null; - } + if (searchDoneAction.dlg != null) { + try { + searchDoneAction.dlg.dismiss(); + } catch (Exception e) { + // ignore + } finally { + searchDoneAction.dlg = null; + } + } searchDoneAction.run(); searchDoneAction = null; } @@ -706,14 +715,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL private void callMenuAction(boolean waitForAddressLookup, MenuAction menuAction) { if (searchingAddress() && waitForAddressLookup) { - menuAction.dlg = new ProgressDialog(mapActivity); - menuAction.dlg.setTitle(""); - menuAction.dlg.setMessage(searchAddressStr); - menuAction.dlg.setButton(Dialog.BUTTON_NEGATIVE, mapActivity.getResources().getString(R.string.shared_string_skip), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - cancelSearchAddress(); - } - }); + menuAction.dlg = buildSearchActionDialog(); menuAction.dlg.show(); searchDoneAction = menuAction; } else { @@ -721,6 +723,18 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } } + private ProgressDialog buildSearchActionDialog() { + ProgressDialog dlg = new ProgressDialog(mapActivity); + dlg.setTitle(""); + dlg.setMessage(searchAddressStr); + dlg.setButton(Dialog.BUTTON_NEGATIVE, mapActivity.getResources().getString(R.string.shared_string_skip), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + cancelSearchAddress(); + } + }); + return dlg; + } + public void addAsLastIntermediate() { mapActivity.getMyApplication().getTargetPointsHelper().navigateToPoint(latLon, true, mapActivity.getMyApplication().getTargetPointsHelper().getIntermediatePoints().size(), diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java index 2c3b18a9c6..108aeb78b9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java @@ -161,18 +161,20 @@ public abstract class MenuTitleController { addressLookupRequest = new AddressLookupRequest(getLatLon(), new GeocodingLookupService.OnAddressLookupResult() { @Override public void geocodingDone(String address) { - addressLookupRequest = null; - if (Algorithms.isEmpty(address)) { - streetStr = PointDescription.getAddressNotFoundStr(getMapActivity()); - } else { - streetStr = address; - } + if (addressLookupRequest != null) { + addressLookupRequest = null; + if (Algorithms.isEmpty(address)) { + streetStr = PointDescription.getAddressNotFoundStr(getMapActivity()); + } else { + streetStr = address; + } - if (displayStreetNameInTitle()) { - nameStr = streetStr; - getPointDescription().setName(nameStr); + if (displayStreetNameInTitle()) { + nameStr = streetStr; + getPointDescription().setName(nameStr); + } + onSearchAddressDone(); } - onSearchAddressDone(); } }, new GeocodingLookupService.OnAddressLookupProgress() { @Override