diff --git a/OsmAnd/res/layout/send_poi_dialog.xml b/OsmAnd/res/layout/send_poi_dialog.xml index ed7dce514f..46ceffeb3b 100644 --- a/OsmAnd/res/layout/send_poi_dialog.xml +++ b/OsmAnd/res/layout/send_poi_dialog.xml @@ -5,46 +5,52 @@ android:orientation="vertical"> + android:layout_height="wrap_content" + android:layout_marginLeft="5dp" + android:text="@string/osb_comment_dialog_message"/> + android:inputType="textMultiLine" + android:minLines="1"/> + + android:layout_height="wrap_content" + android:layout_marginLeft="5dp" + android:text="@string/user_name"/> + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp"/> + android:layout_height="wrap_content" + android:layout_marginLeft="5dp" + android:text="@string/user_password"/> + android:inputType="textPassword"/> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 41f2b11200..1c7fa09744 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2190,6 +2190,7 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A POI was successfully deleted add change + delete Action {0} completed successfully. Unexpected error occurred while performing action {0}. I/O error occurred while performing action {0}. diff --git a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java index d34af05679..8f46e8c385 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java @@ -1,9 +1,11 @@ package net.osmand.plus.osmedit; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; +import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; @@ -11,12 +13,16 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; 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; +import net.osmand.access.AccessibleToast; import net.osmand.data.PointDescription; +import net.osmand.osm.edit.EntityInfo; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.ProgressImplementation; @@ -24,6 +30,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashBaseFragment; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -205,13 +212,15 @@ public class DashOsmEditsFragment extends DashBaseFragment { @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { + final OpenstreetmapPoint poi = (OpenstreetmapPoint) getArguments().getSerializable(OPENSTREETMAP_POINT); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.send_poi_dialog, null); final EditText messageEditText = (EditText) view.findViewById(R.id.messageEditText); final EditText userNameEditText = (EditText) view.findViewById(R.id.userNameEditText); final EditText passwordEditText = (EditText) view.findViewById(R.id.passwordEditText); - + final CheckBox closeChangeSetCheckBox = + (CheckBox) view.findViewById(R.id.closeChangeSetCheckBox); final OsmandSettings settings = ((MapActivity) getActivity()).getMyApplication().getSettings(); userNameEditText.setText(settings.USER_NAME.get()); passwordEditText.setText(settings.USER_PASSWORD.get()); @@ -220,10 +229,61 @@ public class DashOsmEditsFragment extends DashBaseFragment { .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { + final OpenstreetmapRemoteUtil openstreetmapRemoteUtil + = new OpenstreetmapRemoteUtil(getActivity()); settings.USER_NAME.set(userNameEditText.getText().toString()); settings.USER_PASSWORD.set(passwordEditText.getText().toString()); - poi.setComment(messageEditText.getText().toString()); - ((DashOsmEditsFragment) getParentFragment()).showProgressDialog(poi); + final String message = messageEditText.getText().toString(); + final boolean closeChangeSet = closeChangeSetCheckBox.isChecked(); + final Activity activity = getActivity(); + int actionTypeMessageId = -1; + switch (poi.getAction()) { + case CREATE: actionTypeMessageId = R.string.poi_action_add; + break; + case MODIFY: actionTypeMessageId = R.string.poi_action_change; + break; + case DELETE: actionTypeMessageId = R.string.poi_action_delete; + break; + } + final String resultMessage = + getResources().getString(actionTypeMessageId); + final String successTemplate = getResources().getString( + R.string.poi_action_succeded_template); + + new AsyncTask() { + + @Override + protected EntityInfo doInBackground(Void... params) { + return openstreetmapRemoteUtil.loadNode(poi.getEntity()); + } + + @Override + protected void onPostExecute(EntityInfo entityInfo) { + EditPoiFragment.commitNode(poi.getAction(), poi.getEntity(), + entityInfo, + message, + closeChangeSet, + new Runnable() { + @Override + public void run() { + AccessibleToast.makeText( + activity, + MessageFormat.format( + successTemplate, + resultMessage), + Toast.LENGTH_LONG).show(); + + if (activity instanceof MapActivity) { + ((MapActivity) activity) + .getMapView().refreshMap(true); + } + } + }, + activity, openstreetmapRemoteUtil); + } + }.execute(); +// poi.setComment(messageEditText.getText().toString()); +// ((DashOsmEditsFragment) getParentFragment()).showProgressDialog(poi); } }) .setNegativeButton(R.string.shared_string_cancel, null); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java index 5b1e76c870..dde58888a8 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java @@ -419,7 +419,12 @@ public class EditPoiFragment extends DialogFragment { final Runnable successAction, final Activity activity, final OpenstreetmapUtil openstreetmapUtil) { + LOG.debug("commitNode(" + "action=" + action + ", n=" + n + ", info=" + info + + ", comment=" + comment + ", closeChangeSet=" + closeChangeSet + + ", successAction=" + successAction + ", activity=" + activity + + ", openstreetmapUtil=" + openstreetmapUtil + ")"); if (info == null && OsmPoint.Action.CREATE != action) { + AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show(); return; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapUtil.java index 8a1f839fdf..5f212a00a9 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapUtil.java @@ -13,5 +13,4 @@ public interface OpenstreetmapUtil { public void closeChangeSet(); public Node loadNode(Amenity n); - } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java index bb960ebf93..938dfac41f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java @@ -7,22 +7,15 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.LinearLayout; import android.widget.Toast; import net.osmand.access.AccessibleToast; -import net.osmand.data.Amenity; import net.osmand.osm.edit.Node; -import net.osmand.plus.OsmandApplication; 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.EditPoiFragment; import net.osmand.plus.osmedit.OpenstreetmapLocalUtil; -import net.osmand.plus.osmedit.OpenstreetmapRemoteUtil; import net.osmand.plus.osmedit.OpenstreetmapUtil; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmPoint; @@ -38,47 +31,31 @@ public class DeletePoiDialogFragment extends DialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); - OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings(); OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); final OpenstreetmapUtil mOpenstreetmapUtil; - if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) { - mOpenstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity); - } else if (!settings.isInternetConnectionAvailable(true)) { - mOpenstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity); - } else { - mOpenstreetmapUtil = new OpenstreetmapRemoteUtil(activity); - } + mOpenstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity); final Bundle args = getArguments(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.poi_remove_title); - LinearLayout ll = new LinearLayout(activity); - ll.setPadding(4, 2, 4, 0); - ll.setOrientation(LinearLayout.VERTICAL); - final EditText comment = new EditText(activity); - comment.setText(R.string.poi_remove_title); - ll.addView(comment); - final CheckBox closeChangeset; - closeChangeset = new CheckBox(activity); - closeChangeset.setText(R.string.close_changeset); - ll.addView(closeChangeset); - builder.setView(ll); + 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 n = (Node) args.getSerializable(KEY_AMENITY_NODE); - String c = comment.getText().toString(); - EditPoiFragment.commitNode(OsmPoint.Action.DELETE, n, mOpenstreetmapUtil.getEntityInfo(), c, - closeChangeset == null ? false : closeChangeset.isSelected(), new Runnable() { + Node node = (Node) args.getSerializable(KEY_AMENITY_NODE); + EditPoiFragment.commitNode(OsmPoint.Action.DELETE, node, + mOpenstreetmapUtil.getEntityInfo(), null, false, + new Runnable() { @Override public void run() { - AccessibleToast.makeText(activity, R.string.poi_remove_success, Toast.LENGTH_LONG).show(); + AccessibleToast.makeText(activity, R.string.poi_remove_success, + Toast.LENGTH_LONG).show(); if (activity instanceof MapActivity) { ((MapActivity) activity).getMapView().refreshMap(true); } } - }, getActivity(), mOpenstreetmapUtil); + }, + getActivity(), mOpenstreetmapUtil); } }); return builder.create();