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
AMENITY("amenity"), //$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$
TOURISM("tourism"), //$NON-NLS-1$
SPORT("sport"), //$NON-NLS-1$

View file

@ -257,10 +257,9 @@ public class EditingPOIActivity implements DialogProvider {
layout.setLayoutParams(tlParams);
layout.setColumnStretchable(1, true);
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) {
Button addTag = (Button) dlg.findViewById(R.id.addTag);
addTag.setVisibility((layout.getVisibility() == View.VISIBLE) ? View.GONE : View.VISIBLE);
addTag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -269,38 +268,32 @@ public class EditingPOIActivity implements DialogProvider {
tlp.leftMargin = 5;
newTagRow.setLayoutParams(tlp);
final Button tag = new Button(ctx);
final EditText value = new EditText(ctx);
final AutoCompleteTextView tag = new AutoCompleteTextView(ctx);
final AutoCompleteTextView value = new AutoCompleteTextView(ctx);
final Button delete = new Button(ctx);
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() {
@Override
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.setItems(vals, new Dialog.OnClickListener() {
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(vals[which]);
tag.invalidate();
tag.setText(tags[which]);
}
});
@ -314,24 +307,27 @@ public class EditingPOIActivity implements DialogProvider {
tlp.width = 80;
value.setLayoutParams(tlp);
value.setHint("Value");
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(""))) {
System.out.println(tag.getText());
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 beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
@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;

View file

@ -6,7 +6,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.osmand.LogUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.osm.EntityInfo;
import net.osmand.osm.Node;
@ -97,7 +96,6 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
listAdapter.clear();
List<OpenstreetmapPoint> l1 = dbpoi.getOpenstreetmapPoints();
List<OsmbugsPoint> l2 = dbbug.getOsmbugsPoints();
android.util.Log.d(LogUtil.TAG, "List " + (l1.size() + l2.size()) + " length");
for (OpenstreetmapPoint p : l1) {
listAdapter.addOsmPoint(p);
}
@ -122,9 +120,9 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
} else if(itemId == R.id.deletemod) {
OsmPoint info = (OsmPoint) listAdapter.getChild(group, child);
if (info.getGroup() == OsmPoint.Group.POI) {
dbpoi.deleteAllPOIModifications(info.getId());
dbpoi.deletePOI((OpenstreetmapPoint) info);
} else if (info.getGroup() == OsmPoint.Group.BUG) {
dbbug.deleteAllBugModifications(info.getId());
dbbug.deleteAllBugModifications((OsmbugsPoint) info);
}
listAdapter.delete(info);
return true;
@ -216,7 +214,7 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
listAdapter.categoryIdChanged(point.getId(), n.getId());
}
remotepoi.updateNodeInIndexes(LocalOpenstreetmapActivity.this, p.getAction(), n, p.getEntity());
dbpoi.deleteOpenstreetmap(p);
dbpoi.deletePOI(p);
publishProgress(p);
uploaded++;
}
@ -224,14 +222,12 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
OsmbugsPoint p = (OsmbugsPoint) point;
if (p.getAction() == OsmPoint.Action.CREATE) {
remotebug.createNewBug(p.getLatitude(), p.getLongitude(), p.getText(), p.getAuthor());
dbbug.deleteOsmbugs(p);
} else if (p.getAction() == OsmPoint.Action.MODIFY) {
remotebug.addingComment(p.getId(), p.getText(), p.getAuthor());
dbbug.deleteOsmbugs(p);
} else if (p.getAction() == OsmPoint.Action.DELETE) {
remotebug.closingBug(p.getId());
dbbug.deleteOsmbugs(p);
}
dbbug.deleteAllBugModifications(p);
publishProgress(p);
uploaded++;
}
@ -316,13 +312,6 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
public void delete(OsmPoint i) {
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();
if(c != null){
List<OsmPoint> list = data.get(c);
@ -412,9 +401,9 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity {
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);
TextView nameView = ((TextView) v.findViewById(R.id.local_openstreetmap_category_name));
t.append(" [").append(getChildrenCount(groupPosition));
if(getString(R.string.local_openstreetmap_items).length() > 0){
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("]");
TextView nameView = ((TextView) v.findViewById(R.id.local_openstreetmap_category_name));
nameView.setText(t.toString());
adjustIndicator(groupPosition, isExpanded, 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){
Node newNode = n;
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();
p.setEntity(newNode);
p.setAction(action);
p.setComment(comment);
if (p.getAction() == OsmPoint.Action.DELETE && newNode.getId() < 0) { //if it is our local poi
db.deleteAllPOIModifications(p.getId());
db.deletePOI(p);
} else {
db.addOpenstreetmap(p);
}

View file

@ -64,12 +64,6 @@ public class OpenstreetmapPoint extends OsmPoint implements Serializable {
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() {
return entity;

View file

@ -3,9 +3,12 @@ package net.osmand.plus.osmedit;
import java.util.ArrayList;
import java.util.Iterator;
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.OSMSettings.OSMTagKey;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
@ -13,29 +16,24 @@ import android.database.sqlite.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$
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_NAME = "name"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_TYPE = "type"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_SUBTYPE = "subtype"; //$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_LAT= "lat"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_LON= "lon"; //$NON-NLS-1$
private static final String OPENSTREETMAP_COL_TAGS = "tags"; //$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_OPENINGHOURS = "openinghours"; //$NON-NLS-1$
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_LAT + " double, " + OPENSTREETMAP_COL_LON + " double, " + //$NON-NLS-1$ //$NON-NLS-2$
OPENSTREETMAP_COL_ACTION + " TEXT, " + OPENSTREETMAP_COL_COMMENT + " TEXT, " + OPENSTREETMAP_COL_OPENINGHOURS + " TEXT);"; //$NON-NLS-1$ //$NON-NLS-2$
OPENSTREETMAP_COL_ID + " bigint,"+
OPENSTREETMAP_COL_LAT + " double," + OPENSTREETMAP_COL_LON + " double," +
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) {
super(context, OPENSTREETMAP_DB_NAME, null, DATABASE_VERSION);
// this.context = context;
}
@Override
@ -45,94 +43,75 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper {
@Override
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() {
checkOpenstreetmapPoints();
return cachedOpenstreetmapPoints;
return checkOpenstreetmapPoints();
}
public boolean addOpenstreetmap(OpenstreetmapPoint p) {
checkOpenstreetmapPoints();
SQLiteDatabase db = getWritableDatabase();
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 +
" (" + 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 + ")" +
" 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$
cachedOpenstreetmapPoints.add(p);
p.setStored(true);
" (" + OPENSTREETMAP_COL_ID + ", " + OPENSTREETMAP_COL_LAT + ", " + OPENSTREETMAP_COL_LON + ", " + OPENSTREETMAP_COL_TAGS + ", " + OPENSTREETMAP_COL_ACTION + "," + OPENSTREETMAP_COL_COMMENT + ")" +
" VALUES (?, ?, ?, ?, ?, ?)",
new Object[] { p.getId(),p.getLatitude(), p.getLongitude(), tags.toString() , OsmPoint.stringAction.get(p.getAction()), p.getComment(), }); //$NON-NLS-1$ //$NON-NLS-2$
return true;
}
return false;
}
public boolean deleteOpenstreetmap(OpenstreetmapPoint p) {
public boolean deletePOI(OpenstreetmapPoint p) {
checkOpenstreetmapPoints();
SQLiteDatabase db = getWritableDatabase();
if (db != null) {
db.execSQL("DELETE FROM " + OPENSTREETMAP_TABLE_NAME +
" WHERE " + OPENSTREETMAP_COL_ID + " = ? AND " +
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);
" WHERE " + OPENSTREETMAP_COL_ID + " = ?", new Object[] { p.getId() }); //$NON-NLS-1$ //$NON-NLS-2$
return true;
}
return false;
}
public boolean deleteAllPOIModifications(long id) {
checkOpenstreetmapPoints();
private List<OpenstreetmapPoint> checkOpenstreetmapPoints(){
SQLiteDatabase db = getWritableDatabase();
List<OpenstreetmapPoint> cachedOpenstreetmapPoints = new ArrayList<OpenstreetmapPoint>();
if (db != null) {
db.execSQL("DELETE FROM " + OPENSTREETMAP_TABLE_NAME +
" 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$
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$
OPENSTREETMAP_TABLE_NAME, null);
cachedOpenstreetmapPoints.clear();
if (query.moveToFirst()) {
do {
String name = query.getString(1);
OpenstreetmapPoint p = new OpenstreetmapPoint();
Node entity = new Node(query.getDouble(4),
query.getDouble(5),
Node entity = new Node(query.getDouble(1),
query.getDouble(2),
query.getLong(0));
entity.putTag(query.getString(2), query.getString(3));
entity.putTag(OSMTagKey.NAME.getValue(), name);
String openingHours = query.getString(8);
if (openingHours != null && openingHours.length() > 0)
entity.putTag(OSMTagKey.OPENING_HOURS.getValue(), openingHours);
String tags = query.getString(5);
String[] split = tags.split("\\$\\$\\$");
for(int i=0; i<split.length - 1; i+= 2){
entity.putTag(split[i].trim(), split[i+1].trim());
}
p.setEntity(entity);
p.setStored(true);
p.setAction(query.getString(6));
p.setComment(query.getString(7));
p.setAction(query.getString(3));
p.setComment(query.getString(4));
cachedOpenstreetmapPoints.add(p);
} while (query.moveToNext());
}
query.close();
}
return cachedOpenstreetmapPoints;
}
public long getMinID() {

View file

@ -1,7 +1,6 @@
package net.osmand.plus.osmedit;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
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_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) {
super(context, OSMBUGS_DB_NAME, null, DATABASE_VERSION);
// this.context = context;
}
@Override
@ -43,66 +38,39 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper {
}
public List<OsmbugsPoint> getOsmbugsPoints() {
checkOsmbugsPoints();
return cachedOsmbugsPoints;
return checkOsmbugsPoints();
}
public boolean addOsmbugs(OsmbugsPoint p) {
checkOsmbugsPoints();
SQLiteDatabase db = getWritableDatabase();
if (db != null) {
db.execSQL("INSERT INTO " + OSMBUGS_TABLE_NAME +
" (" + OSMBUGS_COL_ID + ", " + OSMBUGS_COL_TEXT + ", " + OSMBUGS_COL_LAT + "," + 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);
db.execSQL(
"INSERT INTO " + OSMBUGS_TABLE_NAME + " (" + OSMBUGS_COL_ID + ", " + OSMBUGS_COL_TEXT + ", " + OSMBUGS_COL_LAT + ","
+ 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$
return true;
}
return false;
}
public boolean deleteOsmbugs(OsmbugsPoint p) {
public boolean deleteAllBugModifications(OsmbugsPoint p) {
checkOsmbugsPoints();
SQLiteDatabase db = getWritableDatabase();
if (db != null) {
db.execSQL("DELETE FROM " + OSMBUGS_TABLE_NAME +
" WHERE " + OSMBUGS_COL_ID + " = ? AND " +
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);
" WHERE " + OSMBUGS_COL_ID + " = ?", new Object[] { p.getId() }); //$NON-NLS-1$ //$NON-NLS-2$
return true;
}
return false;
}
public boolean deleteAllBugModifications(long id) {
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(){
private List<OsmbugsPoint> checkOsmbugsPoints(){
SQLiteDatabase db = getWritableDatabase();
List<OsmbugsPoint> cachedOsmbugsPoints = new ArrayList<OsmbugsPoint>();
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$
OSMBUGS_TABLE_NAME, null);
cachedOsmbugsPoints.clear();
if (query.moveToFirst()) {
do {
OsmbugsPoint p = new OsmbugsPoint();
@ -113,12 +81,12 @@ public class OsmBugsDbHelper extends SQLiteOpenHelper {
p.setLongitude(query.getDouble(3));
p.setAction(query.getString(4));
p.setAuthor(query.getString(5));
p.setStored(true);
cachedOsmbugsPoints.add(p);
} while (query.moveToNext());
}
query.close();
}
return cachedOsmbugsPoints;
}
public long getMinID() {

View file

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