From 28a4bf6d15e5d2530e971f92a1c35586e95791ac Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 7 Sep 2017 10:41:11 +0300 Subject: [PATCH 1/2] Change some code --- .../src/net/osmand/plus/MapMarkersHelper.java | 17 ++++++++++++++--- .../net/osmand/plus/views/MapMarkersLayer.java | 11 +---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 5ddd5eeba2..5660ff5399 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -272,6 +272,7 @@ public class MapMarkersHelper { return list; } + //todo: rewrite with MapMarkersDbHelper public void reverseActiveMarkersOrder() { cancelAddressRequests(); @@ -358,13 +359,23 @@ public class MapMarkersHelper { } } - public void changeActiveMarkerPositionInDb(int currentPos) { - MapMarker moved = mapMarkers.get(currentPos); + public void changeActiveMarkerPositionInDb(int currentPosInMapMarkers) { + MapMarker moved = mapMarkers.get(currentPosInMapMarkers); markersDbHelper.changeActiveMarkerPosition(moved, - currentPos == mapMarkers.size() - 1 ? null : mapMarkers.get(currentPos + 1)); + currentPosInMapMarkers == mapMarkers.size() - 1 ? null : mapMarkers.get(currentPosInMapMarkers + 1)); loadMarkers(); } + public void moveMarkerToTop(MapMarker marker) { + int i = mapMarkers.indexOf(marker); + if (i != -1 && mapMarkers.size() > 1) { + mapMarkers.remove(i); + markersDbHelper.changeActiveMarkerPosition(marker, mapMarkers.get(0)); + loadMarkers(); + refresh(); + } + } + public void saveMapMarkers(List markers, List markersHistory) { if (markers != null) { List ls = new ArrayList<>(markers.size()); diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 296a8de611..8107ee7ba7 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -493,16 +493,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi @Override public void setSelectedObject(Object o) { if (o instanceof MapMarker) { - MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); - MapMarker marker = (MapMarker) o; - List mapMarkers = markersHelper.getMapMarkers(); - int i = mapMarkers.indexOf(marker); - if (i != -1) { - mapMarkers.remove(i); - mapMarkers.add(0, marker); - markersHelper.saveMapMarkers(mapMarkers, null); - marker.index = 0; - } + map.getMyApplication().getMapMarkersHelper().moveMarkerToTop((MapMarker) o); } } From b62f07a3f9ba2a47653225bd92ddd62a214c9c01 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 7 Sep 2017 11:07:55 +0300 Subject: [PATCH 2/2] 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) {