diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index e09a14bd7d..6f3e7af6d3 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -286,8 +286,8 @@ public class MapMarkersHelper { syncGroupAsync(group, null); } - private void syncGroupAsync(@NonNull final MapMarkersGroup group, - @Nullable final OnGroupSyncedListener listener) { + public void syncGroupAsync(@NonNull final MapMarkersGroup group, + @Nullable final OnGroupSyncedListener listener) { ctx.runInUIThread(new Runnable() { @Override public void run() { @@ -312,7 +312,7 @@ public class MapMarkersHelper { public void addAndSyncGroup(@NonNull MapMarkersGroup group, @Nullable OnGroupSyncedListener listener) { if (!isGroupSynced(group.getId())) { - markersDbHelper.addGroup(group.getId(), group.getName(), group.getType(), group.getWptCategoriesString()); + markersDbHelper.addGroup(group); addToGroupsList(group); } else { markersDbHelper.updateGroupCategories(group.getId(), group.getWptCategoriesString()); @@ -332,32 +332,10 @@ public class MapMarkersHelper { String id = group.getId(); if (id != null) { markersDbHelper.updateGroupDisabled(id, disabled); - updateSyncGroupDisabled(group, disabled); + group.disabled = disabled; } } - private void updateSyncGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) { - List groupMarkers = new ArrayList<>(group.getMarkers()); - for (MapMarker marker : groupMarkers) { - if (marker.history) { - if (disabled) { - removeFromMapMarkersHistoryList(marker); - } else { - addToMapMarkersHistoryList(marker); - } - } else { - if (disabled) { - removeFromMapMarkersList(marker); - } else { - addToMapMarkersList(marker); - } - } - } - reorderActiveMarkersIfNeeded(); - sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); - refresh(); - } - private void removeGroupActiveMarkers(MapMarkersGroup group, boolean updateGroup) { if (group != null) { markersDbHelper.removeActiveMarkersFromGroup(group.getId()); @@ -1058,7 +1036,8 @@ public class MapMarkersHelper { if (favGroup == null) { return; } - if (!favGroup.visible) { + group.visible = favGroup.visible; + if (!group.isVisible() || group.isDisabled()) { removeGroupActiveMarkers(group, true); return; } @@ -1077,7 +1056,8 @@ public class MapMarkersHelper { SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(group.getId()); GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile(); - if (gpx == null) { + group.visible = gpx != null; + if (!group.isVisible() || group.isDisabled()) { removeGroupActiveMarkers(group, true); return; } @@ -1121,6 +1101,7 @@ public class MapMarkersHelper { private Set wptCategories; private long creationDate; private boolean disabled; + private boolean visible = true; private List markers = new ArrayList<>(); // TODO should be removed from this class: private GroupHeader header; @@ -1160,6 +1141,10 @@ public class MapMarkersHelper { this.disabled = disabled; } + public boolean isVisible() { + return visible; + } + public List getMarkers() { return markers; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index fa32ca68a5..7219c5f73f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -195,11 +195,12 @@ public class MapMarkersDbHelper { } } - public void addGroup(String id, String name, int type, String categories) { + public void addGroup(MapMarkersGroup group) { SQLiteConnection db = openConnection(false); if (db != null) { try { - db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?)", new Object[]{id, name, type, 0, categories}); + db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?)", + new Object[]{group.getId(), group.getName(), group.getType(), group.isDisabled(), group.getWptCategoriesString()}); } finally { db.close(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 7d6f6bf0c7..ad8a89651d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -19,6 +19,7 @@ import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper.GroupHeader; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup; +import net.osmand.plus.MapMarkersHelper.OnGroupSyncedListener; import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -92,6 +93,9 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter groups = app.getMapMarkersHelper().getMapMarkersGroups(); for (int i = 0; i < groups.size(); i++) { MapMarkersGroup group = groups.get(i); + if (!group.isVisible()) { + continue; + } String markerGroupName = group.getName(); if (markerGroupName == null) { int previousDateHeader = -1; @@ -373,9 +377,13 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter