Add sync after changing favorite group name
This commit is contained in:
parent
f2492c4923
commit
29a4b67e43
3 changed files with 37 additions and 7 deletions
|
@ -132,7 +132,7 @@ public class FavouritesDbHelper {
|
||||||
flatGroups.remove(g.name);
|
flatGroups.remove(g.name);
|
||||||
favoriteGroups.remove(g);
|
favoriteGroups.remove(g);
|
||||||
cachedFavoritePoints.removeAll(g.points);
|
cachedFavoritePoints.removeAll(g.points);
|
||||||
context.getMapMarkersHelper().removeMarkersSyncGroup(g.name);
|
context.getMapMarkersHelper().removeMarkersSyncGroup(g.name, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveCurrentPointsIntoFile();
|
saveCurrentPointsIntoFile();
|
||||||
|
@ -349,7 +349,7 @@ public class FavouritesDbHelper {
|
||||||
if (remove) {
|
if (remove) {
|
||||||
flatGroups.remove(group.name);
|
flatGroups.remove(group.name);
|
||||||
saveCurrentPointsIntoFile();
|
saveCurrentPointsIntoFile();
|
||||||
context.getMapMarkersHelper().removeMarkersSyncGroup(group.name);
|
context.getMapMarkersHelper().removeMarkersSyncGroup(group.name, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -591,6 +591,7 @@ public class FavouritesDbHelper {
|
||||||
|
|
||||||
//todo
|
//todo
|
||||||
public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) {
|
public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) {
|
||||||
|
MapMarkersHelper markersHelper = context.getMapMarkersHelper();
|
||||||
if (color != 0 && group.color != color) {
|
if (color != 0 && group.color != color) {
|
||||||
FavoriteGroup gr = flatGroups.get(group.name);
|
FavoriteGroup gr = flatGroups.get(group.name);
|
||||||
group.color = color;
|
group.color = color;
|
||||||
|
@ -607,6 +608,7 @@ public class FavouritesDbHelper {
|
||||||
}
|
}
|
||||||
if (!group.name.equals(newName)) {
|
if (!group.name.equals(newName)) {
|
||||||
FavoriteGroup gr = flatGroups.remove(group.name);
|
FavoriteGroup gr = flatGroups.remove(group.name);
|
||||||
|
markersHelper.removeMarkersSyncGroup(group.name, true);
|
||||||
gr.name = newName;
|
gr.name = newName;
|
||||||
FavoriteGroup renamedGroup = flatGroups.get(gr.name);
|
FavoriteGroup renamedGroup = flatGroups.get(gr.name);
|
||||||
boolean existing = renamedGroup != null;
|
boolean existing = renamedGroup != null;
|
||||||
|
@ -622,6 +624,9 @@ public class FavouritesDbHelper {
|
||||||
renamedGroup.points.add(p);
|
renamedGroup.points.add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE);
|
||||||
|
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||||
|
markersHelper.syncGroup(syncGroup);
|
||||||
}
|
}
|
||||||
saveCurrentPointsIntoFile();
|
saveCurrentPointsIntoFile();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
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) {
|
if (id != null) {
|
||||||
markersDbHelper.removeMarkersSyncGroup(id);
|
markersDbHelper.removeMarkersSyncGroup(id);
|
||||||
|
if (removeActiveMarkers) {
|
||||||
|
removeActiveMarkersFromSyncGroup(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeActiveMarkersFromSyncGroup(String syncGroupId) {
|
||||||
|
if (syncGroupId != null) {
|
||||||
|
markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId);
|
||||||
|
for (Iterator<MapMarker> iterator = mapMarkers.iterator(); iterator.hasNext(); ) {
|
||||||
|
if (iterator.next().groupKey.equals(syncGroupId)) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkAndFixActiveMarkersOrderIfNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.util.Random;
|
||||||
|
|
||||||
public class MapMarkersDbHelper {
|
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";
|
public static final String DB_NAME = "map_markers_db";
|
||||||
|
|
||||||
private static final String MARKERS_TABLE_NAME = "map_markers";
|
private static final String MARKERS_TABLE_NAME = "map_markers";
|
||||||
|
@ -210,15 +210,24 @@ public class MapMarkersDbHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMarkersSyncGroup(String id) {
|
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);
|
SQLiteConnection db = openConnection(true);
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
try {
|
try {
|
||||||
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME +
|
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME +
|
||||||
" WHERE " + MARKERS_COL_GROUP_KEY + " = ?" +
|
" WHERE " + MARKERS_COL_GROUP_KEY + " = ?" +
|
||||||
" AND " + MARKERS_COL_ACTIVE + " = ?",
|
" AND " + MARKERS_COL_ACTIVE + " = ?",
|
||||||
new Object[]{id, 1});
|
new Object[]{syncGroupId, 1});
|
||||||
|
|
||||||
db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_ID + " = ?", new Object[]{id});
|
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue