Fix crash while dismissing search address dialog (add favorite)

This commit is contained in:
Alexey Kulish 2016-10-26 12:49:52 +03:00
parent 3d72814340
commit d60acbb34f
2 changed files with 38 additions and 22 deletions

View file

@ -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(),

View file

@ -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