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
* 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;
@ -92,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);
@ -126,16 +127,16 @@ public class DashOsmEditsFragment extends DashBaseFragment {
b.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showProgressDialog(point, false);
showProgressDialog(new OsmPoint[] {point}, false);
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.show();
}
private void showProgressDialog(OsmPoint point, boolean closeChangeSet) {
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),

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, false);
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

@ -10,24 +10,20 @@ 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.activities.MapActivity;
import net.osmand.plus.osmedit.DashOsmEditsFragment;
import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmPoint;
/**
* Created by GaidamakUA on 9/7/15.
*/
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 = (OpenstreetmapPoint) getArguments().getSerializable(OPENSTREETMAP_POINT);
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);
@ -35,9 +31,14 @@ public class SendPoiDialogFragment extends DialogFragment {
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();
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() {
@ -45,9 +46,14 @@ public class SendPoiDialogFragment extends DialogFragment {
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());
((ProgressDialogPoiUploader) getParentFragment()).showProgressDialog(poi,
for (OsmPoint osmPoint : poi) {
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
((OpenstreetmapPoint) osmPoint)
.setComment(messageEditText.getText().toString());
break;
}
}
progressDialogPoiUploader.showProgressDialog(poi,
closeChangeSetCheckBox.isChecked());
}
})
@ -63,7 +69,7 @@ public class SendPoiDialogFragment extends DialogFragment {
return fragment;
}
interface ProgressDialogPoiUploader {
public interface ProgressDialogPoiUploader {
void showProgressDialog(OsmPoint[] points, boolean closeChangeSet);
}
}