Update POI ids when creating new POI in offline mode.
This commit is contained in:
parent
391a118eb9
commit
3e29f62079
5 changed files with 41 additions and 3 deletions
|
@ -129,7 +129,7 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
|
|||
listAdapter.delete(info);
|
||||
return true;
|
||||
} else if(itemId == R.id.uploadmods) {
|
||||
List<OsmPoint> list = listAdapter.data.get(group);
|
||||
List<OsmPoint> list = listAdapter.data.get(listAdapter.category.get(group));
|
||||
if (list != null) {
|
||||
toUpload = list.toArray(new OsmPoint[] {});
|
||||
showDialog(DIALOG_PROGRESS_UPLOAD);
|
||||
|
@ -212,6 +212,10 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
|
|||
}
|
||||
Node n;
|
||||
if ((n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo, p.getComment())) != null) {
|
||||
if (point.getId() != n.getId()) {
|
||||
//change all category points...
|
||||
listAdapter.categoryIdChanged(point.getId(), n.getId());
|
||||
}
|
||||
remotepoi.updateNodeInIndexes(LocalOpenstreetmapActivity.this, p.getAction(), n, p.getEntity());
|
||||
publishProgress(p);
|
||||
uploaded++;
|
||||
|
@ -277,6 +281,20 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
|
|||
public LocalOpenstreetmapAdapter() {
|
||||
}
|
||||
|
||||
public void categoryIdChanged(long oldID, long newID) {
|
||||
int index = category.indexOf(oldID);
|
||||
if (index != -1) {
|
||||
category.set(index, newID);
|
||||
List<OsmPoint> list = data.remove(oldID);
|
||||
if (list != null) {
|
||||
for (OsmPoint point : list) {
|
||||
point.updateID(newID);
|
||||
}
|
||||
data.put(newID, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
data.clear();
|
||||
category.clear();
|
||||
|
|
|
@ -19,6 +19,13 @@ public class OpenstreetmapPoint extends OsmPoint implements Serializable {
|
|||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateID(long newID) {
|
||||
if (getId() < 0) {
|
||||
entity = new Node(entity, newID);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
String ret = entity.getTag(OSMTagKey.NAME.getValue());
|
||||
if (ret == null)
|
||||
|
|
|
@ -363,7 +363,7 @@ public class OpenstreetmapRemoteUtil extends AbstractOpenstreetmapUtil {
|
|||
i = i + "new_id=\"".length(); //$NON-NLS-1$
|
||||
int end = res.indexOf("\"", i); //$NON-NLS-1$
|
||||
if (end > 0) {
|
||||
newId = Long.parseLong(res.substring(i, end));
|
||||
newId = Long.parseLong(res.substring(i, end)); // << 1;
|
||||
newN = new Node(n, newId);
|
||||
}
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ public class OpenstreetmapRemoteUtil extends AbstractOpenstreetmapUtil {
|
|||
}
|
||||
|
||||
public EntityInfo loadNode(Node n) {
|
||||
long nodeId = n.getId() >> 1;
|
||||
long nodeId = n.getId(); // >> 1;
|
||||
try {
|
||||
String res = sendRequest(SITE_API + "api/0.6/node/"+nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if(res != null){
|
||||
|
|
|
@ -4,6 +4,9 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public abstract class OsmPoint {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 729654300829771469L;
|
||||
|
||||
public static enum Group {BUG, POI};
|
||||
|
@ -28,6 +31,8 @@ public abstract class OsmPoint {
|
|||
public OsmPoint(){
|
||||
}
|
||||
|
||||
public abstract void updateID(long newID);
|
||||
|
||||
public abstract long getId();
|
||||
|
||||
public abstract double getLatitude();
|
||||
|
@ -61,4 +66,5 @@ public abstract class OsmPoint {
|
|||
return new StringBuffer("Osm Point ").append(this.getAction()).append(" ")
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,13 @@ public class OsmbugsPoint extends OsmPoint implements Serializable {
|
|||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateID(long newID) {
|
||||
if (id < 0) {
|
||||
this.id = newID;
|
||||
}
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue