From b62f07a3f9ba2a47653225bd92ddd62a214c9c01 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 7 Sep 2017 11:07:55 +0300 Subject: [PATCH] Rewrite method reverseActiveMarkersOrder with MapMarkersDbHelper --- .../src/net/osmand/plus/MapMarkersHelper.java | 10 ++-------- .../plus/mapmarkers/MapMarkersDbHelper.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 5660ff5399..044de5d840 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -272,17 +272,11 @@ public class MapMarkersHelper { return list; } - //todo: rewrite with MapMarkersDbHelper public void reverseActiveMarkersOrder() { cancelAddressRequests(); - List markers = new ArrayList<>(mapMarkers.size()); - for (int i = mapMarkers.size() - 1; i >= 0; i--) { - MapMarker marker = mapMarkers.get(i); - markers.add(marker); - } - mapMarkers = markers; - saveMapMarkers(mapMarkers, null); + markersDbHelper.reverseActiveMarkersOrder(); + loadMarkers(); } public void removeActiveMarkers() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index aa4e828b58..03e2253f09 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -139,6 +139,14 @@ public class MapMarkersDbHelper { } } + public void reverseActiveMarkersOrder() { + List markers = getActiveMarkers(); + removeAllActiveMarkers(); + for (int i = markers.size() - 1; i >= 0; i--) { + addMarker(markers.get(i)); + } + } + public void addMarker(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { @@ -271,6 +279,18 @@ public class MapMarkersDbHelper { } } + private void removeAllActiveMarkers() { + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ACTIVE + " = ?", + new Object[]{1}); + } finally { + db.close(); + } + } + } + public void moveMarkerToHistory(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) {