Fix groups after disabling
This commit is contained in:
parent
1e2e23c059
commit
af6670535a
2 changed files with 35 additions and 36 deletions
|
@ -488,21 +488,6 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void addMarker(MapMarker marker, int position) {
|
||||
if (marker != null) {
|
||||
markersDbHelper.addMarker(marker);
|
||||
if (marker.history) {
|
||||
mapMarkersHistory.add(position, marker);
|
||||
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
||||
} else {
|
||||
mapMarkers.add(position, marker);
|
||||
reorderActiveMarkersIfNeeded();
|
||||
}
|
||||
addMarkerToGroup(marker);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreMarkerFromHistory(MapMarker marker, int position) {
|
||||
if (marker != null) {
|
||||
markersDbHelper.restoreMapMarkerFromHistory(marker);
|
||||
|
@ -700,11 +685,34 @@ public class MapMarkersHelper {
|
|||
markersDbHelper.removeDisabledGroups();
|
||||
}
|
||||
|
||||
public void updateGroupDisabled(String id, boolean disabled) {
|
||||
public void updateGroupDisabled(MapMarkersGroup group, boolean disabled) {
|
||||
String id = group.getGroupKey();
|
||||
if (id != null) {
|
||||
markersDbHelper.updateSyncGroupDisabled(id, disabled);
|
||||
updateSyncGroupDisabled(group, disabled);
|
||||
}
|
||||
loadMarkers();
|
||||
}
|
||||
|
||||
private void updateSyncGroupDisabled(MapMarkersGroup group, boolean disabled) {
|
||||
List<MapMarker> groupMarkers = group.getMarkers();
|
||||
for (MapMarker marker : groupMarkers) {
|
||||
if (marker.history) {
|
||||
if (disabled) {
|
||||
mapMarkersHistory.remove(marker);
|
||||
} else {
|
||||
mapMarkersHistory.add(marker);
|
||||
}
|
||||
} else {
|
||||
if (disabled) {
|
||||
mapMarkers.remove(marker);
|
||||
} else {
|
||||
mapMarkers.add(marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
reorderActiveMarkersIfNeeded();
|
||||
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void removeActiveMarkersFromSyncGroup(String syncGroupId) {
|
||||
|
@ -798,16 +806,6 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void moveMarkerToTop(MapMarker marker) {
|
||||
int i = mapMarkers.indexOf(marker);
|
||||
if (i != -1 && mapMarkers.size() > 1) {
|
||||
mapMarkers.remove(i);
|
||||
mapMarkers.add(0, marker);
|
||||
reorderActiveMarkersIfNeeded();
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveMapMarkers(List<MapMarker> markers, List<MapMarker> markersHistory) {
|
||||
if (markers != null) {
|
||||
List<LatLon> ls = new ArrayList<>(markers.size());
|
||||
|
|
|
@ -69,6 +69,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
|
||||
public void createDisplayGroups() {
|
||||
items.clear();
|
||||
app.getMapMarkersHelper().updateGroups();
|
||||
List<MapMarkersGroup> groups = app.getMapMarkersHelper().getMapMarkersGroups();
|
||||
for (int i = 0; i < groups.size(); i++) {
|
||||
MapMarkersGroup group = groups.get(i);
|
||||
|
@ -351,32 +352,32 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
headerViewHolder.disableGroupSwitch.setVisibility(View.GONE);
|
||||
} else if (header instanceof GroupHeader) {
|
||||
final GroupHeader groupHeader = (GroupHeader) header;
|
||||
String groupName = groupHeader.getGroup().getName();
|
||||
final MapMarkersGroup group = groupHeader.getGroup();
|
||||
String groupName = group.getName();
|
||||
if (groupName.equals("")) {
|
||||
groupName = app.getString(R.string.shared_string_favorites);
|
||||
}
|
||||
headerString = groupName + " \u2014 "
|
||||
+ groupHeader.getGroup().getActiveMarkers().size()
|
||||
+ "/" + groupHeader.getGroup().getMarkers().size();
|
||||
+ group.getActiveMarkers().size()
|
||||
+ "/" + group.getMarkers().size();
|
||||
headerViewHolder.icon.setVisibility(View.VISIBLE);
|
||||
headerViewHolder.iconSpace.setVisibility(View.GONE);
|
||||
headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color));
|
||||
boolean groupIsDisabled = groupHeader.getGroup().isDisabled();
|
||||
boolean groupIsDisabled = group.isDisabled();
|
||||
headerViewHolder.disableGroupSwitch.setVisibility(View.VISIBLE);
|
||||
headerViewHolder.disableGroupSwitch.setChecked(!groupIsDisabled);
|
||||
headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
|
||||
groupHeader.getGroup().setDisabled(!enabled);
|
||||
final String groupKey = groupHeader.getGroup().getGroupKey();
|
||||
app.getMapMarkersHelper().updateGroupDisabled(groupKey, !enabled);
|
||||
group.setDisabled(!enabled);
|
||||
app.getMapMarkersHelper().updateGroupDisabled(group, !enabled);
|
||||
if (!enabled) {
|
||||
snackbar = Snackbar.make(holder.itemView, app.getString(R.string.group_will_be_removed_after_restart), Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
groupHeader.getGroup().setDisabled(false);
|
||||
app.getMapMarkersHelper().updateGroupDisabled(groupKey, false);
|
||||
group.setDisabled(false);
|
||||
app.getMapMarkersHelper().updateGroupDisabled(group, false);
|
||||
headerViewHolder.disableGroupSwitch.setChecked(true);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue