This commit is contained in:
Alexey Kulish 2017-05-30 00:27:11 +03:00
parent 82512864c5
commit 95f7133562
5 changed files with 43 additions and 48 deletions

View file

@ -21,6 +21,7 @@ import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.dialogs.ProgressDialogFragment; import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.PoiUploaderType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -111,7 +112,7 @@ public class DashOsmEditsFragment extends DashBaseFragment
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (point.getGroup() == OsmPoint.Group.POI) { if (point.getGroup() == OsmPoint.Group.POI) {
SendPoiDialogFragment.createInstance(new OsmPoint[] {point}) SendPoiDialogFragment.createInstance(new OsmPoint[] {point}, PoiUploaderType.FRAGMENT)
.show(getChildFragmentManager(), "SendPoiDialogFragment"); .show(getChildFragmentManager(), "SendPoiDialogFragment");
} else { } else {
uploadItem(point); uploadItem(point);

View file

@ -2,7 +2,6 @@ package net.osmand.plus.osmedit;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import net.osmand.data.PointDescription; 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.mapcontextmenu.MenuController;
import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.osmedit.OsmPoint.Action;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
public class EditPOIMenuController extends MenuController { public class EditPOIMenuController extends MenuController {
@ -20,27 +18,18 @@ public class EditPOIMenuController extends MenuController {
private OsmPoint osmPoint; private OsmPoint osmPoint;
private OsmEditingPlugin plugin; private OsmEditingPlugin plugin;
private String pointTypeStr; private String pointTypeStr;
private ProgressDialogPoiUploader poiUploader;
public EditPOIMenuController(final MapActivity mapActivity, PointDescription pointDescription, OsmPoint osmPoint) { public EditPOIMenuController(final MapActivity mapActivity, PointDescription pointDescription, OsmPoint osmPoint) {
super(new EditPOIMenuBuilder(mapActivity, osmPoint), pointDescription, mapActivity); super(new EditPOIMenuBuilder(mapActivity, osmPoint), pointDescription, mapActivity);
this.osmPoint = osmPoint; this.osmPoint = osmPoint;
plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
poiUploader = new SendPoiDialogFragment.SimpleProgressDialogPoiUploader() {
@NonNull
@Override
protected MapActivity getMapActivity() {
return mapActivity;
}
};
leftTitleButtonController = new TitleButtonController() { leftTitleButtonController = new TitleButtonController() {
@Override @Override
public void buttonPressed() { public void buttonPressed() {
if (plugin != null) { if (plugin != null) {
SendPoiDialogFragment sendPoiDialogFragment = SendPoiDialogFragment.createInstance(new OsmPoint[]{getOsmPoint()}); SendPoiDialogFragment sendPoiDialogFragment =
sendPoiDialogFragment.setPoiUploader(poiUploader); SendPoiDialogFragment.createInstance(new OsmPoint[]{getOsmPoint()}, SendPoiDialogFragment.PoiUploaderType.SIMPLE);
sendPoiDialogFragment.show(getMapActivity().getSupportFragmentManager(), SendPoiDialogFragment.TAG); sendPoiDialogFragment.show(getMapActivity().getSupportFragmentManager(), SendPoiDialogFragment.TAG);
} }
} }

View file

@ -45,6 +45,7 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.osmedit.OsmPoint.Action;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.PoiUploaderType;
import org.xmlpull.v1.XmlSerializer; import org.xmlpull.v1.XmlSerializer;
@ -543,8 +544,8 @@ public class OsmEditsFragment extends OsmAndListFragment
} }
private void uploadItems(final OsmPoint[] items) { private void uploadItems(final OsmPoint[] items) {
SendPoiDialogFragment.createInstance(items).show(getChildFragmentManager(), SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT)
SendPoiDialogFragment.TAG); .show(getChildFragmentManager(), SendPoiDialogFragment.TAG);
// UploadOsmEditsConfirmDialogFragment.createInstancee(items).show(getChildFragmentManager(), // UploadOsmEditsConfirmDialogFragment.createInstancee(items).show(getChildFragmentManager(),
// UploadOsmEditsConfirmDialogFragment.TAG); // UploadOsmEditsConfirmDialogFragment.TAG);
} }

View file

@ -29,6 +29,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ProgressDialogFragment; import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.PoiUploaderType;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -68,16 +69,11 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
OsmPoint point = loadErrorsMap.keySet().iterator().next(); OsmPoint point = loadErrorsMap.keySet().iterator().next();
String message = loadErrorsMap.get(point); String message = loadErrorsMap.get(point);
if (message.equals(activity.getString(R.string.auth_failed))) { if (message.equals(activity.getString(R.string.auth_failed))) {
SendPoiDialogFragment dialogFragment = SendPoiDialogFragment dialogFragment;
SendPoiDialogFragment.createInstance(new OsmPoint[]{point});
if (activity instanceof MapActivity) { if (activity instanceof MapActivity) {
dialogFragment.setPoiUploader(new SendPoiDialogFragment.SimpleProgressDialogPoiUploader() { dialogFragment = SendPoiDialogFragment.createInstance(new OsmPoint[]{point}, PoiUploaderType.SIMPLE);
@NonNull } else {
@Override dialogFragment = SendPoiDialogFragment.createInstance(new OsmPoint[]{point}, PoiUploaderType.FRAGMENT);
protected MapActivity getMapActivity() {
return (MapActivity) activity;
}
});
} }
dialogFragment.show(activity.getSupportFragmentManager(), "error_loading"); dialogFragment.show(activity.getSupportFragmentManager(), "error_loading");
} else { } else {

View file

@ -32,17 +32,19 @@ import java.util.Map;
public class SendPoiDialogFragment extends DialogFragment { public class SendPoiDialogFragment extends DialogFragment {
public static final String TAG = "SendPoiDialogFragment"; public static final String TAG = "SendPoiDialogFragment";
public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
public static final String POI_UPLOADER_TYPE = "poi_uploader_type";
private static String comment; private static String comment;
private ProgressDialogPoiUploader poiUploader;
public void setPoiUploader(ProgressDialogPoiUploader poiUploader) { public enum PoiUploaderType {
this.poiUploader = poiUploader; SIMPLE,
FRAGMENT
} }
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
final OsmPoint[] poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT); 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()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.send_poi_dialog, null); View view = getActivity().getLayoutInflater().inflate(R.layout.send_poi_dialog, null);
final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch); final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch);
@ -83,41 +85,44 @@ public class SendPoiDialogFragment extends DialogFragment {
}); });
final ProgressDialogPoiUploader progressDialogPoiUploader; final ProgressDialogPoiUploader progressDialogPoiUploader;
if (poiUploader != null) { if (poiUploaderType == PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) {
progressDialogPoiUploader = poiUploader; progressDialogPoiUploader =
new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity());
} else { } else {
progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment(); progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment();
} }
builder.setTitle(hasPOI ? R.string.upload_poi : R.string.upload_osm_note) builder.setTitle(hasPOI ? R.string.upload_poi : R.string.upload_osm_note)
.setView(view) .setView(view)
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
comment = messageEditText.getText().toString(); if (progressDialogPoiUploader != null) {
settings.USER_NAME.set(userNameEditText.getText().toString()); comment = messageEditText.getText().toString();
settings.USER_PASSWORD.set(passwordEditText.getText().toString()); settings.USER_NAME.set(userNameEditText.getText().toString());
if (comment.length() > 0) { settings.USER_PASSWORD.set(passwordEditText.getText().toString());
for (OsmPoint osmPoint : poi) { if (comment.length() > 0) {
if (osmPoint.getGroup() == OsmPoint.Group.POI) { for (OsmPoint osmPoint : poi) {
((OpenstreetmapPoint) osmPoint).setComment(comment); if (osmPoint.getGroup() == OsmPoint.Group.POI) {
break; ((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); .setNegativeButton(R.string.shared_string_cancel, null);
return builder.create(); return builder.create();
} }
public static SendPoiDialogFragment createInstance(OsmPoint[] points) { public static SendPoiDialogFragment createInstance(@NonNull OsmPoint[] points, @NonNull PoiUploaderType uploaderType) {
SendPoiDialogFragment fragment = new SendPoiDialogFragment(); SendPoiDialogFragment fragment = new SendPoiDialogFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable(OPENSTREETMAP_POINT, points); bundle.putSerializable(OPENSTREETMAP_POINT, points);
bundle.putString(POI_UPLOADER_TYPE, uploaderType.name());
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
} }
@ -126,14 +131,20 @@ public class SendPoiDialogFragment extends DialogFragment {
void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously); 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 @Override
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) { public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) {
ProgressDialogFragment dialog = ProgressDialogFragment.createInstance( ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(
R.string.uploading, R.string.uploading,
R.string.local_openstreetmap_uploading, R.string.local_openstreetmap_uploading,
ProgressDialog.STYLE_HORIZONTAL); ProgressDialog.STYLE_HORIZONTAL);
final MapActivity mapActivity = getMapActivity();
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(mapActivity, OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(mapActivity,
mapActivity.getString(R.string.local_openstreetmap_were_uploaded)) { mapActivity.getString(R.string.local_openstreetmap_were_uploaded)) {
@ -153,8 +164,5 @@ public class SendPoiDialogFragment extends DialogFragment {
dialog, listener, plugin, points.length, closeChangeSet, anonymously); dialog, listener, plugin, points.length, closeChangeSet, anonymously);
uploadTask.execute(points); uploadTask.execute(points);
} }
@NonNull
abstract protected MapActivity getMapActivity();
} }
} }