Delete dialog reverted to alert dialog

This commit is contained in:
GaidamakUA 2015-11-09 13:13:50 +02:00
parent aad04aa940
commit e0ec618e69
2 changed files with 51 additions and 80 deletions

View file

@ -38,8 +38,10 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -56,7 +58,6 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; 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.PoiSubTypeDialogFragment;
import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment; import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -247,8 +248,8 @@ public class EditPoiDialogFragment extends DialogFragment {
poiTypeEditText.setText(editPoiData.amenity.getSubType()); poiTypeEditText.setText(editPoiData.amenity.getSubType());
Button saveButton = (Button) view.findViewById(R.id.saveButton); Button saveButton = (Button) view.findViewById(R.id.saveButton);
saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil? R.string.shared_string_upload : saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil
R.string.shared_string_save); ? R.string.shared_string_upload : R.string.shared_string_save);
saveButton.setOnClickListener(new View.OnClickListener() { saveButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -588,14 +589,58 @@ public class EditPoiDialogFragment extends DialogFragment {
return openstreetmapUtil.loadNode(params[0]); return openstreetmapUtil.loadNode(params[0]);
} }
protected void onPostExecute(Node n) { protected void onPostExecute(final Node n) {
if (n == null) { if (n == null) {
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show();
return; return;
} }
// FIXME give back alert dialog and use openstreetmapUtil field! // FIXME give back alert dialog and use openstreetmapUtil field!
DeletePoiDialogFragment.createInstance(n).show(activity.getSupportFragmentManager(), AlertDialog.Builder builder = new AlertDialog.Builder(activity);
"DeletePoiDialogFragment"); 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();
} }
} }

View file

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