From a5fbace3327283696ffbb744c916d273bc2ea7a0 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 8 Sep 2017 12:34:27 +0300 Subject: [PATCH] Fix date for existing markers --- .../plus/mapmarkers/MapMarkersDbHelper.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 4c1de6d643..c9aa1b0da5 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -12,6 +12,7 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.helpers.SearchHistoryHelper; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.Random; @@ -122,7 +123,7 @@ public class MapMarkersDbHelper { MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i); marker.history = false; - addMarker(marker); + addMarker(marker, true); } ips = settings.getMapMarkersHistoryPoints(); @@ -135,7 +136,7 @@ public class MapMarkersDbHelper { MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i); marker.history = true; - addMarker(marker); + addMarker(marker, true); } } @@ -148,25 +149,36 @@ public class MapMarkersDbHelper { } public void addMarker(MapMarker marker) { + addMarker(marker, false); + } + + private void addMarker(MapMarker marker, boolean saveExisting) { SQLiteConnection db = openConnection(false); if (db != null) { try { - insertLast(db, marker); + insertLast(db, marker, saveExisting); } finally { db.close(); } } } - private void insertLast(SQLiteConnection db, MapMarker marker) { - long currentTime = System.currentTimeMillis(); + private void insertLast(SQLiteConnection db, MapMarker marker, boolean saveExisting) { + long currentTime; + if (saveExisting) { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MONTH, -1); + currentTime = cal.getTimeInMillis(); + } else { + currentTime = System.currentTimeMillis(); + } marker.id = Long.parseLong(String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100)); marker.creationDate = currentTime; double lat = marker.getLatitude(); double lon = marker.getLongitude(); String descr = PointDescription.serializeToString(marker.getOriginalPointDescription()); int active = marker.history ? 0 : 1; - long visited = 0; + long visited = saveExisting ? currentTime : 0; int groupKey = 0; int colorIndex = marker.colorIndex;