Update poi uploading

This commit is contained in:
Victor Shcherb 2015-11-15 22:27:34 +01:00
parent a471a38de3
commit 774865dc7f
12 changed files with 91 additions and 76 deletions

View file

@ -12,9 +12,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.mapcontextmenu.builders.EditPOIMenuBuilder;
import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OpenstreetmapRemoteUtil;
import net.osmand.plus.osmedit.OsmBugsLayer;
import net.osmand.plus.osmedit.OsmBugsRemoteUtil;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmedit.OsmEditsUploadListener;
import net.osmand.plus.osmedit.OsmEditsUploadListenerHelper;
@ -62,10 +60,8 @@ public class EditPOIMenuController extends MenuController {
}
}
};
OpenstreetmapRemoteUtil remotepoi = new OpenstreetmapRemoteUtil(getMapActivity());
OsmBugsRemoteUtil remotebug = new OsmBugsRemoteUtil(getMapActivity().getMyApplication());
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
dialog, listener, plugin, remotepoi, remotebug, points.length, closeChangeSet);
dialog, listener, plugin, points.length, closeChangeSet);
uploadTask.execute(points);
dialog.show();

View file

@ -152,9 +152,7 @@ public class DashOsmEditsFragment extends DashBaseFragment
}
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet) {
OpenstreetmapRemoteUtil remotepoi = new OpenstreetmapRemoteUtil(getActivity());
OsmPoint[] toUpload = points;
OsmBugsRemoteUtil remotebug = new OsmBugsRemoteUtil(getMyApplication());
ProgressDialog dialog = ProgressImplementation.createProgressDialog(getActivity(),
getString(R.string.uploading), getString(R.string.local_openstreetmap_uploading),
ProgressDialog.STYLE_HORIZONTAL).getDialog();
@ -177,7 +175,7 @@ public class DashOsmEditsFragment extends DashBaseFragment
}
};
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog,
listener, plugin, remotepoi, remotebug, toUpload.length, closeChangeSet);
listener, plugin, toUpload.length, closeChangeSet);
uploadTask.execute(toUpload);
dialog.show();
}

View file

@ -104,9 +104,9 @@ public class EditPoiDialogFragment extends DialogFragment {
OsmandSettings settings = getMyApplication().getSettings();
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
mOpenstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
} else {
mOpenstreetmapUtil = new OpenstreetmapRemoteUtil(activity);
mOpenstreetmapUtil = plugin.getPoiModificationRemoteUtil();
}
Node node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE);
@ -327,7 +327,7 @@ public class EditPoiDialogFragment extends DialogFragment {
node.putTag(tag.getKey(), tag.getValue());
}
}
commitNode(action, node, mOpenstreetmapUtil.getEntityInfo(),
commitNode(action, node, mOpenstreetmapUtil.getEntityInfo(node.getId()),
"",
false,
new Runnable() {
@ -403,7 +403,6 @@ public class EditPoiDialogFragment extends DialogFragment {
final Activity activity,
final 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;
}
@ -537,12 +536,12 @@ public class EditPoiDialogFragment extends DialogFragment {
final OsmandSettings settings = ((OsmandApplication) activity.getApplication())
.getSettings();
final OpenstreetmapUtil openstreetmapUtilToLoad;
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (//settings.OFFLINE_EDITION.get() ||
!settings.isInternetConnectionAvailable(true)) {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
openstreetmapUtilToLoad = new OpenstreetmapLocalUtil(plugin, activity);
openstreetmapUtilToLoad = plugin.getPoiModificationLocalUtil();
} else {
openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity);
openstreetmapUtilToLoad = plugin.getPoiModificationRemoteUtil();
}
new AsyncTask<Void, Void, Node>() {
@Override
@ -599,11 +598,9 @@ public class EditPoiDialogFragment extends DialogFragment {
OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
} else if (!settings.isInternetConnectionAvailable(true)) {
openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
openstreetmapUtil = plugin.getPoiModificationLocalUtil();
} else {
openstreetmapUtil = new OpenstreetmapRemoteUtil(activity);
openstreetmapUtil = plugin.getPoiModificationRemoteUtil();
}
}
@ -643,7 +640,7 @@ public class EditPoiDialogFragment extends DialogFragment {
String c = comment == null ? null : comment.getText().toString();
boolean closeChangeSet = closeChangesetCheckBox != null
&& closeChangesetCheckBox.isChecked();
commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(), c,
commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(n.getId()), c,
closeChangeSet, new Runnable() {
@Override
public void run() {

View file

@ -1,6 +1,5 @@
package net.osmand.plus.osmedit;
import android.content.Context;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.osm.PoiType;
@ -13,21 +12,18 @@ import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
public class OpenstreetmapLocalUtil implements OpenstreetmapUtil {
private final Context ctx;
public final static Log LOG = PlatformUtil.getLog(OpenstreetmapLocalUtil.class);
private OsmEditingPlugin plugin;
public OpenstreetmapLocalUtil(OsmEditingPlugin plugin, Context uiContext) {
public OpenstreetmapLocalUtil(OsmEditingPlugin plugin) {
this.plugin = plugin;
this.ctx = uiContext;
}
@Override
public EntityInfo getEntityInfo() {
return new EntityInfo();
public EntityInfo getEntityInfo(long id) {
return null;
}
@Override

View file

@ -1,8 +1,20 @@
package net.osmand.plus.osmedit;
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;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
@ -26,21 +38,8 @@ import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
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.util.Xml;
import android.widget.Toast;
public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
@ -48,6 +47,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
private final OsmandApplication ctx;
private EntityInfo entityInfo;
private EntityId entityInfoId;
// reuse changeset
private long changeSetId = NO_CHANGESET_ID;
@ -57,14 +57,18 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
private OsmandSettings settings;
public OpenstreetmapRemoteUtil(Context uiContext) {
this.ctx = ((OsmandApplication) uiContext.getApplicationContext());
public OpenstreetmapRemoteUtil(OsmandApplication app) {
this.ctx = app;
settings = ctx.getSettings();
}
@Override
public EntityInfo getEntityInfo() {
return entityInfo;
public EntityInfo getEntityInfo(long id) {
if(entityInfoId != null && entityInfoId.getId().longValue() == id) {
return entityInfo;
}
return null;
}
private static String getSiteApi() {
@ -333,6 +337,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
n.setLongitude(entity.getLongitude());
}
entityInfo = st.getRegisteredEntityInfo().get(id);
entityInfoId = id;
return entityInfo;
}
@ -360,11 +365,16 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
Node entity = (Node) st.getRegisteredEntities().get(id);
entityInfo = st.getRegisteredEntityInfo().get(id);
entityInfoId = id;
// check whether this is node (because id of node could be the same as relation)
if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
PoiType poiType = n.getType().getPoiTypeByKeyName(n.getSubType());
entity.removeTag(poiType.getOsmTag());
entity.putTag(EditPoiData.POI_TYPE_TAG, poiType.getTranslation());
if(poiType.getOsmValue().equals(entity.getTag(poiType.getOsmTag()))) {
entity.removeTag(poiType.getOsmTag());
entity.putTag(EditPoiData.POI_TYPE_TAG, poiType.getTranslation());
} else {
// later we could try to determine tags
}
return entity;
}
return null;

View file

@ -6,7 +6,7 @@ import net.osmand.osm.edit.Node;
public interface OpenstreetmapUtil {
public EntityInfo getEntityInfo();
public EntityInfo getEntityInfo(long id);
public Node commitNodeImpl(OsmPoint.Action action, Node n, EntityInfo info, String comment, boolean closeChangeSet);

View file

@ -69,14 +69,12 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
private static final int DIALOG_BUG = 305;
private static Bundle dialogBundle = new Bundle();
private OsmBugsLocalUtil local;
private OsmBugsRemoteUtil remote;
private MapLayerData<List<OpenStreetNote>> data;
public OsmBugsLayer(MapActivity activity, OsmEditingPlugin plugin){
this.activity = activity;
this.plugin = plugin;
local = new OsmBugsLocalUtil(activity, plugin.getDBBug());
remote = new OsmBugsRemoteUtil(activity.getMyApplication());
}
public OsmBugsUtil getOsmbugsUtil(OpenStreetNote bug) {
@ -85,7 +83,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
|| !settings.isInternetConnectionAvailable(true)) {
return local;
} else {
return remote;
return plugin.getOsmNotesRemoteUtil();
}
}

View file

@ -13,7 +13,6 @@ import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.data.Amenity;
@ -33,6 +32,7 @@ import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.myplaces.AvailableGPXFragment;
import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.osmedit.OsmPoint.Action;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.Algorithms;
@ -48,6 +48,14 @@ public class OsmEditingPlugin extends OsmandPlugin {
private OsmandApplication app;
OpenstreetmapsDbHelper dbpoi;
OsmBugsDbHelper dbbug;
OpenstreetmapLocalUtil localUtil;
OpenstreetmapRemoteUtil remoteUtil;
private OsmBugsRemoteUtil remoteNotesUtil;
public OsmEditingPlugin(OsmandApplication app) {
this.app = app;
settings = app.getSettings();
}
@Override
public String getId() {
@ -60,6 +68,30 @@ public class OsmEditingPlugin extends OsmandPlugin {
}
return dbpoi;
}
public OpenstreetmapLocalUtil getPoiModificationLocalUtil() {
if(localUtil == null) {
localUtil = new OpenstreetmapLocalUtil(this);
}
return localUtil;
}
public OpenstreetmapRemoteUtil getPoiModificationRemoteUtil() {
if(remoteUtil == null) {
remoteUtil = new OpenstreetmapRemoteUtil(app);
}
return remoteUtil;
}
public OsmBugsRemoteUtil getOsmNotesRemoteUtil() {
if(remoteNotesUtil == null) {
remoteNotesUtil = new OsmBugsRemoteUtil(app);
}
return remoteNotesUtil;
}
public OsmBugsDbHelper getDBBug() {
if (dbbug == null) {
@ -68,10 +100,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
return dbbug;
}
public OsmEditingPlugin(OsmandApplication app) {
this.app = app;
settings = app.getSettings();
}
private OsmBugsLayer osmBugsLayer;
private OsmEditsLayer osmEditsLayer;
@ -180,7 +209,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
if (isEditable) {
adapter.item(R.string.poi_context_menu_modify).iconColor(R.drawable.ic_action_edit_dark).listen(listener).position(1).reg();
adapter.item(R.string.poi_context_menu_delete).iconColor(R.drawable.ic_action_delete_dark).listen(listener).position(2).reg();
} else if (selectedObj instanceof OpenstreetmapPoint) {
} else if (selectedObj instanceof OpenstreetmapPoint && ((OpenstreetmapPoint) selectedObj).getAction() != Action.DELETE) {
adapter.item(R.string.poi_context_menu_modify_osm_change)
.iconColor(R.drawable.ic_action_edit_dark).listen(listener).position(1).reg();
} else {

View file

@ -63,8 +63,6 @@ public class OsmEditsFragment extends OsmAndListFragment
private boolean selectionMode = false;
private OpenstreetmapRemoteUtil remotepoi;
private OsmBugsRemoteUtil remotebug;
private final static int MODE_DELETE = 100;
private final static int MODE_UPLOAD = 101;
@ -81,9 +79,6 @@ public class OsmEditsFragment extends OsmAndListFragment
View view = getActivity().getLayoutInflater().inflate(R.layout.update_index, container, false);
((TextView) view.findViewById(R.id.header)).setText(R.string.your_edits);
remotepoi = new OpenstreetmapRemoteUtil(getActivity());
remotebug = new OsmBugsRemoteUtil(getMyApplication());
final CheckBox selectAll = (CheckBox) view.findViewById(R.id.select_all);
selectAll.setVisibility(View.GONE);
selectAll.setOnClickListener(new View.OnClickListener() {
@ -535,7 +530,7 @@ public class OsmEditsFragment extends OsmAndListFragment
}
};
UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(
dialog, listener, plugin, remotepoi, remotebug, points.length, closeChangeSet);
dialog, listener, plugin, points.length, closeChangeSet);
uploadTask.execute(points);
dialog.show();

View file

@ -81,9 +81,6 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener {
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));
@ -94,7 +91,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, false);
dialog, helper, plugin, toUpload.length, false);
uploadTask.execute(toUpload);
dialog.show();

View file

@ -3,6 +3,7 @@ package net.osmand.plus.osmedit;
import java.io.File;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
import net.osmand.plus.osmedit.OsmEditingPlugin.UploadVisibility;
@ -34,7 +35,7 @@ public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> {
if (!isCancelled() && info.file != null) {
String warning = null;
File file = info.file;
warning = new OpenstreetmapRemoteUtil(la).uploadGPXFile(tagstring, description, visibility,
warning = new OpenstreetmapRemoteUtil((OsmandApplication) la.getApplication()).uploadGPXFile(tagstring, description, visibility,
file);
total++;
if (warning == null) {

View file

@ -26,14 +26,12 @@ public class UploadOpenstreetmapPointAsyncTask
public UploadOpenstreetmapPointAsyncTask(ProgressDialog progress,
OsmEditsUploadListener listener,
OsmEditingPlugin plugin,
OpenstreetmapRemoteUtil remotepoi,
OsmBugsRemoteUtil remotebug,
int listSize,
boolean closeChangeSet) {
this.progress = progress;
this.plugin = plugin;
this.remotepoi = remotepoi;
this.remotebug = remotebug;
this.remotepoi = plugin.getPoiModificationRemoteUtil();
this.remotebug = plugin.getOsmNotesRemoteUtil();
this.listSize = listSize;
this.listener = listener;
this.closeChangeSet = closeChangeSet;