New upload dialog implemented.

This commit is contained in:
GaidamakUA 2015-09-07 16:17:44 +03:00
parent 9595b25fc6
commit f318f6322c
3 changed files with 66 additions and 55 deletions

View file

@ -28,7 +28,8 @@ import java.util.Map;
* Created by Denis * Created by Denis
* on 20.01.2015. * 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"; public static final String TAG = "DASH_OSM_EDITS_FRAGMENT";
OsmEditingPlugin plugin; OsmEditingPlugin plugin;
@ -92,7 +93,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((OpenstreetmapPoint) point) SendPoiDialogFragment.createInstance(new OsmPoint[] {point})
.show(getChildFragmentManager(), "SendPoiDialogFragment"); .show(getChildFragmentManager(), "SendPoiDialogFragment");
} else { } else {
uploadItem(point); uploadItem(point);
@ -126,16 +127,16 @@ public class DashOsmEditsFragment extends DashBaseFragment {
b.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { b.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
showProgressDialog(point, false); showProgressDialog(new OsmPoint[] {point}, false);
} }
}); });
b.setNegativeButton(R.string.shared_string_cancel, null); b.setNegativeButton(R.string.shared_string_cancel, null);
b.show(); b.show();
} }
private void showProgressDialog(OsmPoint point, boolean closeChangeSet) { public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet) {
OpenstreetmapRemoteUtil remotepoi = new OpenstreetmapRemoteUtil(getActivity()); OpenstreetmapRemoteUtil remotepoi = new OpenstreetmapRemoteUtil(getActivity());
OsmPoint[] toUpload = new OsmPoint[]{point}; OsmPoint[] toUpload = points;
OsmBugsRemoteUtil remotebug = new OsmBugsRemoteUtil(getMyApplication()); OsmBugsRemoteUtil remotebug = new OsmBugsRemoteUtil(getMyApplication());
ProgressDialog dialog = ProgressImplementation.createProgressDialog(getActivity(), ProgressDialog dialog = ProgressImplementation.createProgressDialog(getActivity(),
getString(R.string.uploading), getString(R.string.local_openstreetmap_uploading), getString(R.string.uploading), getString(R.string.local_openstreetmap_uploading),

View file

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

View file

@ -10,24 +10,20 @@ import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import net.osmand.plus.OsmandApplication;
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.osmedit.DashOsmEditsFragment;
import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.osmedit.OsmPoint;
/**
* Created by GaidamakUA on 9/7/15.
*/
public class SendPoiDialogFragment extends DialogFragment { public class SendPoiDialogFragment extends DialogFragment {
public static final String TAG = "SendPoiDialogFragment";
public static final String OPENSTREETMAP_POINT = "openstreetmap_point"; public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
@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 = (OpenstreetmapPoint) getArguments().getSerializable(OPENSTREETMAP_POINT);
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 EditText messageEditText = (EditText) view.findViewById(R.id.messageEditText); final EditText messageEditText = (EditText) view.findViewById(R.id.messageEditText);
@ -35,9 +31,14 @@ public class SendPoiDialogFragment extends DialogFragment {
final EditText passwordEditText = (EditText) view.findViewById(R.id.passwordEditText); final EditText passwordEditText = (EditText) view.findViewById(R.id.passwordEditText);
final CheckBox closeChangeSetCheckBox = final CheckBox closeChangeSetCheckBox =
(CheckBox) view.findViewById(R.id.closeChangeSetCheckBox); (CheckBox) view.findViewById(R.id.closeChangeSetCheckBox);
final OsmandSettings settings = ((MapActivity) getActivity()).getMyApplication().getSettings(); final OsmandSettings settings = ((OsmandApplication) getActivity().getApplication())
.getSettings();
userNameEditText.setText(settings.USER_NAME.get()); userNameEditText.setText(settings.USER_NAME.get());
passwordEditText.setText(settings.USER_PASSWORD.get()); passwordEditText.setText(settings.USER_PASSWORD.get());
final ProgressDialogPoiUploader progressDialogPoiUploader =
(ProgressDialogPoiUploader) getParentFragment();
builder.setTitle(R.string.commit_poi) builder.setTitle(R.string.commit_poi)
.setView(view) .setView(view)
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@ -45,9 +46,14 @@ public class SendPoiDialogFragment extends DialogFragment {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
settings.USER_NAME.set(userNameEditText.getText().toString()); settings.USER_NAME.set(userNameEditText.getText().toString());
settings.USER_PASSWORD.set(passwordEditText.getText().toString()); settings.USER_PASSWORD.set(passwordEditText.getText().toString());
for (OsmPoint osmPoint : poi) {
poi.setComment(messageEditText.getText().toString()); if (osmPoint.getGroup() == OsmPoint.Group.POI) {
((ProgressDialogPoiUploader) getParentFragment()).showProgressDialog(poi, ((OpenstreetmapPoint) osmPoint)
.setComment(messageEditText.getText().toString());
break;
}
}
progressDialogPoiUploader.showProgressDialog(poi,
closeChangeSetCheckBox.isChecked()); closeChangeSetCheckBox.isChecked());
} }
}) })
@ -63,7 +69,7 @@ public class SendPoiDialogFragment extends DialogFragment {
return fragment; return fragment;
} }
interface ProgressDialogPoiUploader { public interface ProgressDialogPoiUploader {
void showProgressDialog(OsmPoint[] points, boolean closeChangeSet); void showProgressDialog(OsmPoint[] points, boolean closeChangeSet);
} }
} }