Fix groups displaying

This commit is contained in:
Alexander Sytnyk 2018-03-21 14:07:22 +02:00
parent 140a23457f
commit f19477be2b
3 changed files with 33 additions and 40 deletions

View file

@ -286,8 +286,8 @@ public class MapMarkersHelper {
syncGroupAsync(group, null); syncGroupAsync(group, null);
} }
private void syncGroupAsync(@NonNull final MapMarkersGroup group, public void syncGroupAsync(@NonNull final MapMarkersGroup group,
@Nullable final OnGroupSyncedListener listener) { @Nullable final OnGroupSyncedListener listener) {
ctx.runInUIThread(new Runnable() { ctx.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -312,7 +312,7 @@ public class MapMarkersHelper {
public void addAndSyncGroup(@NonNull MapMarkersGroup group, @Nullable OnGroupSyncedListener listener) { public void addAndSyncGroup(@NonNull MapMarkersGroup group, @Nullable OnGroupSyncedListener listener) {
if (!isGroupSynced(group.getId())) { if (!isGroupSynced(group.getId())) {
markersDbHelper.addGroup(group.getId(), group.getName(), group.getType(), group.getWptCategoriesString()); markersDbHelper.addGroup(group);
addToGroupsList(group); addToGroupsList(group);
} else { } else {
markersDbHelper.updateGroupCategories(group.getId(), group.getWptCategoriesString()); markersDbHelper.updateGroupCategories(group.getId(), group.getWptCategoriesString());
@ -332,32 +332,10 @@ public class MapMarkersHelper {
String id = group.getId(); String id = group.getId();
if (id != null) { if (id != null) {
markersDbHelper.updateGroupDisabled(id, disabled); markersDbHelper.updateGroupDisabled(id, disabled);
updateSyncGroupDisabled(group, disabled); group.disabled = disabled;
} }
} }
private void updateSyncGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) {
List<MapMarker> 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) { private void removeGroupActiveMarkers(MapMarkersGroup group, boolean updateGroup) {
if (group != null) { if (group != null) {
markersDbHelper.removeActiveMarkersFromGroup(group.getId()); markersDbHelper.removeActiveMarkersFromGroup(group.getId());
@ -1058,7 +1036,8 @@ public class MapMarkersHelper {
if (favGroup == null) { if (favGroup == null) {
return; return;
} }
if (!favGroup.visible) { group.visible = favGroup.visible;
if (!group.isVisible() || group.isDisabled()) {
removeGroupActiveMarkers(group, true); removeGroupActiveMarkers(group, true);
return; return;
} }
@ -1077,7 +1056,8 @@ public class MapMarkersHelper {
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(group.getId()); SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(group.getId());
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile(); GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
if (gpx == null) { group.visible = gpx != null;
if (!group.isVisible() || group.isDisabled()) {
removeGroupActiveMarkers(group, true); removeGroupActiveMarkers(group, true);
return; return;
} }
@ -1121,6 +1101,7 @@ public class MapMarkersHelper {
private Set<String> wptCategories; private Set<String> wptCategories;
private long creationDate; private long creationDate;
private boolean disabled; private boolean disabled;
private boolean visible = true;
private List<MapMarker> markers = new ArrayList<>(); private List<MapMarker> markers = new ArrayList<>();
// TODO should be removed from this class: // TODO should be removed from this class:
private GroupHeader header; private GroupHeader header;
@ -1160,6 +1141,10 @@ public class MapMarkersHelper {
this.disabled = disabled; this.disabled = disabled;
} }
public boolean isVisible() {
return visible;
}
public List<MapMarker> getMarkers() { public List<MapMarker> getMarkers() {
return markers; return markers;
} }

View file

@ -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); SQLiteConnection db = openConnection(false);
if (db != null) { if (db != null) {
try { 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 { } finally {
db.close(); db.close();
} }

View file

@ -19,6 +19,7 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper.GroupHeader; import net.osmand.plus.MapMarkersHelper.GroupHeader;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.MapMarkersHelper.OnGroupSyncedListener;
import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton; import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -92,6 +93,9 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
List<MapMarkersGroup> groups = app.getMapMarkersHelper().getMapMarkersGroups(); List<MapMarkersGroup> groups = app.getMapMarkersHelper().getMapMarkersGroups();
for (int i = 0; i < groups.size(); i++) { for (int i = 0; i < groups.size(); i++) {
MapMarkersGroup group = groups.get(i); MapMarkersGroup group = groups.get(i);
if (!group.isVisible()) {
continue;
}
String markerGroupName = group.getName(); String markerGroupName = group.getName();
if (markerGroupName == null) { if (markerGroupName == null) {
int previousDateHeader = -1; int previousDateHeader = -1;
@ -373,9 +377,13 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
if (groupName.equals("")) { if (groupName.equals("")) {
groupName = app.getString(R.string.shared_string_favorites); groupName = app.getString(R.string.shared_string_favorites);
} }
headerString = groupName + " \u2014 " if (group.isDisabled()) {
+ group.getActiveMarkers().size() headerString = groupName;
+ "/" + group.getMarkers().size(); } else {
headerString = groupName + " \u2014 "
+ group.getActiveMarkers().size()
+ "/" + group.getMarkers().size();
}
headerViewHolder.icon.setVisibility(View.VISIBLE); headerViewHolder.icon.setVisibility(View.VISIBLE);
headerViewHolder.iconSpace.setVisibility(View.GONE); headerViewHolder.iconSpace.setVisibility(View.GONE);
headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color)); headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color));
@ -392,7 +400,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
switchGpxVisibility(gpxFile[0], false); switchGpxVisibility(gpxFile[0], false);
} }
} }
group.setDisabled(disabled);
app.getMapMarkersHelper().updateGroupDisabled(group, disabled); app.getMapMarkersHelper().updateGroupDisabled(group, disabled);
updateDisplayedData(); updateDisplayedData();
if (disabled) { if (disabled) {
@ -411,6 +418,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark)); tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
snackbar.show(); snackbar.show();
} }
app.getMapMarkersHelper().syncGroupAsync(group, new OnGroupSyncedListener() {
@Override
public void onSyncDone() {
updateDisplayedData();
}
});
} }
}; };
headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(null); headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(null);
@ -445,12 +458,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private void switchGpxVisibility(@NonNull GPXFile gpxFile, boolean visible) { private void switchGpxVisibility(@NonNull GPXFile gpxFile, boolean visible) {
GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper(); GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
gpxHelper.selectGpxFile(gpxFile, visible, false, false); gpxHelper.selectGpxFile(gpxFile, visible, false, false);
// gpxHelper.syncGpx(gpxFile, new OnGroupSyncedListener() {
// @Override
// public void onSyncDone() {
// updateDisplayedData();
// }
// });
} }
public void hideSnackbar() { public void hideSnackbar() {