Fix issues related to local osm editing functionality

This commit is contained in:
Victor Shcherb 2012-09-11 19:42:31 +02:00
parent 2a8f90aa07
commit 00934b5601
11 changed files with 180 additions and 285 deletions

View file

@ -9,7 +9,7 @@
android:layout_marginLeft = "3dp" android:layout_marginTop ="3dp" android:layout_marginRight = "3dp"/> android:layout_marginLeft = "3dp" android:layout_marginTop ="3dp" android:layout_marginRight = "3dp"/>
</LinearLayout> </LinearLayout>
<ExpandableListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content" <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_marginLeft="3dp" android:layout_marginTop="3dp" android:layout_marginRight="3dp" ></ExpandableListView> android:layout_marginLeft="3dp" android:layout_marginTop="3dp" android:layout_marginRight="3dp" ></ListView>
</LinearLayout> </LinearLayout>

View file

@ -2,6 +2,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/showmod" android:title="@string/local_openstreetmap_show"></item> <item android:id="@+id/showmod" android:title="@string/local_openstreetmap_show"></item>
<item android:id="@+id/deletemod" android:title="@string/local_openstreetmap_delete"></item> <item android:id="@+id/deletemod" android:title="@string/local_openstreetmap_delete"></item>
<item android:id="@+id/uploadmods" android:title="@string/local_openstreetmap_upload"></item>
</menu> </menu>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/uploadmods" android:title="@string/local_openstreetmap_upload"></item>
</menu>

View file

@ -9,7 +9,6 @@
1. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 1. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="show_warnings_title">Show alarms&#8230;</string> <string name="show_warnings_title">Show alarms&#8230;</string>
<string name="show_warnings_descr">Show speed limits, speed cameras, speed bumps, and other warnings</string> <string name="show_warnings_descr">Show speed limits, speed cameras, speed bumps, and other warnings</string>
<string name="use_compass_navigation_descr">Use the compass when no heading is detected otherwise</string> <string name="use_compass_navigation_descr">Use the compass when no heading is detected otherwise</string>

View file

@ -14,7 +14,6 @@ import android.app.Activity;
public abstract class AbstractOpenstreetmapUtil implements OpenstreetmapUtil { public abstract class AbstractOpenstreetmapUtil implements OpenstreetmapUtil {
@Override @Override
public void updateNodeInIndexes(Activity ctx, OsmPoint.Action action, Node n, Node oldNode) { public void updateNodeInIndexes(Activity ctx, OsmPoint.Action action, Node n, Node oldNode) {
final OsmandApplication app = (OsmandApplication) ctx.getApplication(); final OsmandApplication app = (OsmandApplication) ctx.getApplication();

View file

@ -2,7 +2,6 @@ package net.osmand.plus.osmedit;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -121,7 +120,7 @@ public class EditingPOIActivity implements DialogProvider {
} }
public void showDeleteDialog(Amenity a){ public void showDeleteDialog(Amenity a){
final Node n = openstreetmapUtilToLoad.loadNode(a); final Node n = openstreetmapUtil.loadNode(a);
if(n == null){ if(n == null){
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show();
return; return;
@ -174,9 +173,105 @@ public class EditingPOIActivity implements DialogProvider {
phoneText.setText(a.getPhone()); phoneText.setText(a.getPhone());
EditText websiteText = ((EditText)dlg.findViewById(R.id.Website)); EditText websiteText = ((EditText)dlg.findViewById(R.id.Website));
websiteText.setText(a.getSite()); websiteText.setText(a.getSite());
final TableLayout layout = ((TableLayout)dlg.findViewById(R.id.advancedModeTable));
layout.setVisibility(View.GONE);
updateType(a); updateType(a);
} }
private void addTagValueRow(final Node n, final TableLayout layout, String tg, String vl) {
final TableRow newTagRow = new TableRow(ctx);
TableRow.LayoutParams tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
tlp.leftMargin = 5;
newTagRow.setLayoutParams(tlp);
final AutoCompleteTextView tag = new AutoCompleteTextView(ctx);
final AutoCompleteTextView value = new AutoCompleteTextView(ctx);
final Button delete = new Button(ctx);
tag.setLayoutParams(tlp);
if(tg != null) {
tag.setText(tg);
} else {
tag.setHint("Tag");
}
final Set<String> tagKeys = new TreeSet<String>();
for (OSMTagKey t : OSMTagKey.values()) {
if ((t != OSMTagKey.NAME) && (t != OSMTagKey.OPENING_HOURS) && (t != OSMTagKey.PHONE)
&& (t != OSMTagKey.WEBSITE)) {
tagKeys.add(t.getValue());
}
}
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, tagKeys.toArray());
tag.setAdapter(adapter);
tag.setThreshold(1);
tag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Builder builder = new AlertDialog.Builder(ctx);
final String[] tags = tagKeys.toArray(new String[tagKeys.size()]);
builder.setItems(tags, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
tag.setText(tags[which]);
}
});
builder.create();
builder.show();
}
});
tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.FILL_PARENT);
tlp.leftMargin = 5;
tlp.rightMargin = 5;
tlp.width = 80;
value.setLayoutParams(tlp);
if(vl != null) {
value.setText(vl);
} else {
value.setHint("Value");
}
Set<String> subCategories = MapRenderingTypes.getDefault().getAmenityNameToType().keySet();
ArrayAdapter<Object> valueAdapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.toArray());
value.setThreshold(1);
value.setAdapter(valueAdapter);
value.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if ((newTagRow != null) && (tag != null) && (value != null) && (tag.getText() != null)
&& (value.getText() != null) && (!tag.getText().equals("")) && (!value.getText().equals(""))) {
n.putTag(tag.getText().toString(), value.getText().toString());
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
tlp.gravity = Gravity.CENTER;
tlp.rightMargin = 5;
delete.setLayoutParams(tlp);
delete.setText("X");
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
layout.removeView(newTagRow);
layout.invalidate();
n.removeTag(tag.getText().toString());
}
});
newTagRow.addView(tag);
newTagRow.addView(value);
newTagRow.addView(delete);
layout.addView(newTagRow);
layout.invalidate();
}
private Dialog createPOIDialog(final int dialogID, final Bundle args) { private Dialog createPOIDialog(final int dialogID, final Bundle args) {
final Dialog dlg = new Dialog(ctx); final Dialog dlg = new Dialog(ctx);
dlg.setContentView(R.layout.editing_poi); dlg.setContentView(R.layout.editing_poi);
@ -256,14 +351,15 @@ public class EditingPOIActivity implements DialogProvider {
}); });
final Button advancedModeButton = ((Button)dlg.findViewById(R.id.advancedMode)); final Button advancedModeButton = ((Button)dlg.findViewById(R.id.advancedMode));
final Map<String, String> additionalTags = new HashMap<String, String>();
advancedModeButton.setOnClickListener(new View.OnClickListener() { advancedModeButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final TableLayout layout = ((TableLayout)dlg.findViewById(R.id.advancedModeTable)); final Node n = (Node) args.getSerializable(KEY_AMENITY_NODE);
TableLayout.LayoutParams tlParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT); final TableLayout layout = ((TableLayout) dlg.findViewById(R.id.advancedModeTable));
layout.setLayoutParams(tlParams); TableLayout.LayoutParams tlParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,
layout.setColumnStretchable(1, true); TableLayout.LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(tlParams);
layout.setColumnStretchable(1, true);
layout.setVisibility((layout.getVisibility() == View.VISIBLE) ? View.GONE : View.VISIBLE); layout.setVisibility((layout.getVisibility() == View.VISIBLE) ? View.GONE : View.VISIBLE);
Button addTag = (Button) dlg.findViewById(R.id.addTag); Button addTag = (Button) dlg.findViewById(R.id.addTag);
addTag.setVisibility((layout.getVisibility() == View.VISIBLE) ? View.VISIBLE : View.GONE); addTag.setVisibility((layout.getVisibility() == View.VISIBLE) ? View.VISIBLE : View.GONE);
@ -271,93 +367,23 @@ public class EditingPOIActivity implements DialogProvider {
addTag.setOnClickListener(new View.OnClickListener() { addTag.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final TableRow newTagRow = new TableRow(ctx); addTagValueRow(n, layout, null, null);
TableRow.LayoutParams tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
tlp.leftMargin = 5;
newTagRow.setLayoutParams(tlp);
final AutoCompleteTextView tag = new AutoCompleteTextView(ctx);
final AutoCompleteTextView value = new AutoCompleteTextView(ctx);
final Button delete = new Button(ctx);
tag.setLayoutParams(tlp);
tag.setHint("Tag");
final Set<String> tagKeys = new TreeSet<String>();
for (OSMTagKey t : OSMTagKey.values()) {
if ((t != OSMTagKey.NAME) && (t != OSMTagKey.OPENING_HOURS) && (t != OSMTagKey.PHONE)
&& (t != OSMTagKey.WEBSITE)) {
tagKeys.add(t.getValue());
}
}
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, tagKeys.toArray());
tag.setAdapter(adapter);
tag.setThreshold(1);
tag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Builder builder = new AlertDialog.Builder(ctx);
final String[] tags = tagKeys.toArray(new String[tagKeys.size()]);
builder.setItems(tags, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
tag.setText(tags[which]);
}
});
builder.create();
builder.show();
}
});
tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.FILL_PARENT);
tlp.leftMargin = 5;
tlp.rightMargin = 5;
tlp.width = 80;
value.setLayoutParams(tlp);
value.setHint("Value");
Set<String> subCategories = MapRenderingTypes.getDefault().getAmenityNameToType().keySet();
ArrayAdapter<Object> valueAdapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.toArray());
value.setThreshold(1);
value.setAdapter(valueAdapter);
value.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if ((newTagRow != null) && (tag != null) && (value != null) && (tag.getText() != null)
&& (value.getText() != null) && (!tag.getText().equals("")) && (!value.getText().equals(""))) {
additionalTags.put(tag.getText().toString(), value.getText().toString());
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
tlp.gravity = Gravity.CENTER;
tlp.rightMargin = 5;
delete.setLayoutParams(tlp);
delete.setText("X");
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
layout.removeView(newTagRow);
layout.invalidate();
additionalTags.remove(tag.getText().toString());
}
});
newTagRow.addView(tag);
newTagRow.addView(value);
newTagRow.addView(delete);
layout.addView(newTagRow);
layout.invalidate();
} }
}); });
} }
while (layout.getChildCount() > 0) {
layout.removeViewAt(0);
}
layout.requestLayout(); layout.requestLayout();
Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
for (String tg : n.getTagKeySet()) {
if (!tg.equals(OSMTagKey.NAME.getValue()) && !tg.equals(OSMTagKey.OPENING_HOURS.getValue())
&& !tg.equals(OSMTagKey.PHONE.getValue()) && !tg.equals(OSMTagKey.WEBSITE.getValue())) {
if(a == null || a.getType() == null || !a.getType().getDefaultTag().equals(tg)) {
addTagValueRow(n, layout, tg, n.getTag(tg));
}
}
}
} }
}); });
@ -415,11 +441,6 @@ public class EditingPOIActivity implements DialogProvider {
if (phone.length() > 0 ){ if (phone.length() > 0 ){
n.putTag(OSMTagKey.PHONE.getValue(),phone); n.putTag(OSMTagKey.PHONE.getValue(),phone);
} }
if ((additionalTags != null) && (!additionalTags.isEmpty())) {
for (String tk : additionalTags.keySet()) {
n.putTag(tk, additionalTags.get(tk));
}
}
commitNode(action, n, openstreetmapUtil.getEntityInfo(), commentText.getText().toString(), new Runnable() { commitNode(action, n, openstreetmapUtil.getEntityInfo(), commentText.getText().toString(), new Runnable() {
@Override @Override
public void run() { public void run() {

View file

@ -2,22 +2,20 @@ package net.osmand.plus.osmedit;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.osm.EntityInfo; import net.osmand.osm.EntityInfo;
import net.osmand.osm.Node; import net.osmand.osm.Node;
import net.osmand.plus.AmenityIndexRepositoryOdb; import net.osmand.plus.AmenityIndexRepositoryOdb;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.ProgressDialogImplementation; import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListActivity;
import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.osmedit.OsmPoint.Action;
import android.app.Dialog; import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -29,12 +27,12 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ExpandableListView; import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo; import android.widget.ArrayAdapter;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { public class LocalOpenstreetmapActivity extends ListActivity {
/** dialogs **/ /** dialogs **/
protected static final int DIALOG_PROGRESS_UPLOAD = 0; protected static final int DIALOG_PROGRESS_UPLOAD = 0;
@ -49,6 +47,10 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
private OsmBugsRemoteUtil remotebug; private OsmBugsRemoteUtil remotebug;
protected OsmPoint[] toUpload; protected OsmPoint[] toUpload;
private ArrayList<OsmPoint> dataPoints;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -57,18 +59,11 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
setContentView(R.layout.local_openstreetmap); setContentView(R.layout.local_openstreetmap);
listAdapter = new LocalOpenstreetmapAdapter(); listAdapter = new LocalOpenstreetmapAdapter();
getExpandableListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { getListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
long packedPos = ((ExpandableListContextMenuInfo)menuInfo).packedPosition;
int group = ExpandableListView.getPackedPositionGroup(packedPos);
int child = ExpandableListView.getPackedPositionChild(packedPos);
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
if (child >= 0 && group >= 0) { inflater.inflate(R.menu.localosm_child, menu);
inflater.inflate(R.menu.localosm_child, menu);
} else if (group >= 0) { //group menu
inflater.inflate(R.menu.localosm_group, menu);
}
} }
}); });
setListAdapter(listAdapter); setListAdapter(listAdapter);
@ -80,12 +75,9 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
remotebug = new OsmBugsRemoteUtil(); remotebug = new OsmBugsRemoteUtil();
findViewById(R.id.UploadAllButton).setOnClickListener(new View.OnClickListener() { findViewById(R.id.UploadAllButton).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
//NOTE, the order of upload is important, there can be more edits per one POI!! toUpload = dataPoints.toArray(new OsmPoint[0]);
toUpload = listAdapter.values().toArray(new OsmPoint[0]);
showDialog(DIALOG_PROGRESS_UPLOAD); showDialog(DIALOG_PROGRESS_UPLOAD);
} }
}); });
@ -94,51 +86,59 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
listAdapter.clear();
dataPoints = new ArrayList<OsmPoint>();
List<OpenstreetmapPoint> l1 = dbpoi.getOpenstreetmapPoints(); List<OpenstreetmapPoint> l1 = dbpoi.getOpenstreetmapPoints();
List<OsmbugsPoint> l2 = dbbug.getOsmbugsPoints(); List<OsmbugsPoint> l2 = dbbug.getOsmbugsPoints();
dataPoints.addAll(l1);
dataPoints.addAll(l2);
listAdapter.clear();
for (OpenstreetmapPoint p : l1) { for (OpenstreetmapPoint p : l1) {
listAdapter.addOsmPoint(p); listAdapter.add(p);
} }
for (OsmbugsPoint p : l2) { for (OsmbugsPoint p : l2) {
listAdapter.addOsmPoint(p); listAdapter.add(p);
} }
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
@Override @Override
public boolean onContextItemSelected(MenuItem item) { public boolean onContextItemSelected(MenuItem item) {
long packedPos = ((ExpandableListContextMenuInfo)item.getMenuInfo()).packedPosition; int pos = ((AdapterContextMenuInfo)item.getMenuInfo()).position;
int group = ExpandableListView.getPackedPositionGroup(packedPos);
int child = ExpandableListView.getPackedPositionChild(packedPos);
int itemId = item.getItemId(); int itemId = item.getItemId();
if(itemId == R.id.showmod) { if(itemId == R.id.showmod) {
OsmandSettings settings = getMyApplication().getSettings(); OsmandSettings settings = getMyApplication().getSettings();
OsmPoint info = (OsmPoint) listAdapter.getChild(group, child); OsmPoint info = (OsmPoint) listAdapter.getItem(pos);
settings.setMapLocationToShow(info.getLatitude(), info.getLongitude(), settings.getLastKnownMapZoom()); settings.setMapLocationToShow(info.getLatitude(), info.getLongitude(), settings.getLastKnownMapZoom());
MapActivity.launchMapActivityMoveToTop(LocalOpenstreetmapActivity.this); MapActivity.launchMapActivityMoveToTop(LocalOpenstreetmapActivity.this);
return true; return true;
} else if(itemId == R.id.deletemod) { } else if(itemId == R.id.deletemod) {
OsmPoint info = (OsmPoint) listAdapter.getChild(group, child); OsmPoint info = (OsmPoint) listAdapter.getItem(pos);
if (info.getGroup() == OsmPoint.Group.POI) { if (info.getGroup() == OsmPoint.Group.POI) {
dbpoi.deletePOI((OpenstreetmapPoint) info); dbpoi.deletePOI((OpenstreetmapPoint) info);
if (info.getAction() == Action.CREATE) {
AmenityIndexRepositoryOdb repo = getMyApplication().getResourceManager().getUpdatablePoiDb();
repo.deleteAmenities(info.getId() << 1);
repo.clearCache();
}
} else if (info.getGroup() == OsmPoint.Group.BUG) { } else if (info.getGroup() == OsmPoint.Group.BUG) {
dbbug.deleteAllBugModifications((OsmbugsPoint) info); dbbug.deleteAllBugModifications((OsmbugsPoint) info);
} }
listAdapter.delete(info); listAdapter.delete(info);
return true; return true;
} else if(itemId == R.id.uploadmods) { } else if (itemId == R.id.uploadmods) {
List<OsmPoint> list = listAdapter.data.get(listAdapter.category.get(group)); toUpload = new OsmPoint[]{ listAdapter.getItem(pos)};
if (list != null) { showDialog(DIALOG_PROGRESS_UPLOAD);
toUpload = list.toArray(new OsmPoint[] {}); return true;
showDialog(DIALOG_PROGRESS_UPLOAD); }
return true;
}
}
return super.onContextItemSelected(item); return super.onContextItemSelected(item);
} }
private OsmandApplication getMyApplication() {
return (OsmandApplication) getApplication();
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -222,7 +222,7 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
} else if (p.getAction() == OsmPoint.Action.MODIFY) { } else if (p.getAction() == OsmPoint.Action.MODIFY) {
remotebug.addingComment(p.getId(), p.getText(), p.getAuthor()); remotebug.addingComment(p.getId(), p.getText(), p.getAuthor());
} else if (p.getAction() == OsmPoint.Action.DELETE) { } else if (p.getAction() == OsmPoint.Action.DELETE) {
remotebug.closingBug(p.getId()); remotebug.closingBug(p.getId(), p.getText(), p.getAuthor());
} }
dbbug.deleteAllBugModifications(p); dbbug.deleteAllBugModifications(p);
publishProgress(p); publishProgress(p);
@ -265,59 +265,25 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
@Override @Override
protected void onProgressUpdate(OsmPoint... points) { protected void onProgressUpdate(OsmPoint... points) {
listAdapter.delete(points[0]); for(OsmPoint p : points) {
progress.incrementProgressBy(1); listAdapter.delete(p);
progress.incrementProgressBy(1);
}
} }
} }
protected class LocalOpenstreetmapAdapter extends OsmandBaseExpandableListAdapter { protected class LocalOpenstreetmapAdapter extends ArrayAdapter<OsmPoint> {
Map<Long, List<OsmPoint>> data = new LinkedHashMap<Long, List<OsmPoint>>();
List<Long> category = new ArrayList<Long>();
public LocalOpenstreetmapAdapter() { public LocalOpenstreetmapAdapter() {
super(LocalOpenstreetmapActivity.this, net.osmand.plus.R.layout.local_openstreetmap_list_item);
} }
public void clear() {
data.clear();
category.clear();
notifyDataSetChanged();
}
public List<OsmPoint> values() {
List<OsmPoint> values = new ArrayList<OsmPoint>();
for (List<OsmPoint> v : data.values()) {
values.addAll(v);
}
return values;
}
public void delete(OsmPoint i) { public void delete(OsmPoint i) {
final AmenityIndexRepositoryOdb repo = getMyApplication().getResourceManager().getUpdatablePoiDb(); dataPoints.remove(i);
Long c = i.getId(); remove(i);
if(c != null){
List<OsmPoint> list = data.get(c);
list.remove(i);
if (list.isEmpty()) {
data.remove(c);
category.remove(c);
}
if (i.getGroup() == OsmPoint.Group.POI && i.getAction() == Action.CREATE) {
repo.deleteAmenities(i.getId() << 1);
repo.clearCache();
}
// We need to re-insert the POI if it is a delete or modify
// problem with bulk upload
// for (OsmPoint point : list) {
// if (point.getGroup() == OsmPoint.Group.POI) {
// OpenstreetmapPoint p = (OpenstreetmapPoint) point;
// remotepoi.updateNodeInIndexes(LocalOpenstreetmapActivity.this, p.getAction(), p.getEntity(), p.getEntity());
// }
// }
}
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
@ -325,51 +291,20 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
notifyDataSetChanged(); notifyDataSetChanged();
} }
public void addOsmPoint(OsmPoint info) {
int found = -1;
// search from end
for (int i = category.size() - 1; i >= 0; i--) {
Long cat = category.get(i);
if (cat.compareTo(info.getId()) == 0) {
found = i;
break;
}
}
if (found == -1) {
found = category.size();
category.add(info.getId());
}
if (!data.containsKey(category.get(found))) {
data.put(category.get(found), new ArrayList<OsmPoint>());
}
data.get(category.get(found)).add(info);
}
@Override @Override
public OsmPoint getChild(int groupPosition, int childPosition) { public View getView(int position, View convertView, ViewGroup parent) {
Long cat = category.get(groupPosition);
return data.get(cat).get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// it would be unusable to have 10000 local categories
return groupPosition * 10000 + childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView; View v = convertView;
final OsmPoint child = (OsmPoint) getChild(groupPosition, childPosition); final OsmPoint child = getItem(position);
if (v == null ) { if (v == null ) {
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
v = inflater.inflate(net.osmand.plus.R.layout.local_openstreetmap_list_item, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.local_openstreetmap_list_item, parent, false);
} }
TextView viewName = ((TextView) v.findViewById(R.id.local_openstreetmap_name)); TextView viewName = ((TextView) v.findViewById(R.id.local_openstreetmap_name));
String idPrefix = (child.getGroup() == OsmPoint.Group.POI ? "POI " : "Bug ") + " id: " + child.getId();
if (child.getGroup() == OsmPoint.Group.POI) if (child.getGroup() == OsmPoint.Group.POI)
viewName.setText("(" + ((OpenstreetmapPoint) child).getSubtype() + ") " + ((OpenstreetmapPoint) child).getName()); viewName.setText(idPrefix + " (" + ((OpenstreetmapPoint) child).getSubtype() + ") " + ((OpenstreetmapPoint) child).getName());
else if (child.getGroup() == OsmPoint.Group.BUG) else if (child.getGroup() == OsmPoint.Group.BUG)
viewName.setText("(" + ((OsmbugsPoint) child).getAuthor() + ") " + ((OsmbugsPoint) child).getText()); viewName.setText(idPrefix + " (" + ((OsmbugsPoint) child).getAuthor() + ") " + ((OsmbugsPoint) child).getText());
if (child.getAction() == OsmPoint.Action.CREATE) { if (child.getAction() == OsmPoint.Action.CREATE) {
viewName.setTextColor(getResources().getColor(R.color.osm_create)); viewName.setTextColor(getResources().getColor(R.color.osm_create));
} else if (child.getAction() == OsmPoint.Action.MODIFY) { } else if (child.getAction() == OsmPoint.Action.MODIFY) {
@ -381,61 +316,5 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
return v; return v;
} }
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView;
Long group = getGroup(groupPosition);
if (v == null) {
LayoutInflater inflater = getLayoutInflater();
v = inflater.inflate(net.osmand.plus.R.layout.local_openstreetmap_list_item_category, parent, false);
}
adjustIndicator(groupPosition, isExpanded, v);
StringBuilder t = new StringBuilder();
t.append(" id:").append(group);
t.append(" [").append(getChildrenCount(groupPosition));
if(getString(R.string.local_openstreetmap_items).length() > 0){
t.append(" ").append(getString(R.string.local_openstreetmap_items));
}
if(getString(R.string.local_openstreetmap_items).length() > 0){
t.append(" ").append(getString(R.string.local_openstreetmap_items));
}
t.append("]");
TextView nameView = ((TextView) v.findViewById(R.id.local_openstreetmap_category_name));
nameView.setText(t.toString());
return v;
}
@Override
public int getChildrenCount(int groupPosition) {
Long cat = category.get(groupPosition);
return data.get(cat).size();
}
@Override
public Long getGroup(int groupPosition) {
return category.get(groupPosition);
}
@Override
public int getGroupCount() {
return category.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
} }
} }

View file

@ -20,7 +20,6 @@ import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.OsmandApplication; 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.R.drawable;
import net.osmand.plus.activities.DialogProvider; import net.osmand.plus.activities.DialogProvider;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
@ -399,7 +398,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
OpenStreetBug bug = (OpenStreetBug) args.getSerializable(KEY_BUG); OpenStreetBug bug = (OpenStreetBug) args.getSerializable(KEY_BUG);
boolean closed = osmbugsUtil.closingBug(bug.getId()); boolean closed = osmbugsUtil.closingBug(bug.getId(), "", ((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_OSM_BUG_NAME.get());
if (closed) { if (closed) {
AccessibleToast.makeText(activity, activity.getString(R.string.osb_close_dialog_success), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(activity, activity.getString(R.string.osb_close_dialog_success), Toast.LENGTH_LONG).show();
clearCache(); clearCache();

View file

@ -1,14 +1,11 @@
package net.osmand.plus.osmedit; package net.osmand.plus.osmedit;
import net.osmand.LogUtil;
import org.apache.commons.logging.Log;
import android.content.Context; import android.content.Context;
public class OsmBugsLocalUtil implements OsmBugsUtil { public class OsmBugsLocalUtil implements OsmBugsUtil {
private static final Log log = LogUtil.getLog(OsmBugsLocalUtil.class);
private final Context ctx; private final Context ctx;
private final OsmBugsDbHelper db; private final OsmBugsDbHelper db;
@ -41,9 +38,11 @@ public class OsmBugsLocalUtil implements OsmBugsUtil {
} }
@Override @Override
public boolean closingBug(long id){ public boolean closingBug(long id, String text, String authorName){
OsmbugsPoint p = new OsmbugsPoint(); OsmbugsPoint p = new OsmbugsPoint();
p.setId(id); p.setId(id);
p.setAuthor(authorName);
p.setText(text);
p.setAction(OsmPoint.Action.DELETE); p.setAction(OsmPoint.Action.DELETE);
return db.addOsmbugs(p); return db.addOsmbugs(p);
} }

View file

@ -41,10 +41,15 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
} }
@Override @Override
public boolean closingBug(long id){ public boolean closingBug(long id, String text, String authorName){
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
b.append(SITE_API).append("closePOIexec?"); //$NON-NLS-1$ b.append(SITE_API).append("closePOIexec?"); //$NON-NLS-1$
b.append("id=").append(id); //$NON-NLS-1$ b.append("id=").append(id); //$NON-NLS-1$
if(text != null) {
b.append("&text=").append(URLEncoder.encode(text)); //$NON-NLS-1$
}
b.append("&name=").append(URLEncoder.encode(authorName)); //$NON-NLS-1$
return editingPOI(b.toString(),"closing bug"); //$NON-NLS-1$ return editingPOI(b.toString(),"closing bug"); //$NON-NLS-1$
} }

View file

@ -8,5 +8,5 @@ public interface OsmBugsUtil {
public boolean addingComment(long id, String text, String authorName); public boolean addingComment(long id, String text, String authorName);
public boolean closingBug(long id); public boolean closingBug(long id, String text, String authorName);
} }