Fix MapMultiSelectionMenu crash

This commit is contained in:
crimean 2018-08-06 10:56:38 +03:00
parent e99ae6b63b
commit bbff59a88b

View file

@ -44,16 +44,17 @@ public class MapMultiSelectionMenu extends BaseMenuController {
this.pointDescription = pointDescription; this.pointDescription = pointDescription;
this.object = object; this.object = object;
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
if (mapActivity != null) {
init(); init();
} }
}
protected void init() { protected void init() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
controller = MenuController.getMenuController(mapActivity, latLon, pointDescription, object, MenuType.MULTI_LINE); controller = MenuController.getMenuController(mapActivity, latLon, pointDescription, object, MenuType.MULTI_LINE);
controller.setActive(true); controller.setActive(true);
initTitle(); initTitle();
} }
}
protected void deinit() { protected void deinit() {
controller = null; controller = null;
@ -160,7 +161,10 @@ public class MapMultiSelectionMenu extends BaseMenuController {
private void clearMenu() { private void clearMenu() {
clearSelectedObjects(); clearSelectedObjects();
objects.clear(); objects.clear();
getMapActivity().refreshMap(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.refreshMap();
}
} }
public void show(LatLon latLon, Map<Object, IContextMenuProvider> selectedObjects) { public void show(LatLon latLon, Map<Object, IContextMenuProvider> selectedObjects) {
@ -170,8 +174,11 @@ public class MapMultiSelectionMenu extends BaseMenuController {
this.latLon = latLon; this.latLon = latLon;
createCollection(selectedObjects); createCollection(selectedObjects);
updateNightMode(); updateNightMode();
MapMultiSelectionMenuFragment.showInstance(getMapActivity()); MapActivity mapActivity = getMapActivity();
getMapActivity().refreshMap(); if (mapActivity != null) {
MapMultiSelectionMenuFragment.showInstance(mapActivity);
mapActivity.refreshMap();
}
} }
public boolean isVisible() { public boolean isVisible() {
@ -180,7 +187,12 @@ public class MapMultiSelectionMenu extends BaseMenuController {
} }
public Fragment getFragmentByTag() { public Fragment getFragmentByTag() {
return getMapActivity().getSupportFragmentManager().findFragmentByTag(MapMultiSelectionMenuFragment.TAG); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
return mapActivity.getSupportFragmentManager().findFragmentByTag(MapMultiSelectionMenuFragment.TAG);
} else {
return null;
}
} }
public void hide() { public void hide() {
@ -199,9 +211,12 @@ public class MapMultiSelectionMenu extends BaseMenuController {
public void openContextMenu(@NonNull MenuObject menuObject) { public void openContextMenu(@NonNull MenuObject menuObject) {
IContextMenuProvider provider = selectedObjects.remove(menuObject.getObject()); IContextMenuProvider provider = selectedObjects.remove(menuObject.getObject());
hide(); hide();
ContextMenuLayer contextMenuLayer = getMapActivity().getMapLayers().getContextMenuLayer(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
ContextMenuLayer contextMenuLayer = mapActivity.getMapLayers().getContextMenuLayer();
contextMenuLayer.showContextMenu(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject(), provider); contextMenuLayer.showContextMenu(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject(), provider);
} }
}
private void clearSelectedObjects() { private void clearSelectedObjects() {
for(IContextMenuProvider p : selectedObjects.values()) { for(IContextMenuProvider p : selectedObjects.values()) {