diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index a5bf7e7e4c..53fb922d9f 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -519,7 +519,6 @@ public class AppInitializer implements IProgress { indexRegionsBoundaries(warnings); notifyEvent(InitEvents.INDEX_REGION_BOUNDARIES); app.selectedGpxHelper.loadGPXTracks(this); - app.mapMarkersHelper.loadMapMarkersFromSelectedGpx(); notifyEvent(InitEvents.LOAD_GPX_TRACKS); saveGPXTracks(); notifyEvent(InitEvents.SAVE_GPX_TRACKS); diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index ad5f87f476..b26783cd1d 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -482,7 +482,7 @@ public class GpxSelectionHelper { selectedGPXFiles.remove(sf); } } - syncGpx(gpx); + syncGpx(gpx, true); return sf; } @@ -514,10 +514,25 @@ public class GpxSelectionHelper { } private void syncGpx(GPXFile gpxFile) { + syncGpx(gpxFile, false); + } + + private void syncGpx(GPXFile gpxFile, boolean createOrDeleteGroup) { File gpx = new File(gpxFile.path); if (gpx.exists()) { - app.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gpx.getAbsolutePath(), - AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE)); + MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper(); + MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE); + boolean enabled = true; + if (createOrDeleteGroup) { + boolean show = getSelectedFileByPath(gpx.getAbsolutePath()) != null; + enabled = mapMarkersHelper.isGroupSynced(gpx.getAbsolutePath()); + if (show && !enabled) { + mapMarkersHelper.addMarkersSyncGroup(syncGroup); + } else if (!show && mapMarkersHelper.isGroupDisabled(gpx.getAbsolutePath())) { + mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath(), true); + } + } + mapMarkersHelper.syncGroup(syncGroup, enabled); } } diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 59c36a629d..3b70e6e63d 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -390,6 +390,10 @@ public class MapMarkersHelper { return markersDbHelper.getGroup(id) != null; } + public boolean isGroupDisabled(String id) { + return markersDbHelper.isGroupDisabled(id); + } + public void syncAllGroups() { List groups = markersDbHelper.getAllGroups(); for (MarkersSyncGroup gr : groups) { @@ -721,7 +725,7 @@ public class MapMarkersHelper { if (removeActiveMarkers) { removeActiveMarkersFromSyncGroup(id); } - MapMarkersGroup group = getMapMarkerGroupByName(id); + MapMarkersGroup group = getMapMarkerGroupByKey(id); if (group != null) { mapMarkersGroups.remove(group); } @@ -1164,19 +1168,6 @@ public class MapMarkersHelper { } } - public void loadMapMarkersFromSelectedGpx() { - List selectedGpxFiles = ctx.getSelectedGpxHelper().getSelectedGPXFiles(); - for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) { - GPXFile gpx = selectedGpxFile.getGpxFile(); - if (gpx.getPoints().size() > 0) { - File gpxFile = new File(gpx.path); - final MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpxFile.getAbsolutePath(), AndroidUtils.trimExtension(gpxFile.getName()), MarkersSyncGroup.GPX_TYPE); - addMarkersSyncGroup(syncGroup); - syncGroup(syncGroup, false); - } - } - } - private void sortGroups() { if (mapMarkersGroups.size() > 0) { MapMarkersGroup noGroup = null; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index c9547abd33..fdb2b315ef 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -87,7 +87,8 @@ public class MapMarkersDbHelper { private static final String GROUPS_TABLE_SELECT = "SELECT " + GROUPS_COL_ID + ", " + GROUPS_COL_NAME + ", " + - GROUPS_COL_TYPE + + GROUPS_COL_TYPE + ", " + + GROUPS_COL_DISABLED + " FROM " + GROUPS_TABLE_NAME; public static final String TAIL_NEXT_VALUE = "tail_next"; @@ -275,6 +276,23 @@ public class MapMarkersDbHelper { } } + public boolean isGroupDisabled(String id) { + boolean disabled = false; + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_ID + " = ?", new String[]{id}); + if (query.moveToFirst()) { + disabled = query.getInt(3) == 1; + } + query.close(); + } finally { + db.close(); + } + } + return disabled; + } + public void removeDisabledGroups() { SQLiteConnection db = openConnection(false); if (db != null) {