Upgrade offline poi/bug editing

This commit is contained in:
Victor Shcherb 2012-09-11 01:45:22 +02:00
parent f1e1ef533f
commit 3d9cf54ec3
8 changed files with 107 additions and 184 deletions

View file

@ -44,6 +44,13 @@ public class OSMSettings {
// POI // POI
AMENITY("amenity"), //$NON-NLS-1$ AMENITY("amenity"), //$NON-NLS-1$
SHOP("shop"), //$NON-NLS-1$ SHOP("shop"), //$NON-NLS-1$
LANDUSE("landuse"), //$NON-NLS-1$
OFFICE("office"), //$NON-NLS-1$
EMERGENCY("emergency"), //$NON-NLS-1$
MILITARY("military"), //$NON-NLS-1$
ADMINISTRATIVE("administrative"), //$NON-NLS-1$
MAN_MADE("man_made"), //$NON-NLS-1$
BARRIER("barrier"), //$NON-NLS-1$
LEISURE("leisure"), //$NON-NLS-1$ LEISURE("leisure"), //$NON-NLS-1$
TOURISM("tourism"), //$NON-NLS-1$ TOURISM("tourism"), //$NON-NLS-1$
SPORT("sport"), //$NON-NLS-1$ SPORT("sport"), //$NON-NLS-1$

View file

@ -257,10 +257,9 @@ public class EditingPOIActivity implements DialogProvider {
layout.setLayoutParams(tlParams); layout.setLayoutParams(tlParams);
layout.setColumnStretchable(1, true); 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);
addTag.setVisibility((layout.getVisibility() == View.VISIBLE) ? View.VISIBLE : View.GONE);
if (layout.getVisibility() == View.VISIBLE) { if (layout.getVisibility() == View.VISIBLE) {
Button addTag = (Button) dlg.findViewById(R.id.addTag);
addTag.setVisibility((layout.getVisibility() == View.VISIBLE) ? View.GONE : View.VISIBLE);
addTag.setOnClickListener(new View.OnClickListener() { addTag.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -269,38 +268,32 @@ public class EditingPOIActivity implements DialogProvider {
tlp.leftMargin = 5; tlp.leftMargin = 5;
newTagRow.setLayoutParams(tlp); newTagRow.setLayoutParams(tlp);
final Button tag = new Button(ctx); final AutoCompleteTextView tag = new AutoCompleteTextView(ctx);
final EditText value = new EditText(ctx); final AutoCompleteTextView value = new AutoCompleteTextView(ctx);
final Button delete = new Button(ctx); final Button delete = new Button(ctx);
tag.setLayoutParams(tlp); tag.setLayoutParams(tlp);
tag.setText("<Tag>"); tag.setHint("Tag");
final Set<String> tagKeys = new LinkedHashSet<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() { tag.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// Comment: To exclude basic tags OSMTagKey.NAME, OSMTagKey.OPENING_HOURS, OSMTagKey.PHONE, OSMTagKey.WEBSITE;
final OSMTagKey[] allValues = OSMTagKey.values();
final OSMTagKey[] values = new OSMTagKey[allValues.length-4];
int j = 0;
for (int i = 0; i < allValues.length; i++) {
if ( (allValues[i] != OSMTagKey.NAME) &&
(allValues[i] != OSMTagKey.OPENING_HOURS) &&
(allValues[i] != OSMTagKey.PHONE) &&
(allValues[i] != OSMTagKey.WEBSITE) ) {
values[j] = allValues[i];
j++;
}
}
final String[] vals = new String[values.length];
for (int i=0; i<values.length; i++) {
vals[i] = values[i].getValue();
}
Builder builder = new AlertDialog.Builder(ctx); Builder builder = new AlertDialog.Builder(ctx);
builder.setItems(vals, new Dialog.OnClickListener() { final String[] tags = tagKeys.toArray(new String[tagKeys.size()]);
builder.setItems(tags, new Dialog.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
tag.setText(vals[which]); tag.setText(tags[which]);
tag.invalidate();
} }
}); });
@ -314,24 +307,27 @@ public class EditingPOIActivity implements DialogProvider {
tlp.width = 80; tlp.width = 80;
value.setLayoutParams(tlp); value.setLayoutParams(tlp);
value.setHint("Value"); value.setHint("Value");
value.addTextChangedListener(new TextWatcher() { Set<String> subCategories = MapRenderingTypes.getDefault().getAmenityNameToType().keySet();
@Override ArrayAdapter<Object> valueAdapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.toArray());
public void afterTextChanged(Editable s) { value.setThreshold(1);
if ((newTagRow != null) value.setAdapter(valueAdapter);
&& (tag != null) && (value != null) value.addTextChangedListener(new TextWatcher() {
&& (tag.getText() != null) && (value.getText() != null) @Override
&& (!tag.getText().equals("")) && (!value.getText().equals(""))) { public void afterTextChanged(Editable s) {
System.out.println(tag.getText()); 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()); additionalTags.put(tag.getText().toString(), value.getText().toString());
} }
} }
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {} public void onTextChanged(CharSequence s, int start, int before, int count) {
}); }
});
tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
tlp.gravity = Gravity.CENTER; tlp.gravity = Gravity.CENTER;
tlp.rightMargin = 5; tlp.rightMargin = 5;

View file

@ -6,7 +6,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.osmand.LogUtil;
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;
@ -97,7 +96,6 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
listAdapter.clear(); listAdapter.clear();
List<OpenstreetmapPoint> l1 = dbpoi.getOpenstreetmapPoints(); List<OpenstreetmapPoint> l1 = dbpoi.getOpenstreetmapPoints();
List<OsmbugsPoint> l2 = dbbug.getOsmbugsPoints(); List<OsmbugsPoint> l2 = dbbug.getOsmbugsPoints();
android.util.Log.d(LogUtil.TAG, "List " + (l1.size() + l2.size()) + " length");
for (OpenstreetmapPoint p : l1) { for (OpenstreetmapPoint p : l1) {
listAdapter.addOsmPoint(p); listAdapter.addOsmPoint(p);
} }
@ -122,9 +120,9 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
} else if(itemId == R.id.deletemod) { } else if(itemId == R.id.deletemod) {
OsmPoint info = (OsmPoint) listAdapter.getChild(group, child); OsmPoint info = (OsmPoint) listAdapter.getChild(group, child);
if (info.getGroup() == OsmPoint.Group.POI) { if (info.getGroup() == OsmPoint.Group.POI) {
dbpoi.deleteAllPOIModifications(info.getId()); dbpoi.deletePOI((OpenstreetmapPoint) info);
} else if (info.getGroup() == OsmPoint.Group.BUG) { } else if (info.getGroup() == OsmPoint.Group.BUG) {
dbbug.deleteAllBugModifications(info.getId()); dbbug.deleteAllBugModifications((OsmbugsPoint) info);
} }
listAdapter.delete(info); listAdapter.delete(info);
return true; return true;
@ -216,7 +214,7 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
listAdapter.categoryIdChanged(point.getId(), n.getId()); listAdapter.categoryIdChanged(point.getId(), n.getId());
} }
remotepoi.updateNodeInIndexes(LocalOpenstreetmapActivity.this, p.getAction(), n, p.getEntity()); remotepoi.updateNodeInIndexes(LocalOpenstreetmapActivity.this, p.getAction(), n, p.getEntity());
dbpoi.deleteOpenstreetmap(p); dbpoi.deletePOI(p);
publishProgress(p); publishProgress(p);
uploaded++; uploaded++;
} }
@ -224,14 +222,12 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
OsmbugsPoint p = (OsmbugsPoint) point; OsmbugsPoint p = (OsmbugsPoint) point;
if (p.getAction() == OsmPoint.Action.CREATE) { if (p.getAction() == OsmPoint.Action.CREATE) {
remotebug.createNewBug(p.getLatitude(), p.getLongitude(), p.getText(), p.getAuthor()); remotebug.createNewBug(p.getLatitude(), p.getLongitude(), p.getText(), p.getAuthor());
dbbug.deleteOsmbugs(p);
} 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());
dbbug.deleteOsmbugs(p);
} else if (p.getAction() == OsmPoint.Action.DELETE) { } else if (p.getAction() == OsmPoint.Action.DELETE) {
remotebug.closingBug(p.getId()); remotebug.closingBug(p.getId());
dbbug.deleteOsmbugs(p);
} }
dbbug.deleteAllBugModifications(p);
publishProgress(p); publishProgress(p);
uploaded++; uploaded++;
} }
@ -316,13 +312,6 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
public void delete(OsmPoint i) { public void delete(OsmPoint i) {
final AmenityIndexRepositoryOdb repo = getMyApplication().getResourceManager().getUpdatablePoiDb(); final AmenityIndexRepositoryOdb repo = getMyApplication().getResourceManager().getUpdatablePoiDb();
android.util.Log.d(LogUtil.TAG, "Delete " + i);
if (i.getGroup() == OsmPoint.Group.POI) {
dbpoi.deleteOpenstreetmap((OpenstreetmapPoint) i);
} else if (i.getGroup() == OsmPoint.Group.BUG) {
dbbug.deleteOsmbugs((OsmbugsPoint) i);
}
Long c = i.getId(); Long c = i.getId();
if(c != null){ if(c != null){
List<OsmPoint> list = data.get(c); List<OsmPoint> list = data.get(c);
@ -412,9 +401,9 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
v = inflater.inflate(net.osmand.plus.R.layout.local_openstreetmap_list_item_category, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.local_openstreetmap_list_item_category, parent, false);
} }
adjustIndicator(groupPosition, isExpanded, v);
StringBuilder t = new StringBuilder(); StringBuilder t = new StringBuilder();
t.append(" id:").append(group); t.append(" id:").append(group);
TextView nameView = ((TextView) v.findViewById(R.id.local_openstreetmap_category_name));
t.append(" [").append(getChildrenCount(groupPosition)); t.append(" [").append(getChildrenCount(groupPosition));
if(getString(R.string.local_openstreetmap_items).length() > 0){ if(getString(R.string.local_openstreetmap_items).length() > 0){
t.append(" ").append(getString(R.string.local_openstreetmap_items)); t.append(" ").append(getString(R.string.local_openstreetmap_items));
@ -423,8 +412,9 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
t.append(" ").append(getString(R.string.local_openstreetmap_items)); t.append(" ").append(getString(R.string.local_openstreetmap_items));
} }
t.append("]"); t.append("]");
TextView nameView = ((TextView) v.findViewById(R.id.local_openstreetmap_category_name));
nameView.setText(t.toString()); nameView.setText(t.toString());
adjustIndicator(groupPosition, isExpanded, v);
return v; return v;
} }

View file

@ -40,14 +40,14 @@ public class OpenstreetmapLocalUtil extends AbstractOpenstreetmapUtil {
public Node commitNodeImpl(OsmPoint.Action action, Node n, EntityInfo info, String comment){ public Node commitNodeImpl(OsmPoint.Action action, Node n, EntityInfo info, String comment){
Node newNode = n; Node newNode = n;
if (n.getId() == -1) { if (n.getId() == -1) {
newNode = new Node(n,--nextid); //generate local id for the created node newNode = new Node(n, --nextid); // generate local id for the created node
} }
OpenstreetmapPoint p = new OpenstreetmapPoint(); OpenstreetmapPoint p = new OpenstreetmapPoint();
p.setEntity(newNode); p.setEntity(newNode);
p.setAction(action); p.setAction(action);
p.setComment(comment); p.setComment(comment);
if (p.getAction() == OsmPoint.Action.DELETE && newNode.getId() < 0) { //if it is our local poi if (p.getAction() == OsmPoint.Action.DELETE && newNode.getId() < 0) { //if it is our local poi
db.deleteAllPOIModifications(p.getId()); db.deletePOI(p);
} else { } else {
db.addOpenstreetmap(p); db.addOpenstreetmap(p);
} }

View file

@ -64,12 +64,6 @@ public class OpenstreetmapPoint extends OsmPoint implements Serializable {
return Group.POI; return Group.POI;
} }
public String getOpeninghours() {
String ret = entity.getTag(OSMTagKey.OPENING_HOURS.getValue());
if (ret == null)
return "";
return entity.getTag(ret);
}
public Node getEntity() { public Node getEntity() {
return entity; return entity;

View file

@ -3,9 +3,12 @@ package net.osmand.plus.osmedit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import com.ibm.icu.impl.locale.StringTokenIterator;
import com.ibm.icu.util.StringTokenizer;
import net.osmand.osm.Node; import net.osmand.osm.Node;
import net.osmand.osm.OSMSettings.OSMTagKey;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
@ -13,29 +16,24 @@ import android.database.sqlite.SQLiteOpenHelper;
public class OpenstreetmapsDbHelper extends SQLiteOpenHelper { public class OpenstreetmapsDbHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1; private static final int DATABASE_VERSION = 2;
public static final String OPENSTREETMAP_DB_NAME = "openstreetmap"; //$NON-NLS-1$ public static final String OPENSTREETMAP_DB_NAME = "openstreetmap"; //$NON-NLS-1$
private static final String OPENSTREETMAP_TABLE_NAME = "openstreetmap"; //$NON-NLS-1$ private static final String OPENSTREETMAP_TABLE_NAME = "openstreetmaptable"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_ID = "id"; //$NON-NLS-1$ private static final String OPENSTREETMAP_COL_ID = "id"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_NAME = "name"; //$NON-NLS-1$ private static final String OPENSTREETMAP_COL_LAT= "lat"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_TYPE = "type"; //$NON-NLS-1$ private static final String OPENSTREETMAP_COL_LON= "lon"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_SUBTYPE = "subtype"; //$NON-NLS-1$ private static final String OPENSTREETMAP_COL_TAGS = "tags"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_LAT = "latitude"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_LON = "longitude"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_ACTION = "action"; //$NON-NLS-1$ private static final String OPENSTREETMAP_COL_ACTION = "action"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_COMMENT = "comment"; //$NON-NLS-1$ private static final String OPENSTREETMAP_COL_COMMENT = "comment"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_OPENINGHOURS = "openinghours"; //$NON-NLS-1$
private static final String OPENSTREETMAP_TABLE_CREATE = "CREATE TABLE " + OPENSTREETMAP_TABLE_NAME + " (" + //$NON-NLS-1$ //$NON-NLS-2$ private static final String OPENSTREETMAP_TABLE_CREATE = "CREATE TABLE " + OPENSTREETMAP_TABLE_NAME + " (" + //$NON-NLS-1$ //$NON-NLS-2$
OPENSTREETMAP_COL_ID + " INTEGER, " + OPENSTREETMAP_COL_NAME + " TEXT, " + OPENSTREETMAP_COL_TYPE + " TEXT, " + OPENSTREETMAP_COL_SUBTYPE + " TEXT, " + //$NON-NLS-1$ //$NON-NLS-2$ OPENSTREETMAP_COL_ID + " bigint,"+
OPENSTREETMAP_COL_LAT + " double, " + OPENSTREETMAP_COL_LON + " double, " + //$NON-NLS-1$ //$NON-NLS-2$ OPENSTREETMAP_COL_LAT + " double," + OPENSTREETMAP_COL_LON + " double," +
OPENSTREETMAP_COL_ACTION + " TEXT, " + OPENSTREETMAP_COL_COMMENT + " TEXT, " + OPENSTREETMAP_COL_OPENINGHOURS + " TEXT);"; //$NON-NLS-1$ //$NON-NLS-2$ OPENSTREETMAP_COL_TAGS + " VARCHAR(2048)," +
OPENSTREETMAP_COL_ACTION + " TEXT, " + OPENSTREETMAP_COL_COMMENT + " TEXT);"; //$NON-NLS-1$ //$NON-NLS-2$
private List<OpenstreetmapPoint> cachedOpenstreetmapPoints = new ArrayList<OpenstreetmapPoint>();
// private final Context context;
public OpenstreetmapsDbHelper(Context context) { public OpenstreetmapsDbHelper(Context context) {
super(context, OPENSTREETMAP_DB_NAME, null, DATABASE_VERSION); super(context, OPENSTREETMAP_DB_NAME, null, DATABASE_VERSION);
// this.context = context;
} }
@Override @Override
@ -45,94 +43,75 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper {
@Override @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if(newVersion == 2) {
// db.execSQL("DROP TABLE " + OPENSTREETMAP_TABLE_NAME);
db.execSQL(OPENSTREETMAP_TABLE_CREATE);
}
} }
public List<OpenstreetmapPoint> getOpenstreetmapPoints() { public List<OpenstreetmapPoint> getOpenstreetmapPoints() {
checkOpenstreetmapPoints(); return checkOpenstreetmapPoints();
return cachedOpenstreetmapPoints;
} }
public boolean addOpenstreetmap(OpenstreetmapPoint p) { public boolean addOpenstreetmap(OpenstreetmapPoint p) {
checkOpenstreetmapPoints(); checkOpenstreetmapPoints();
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
if (db != null) { if (db != null) {
StringBuilder tags = new StringBuilder();
Iterator<Entry<String, String>> eit = p.getEntity().getTags().entrySet().iterator();
while(eit.hasNext()) {
Entry<String, String> e = eit.next();
tags.append(e.getKey()).append("$$$").append(e.getValue());
if(eit.hasNext()) {
tags.append("$$$");
}
}
db.execSQL("INSERT INTO " + OPENSTREETMAP_TABLE_NAME + db.execSQL("INSERT INTO " + OPENSTREETMAP_TABLE_NAME +
" (" + OPENSTREETMAP_COL_ID + ", " + OPENSTREETMAP_COL_NAME + ", " + OPENSTREETMAP_COL_TYPE + ", " + OPENSTREETMAP_COL_SUBTYPE + ", " + OPENSTREETMAP_COL_LAT + "," + OPENSTREETMAP_COL_LON + "," + OPENSTREETMAP_COL_ACTION + "," + OPENSTREETMAP_COL_COMMENT + "," + OPENSTREETMAP_COL_OPENINGHOURS + ")" + " (" + OPENSTREETMAP_COL_ID + ", " + OPENSTREETMAP_COL_LAT + ", " + OPENSTREETMAP_COL_LON + ", " + OPENSTREETMAP_COL_TAGS + ", " + OPENSTREETMAP_COL_ACTION + "," + OPENSTREETMAP_COL_COMMENT + ")" +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] { p.getId(), p.getName(), p.getType(), p.getSubtype(), p.getLatitude(), p.getLongitude(), OsmPoint.stringAction.get(p.getAction()), p.getComment(), p.getOpeninghours() }); //$NON-NLS-1$ //$NON-NLS-2$ " VALUES (?, ?, ?, ?, ?, ?)",
cachedOpenstreetmapPoints.add(p); new Object[] { p.getId(),p.getLatitude(), p.getLongitude(), tags.toString() , OsmPoint.stringAction.get(p.getAction()), p.getComment(), }); //$NON-NLS-1$ //$NON-NLS-2$
p.setStored(true);
return true; return true;
} }
return false; return false;
} }
public boolean deleteOpenstreetmap(OpenstreetmapPoint p) { public boolean deletePOI(OpenstreetmapPoint p) {
checkOpenstreetmapPoints(); checkOpenstreetmapPoints();
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
if (db != null) { if (db != null) {
db.execSQL("DELETE FROM " + OPENSTREETMAP_TABLE_NAME + db.execSQL("DELETE FROM " + OPENSTREETMAP_TABLE_NAME +
" WHERE " + OPENSTREETMAP_COL_ID + " = ? AND " + " WHERE " + OPENSTREETMAP_COL_ID + " = ?", new Object[] { p.getId() }); //$NON-NLS-1$ //$NON-NLS-2$
OPENSTREETMAP_COL_NAME + " = ? AND " +
OPENSTREETMAP_COL_TYPE + " = ? AND " +
OPENSTREETMAP_COL_SUBTYPE + " = ? AND " +
OPENSTREETMAP_COL_LAT + " = ? AND " +
OPENSTREETMAP_COL_LON + " = ? AND " +
OPENSTREETMAP_COL_ACTION + " = ? AND " +
OPENSTREETMAP_COL_COMMENT + " = ? AND " +
OPENSTREETMAP_COL_OPENINGHOURS + " = ?",
new Object[] { p.getId(), p.getName(), p.getType(), p.getSubtype(), p.getLatitude(), p.getLongitude(), OsmPoint.stringAction.get(p.getAction()), p.getComment(), p.getOpeninghours() }); //$NON-NLS-1$ //$NON-NLS-2$
cachedOpenstreetmapPoints.remove(p);
p.setStored(false);
return true; return true;
} }
return false; return false;
} }
public boolean deleteAllPOIModifications(long id) { private List<OpenstreetmapPoint> checkOpenstreetmapPoints(){
checkOpenstreetmapPoints();
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
List<OpenstreetmapPoint> cachedOpenstreetmapPoints = new ArrayList<OpenstreetmapPoint>();
if (db != null) { if (db != null) {
db.execSQL("DELETE FROM " + OPENSTREETMAP_TABLE_NAME + Cursor query = db.rawQuery("SELECT " + OPENSTREETMAP_COL_ID + ", " + OPENSTREETMAP_COL_LAT + "," + OPENSTREETMAP_COL_LON + "," + OPENSTREETMAP_COL_ACTION + "," + OPENSTREETMAP_COL_COMMENT + "," + OPENSTREETMAP_COL_TAGS+ " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
" WHERE " + OPENSTREETMAP_COL_ID + " = ?", new Object[] { id }); //$NON-NLS-1$ //$NON-NLS-2$
//remove all associated actions with that POI
for (Iterator<OpenstreetmapPoint> it = cachedOpenstreetmapPoints.iterator(); it.hasNext();) {
if (it.next().getId() == id) {
it.remove();
}
};
return true;
}
return false;
}
private void checkOpenstreetmapPoints(){
SQLiteDatabase db = getWritableDatabase();
if (db != null) {
Cursor query = db.rawQuery("SELECT " + OPENSTREETMAP_COL_ID + ", " + OPENSTREETMAP_COL_NAME + ", " + OPENSTREETMAP_COL_TYPE + ", " + OPENSTREETMAP_COL_SUBTYPE + ", " + OPENSTREETMAP_COL_LAT + "," + OPENSTREETMAP_COL_LON + "," + OPENSTREETMAP_COL_ACTION + "," + OPENSTREETMAP_COL_COMMENT + "," + OPENSTREETMAP_COL_OPENINGHOURS + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
OPENSTREETMAP_TABLE_NAME, null); OPENSTREETMAP_TABLE_NAME, null);
cachedOpenstreetmapPoints.clear();
if (query.moveToFirst()) { if (query.moveToFirst()) {
do { do {
String name = query.getString(1);
OpenstreetmapPoint p = new OpenstreetmapPoint(); OpenstreetmapPoint p = new OpenstreetmapPoint();
Node entity = new Node(query.getDouble(4), Node entity = new Node(query.getDouble(1),
query.getDouble(5), query.getDouble(2),
query.getLong(0)); query.getLong(0));
String tags = query.getString(5);
entity.putTag(query.getString(2), query.getString(3)); String[] split = tags.split("\\$\\$\\$");
entity.putTag(OSMTagKey.NAME.getValue(), name); for(int i=0; i<split.length - 1; i+= 2){
String openingHours = query.getString(8); entity.putTag(split[i].trim(), split[i+1].trim());
if (openingHours != null && openingHours.length() > 0) }
entity.putTag(OSMTagKey.OPENING_HOURS.getValue(), openingHours);
p.setEntity(entity); p.setEntity(entity);
p.setStored(true); p.setAction(query.getString(3));
p.setAction(query.getString(6)); p.setComment(query.getString(4));
p.setComment(query.getString(7));
cachedOpenstreetmapPoints.add(p); cachedOpenstreetmapPoints.add(p);
} while (query.moveToNext()); } while (query.moveToNext());
} }
query.close(); query.close();
} }
return cachedOpenstreetmapPoints;
} }
public long getMinID() { public long getMinID() {

View file

@ -1,7 +1,6 @@
package net.osmand.plus.osmedit; package net.osmand.plus.osmedit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import android.content.Context; import android.content.Context;
@ -25,12 +24,8 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper {
OSMBUGS_COL_LAT + " double, " + OSMBUGS_COL_LON + " double, " + //$NON-NLS-1$ //$NON-NLS-2$ OSMBUGS_COL_LAT + " double, " + OSMBUGS_COL_LON + " double, " + //$NON-NLS-1$ //$NON-NLS-2$
OSMBUGS_COL_ACTION + " TEXT, " + OSMBUGS_COL_AUTHOR + " TEXT);"; //$NON-NLS-1$ //$NON-NLS-2$ OSMBUGS_COL_ACTION + " TEXT, " + OSMBUGS_COL_AUTHOR + " TEXT);"; //$NON-NLS-1$ //$NON-NLS-2$
private List<OsmbugsPoint> cachedOsmbugsPoints = new ArrayList<OsmbugsPoint>();
// private final Context context;
public OsmBugsDbHelper(Context context) { public OsmBugsDbHelper(Context context) {
super(context, OSMBUGS_DB_NAME, null, DATABASE_VERSION); super(context, OSMBUGS_DB_NAME, null, DATABASE_VERSION);
// this.context = context;
} }
@Override @Override
@ -43,66 +38,39 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper {
} }
public List<OsmbugsPoint> getOsmbugsPoints() { public List<OsmbugsPoint> getOsmbugsPoints() {
checkOsmbugsPoints(); return checkOsmbugsPoints();
return cachedOsmbugsPoints;
} }
public boolean addOsmbugs(OsmbugsPoint p) { public boolean addOsmbugs(OsmbugsPoint p) {
checkOsmbugsPoints(); checkOsmbugsPoints();
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
if (db != null) { if (db != null) {
db.execSQL("INSERT INTO " + OSMBUGS_TABLE_NAME + db.execSQL(
" (" + OSMBUGS_COL_ID + ", " + OSMBUGS_COL_TEXT + ", " + OSMBUGS_COL_LAT + "," + OSMBUGS_COL_LON + "," + OSMBUGS_COL_ACTION + "," + OSMBUGS_COL_AUTHOR + ")" + "INSERT INTO " + OSMBUGS_TABLE_NAME + " (" + OSMBUGS_COL_ID + ", " + OSMBUGS_COL_TEXT + ", " + OSMBUGS_COL_LAT + ","
" VALUES (?, ?, ?, ?, ?, ?)", new Object[] { p.getId(), p.getText(), p.getLatitude(), p.getLongitude(), OsmPoint.stringAction.get(p.getAction()), p.getAuthor() }); //$NON-NLS-1$ //$NON-NLS-2$ + OSMBUGS_COL_LON + "," + OSMBUGS_COL_ACTION + "," + OSMBUGS_COL_AUTHOR + ")" + " VALUES (?, ?, ?, ?, ?, ?)", new Object[] { p.getId(), p.getText(), p.getLatitude(), p.getLongitude(), OsmPoint.stringAction.get(p.getAction()), p.getAuthor() }); //$NON-NLS-1$ //$NON-NLS-2$
cachedOsmbugsPoints.add(p);
p.setStored(true);
return true; return true;
} }
return false; return false;
} }
public boolean deleteOsmbugs(OsmbugsPoint p) { public boolean deleteAllBugModifications(OsmbugsPoint p) {
checkOsmbugsPoints(); checkOsmbugsPoints();
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
if (db != null) { if (db != null) {
db.execSQL("DELETE FROM " + OSMBUGS_TABLE_NAME + db.execSQL("DELETE FROM " + OSMBUGS_TABLE_NAME +
" WHERE " + OSMBUGS_COL_ID + " = ? AND " + " WHERE " + OSMBUGS_COL_ID + " = ?", new Object[] { p.getId() }); //$NON-NLS-1$ //$NON-NLS-2$
OSMBUGS_COL_TEXT + " = ? AND " +
OSMBUGS_COL_LAT + " = ? AND " +
OSMBUGS_COL_LON + " = ? AND " +
OSMBUGS_COL_ACTION + " = ? AND " +
OSMBUGS_COL_AUTHOR + " = ?",
new Object[] { p.getId(), p.getText(), p.getLatitude(), p.getLongitude(), OsmPoint.stringAction.get(p.getAction()), p.getAuthor() }); //$NON-NLS-1$ //$NON-NLS-2$
cachedOsmbugsPoints.remove(p);
p.setStored(false);
return true; return true;
} }
return false; return false;
} }
public boolean deleteAllBugModifications(long id) { private List<OsmbugsPoint> checkOsmbugsPoints(){
checkOsmbugsPoints();
SQLiteDatabase db = getWritableDatabase();
if (db != null) {
db.execSQL("DELETE FROM " + OSMBUGS_TABLE_NAME +
" WHERE " + OSMBUGS_COL_ID + " = ?", new Object[] { id }); //$NON-NLS-1$ //$NON-NLS-2$
//remove all associated actions with that Bug
for (Iterator<OsmbugsPoint> it = cachedOsmbugsPoints.iterator(); it.hasNext();) {
if (it.next().getId() == id) {
it.remove();
}
};
return true;
}
return false;
}
private void checkOsmbugsPoints(){
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
List<OsmbugsPoint> cachedOsmbugsPoints = new ArrayList<OsmbugsPoint>();
if (db != null) { if (db != null) {
Cursor query = db.rawQuery("SELECT " + OSMBUGS_COL_ID + ", " + OSMBUGS_COL_TEXT + ", " + OSMBUGS_COL_LAT + "," + OSMBUGS_COL_LON + "," + OSMBUGS_COL_ACTION + "," + OSMBUGS_COL_AUTHOR + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ Cursor query = db.rawQuery("SELECT " + OSMBUGS_COL_ID + ", " + OSMBUGS_COL_TEXT + ", " + OSMBUGS_COL_LAT + "," + OSMBUGS_COL_LON + "," + OSMBUGS_COL_ACTION + "," + OSMBUGS_COL_AUTHOR + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
OSMBUGS_TABLE_NAME, null); OSMBUGS_TABLE_NAME, null);
cachedOsmbugsPoints.clear();
if (query.moveToFirst()) { if (query.moveToFirst()) {
do { do {
OsmbugsPoint p = new OsmbugsPoint(); OsmbugsPoint p = new OsmbugsPoint();
@ -113,12 +81,12 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper {
p.setLongitude(query.getDouble(3)); p.setLongitude(query.getDouble(3));
p.setAction(query.getString(4)); p.setAction(query.getString(4));
p.setAuthor(query.getString(5)); p.setAuthor(query.getString(5));
p.setStored(true);
cachedOsmbugsPoints.add(p); cachedOsmbugsPoints.add(p);
} while (query.moveToNext()); } while (query.moveToNext());
} }
query.close(); query.close();
} }
return cachedOsmbugsPoints;
} }
public long getMinID() { public long getMinID() {

View file

@ -4,10 +4,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public abstract class OsmPoint { public abstract class OsmPoint {
/**
*
*/
private static final long serialVersionUID = 729654300829771469L;
public static enum Group {BUG, POI}; public static enum Group {BUG, POI};
@ -26,7 +22,6 @@ public abstract class OsmPoint {
}; };
private Action action; private Action action;
private boolean stored = false;
public OsmPoint(){ public OsmPoint(){
} }
@ -45,9 +40,6 @@ public abstract class OsmPoint {
return action; return action;
} }
public boolean isStored() {
return stored;
}
public void setAction(String action) { public void setAction(String action) {
this.action = actionString.get(action); this.action = actionString.get(action);
@ -57,9 +49,6 @@ public abstract class OsmPoint {
this.action = action; this.action = action;
} }
public void setStored(boolean stored) {
this.stored = stored;
}
@Override @Override
public String toString() { public String toString() {