From 77a7b03144743b1468803e134d7bc5300604e060 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 16 Nov 2020 16:55:06 +0200 Subject: [PATCH] Fix crash on taping "Upload" in My places. --- .../SendOsmNoteBottomSheetFragment.java | 15 ++++++++-- .../dialogs/SendPoiBottomSheetFragment.java | 28 ++++++++++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java index 407e8c0b5f..8cd61909e4 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.osmedit.dialogs; +import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.ContextThemeWrapper; @@ -24,6 +25,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.dialogs.ProgressDialogFragment; import net.osmand.plus.osmedit.OsmNotesPoint; import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; @@ -171,9 +173,16 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen @Override protected void onRightBottomButtonClick() { - ProgressDialogPoiUploader progressDialogPoiUploader; - progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity()); - progressDialogPoiUploader.showProgressDialog(poi, false, uploadAnonymously.isChecked()); + ProgressDialogPoiUploader progressDialogPoiUploader = null; + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) activity); + } else if (getParentFragment() instanceof ProgressDialogFragment) { + progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment(); + } + if (progressDialogPoiUploader != null) { + progressDialogPoiUploader.showProgressDialog(poi, false, uploadAnonymously.isChecked()); + } dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java index 7755568e43..dd862d0608 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.osmedit.dialogs; +import android.app.Activity; import android.os.Bundle; import android.view.ContextThemeWrapper; import android.view.View; @@ -20,6 +21,7 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.dialogs.ProgressDialogFragment; import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.settings.backend.OsmandSettings; @@ -109,19 +111,25 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { @Override protected void onRightBottomButtonClick() { - final ProgressDialogPoiUploader progressDialogPoiUploader; - progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity()); - - String comment = messageEditText.getText().toString(); - if (comment.length() > 0) { - for (OsmPoint osmPoint : poi) { - if (osmPoint.getGroup() == OsmPoint.Group.POI) { - ((OpenstreetmapPoint) osmPoint).setComment(comment); - break; + ProgressDialogPoiUploader progressDialogPoiUploader = null; + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) activity); + } else if (getParentFragment() instanceof ProgressDialogFragment) { + progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment(); + } + if (progressDialogPoiUploader != null) { + String comment = messageEditText.getText().toString(); + if (comment.length() > 0) { + for (OsmPoint osmPoint : poi) { + if (osmPoint.getGroup() == OsmPoint.Group.POI) { + ((OpenstreetmapPoint) osmPoint).setComment(comment); + break; + } } } + progressDialogPoiUploader.showProgressDialog(poi, closeChangeSet.isChecked(), false); } - progressDialogPoiUploader.showProgressDialog(poi, closeChangeSet.isChecked(), false); dismiss(); }