Merge branch 'deletion_dialog_redesign'

This commit is contained in:
GaidamakUA 2015-09-07 16:18:10 +03:00
commit e9060b201c
10 changed files with 174 additions and 144 deletions

View file

@ -5,46 +5,52 @@
android:orientation="vertical">
<TextView
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/osb_comment_dialog_message" />
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/osb_comment_dialog_message"/>
<EditText
android:id="@+id/messageEditText"
android:minLines="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="textMultiLine" />
android:inputType="textMultiLine"
android:minLines="1"/>
<CheckBox
android:id="@+id/closeChangeSetCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/close_changeset"/>
<TextView
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/user_name" />
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/user_name"/>
<EditText
android:id="@+id/userNameEditText"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
<TextView
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/user_password" />
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/user_password"/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="textPassword" />
android:inputType="textPassword"/>
</LinearLayout>

View file

@ -2190,6 +2190,7 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="poi_remove_success">POI was successfully deleted</string>
<string name="poi_action_add">add</string>
<string name="poi_action_change">change</string>
<string name="poi_action_delete">delete</string>
<string name="poi_action_succeded_template">Action {0} completed successfully.</string>
<string name="poi_error_unexpected_template">Unexpected error occurred while performing action {0}.</string>
<string name="poi_error_io_error_template">I/O error occurred while performing action {0}.</string>

View file

@ -1,28 +1,24 @@
package net.osmand.plus.osmedit;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashBaseFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
import java.util.ArrayList;
import java.util.List;
@ -32,7 +28,8 @@ import java.util.Map;
* Created by Denis
* on 20.01.2015.
*/
public class DashOsmEditsFragment extends DashBaseFragment {
public class DashOsmEditsFragment extends DashBaseFragment
implements SendPoiDialogFragment.ProgressDialogPoiUploader {
public static final String TAG = "DASH_OSM_EDITS_FRAGMENT";
OsmEditingPlugin plugin;
@ -96,7 +93,7 @@ public class DashOsmEditsFragment extends DashBaseFragment {
@Override
public void onClick(View v) {
if (point.getGroup() == OsmPoint.Group.POI) {
SendPoiDialogFragment.createInstance((OpenstreetmapPoint) point)
SendPoiDialogFragment.createInstance(new OsmPoint[] {point})
.show(getChildFragmentManager(), "SendPoiDialogFragment");
} else {
uploadItem(point);
@ -123,22 +120,23 @@ public class DashOsmEditsFragment extends DashBaseFragment {
}
}
// TODO: 9/7/15 Redesign osm notes.
private void uploadItem(final OsmPoint point) {
AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setMessage(getString(R.string.local_osm_changes_upload_all_confirm, 1));
b.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showProgressDialog(point);
showProgressDialog(new OsmPoint[] {point}, false);
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.show();
}
private void showProgressDialog(OsmPoint point) {
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet) {
OpenstreetmapRemoteUtil remotepoi = new OpenstreetmapRemoteUtil(getActivity());
OsmPoint[] toUpload = new OsmPoint[]{point};
OsmPoint[] toUpload = points;
OsmBugsRemoteUtil remotebug = new OsmBugsRemoteUtil(getMyApplication());
ProgressDialog dialog = ProgressImplementation.createProgressDialog(getActivity(),
getString(R.string.uploading), getString(R.string.local_openstreetmap_uploading),
@ -162,7 +160,7 @@ public class DashOsmEditsFragment extends DashBaseFragment {
}
};
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog,
listener, plugin, remotepoi, remotebug, toUpload.length);
listener, plugin, remotepoi, remotebug, toUpload.length, closeChangeSet);
uploadTask.execute(toUpload);
dialog.show();
}
@ -199,43 +197,4 @@ public class DashOsmEditsFragment extends DashBaseFragment {
}
}
public static class SendPoiDialogFragment extends DialogFragment {
public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
@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 OsmandSettings settings = ((MapActivity) getActivity()).getMyApplication().getSettings();
userNameEditText.setText(settings.USER_NAME.get());
passwordEditText.setText(settings.USER_PASSWORD.get());
builder.setTitle(R.string.commit_poi)
.setView(view)
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
settings.USER_NAME.set(userNameEditText.getText().toString());
settings.USER_PASSWORD.set(passwordEditText.getText().toString());
poi.setComment(messageEditText.getText().toString());
((DashOsmEditsFragment) getParentFragment()).showProgressDialog(poi);
}
})
.setNegativeButton(R.string.shared_string_cancel, null);
return builder.create();
}
public static SendPoiDialogFragment createInstance(OpenstreetmapPoint poi) {
SendPoiDialogFragment fragment = new SendPoiDialogFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(OPENSTREETMAP_POINT, poi);
fragment.setArguments(bundle);
return fragment;
}
}
}

View file

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

View file

@ -13,5 +13,4 @@ public interface OpenstreetmapUtil {
public void closeChangeSet();
public Node loadNode(Amenity n);
}

View file

@ -42,6 +42,7 @@ import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
import org.xmlpull.v1.XmlSerializer;
@ -56,7 +57,8 @@ import java.util.List;
* Created by Denis
* on 06.03.2015.
*/
public class OsmEditsFragment extends OsmAndListFragment {
public class OsmEditsFragment extends OsmAndListFragment
implements SendPoiDialogFragment.ProgressDialogPoiUploader {
OsmEditingPlugin plugin;
private OsmEditsAdapter listAdapter;
@ -488,11 +490,13 @@ public class OsmEditsFragment extends OsmAndListFragment {
}
private void uploadItems(final OsmPoint[] items) {
UploadOsmEditsConfirmDialogFragment.createInstance(items).show(getChildFragmentManager(),
UploadOsmEditsConfirmDialogFragment.TAG);
SendPoiDialogFragment.createInstance(items).show(getChildFragmentManager(),
SendPoiDialogFragment.TAG);
// UploadOsmEditsConfirmDialogFragment.createInstancee(items).show(getChildFragmentManager(),
// UploadOsmEditsConfirmDialogFragment.TAG);
}
private void showUploadItemsProgressDialog(OsmPoint[] toUpload) {
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet) {
ProgressDialog dialog = ProgressImplementation.createProgressDialog(
getActivity(),
getString(R.string.uploading),
@ -501,8 +505,8 @@ public class OsmEditsFragment extends OsmAndListFragment {
OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(getActivity(),
getString(R.string.local_openstreetmap_were_uploaded));
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
dialog, listener, plugin, remotepoi, remotebug, toUpload.length);
uploadTask.execute(toUpload);
dialog, listener, plugin, remotepoi, remotebug, points.length, closeChangeSet);
uploadTask.execute(points);
dialog.show();
}
@ -676,36 +680,36 @@ public class OsmEditsFragment extends OsmAndListFragment {
}
}
public static class UploadOsmEditsConfirmDialogFragment extends DialogFragment {
public static final String TAG = "UploadOsmEditsConfirmDialogFragment";
private static final String POINTS_ARRAY = "points_list";
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final OsmPoint[] points = (OsmPoint[]) getArguments().getSerializable(POINTS_ARRAY);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(
getString(R.string.local_osm_changes_upload_all_confirm, points.length));
builder.setPositiveButton(R.string.shared_string_yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((OsmEditsFragment) getParentFragment())
.showUploadItemsProgressDialog(points);
}
});
builder.setNegativeButton(R.string.shared_string_cancel, null);
return builder.create();
}
public static UploadOsmEditsConfirmDialogFragment createInstance(OsmPoint[] points) {
UploadOsmEditsConfirmDialogFragment fragment =
new UploadOsmEditsConfirmDialogFragment();
Bundle args = new Bundle();
args.putSerializable(POINTS_ARRAY, points);
fragment.setArguments(args);
return fragment;
}
}
// public static class UploadOsmEditsConfirmDialogFragment extends DialogFragment {
// public static final String TAG = "UploadOsmEditsConfirmDialogFragment";
// private static final String POINTS_ARRAY = "points_list";
//
// @NonNull
// @Override
// public Dialog onCreateDialog(Bundle savedInstanceState) {
// final OsmPoint[] points = (OsmPoint[]) getArguments().getSerializable(POINTS_ARRAY);
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// builder.setMessage(
// getString(R.string.local_osm_changes_upload_all_confirm, points.length));
// builder.setPositiveButton(R.string.shared_string_yes,
// new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// ((OsmEditsFragment) getParentFragment())
// .showUploadItemsProgressDialog(points);
// }
// });
// builder.setNegativeButton(R.string.shared_string_cancel, null);
// return builder.create();
// }
//
// public static UploadOsmEditsConfirmDialogFragment createInstance(OsmPoint[] points) {
// UploadOsmEditsConfirmDialogFragment fragment =
// new UploadOsmEditsConfirmDialogFragment();
// Bundle args = new Bundle();
// args.putSerializable(POINTS_ARRAY, points);
// fragment.setArguments(args);
// return fragment;
// }
// }
}

View file

@ -94,7 +94,7 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
resources.getString(R.string.local_openstreetmap_uploading),
ProgressDialog.STYLE_HORIZONTAL).getDialog();
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
dialog, helper, plugin, remotepoi, remotebug, toUpload.length);
dialog, helper, plugin, remotepoi, remotebug, toUpload.length, false);
uploadTask.execute(toUpload);
dialog.show();

View file

@ -23,19 +23,22 @@ public class UploadOpenstreetmapPointAsyncTask
private boolean interruptUploading = false;
private OsmEditsUploadListener listener;
private OsmEditingPlugin plugin;
private final boolean closeChangeSet;
public UploadOpenstreetmapPointAsyncTask(ProgressDialog progress,
OsmEditsUploadListener listener,
OsmEditingPlugin plugin,
OpenstreetmapRemoteUtil remotepoi,
OsmBugsRemoteUtil remotebug,
int listSize) {
int listSize,
boolean closeChangeSet) {
this.progress = progress;
this.plugin = plugin;
this.remotepoi = remotepoi;
this.remotebug = remotebug;
this.listSize = listSize;
this.listener = listener;
this.closeChangeSet = closeChangeSet;
}
@Override
@ -52,7 +55,8 @@ public class UploadOpenstreetmapPointAsyncTask
if (OsmPoint.Action.CREATE != p.getAction()) {
entityInfo = remotepoi.loadNode(p.getEntity());
}
Node n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo, p.getComment(), false);
Node n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo,
p.getComment(), closeChangeSet);
if (n != null) {
plugin.getDBPOI().deletePOI(p);
publishProgress(p);

View file

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

View file

@ -0,0 +1,75 @@
package net.osmand.plus.osmedit.dialogs;
import android.app.AlertDialog;
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.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmPoint;
public class SendPoiDialogFragment extends DialogFragment {
public static final String TAG = "SendPoiDialogFragment";
public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final OsmPoint[] poi = (OsmPoint[]) 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 = ((OsmandApplication) getActivity().getApplication())
.getSettings();
userNameEditText.setText(settings.USER_NAME.get());
passwordEditText.setText(settings.USER_PASSWORD.get());
final ProgressDialogPoiUploader progressDialogPoiUploader =
(ProgressDialogPoiUploader) getParentFragment();
builder.setTitle(R.string.commit_poi)
.setView(view)
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
settings.USER_NAME.set(userNameEditText.getText().toString());
settings.USER_PASSWORD.set(passwordEditText.getText().toString());
for (OsmPoint osmPoint : poi) {
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
((OpenstreetmapPoint) osmPoint)
.setComment(messageEditText.getText().toString());
break;
}
}
progressDialogPoiUploader.showProgressDialog(poi,
closeChangeSetCheckBox.isChecked());
}
})
.setNegativeButton(R.string.shared_string_cancel, null);
return builder.create();
}
public static SendPoiDialogFragment createInstance(OsmPoint[] points) {
SendPoiDialogFragment fragment = new SendPoiDialogFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(OPENSTREETMAP_POINT, points);
fragment.setArguments(bundle);
return fragment;
}
public interface ProgressDialogPoiUploader {
void showProgressDialog(OsmPoint[] points, boolean closeChangeSet);
}
}