From e0ec618e6957541a6fdda1b9bc1747eaa0594aae Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Mon, 9 Nov 2015 13:13:50 +0200 Subject: [PATCH] Delete dialog reverted to alert dialog --- .../plus/osmedit/EditPoiDialogFragment.java | 57 ++++++++++++-- .../dialogs/DeletePoiDialogFragment.java | 74 ------------------- 2 files changed, 51 insertions(+), 80 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index 2e998be40e..0e9fe69797 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -38,8 +38,10 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; +import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageButton; +import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -56,7 +58,6 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.osmedit.dialogs.DeletePoiDialogFragment; import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment; import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment; import net.osmand.util.Algorithms; @@ -247,8 +248,8 @@ public class EditPoiDialogFragment extends DialogFragment { poiTypeEditText.setText(editPoiData.amenity.getSubType()); Button saveButton = (Button) view.findViewById(R.id.saveButton); - saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil? R.string.shared_string_upload : - R.string.shared_string_save); + saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil + ? R.string.shared_string_upload : R.string.shared_string_save); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -588,14 +589,58 @@ public class EditPoiDialogFragment extends DialogFragment { return openstreetmapUtil.loadNode(params[0]); } - protected void onPostExecute(Node n) { + protected void onPostExecute(final Node n) { if (n == null) { AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show(); return; } // FIXME give back alert dialog and use openstreetmapUtil field! - DeletePoiDialogFragment.createInstance(n).show(activity.getSupportFragmentManager(), - "DeletePoiDialogFragment"); + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(R.string.poi_remove_title); + final EditText comment; + final CheckBox closeChangesetCheckBox; + final boolean isLocalEdit = openstreetmapUtil instanceof OpenstreetmapLocalUtil; + if (isLocalEdit) { + closeChangesetCheckBox = null; + comment = null; + } else { + LinearLayout ll = new LinearLayout(activity); + ll.setPadding(16, 2, 16, 0); + ll.setOrientation(LinearLayout.VERTICAL); + closeChangesetCheckBox = new CheckBox(activity); + closeChangesetCheckBox.setText(R.string.close_changeset); + ll.addView(closeChangesetCheckBox); + comment = new EditText(activity); + comment.setText(R.string.poi_remove_title); + ll.addView(comment); + builder.setView(ll); + } + builder.setNegativeButton(R.string.shared_string_cancel, null); + builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String c = comment == null ? null : comment.getText().toString(); + boolean closeChangeSet = closeChangesetCheckBox != null + && closeChangesetCheckBox.isSelected(); + commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(), c, + closeChangeSet, new Runnable() { + @Override + public void run() { + if (isLocalEdit) { + AccessibleToast.makeText( + activity, R.string.osm_changes_added_to_local_edits, + Toast.LENGTH_LONG).show(); + } else { + AccessibleToast.makeText(activity, R.string.poi_remove_success, Toast.LENGTH_LONG).show(); + } + if (activity instanceof MapActivity) { + ((MapActivity) activity).getMapView().refreshMap(true); + } + } + }, activity, openstreetmapUtil); + } + }); + builder.create().show(); } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java deleted file mode 100644 index 66bfa44ae2..0000000000 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java +++ /dev/null @@ -1,74 +0,0 @@ -package net.osmand.plus.osmedit.dialogs; - -import android.app.Activity; -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.DialogFragment; -import android.support.v7.app.AlertDialog; -import android.widget.Toast; - -import net.osmand.access.AccessibleToast; -import net.osmand.osm.edit.Node; -import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.osmedit.EditPoiDialogFragment; -import net.osmand.plus.osmedit.OpenstreetmapLocalUtil; -import net.osmand.plus.osmedit.OpenstreetmapUtil; -import net.osmand.plus.osmedit.OsmEditingPlugin; -import net.osmand.plus.osmedit.OsmPoint; - -public class DeletePoiDialogFragment extends DialogFragment { - private static final String KEY_AMENITY_NODE = "amenity_node"; - Activity activity; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - this.activity = activity; - } - - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); - final OpenstreetmapUtil mOpenstreetmapUtil; - mOpenstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity); - - final Bundle args = getArguments(); - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.poi_remove_title); - builder.setNegativeButton(R.string.shared_string_cancel, null); - builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Node node = (Node) args.getSerializable(KEY_AMENITY_NODE); - EditPoiDialogFragment.commitNode(OsmPoint.Action.DELETE, node, - mOpenstreetmapUtil.getEntityInfo(), null, false, - new Runnable() { - @Override - public void run() { - AccessibleToast.makeText(activity, - getString(R.string.poi_deleted_localy), - Toast.LENGTH_LONG).show(); - if (activity instanceof MapActivity) { - ((MapActivity) activity).getMapView().refreshMap(true); - } - } - }, - getActivity(), mOpenstreetmapUtil); - } - }); - return builder.create(); - } - - public static DeletePoiDialogFragment createInstance(Node amenityNode) { - DeletePoiDialogFragment fragment = new DeletePoiDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putSerializable(KEY_AMENITY_NODE, amenityNode); - fragment.setArguments(bundle); - return fragment; - } -}