Rewrite method reverseActiveMarkersOrder with MapMarkersDbHelper

This commit is contained in:
Alexander Sytnyk 2017-09-07 11:07:55 +03:00
parent 28a4bf6d15
commit b62f07a3f9
2 changed files with 22 additions and 8 deletions

View file

@ -272,17 +272,11 @@ public class MapMarkersHelper {
return list; return list;
} }
//todo: rewrite with MapMarkersDbHelper
public void reverseActiveMarkersOrder() { public void reverseActiveMarkersOrder() {
cancelAddressRequests(); cancelAddressRequests();
List<MapMarker> markers = new ArrayList<>(mapMarkers.size()); markersDbHelper.reverseActiveMarkersOrder();
for (int i = mapMarkers.size() - 1; i >= 0; i--) { loadMarkers();
MapMarker marker = mapMarkers.get(i);
markers.add(marker);
}
mapMarkers = markers;
saveMapMarkers(mapMarkers, null);
} }
public void removeActiveMarkers() { public void removeActiveMarkers() {

View file

@ -139,6 +139,14 @@ public class MapMarkersDbHelper {
} }
} }
public void reverseActiveMarkersOrder() {
List<MapMarker> markers = getActiveMarkers();
removeAllActiveMarkers();
for (int i = markers.size() - 1; i >= 0; i--) {
addMarker(markers.get(i));
}
}
public void addMarker(MapMarker marker) { public void addMarker(MapMarker marker) {
SQLiteConnection db = openConnection(false); SQLiteConnection db = openConnection(false);
if (db != null) { 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) { public void moveMarkerToHistory(MapMarker marker) {
SQLiteConnection db = openConnection(false); SQLiteConnection db = openConnection(false);
if (db != null) { if (db != null) {