Fix dublicate markers in groups

This commit is contained in:
PavelRatushny 2017-09-26 12:29:25 +03:00
parent b6a90eb774
commit cdc85b903e

View file

@ -369,6 +369,7 @@ public class MapMarkersHelper {
} }
if (!favGroup.visible) { if (!favGroup.visible) {
removeActiveMarkersFromSyncGroup(group.getId()); removeActiveMarkersFromSyncGroup(group.getId());
removeActiveMarkersFromGroup(group.getId());
return; return;
} }
if (group.getColor() == -1) { if (group.getColor() == -1) {
@ -391,6 +392,7 @@ public class MapMarkersHelper {
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile(); GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
if (gpx == null) { if (gpx == null) {
removeActiveMarkersFromSyncGroup(group.getId()); removeActiveMarkersFromSyncGroup(group.getId());
removeActiveMarkersFromGroup(group.getId());
return; return;
} }
@ -438,6 +440,7 @@ public class MapMarkersHelper {
if (!marker.history) { if (!marker.history) {
markersDbHelper.removeMarker(marker, false); markersDbHelper.removeMarker(marker, false);
mapMarkers.remove(marker); mapMarkers.remove(marker);
removeMarkerFromGroup(marker);
needRefresh = true; needRefresh = true;
} }
} }
@ -861,6 +864,21 @@ public class MapMarkersHelper {
} }
} }
private void removeActiveMarkersFromGroup(String groupId) {
MapMarkersGroup group = getMapMarkerGroupByKey(groupId);
if (group != null) {
List<MapMarker> markers = group.getMarkers();
List<MapMarker> historyMarkers = new ArrayList<>();
for (MapMarker marker : markers) {
if (marker.history) {
historyMarkers.add(marker);
}
}
group.setMarkers(historyMarkers);
updateGroup(group);
}
}
public void updateGroup(MapMarkersGroup mapMarkersGroup) { public void updateGroup(MapMarkersGroup mapMarkersGroup) {
if (mapMarkersGroup.getMarkers().size() == 0) { if (mapMarkersGroup.getMarkers().size() == 0) {
mapMarkersGroups.remove(mapMarkersGroup); mapMarkersGroups.remove(mapMarkersGroup);
@ -1029,6 +1047,16 @@ public class MapMarkersHelper {
return null; return null;
} }
public MapMarkersGroup getMapMarkerGroupByKey(String key) {
for (MapMarkersGroup group : mapMarkersGroups) {
if ((key == null && group.getGroupKey() == null)
|| (group.getGroupKey() != null && group.getGroupKey().equals(key))) {
return group;
}
}
return null;
}
public static class MapMarkersGroup { public static class MapMarkersGroup {
private String name; private String name;
private String groupKey; private String groupKey;