Merge pull request #1509 from GaidamakUA/dialog_for_failed_uploading

Dialog for issue #1291
This commit is contained in:
vshcherb 2015-07-31 10:19:17 +02:00
commit 920592c182
12 changed files with 501 additions and 219 deletions

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/list_item_height">
<TextView
android:id="@+id/nameTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/dialog_elements_vertical_margin"
android:layout_marginRight="@dimen/dialog_elements_vertical_margin"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/lorem_ipsum"/>
<ImageView
android:id="@+id/iconImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="3dp"
android:layout_marginRight="@dimen/dialog_elements_vertical_margin"
android:gravity="center_vertical"
android:maxLines="2"
android:src="@drawable/ic_action_remove_dark"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>

View file

@ -2222,4 +2222,9 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="rate_this_app_long">Please give OsmAnd a score on Google Play</string>
<string name="user_hates_app_get_feedback">Tell us why.</string>
<string name="user_hates_app_get_feedback_long">Please tell us what would you want to change in this app.</string>
<string name="failed_to_upload">Failed to upload</string>
<string name="delete_change">Delete change</string>
<string name="successfully_uploaded_pattern">Successfully uploaded {0}/{1}</string>
<string name="try_again">Try again</string>
<string name="error_message_pattern">Error: {0}</string>
</resources>

View file

@ -1,16 +1,5 @@
package net.osmand.plus.osmedit;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import net.osmand.access.AccessibleToast;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashBaseFragment;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
@ -22,13 +11,23 @@ import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashBaseFragment;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by Denis
* on 20.01.2015.
*/
public class DashOsmEditsFragment extends DashBaseFragment implements OsmEditsUploadListener {
public class DashOsmEditsFragment extends DashBaseFragment {
public static final String TAG = "DASH_OSM_EDITS_FRAGMENT";
OsmEditingPlugin plugin;
@ -134,8 +133,26 @@ public class DashOsmEditsFragment extends DashBaseFragment implements OsmEditsUp
ProgressDialog dialog = ProgressImplementation.createProgressDialog(getActivity(),
getString(R.string.uploading), getString(R.string.local_openstreetmap_uploading),
ProgressDialog.STYLE_HORIZONTAL).getDialog();
OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(getActivity(),
getString(R.string.local_openstreetmap_were_uploaded)) {
@Override
public void uploadUpdated(OsmPoint point) {
super.uploadUpdated(point);
if (!DashOsmEditsFragment.this.isDetached()) {
onOpenDash();
}
}
@Override
public void uploadEnded(Map<OsmPoint, String> loadErrorsMap) {
super.uploadEnded(loadErrorsMap);
if (!DashOsmEditsFragment.this.isDetached()) {
onOpenDash();
}
}
};
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog,
DashOsmEditsFragment.this, plugin, remotepoi, remotebug, toUpload.length);
listener, plugin, remotepoi, remotebug, toUpload.length);
uploadTask.execute(toUpload);
dialog.show();
}
@ -171,23 +188,4 @@ public class DashOsmEditsFragment extends DashBaseFragment implements OsmEditsUp
}
}
}
@Override
public void uploadUpdated(OsmPoint point) {
if (!this.isDetached()){
onOpenDash();
}
}
@Override
public void uploadEnded(Integer result) {
if (result != null) {
AccessibleToast.makeText(getActivity(),
MessageFormat.format(getString(R.string.local_openstreetmap_were_uploaded), result), Toast.LENGTH_LONG)
.show();
}
if (!this.isDetached()){
onOpenDash();
}
}
}

View file

@ -1,11 +1,9 @@
package net.osmand.plus.osmedit;
import java.io.Serializable;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
public class OpenstreetmapPoint extends OsmPoint implements Serializable {
public class OpenstreetmapPoint extends OsmPoint {
private static final long serialVersionUID = 729654300829771467L;
private Node entity;
private String comment;

View file

@ -1,20 +1,8 @@
package net.osmand.plus.osmedit;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.text.MessageFormat;
import java.util.LinkedHashMap;
import java.util.Map;
import android.content.Context;
import android.util.Xml;
import android.widget.Toast;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
@ -37,9 +25,21 @@ import org.apache.commons.logging.Log;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlSerializer;
import android.content.Context;
import android.util.Xml;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.text.MessageFormat;
import java.util.LinkedHashMap;
import java.util.Map;
public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
@ -335,11 +335,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
return entityInfo;
}
} catch (IOException e) {
log.error("Loading node failed " + nodeId, e); //$NON-NLS-1$
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error),
Toast.LENGTH_LONG).show();
} catch (SAXException e) {
} catch (IOException | SAXException e) {
log.error("Loading node failed " + nodeId, e); //$NON-NLS-1$
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error),
Toast.LENGTH_LONG).show();

View file

@ -1,14 +1,5 @@
package net.osmand.plus.osmedit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import net.osmand.PlatformUtil;
import net.osmand.osm.io.Base64;
import net.osmand.osm.io.NetworkUtils;
@ -19,20 +10,26 @@ import net.osmand.plus.Version;
import org.apache.commons.logging.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URLEncoder;
public class OsmBugsRemoteUtil implements OsmBugsUtil {
private static final Log log = PlatformUtil.getLog(OsmBugsRemoteUtil.class);
static String getNotesApi()
{
static String getNotesApi() {
final int deviceApiVersion = android.os.Build.VERSION.SDK_INT;
String RETURN_API;
if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) {
RETURN_API = "https://api.openstreetmap.org/api/0.6/notes";
}
else {
} else {
RETURN_API = "http://api.openstreetmap.org/api/0.6/notes";
}
@ -106,7 +103,6 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
// populate return fields.
StringBuilder responseBody = new StringBuilder();
if (true) {
responseBody.setLength(0);
InputStream i = connection.getInputStream();
if (i != null) {
@ -123,7 +119,6 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
}
}
log.info("Response : " + responseBody); //$NON-NLS-1$
}
connection.disconnect();
if (!ok) {
return msg + "\n" + responseBody;
@ -138,7 +133,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
return e.getMessage() + "";
} catch (IOException e) {
log.error(userOperation + " " + app.getString(R.string.failed_op), e); //$NON-NLS-1$
return e.getMessage() + "";
return e.getMessage() + " link unavailable";
}
return null;
}

View file

@ -1,12 +1,29 @@
package net.osmand.plus.osmedit;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.PopupMenu;
import android.util.Xml;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.access.AccessibleToast;
import net.osmand.data.PointDescription;
@ -25,37 +42,18 @@ import net.osmand.plus.myplaces.FavoritesActivity;
import org.xmlpull.v1.XmlSerializer;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.PopupMenu;
import android.util.Xml;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Created by Denis
* on 06.03.2015.
*/
public class OsmEditsFragment extends OsmAndListFragment implements OsmEditsUploadListener {
public class OsmEditsFragment extends OsmAndListFragment {
OsmEditingPlugin plugin;
private ArrayList<OsmPoint> dataPoints;
private OsmEditsAdapter listAdapter;
@ -502,8 +500,10 @@ public class OsmEditsFragment extends OsmAndListFragment implements OsmEditsUplo
getString(R.string.uploading),
getString(R.string.local_openstreetmap_uploading),
ProgressDialog.STYLE_HORIZONTAL).getDialog();
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog, this, plugin, remotepoi,
remotebug, toUpload.length);
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.show();
@ -614,21 +614,6 @@ public class OsmEditsFragment extends OsmAndListFragment implements OsmEditsUplo
}
}
@Override
public void uploadUpdated(OsmPoint point) {
listAdapter.delete(point);
}
@Override
public void uploadEnded(Integer result) {
listAdapter.notifyDataSetChanged();
if (result != null) {
AccessibleToast.makeText(getActivity(),
MessageFormat.format(getString(R.string.local_openstreetmap_were_uploaded), result), Toast.LENGTH_LONG)
.show();
}
}
private void showOnMap(OsmPoint osmPoint) {
boolean isOsmPoint = osmPoint instanceof OpenstreetmapPoint;
String type = osmPoint.getGroup() == OsmPoint.Group.POI ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG;
@ -637,6 +622,4 @@ public class OsmEditsFragment extends OsmAndListFragment implements OsmEditsUplo
new PointDescription(type, name), true, osmPoint); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(getActivity());
}
}

View file

@ -1,12 +1,12 @@
package net.osmand.plus.osmedit;
import java.util.Map;
/**
* Created by Denis
* on 11.03.2015.
*/
public interface OsmEditsUploadListener {
public void uploadUpdated(OsmPoint point);
public void uploadEnded(Integer result);
void uploadUpdated(OsmPoint point);
void uploadEnded(Map<OsmPoint, String> loadErrorsMap);
}

View file

@ -0,0 +1,285 @@
package net.osmand.plus.osmedit;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Map;
public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
public static final String TAG = "OsmEditUploadListenerHe";
private final FragmentActivity activity;
private final String numberFormat;
public OsmEditsUploadListenerHelper(FragmentActivity activity, String numberFormat) {
this.activity = activity;
this.numberFormat = numberFormat;
}
@Override
public void uploadUpdated(OsmPoint point) {
}
@MainThread
@Override
public void uploadEnded(Map<OsmPoint, String> loadErrorsMap) {
int uploaded = 0;
int pointsNum = loadErrorsMap.keySet().size();
for (OsmPoint point : loadErrorsMap.keySet()) {
if (loadErrorsMap.get(point) == null) {
uploaded++;
}
}
if (uploaded == pointsNum) {
AccessibleToast.makeText(activity,
MessageFormat.format(numberFormat, uploaded),
Toast.LENGTH_LONG)
.show();
} else if (pointsNum == 1) {
Log.v(TAG, "in if1");
OsmPoint point = loadErrorsMap.keySet().iterator().next();
String message = loadErrorsMap.get(point);
DialogFragment dialogFragment =
UploadingErrorDialogFragment.getInstance(message, point);
dialogFragment.show(activity.getSupportFragmentManager(), "error_loading");
} else {
UploadingMultipleErrorDialogFragment dialogFragment =
UploadingMultipleErrorDialogFragment.createInstance(loadErrorsMap);
dialogFragment.show(activity.getSupportFragmentManager(), "multiple_error_loading");
}
}
private static void showUploadItemsProgressDialog(Fragment fragment, OsmPoint[] toUpload) {
FragmentActivity activity = fragment.getActivity();
OsmEditingPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
OpenstreetmapRemoteUtil remotepoi = new OpenstreetmapRemoteUtil(activity);
OsmBugsRemoteUtil remotebug = new OsmBugsRemoteUtil((OsmandApplication) activity.getApplication());
OsmEditsUploadListenerHelper helper = new OsmEditsUploadListenerHelper(activity,
activity.getResources().getString(R.string.local_openstreetmap_were_uploaded));
Resources resources = activity.getResources();
ProgressDialog dialog = ProgressImplementation.createProgressDialog(
activity,
resources.getString(R.string.uploading),
resources.getString(R.string.local_openstreetmap_uploading),
ProgressDialog.STYLE_HORIZONTAL).getDialog();
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
dialog, helper, plugin, remotepoi, remotebug, toUpload.length);
uploadTask.execute(toUpload);
dialog.show();
}
public static final class UploadingErrorDialogFragment extends DialogFragment {
private static final String ERROR_MESSAGE = "error_message";
private static final String POINT = "point";
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle argument = getArguments();
String errorMessage = argument.getString(ERROR_MESSAGE);
final OsmPoint point = (OsmPoint) argument.getSerializable(POINT);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(getResources().getString(R.string.failed_to_upload))
.setMessage(MessageFormat.format(
getResources().getString(R.string.error_message_pattern), errorMessage))
.setPositiveButton(R.string.shared_string_ok, null)
.setNeutralButton(getResources().getString(R.string.delete_change),
new DialogInterface.OnClickListener() {
public void onClick(@Nullable DialogInterface dialog, int id) {
OsmEditingPlugin plugin =
OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
if (point.getGroup() == OsmPoint.Group.BUG) {
plugin.getDBBug().deleteAllBugModifications(
(OsmNotesPoint) point);
} else if (point.getGroup() == OsmPoint.Group.POI) {
plugin.getDBPOI().deletePOI((OpenstreetmapPoint) point);
}
}
});
return builder.create();
}
public static UploadingErrorDialogFragment getInstance(String errorMessage,
OsmPoint point) {
UploadingErrorDialogFragment fragment = new UploadingErrorDialogFragment();
Bundle bundle = new Bundle();
bundle.putString(ERROR_MESSAGE, errorMessage);
bundle.putSerializable(POINT, point);
fragment.setArguments(bundle);
return fragment;
}
}
public static final class UploadingMultipleErrorDialogFragment extends DialogFragment {
private static final String HAS_ERROR = "has_error";
private static final String POINT_NAMES = "point_names";
private static final String POINTS_WITH_ERRORS = "points_with_errors";
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle arguments = getArguments();
String[] pointNames = arguments.getStringArray(POINT_NAMES);
boolean[] hasErrors = arguments.getBooleanArray(HAS_ERROR);
final OsmPoint[] points = (OsmPoint[]) arguments.getSerializable(POINTS_WITH_ERRORS);
int successfulUploads = 0;
for (boolean hasError : hasErrors) {
if (!hasError) {
successfulUploads++;
}
}
PointsWithErrorsAdapter adapter =
PointsWithErrorsAdapter.createInstance(getActivity(), pointNames, hasErrors);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(MessageFormat.format(getResources()
.getString(R.string.successfully_uploaded_pattern),
successfulUploads, hasErrors.length))
.setAdapter(adapter, null)
.setPositiveButton(R.string.shared_string_ok, null)
.setNeutralButton(getResources().getString(R.string.try_again),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
OsmEditsUploadListenerHelper
.showUploadItemsProgressDialog(
UploadingMultipleErrorDialogFragment.this,
points);
}
});
return builder.create();
}
public static UploadingMultipleErrorDialogFragment createInstance(
Map<OsmPoint, String> loadErrorsMap) {
String[] pointNames = new String[loadErrorsMap.keySet().size()];
boolean[] hasErrors = new boolean[loadErrorsMap.keySet().size()];
ArrayList<OsmPoint> pointsWithErrors = new ArrayList<>();
int i = 0;
for (OsmPoint point : loadErrorsMap.keySet()) {
pointNames[i] = point.getGroup() == OsmPoint.Group.BUG ?
((OsmNotesPoint) point).getText() :
((OpenstreetmapPoint) point).getName();
pointNames[i] = TextUtils.isEmpty(pointNames[i]) ?
"id:" + point.getId() : pointNames[i];
hasErrors[i] = loadErrorsMap.get(point) != null;
if (hasErrors[i]) {
pointsWithErrors.add(point);
}
i++;
}
if (pointNames.length != hasErrors.length) {
throw new IllegalArgumentException("pointNames and hasError arrays " +
"must me of equal length");
}
UploadingMultipleErrorDialogFragment fragment =
new UploadingMultipleErrorDialogFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(POINTS_WITH_ERRORS,
pointsWithErrors.toArray(new OsmPoint[pointsWithErrors.size()]));
bundle.putStringArray(POINT_NAMES, pointNames);
bundle.putBooleanArray(HAS_ERROR, hasErrors);
fragment.setArguments(bundle);
return fragment;
}
}
private static final class PointWithPotentialError {
String point;
boolean hasError;
public PointWithPotentialError(String point, boolean hasError) {
this.point = point;
this.hasError = hasError;
}
}
private static final class PointsWithErrorsAdapter extends ArrayAdapter<PointWithPotentialError> {
private final int layoutResourceId;
PointWithPotentialError[] data;
Activity context;
private PointsWithErrorsAdapter(Activity context, int layoutResourceId,
PointWithPotentialError[] objects) {
super(context, layoutResourceId, objects);
data = objects;
this.context = context;
this.layoutResourceId = layoutResourceId;
}
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View row = convertView;
PointHolder holder = null;
if (row == null) {
LayoutInflater inflater = context.getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new PointHolder();
holder.checkedUncheckedImageView = (ImageView) row.findViewById(R.id.iconImageView);
holder.pointNameTextView = (TextView) row.findViewById(R.id.nameTextView);
row.setTag(holder);
} else {
holder = (PointHolder) row.getTag();
}
PointWithPotentialError pointWrapper = data[position];
holder.pointNameTextView.setText(pointWrapper.point);
IconsCache cache = ((OsmandApplication) context.getApplication()).getIconsCache();
holder.checkedUncheckedImageView.setImageDrawable(pointWrapper.hasError ?
cache.getContentIcon(R.drawable.ic_action_remove_dark) :
cache.getContentIcon(R.drawable.ic_action_done));
return row;
}
public static PointsWithErrorsAdapter createInstance(Activity activity,
String[] pointNames,
boolean[] hasError) {
PointWithPotentialError[] array = new PointWithPotentialError[pointNames.length];
for (int i = 0; i < pointNames.length; i++) {
array[i] = new PointWithPotentialError(pointNames[i], hasError[i]);
}
return new PointsWithErrorsAdapter(activity, R.layout.osm_edit_list_item, array);
}
private static class PointHolder {
TextView pointNameTextView;
ImageView checkedUncheckedImageView;
}
}
}

View file

@ -1,8 +1,6 @@
package net.osmand.plus.osmedit;
import java.io.Serializable;
public class OsmNotesPoint extends OsmPoint implements Serializable {
public class OsmNotesPoint extends OsmPoint {
private static final long serialVersionUID = 729654300829771468L;
private long id;

View file

@ -1,9 +1,10 @@
package net.osmand.plus.osmedit;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
public abstract class OsmPoint {
public abstract class OsmPoint implements Serializable {
public static enum Group {BUG, POI};

View file

@ -3,47 +3,44 @@ package net.osmand.plus.osmedit;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.support.v4.app.Fragment;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Denis
* on 11.03.2015.
*/
public class UploadOpenstreetmapPointAsyncTask extends AsyncTask<OsmPoint, OsmPoint, Integer> {
public class UploadOpenstreetmapPointAsyncTask
extends AsyncTask<OsmPoint, OsmPoint, Map<OsmPoint, String>> {
private ProgressDialog progress;
private OpenstreetmapRemoteUtil remotepoi;
private OsmBugsRemoteUtil remotebug;
private int listSize = 0;
private boolean interruptUploading = false;
private Fragment ctx;
private OsmEditsUploadListener listener;
private OsmEditingPlugin plugin;
public UploadOpenstreetmapPointAsyncTask(ProgressDialog progress,Fragment ctx,
public UploadOpenstreetmapPointAsyncTask(ProgressDialog progress,
OsmEditsUploadListener listener,
OsmEditingPlugin plugin,
OpenstreetmapRemoteUtil remotepoi, OsmBugsRemoteUtil remotebug,
OpenstreetmapRemoteUtil remotepoi,
OsmBugsRemoteUtil remotebug,
int listSize) {
this.progress = progress;
this.plugin = plugin;
this.remotepoi = remotepoi;
this.remotebug = remotebug;
this.listSize = listSize;
this.ctx = ctx;
this.listener = listener;
}
@Override
protected Integer doInBackground(OsmPoint... points) {
int uploaded = 0;
protected Map<OsmPoint, String> doInBackground(OsmPoint... points) {
Map<OsmPoint, String> loadErrorsMap = new HashMap<>();
for (OsmPoint point : points) {
if (interruptUploading)
@ -57,31 +54,29 @@ public class UploadOpenstreetmapPointAsyncTask extends AsyncTask<OsmPoint, OsmPo
}
Node n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo, p.getComment(), false);
if (n != null) {
plugin.getDBPOI().deletePOI(p);
publishProgress(p);
uploaded++;
}
loadErrorsMap.put(point, n != null ? null : "Unknown problem");
} else if (point.getGroup() == OsmPoint.Group.BUG) {
OsmNotesPoint p = (OsmNotesPoint) point;
boolean success = false;
String errorMessage = null;
if (p.getAction() == OsmPoint.Action.CREATE) {
success = remotebug.createNewBug(p.getLatitude(), p.getLongitude(), p.getText(), p.getAuthor()) == null;
errorMessage = remotebug.createNewBug(p.getLatitude(), p.getLongitude(), p.getText(), p.getAuthor());
} else if (p.getAction() == OsmPoint.Action.MODIFY) {
success = remotebug.addingComment(p.getId(), p.getText(), p.getAuthor()) == null;
errorMessage = remotebug.addingComment(p.getId(), p.getText(), p.getAuthor());
} else if (p.getAction() == OsmPoint.Action.DELETE) {
success = remotebug.closingBug(p.getId(), p.getText(), p.getAuthor()) == null;
errorMessage = remotebug.closingBug(p.getId(), p.getText(), p.getAuthor());
}
if (success) {
if (errorMessage == null) {
plugin.getDBBug().deleteAllBugModifications(p);
uploaded++;
publishProgress(p);
}
loadErrorsMap.put(point, errorMessage);
}
}
return uploaded;
return loadErrorsMap;
}
@Override
@ -100,11 +95,9 @@ public class UploadOpenstreetmapPointAsyncTask extends AsyncTask<OsmPoint, OsmPo
}
@Override
protected void onPostExecute(Integer result) {
protected void onPostExecute(Map<OsmPoint, String> loadErrorsMap) {
progress.dismiss();
if (ctx instanceof OsmEditsUploadListener){
((OsmEditsUploadListener)ctx).uploadEnded(result);
}
listener.uploadEnded(loadErrorsMap);
}
public void setInterruptUploading(boolean b) {
@ -114,9 +107,7 @@ public class UploadOpenstreetmapPointAsyncTask extends AsyncTask<OsmPoint, OsmPo
@Override
protected void onProgressUpdate(OsmPoint... points) {
for (OsmPoint p : points) {
if (ctx instanceof OsmEditsUploadListener){
((OsmEditsUploadListener)ctx).uploadUpdated(p);
}
listener.uploadUpdated(p);
progress.incrementProgressBy(1);
}
}