diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-10-26 07:13:53 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-11-09 17:50:38 +0100 |
| commit | 26ba5c2375e604fdb65c36c095cfe6f9210c3ad1 (patch) | |
| tree | 12deb4d48559d50f687c1ac24ee3a775196e59f0 | |
| parent | 0cf2f15d3ad8137653756f6bda7dda29fbe3487e (diff) | |
| download | cgeo-26ba5c2375e604fdb65c36c095cfe6f9210c3ad1.zip cgeo-26ba5c2375e604fdb65c36c095cfe6f9210c3ad1.tar.gz cgeo-26ba5c2375e604fdb65c36c095cfe6f9210c3ad1.tar.bz2 | |
fix #3377: OC waypoints get duplicated
* delete outdated waypoints from database after saving
| -rw-r--r-- | main/src/cgeo/geocaching/DataStore.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java index 4677f03..a231e8b 100644 --- a/main/src/cgeo/geocaching/DataStore.java +++ b/main/src/cgeo/geocaching/DataStore.java @@ -1191,10 +1191,12 @@ public class DataStore { List<Waypoint> waypoints = cache.getWaypoints(); if (CollectionUtils.isNotEmpty(waypoints)) { + final ArrayList<String> currentWaypointIds = new ArrayList<String>(); ContentValues values = new ContentValues(); long timeStamp = System.currentTimeMillis(); for (Waypoint oneWaypoint : waypoints) { if (oneWaypoint.isUserDefined()) { + currentWaypointIds.add(Integer.toString(oneWaypoint.getId())); continue; } @@ -1216,13 +1218,28 @@ public class DataStore { } else { database.update(dbTableWaypoints, values, "_id = ?", new String[] { Integer.toString(oneWaypoint.getId(), 10) }); } + currentWaypointIds.add(Integer.toString(oneWaypoint.getId())); } + + removeOutdatedWaypointsOfCache(cache, currentWaypointIds); } } /** + * remove all waypoints of the given cache, where the id is not in the given list + * + * @param cache + * @param remainingWaypointIds + * ids of waypoints which shall not be deleted + */ + private static void removeOutdatedWaypointsOfCache(final @NonNull Geocache cache, final @NonNull Collection<String> remainingWaypointIds) { + final String idList = StringUtils.join(remainingWaypointIds, ','); + database.delete(dbTableWaypoints, "geocode = ? AND _id NOT in (" + idList + ")", new String[] { cache.getGeocode() }); + } + + /** * Save coordinates into a ContentValues - * + * * @param values * a ContentValues to save coordinates in * @param oneWaypoint |
