diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 4213b31847..60d9370b72 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -132,7 +132,7 @@ public class FavouritesDbHelper { flatGroups.remove(g.name); favoriteGroups.remove(g); cachedFavoritePoints.removeAll(g.points); - context.getMapMarkersHelper().removeMarkersSyncGroup(g.name); + context.getMapMarkersHelper().removeMarkersSyncGroup(g.name, true); } } saveCurrentPointsIntoFile(); @@ -349,7 +349,7 @@ public class FavouritesDbHelper { if (remove) { flatGroups.remove(group.name); saveCurrentPointsIntoFile(); - context.getMapMarkersHelper().removeMarkersSyncGroup(group.name); + context.getMapMarkersHelper().removeMarkersSyncGroup(group.name, true); return true; } return false; @@ -591,6 +591,7 @@ public class FavouritesDbHelper { //todo public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) { + MapMarkersHelper markersHelper = context.getMapMarkersHelper(); if (color != 0 && group.color != color) { FavoriteGroup gr = flatGroups.get(group.name); group.color = color; @@ -607,6 +608,7 @@ public class FavouritesDbHelper { } if (!group.name.equals(newName)) { FavoriteGroup gr = flatGroups.remove(group.name); + markersHelper.removeMarkersSyncGroup(group.name, true); gr.name = newName; FavoriteGroup renamedGroup = flatGroups.get(gr.name); boolean existing = renamedGroup != null; @@ -622,6 +624,9 @@ public class FavouritesDbHelper { renamedGroup.points.add(p); } } + MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE); + markersHelper.addMarkersSyncGroup(syncGroup); + markersHelper.syncGroup(syncGroup); } saveCurrentPointsIntoFile(); } diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 6ce78edacd..e686cebb4b 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -479,9 +480,24 @@ public class MapMarkersHelper { } } - public void removeMarkersSyncGroup(String id) { + public void removeMarkersSyncGroup(String id, boolean removeActiveMarkers) { if (id != null) { markersDbHelper.removeMarkersSyncGroup(id); + if (removeActiveMarkers) { + removeActiveMarkersFromSyncGroup(id); + } + } + } + + public void removeActiveMarkersFromSyncGroup(String syncGroupId) { + if (syncGroupId != null) { + markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId); + for (Iterator iterator = mapMarkers.iterator(); iterator.hasNext(); ) { + if (iterator.next().groupKey.equals(syncGroupId)) { + iterator.remove(); + } + } + checkAndFixActiveMarkersOrderIfNeeded(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index a6804667bb..939e1732c3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -21,7 +21,7 @@ import java.util.Random; public class MapMarkersDbHelper { - private static final int DB_VERSION = 1; + private static final int DB_VERSION = 2; public static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; @@ -210,15 +210,24 @@ public class MapMarkersDbHelper { } public void removeMarkersSyncGroup(String id) { + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_ID + " = ?", new Object[]{id}); + } finally { + db.close(); + } + } + } + + public void removeActiveMarkersFromSyncGroup(String syncGroupId) { SQLiteConnection db = openConnection(true); if (db != null) { try { db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_GROUP_KEY + " = ?" + " AND " + MARKERS_COL_ACTIVE + " = ?", - new Object[]{id, 1}); - - db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_ID + " = ?", new Object[]{id}); + new Object[]{syncGroupId, 1}); } finally { db.close(); }