aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/DataStore.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/DataStore.java')
-rw-r--r--main/src/cgeo/geocaching/DataStore.java24
1 files changed, 21 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java
index 7c19a83..a231e8b 100644
--- a/main/src/cgeo/geocaching/DataStore.java
+++ b/main/src/cgeo/geocaching/DataStore.java
@@ -1067,10 +1067,11 @@ public class DataStore {
values.put("name", cache.getName());
values.put("owner", cache.getOwnerDisplayName());
values.put("owner_real", cache.getOwnerUserId());
- if (cache.getHiddenDate() == null) {
+ final Date hiddenDate = cache.getHiddenDate();
+ if (hiddenDate == null) {
values.put("hidden", 0);
} else {
- values.put("hidden", cache.getHiddenDate().getTime());
+ values.put("hidden", hiddenDate.getTime());
}
values.put("hint", cache.getHint());
values.put("size", cache.getSize() == null ? "" : cache.getSize().id);
@@ -1190,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;
}
@@ -1215,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