From 95f7133562733b498c3d325114d033851a6584e8 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Tue, 30 May 2017 00:27:11 +0300 Subject: [PATCH] Fix #3746 --- .../plus/osmedit/DashOsmEditsFragment.java | 3 +- .../plus/osmedit/EditPOIMenuController.java | 15 +----- .../osmand/plus/osmedit/OsmEditsFragment.java | 5 +- .../osmedit/OsmEditsUploadListenerHelper.java | 14 ++--- .../dialogs/SendPoiDialogFragment.java | 54 +++++++++++-------- 5 files changed, 43 insertions(+), 48 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java index fcce5cbf3f..721bc99fb3 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java @@ -21,6 +21,7 @@ import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.dialogs.ProgressDialogFragment; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; +import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.PoiUploaderType; import java.util.ArrayList; import java.util.List; @@ -111,7 +112,7 @@ public class DashOsmEditsFragment extends DashBaseFragment @Override public void onClick(View v) { if (point.getGroup() == OsmPoint.Group.POI) { - SendPoiDialogFragment.createInstance(new OsmPoint[] {point}) + SendPoiDialogFragment.createInstance(new OsmPoint[] {point}, PoiUploaderType.FRAGMENT) .show(getChildFragmentManager(), "SendPoiDialogFragment"); } else { uploadItem(point); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index adca30c1f8..4c2e5a7618 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -2,7 +2,6 @@ package net.osmand.plus.osmedit; import android.content.DialogInterface; import android.graphics.drawable.Drawable; -import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; import net.osmand.data.PointDescription; @@ -12,7 +11,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; -import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader; import net.osmand.util.Algorithms; public class EditPOIMenuController extends MenuController { @@ -20,27 +18,18 @@ public class EditPOIMenuController extends MenuController { private OsmPoint osmPoint; private OsmEditingPlugin plugin; private String pointTypeStr; - private ProgressDialogPoiUploader poiUploader; public EditPOIMenuController(final MapActivity mapActivity, PointDescription pointDescription, OsmPoint osmPoint) { super(new EditPOIMenuBuilder(mapActivity, osmPoint), pointDescription, mapActivity); this.osmPoint = osmPoint; plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); - poiUploader = new SendPoiDialogFragment.SimpleProgressDialogPoiUploader() { - @NonNull - @Override - protected MapActivity getMapActivity() { - return mapActivity; - } - }; - leftTitleButtonController = new TitleButtonController() { @Override public void buttonPressed() { if (plugin != null) { - SendPoiDialogFragment sendPoiDialogFragment = SendPoiDialogFragment.createInstance(new OsmPoint[]{getOsmPoint()}); - sendPoiDialogFragment.setPoiUploader(poiUploader); + SendPoiDialogFragment sendPoiDialogFragment = + SendPoiDialogFragment.createInstance(new OsmPoint[]{getOsmPoint()}, SendPoiDialogFragment.PoiUploaderType.SIMPLE); sendPoiDialogFragment.show(getMapActivity().getSupportFragmentManager(), SendPoiDialogFragment.TAG); } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 2e93eef6a3..356d6765b6 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -45,6 +45,7 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; +import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.PoiUploaderType; import org.xmlpull.v1.XmlSerializer; @@ -543,8 +544,8 @@ public class OsmEditsFragment extends OsmAndListFragment } private void uploadItems(final OsmPoint[] items) { - SendPoiDialogFragment.createInstance(items).show(getChildFragmentManager(), - SendPoiDialogFragment.TAG); + SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT) + .show(getChildFragmentManager(), SendPoiDialogFragment.TAG); // UploadOsmEditsConfirmDialogFragment.createInstancee(items).show(getChildFragmentManager(), // UploadOsmEditsConfirmDialogFragment.TAG); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java index 37c47e8b5a..291fd95011 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java @@ -29,6 +29,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.ProgressDialogFragment; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; +import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.PoiUploaderType; import java.text.MessageFormat; import java.util.ArrayList; @@ -68,16 +69,11 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener { OsmPoint point = loadErrorsMap.keySet().iterator().next(); String message = loadErrorsMap.get(point); if (message.equals(activity.getString(R.string.auth_failed))) { - SendPoiDialogFragment dialogFragment = - SendPoiDialogFragment.createInstance(new OsmPoint[]{point}); + SendPoiDialogFragment dialogFragment; if (activity instanceof MapActivity) { - dialogFragment.setPoiUploader(new SendPoiDialogFragment.SimpleProgressDialogPoiUploader() { - @NonNull - @Override - protected MapActivity getMapActivity() { - return (MapActivity) activity; - } - }); + dialogFragment = SendPoiDialogFragment.createInstance(new OsmPoint[]{point}, PoiUploaderType.SIMPLE); + } else { + dialogFragment = SendPoiDialogFragment.createInstance(new OsmPoint[]{point}, PoiUploaderType.FRAGMENT); } dialogFragment.show(activity.getSupportFragmentManager(), "error_loading"); } else { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java index 33157471ff..72890060f2 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java @@ -32,17 +32,19 @@ import java.util.Map; public class SendPoiDialogFragment extends DialogFragment { public static final String TAG = "SendPoiDialogFragment"; public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; + public static final String POI_UPLOADER_TYPE = "poi_uploader_type"; private static String comment; - private ProgressDialogPoiUploader poiUploader; - public void setPoiUploader(ProgressDialogPoiUploader poiUploader) { - this.poiUploader = poiUploader; + public enum PoiUploaderType { + SIMPLE, + FRAGMENT } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final OsmPoint[] poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); + final PoiUploaderType poiUploaderType = PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, PoiUploaderType.SIMPLE.name())); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.send_poi_dialog, null); final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch); @@ -83,41 +85,44 @@ public class SendPoiDialogFragment extends DialogFragment { }); final ProgressDialogPoiUploader progressDialogPoiUploader; - if (poiUploader != null) { - progressDialogPoiUploader = poiUploader; + if (poiUploaderType == PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) { + progressDialogPoiUploader = + new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity()); } else { progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment(); } - builder.setTitle(hasPOI ? R.string.upload_poi : R.string.upload_osm_note) .setView(view) .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - comment = messageEditText.getText().toString(); - settings.USER_NAME.set(userNameEditText.getText().toString()); - settings.USER_PASSWORD.set(passwordEditText.getText().toString()); - if (comment.length() > 0) { - for (OsmPoint osmPoint : poi) { - if (osmPoint.getGroup() == OsmPoint.Group.POI) { - ((OpenstreetmapPoint) osmPoint).setComment(comment); - break; + if (progressDialogPoiUploader != null) { + comment = messageEditText.getText().toString(); + settings.USER_NAME.set(userNameEditText.getText().toString()); + settings.USER_PASSWORD.set(passwordEditText.getText().toString()); + if (comment.length() > 0) { + for (OsmPoint osmPoint : poi) { + if (osmPoint.getGroup() == OsmPoint.Group.POI) { + ((OpenstreetmapPoint) osmPoint).setComment(comment); + break; + } } } + progressDialogPoiUploader.showProgressDialog(poi, + closeChangeSetCheckBox.isChecked(), + !hasPOI && uploadAnonymously.isChecked()); } - progressDialogPoiUploader.showProgressDialog(poi, - closeChangeSetCheckBox.isChecked(), - !hasPOI && uploadAnonymously.isChecked()); } }) .setNegativeButton(R.string.shared_string_cancel, null); return builder.create(); } - public static SendPoiDialogFragment createInstance(OsmPoint[] points) { + public static SendPoiDialogFragment createInstance(@NonNull OsmPoint[] points, @NonNull PoiUploaderType uploaderType) { SendPoiDialogFragment fragment = new SendPoiDialogFragment(); Bundle bundle = new Bundle(); bundle.putSerializable(OPENSTREETMAP_POINT, points); + bundle.putString(POI_UPLOADER_TYPE, uploaderType.name()); fragment.setArguments(bundle); return fragment; } @@ -126,14 +131,20 @@ public class SendPoiDialogFragment extends DialogFragment { void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously); } - public static abstract class SimpleProgressDialogPoiUploader implements ProgressDialogPoiUploader { + public static class SimpleProgressDialogPoiUploader implements ProgressDialogPoiUploader { + + private MapActivity mapActivity; + + public SimpleProgressDialogPoiUploader(MapActivity mapActivity) { + this.mapActivity = mapActivity; + } + @Override public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) { ProgressDialogFragment dialog = ProgressDialogFragment.createInstance( R.string.uploading, R.string.local_openstreetmap_uploading, ProgressDialog.STYLE_HORIZONTAL); - final MapActivity mapActivity = getMapActivity(); OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(mapActivity, mapActivity.getString(R.string.local_openstreetmap_were_uploaded)) { @@ -153,8 +164,5 @@ public class SendPoiDialogFragment extends DialogFragment { dialog, listener, plugin, points.length, closeChangeSet, anonymously); uploadTask.execute(points); } - - @NonNull - abstract protected MapActivity getMapActivity(); } }