diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 1830656109..b34d091143 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -214,6 +214,10 @@ public class MapMarkersHelper { public int getColor() { return color; } + + public void setColor(int color) { + this.color = color; + } } public MapMarkersHelper(OsmandApplication ctx) { @@ -417,6 +421,9 @@ public class MapMarkersHelper { removeActiveMarkersFromSyncGroup(group.getId()); return; } + if (group.getColor() == -1) { + group.setColor(favGroup.color); + } for (FavouritePoint fp : favGroup.points) { addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName()); @@ -439,6 +446,7 @@ public class MapMarkersHelper { List gpxPoints = new LinkedList<>(gpx.getPoints()); for (WptPt pt : gpxPoints) { + group.setColor(pt.getColor(ContextCompat.getColor(ctx, R.color.marker_red))); addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 4d22d464d1..f65c78fd9e 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -69,6 +69,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -90,7 +91,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { final private PointGPXAdapter adapter = new PointGPXAdapter(); private GpxDisplayItemType[] filterTypes = { GpxDisplayItemType.TRACK_POINTS, GpxDisplayItemType.TRACK_ROUTE_POINTS }; private boolean selectionMode = false; - private Set selectedItems = new LinkedHashSet<>(); + private LinkedHashMap> selectedItems = new LinkedHashMap<>(); private Set selectedGroups = new LinkedHashSet<>(); private ActionMode actionMode; private SearchView searchView; @@ -213,6 +214,26 @@ public class TrackPointFragment extends OsmandExpandableListFragment { return view; } + private int getSelectedItemsCount() { + int count = 0; + for (Set set : selectedItems.values()) { + if (set != null) { + count += set.size(); + } + } + return count; + } + + private Set getSelectedItems() { + Set result = new LinkedHashSet<>(); + for (Set set : selectedItems.values()) { + if (set != null) { + result.addAll(set); + } + } + return result; + } + private void addPoint(PointDescription pointDescription) { getTrackActivity().addPoint(pointDescription); } @@ -488,9 +509,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } private void deleteItemsAction() { - if (selectedItems.size() > 0) { + int size = getSelectedItemsCount(); + if (size > 0) { AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); - b.setMessage(getString(R.string.points_delete_multiple, selectedItems.size())); + b.setMessage(getString(R.string.points_delete_multiple, size)); b.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -524,7 +546,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { GPXFile gpx = getGpx(); SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper(); if (gpx != null) { - for (GpxDisplayItem item : selectedItems) { + for (GpxDisplayItem item : getSelectedItems()) { if (gpx.showCurrentTrack) { savingTrackHelper.deletePointData(item.locationStart); } else { @@ -606,26 +628,32 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } private void selectMapMarkersImpl() { - if (!selectedItems.isEmpty()) { + if (getSelectedItemsCount() > 0) { if (getSettings().USE_MAP_MARKERS.get()) { MapMarkersHelper markersHelper = app.getMapMarkersHelper(); - List points = new ArrayList<>(); - List names = new ArrayList<>(); - for(GpxDisplayItem i : selectedItems) { - if (i.locationStart != null) { - points.add(new LatLon(i.locationStart.lat, i.locationStart.lon)); - names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, i.name)); + List points = new LinkedList<>(); + List names = new LinkedList<>(); + for (Map.Entry> entry : selectedItems.entrySet()) { + if (entry.getKey() == GpxDisplayItemType.TRACK_POINTS) { + File gpx = getGpxDataItem().getFile(); + MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), + AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE); + markersHelper.addMarkersSyncGroup(syncGroup); + markersHelper.syncGroup(syncGroup); + } else { + for (GpxDisplayItem i : entry.getValue()) { + if (i.locationStart != null) { + points.add(new LatLon(i.locationStart.lat, i.locationStart.lon)); + names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, i.name)); + } + } + markersHelper.addMapMarkers(points, names, null); } } - File gpx = getGpxDataItem().getFile(); - MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), - AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE); - markersHelper.addMarkersSyncGroup(syncGroup); - markersHelper.addMapMarkers(points, names, syncGroup); MapActivity.launchMapActivityMoveToTop(getActivity()); } else { final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper(); - for (GpxDisplayItem i : selectedItems) { + for (GpxDisplayItem i : getSelectedItems()) { if (i.locationStart != null) { targetPointsHelper.navigateToPoint(new LatLon(i.locationStart.lat, i.locationStart.lon), false, targetPointsHelper.getIntermediatePoints().size() + 1, @@ -679,10 +707,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } private void selectFavoritesImpl() { - if (!selectedItems.isEmpty()) { + if (getSelectedItemsCount() > 0) { AlertDialog.Builder b = new AlertDialog.Builder(getTrackActivity()); final EditText editText = new EditText(getTrackActivity()); - String name = selectedItems.iterator().next().group.getName(); + String name = getSelectedItems().iterator().next().group.getName(); if(name.indexOf('\n') > 0) { name = name.substring(0, name.indexOf('\n')); } @@ -700,7 +728,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { actionMode.finish(); } FavouritesDbHelper fdb = app.getFavorites(); - for(GpxDisplayItem i : selectedItems) { + for(GpxDisplayItem i : getSelectedItems()) { if (i.locationStart != null) { FavouritePoint fp = new FavouritePoint(i.locationStart.lat, i.locationStart.lon, i.name, editText.getText().toString()); if (!Algorithms.isEmpty(i.description)) { @@ -719,8 +747,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } private void updateSelectionMode(ActionMode m) { - if (selectedItems.size() > 0) { - m.setTitle(selectedItems.size() + " " + getMyApplication().getString(R.string.shared_string_selected_lowercase)); + int size = getSelectedItemsCount(); + if (size > 0) { + m.setTitle(size + " " + getMyApplication().getString(R.string.shared_string_selected_lowercase)); } else { m.setTitle(""); } @@ -733,9 +762,19 @@ public class TrackPointFragment extends OsmandExpandableListFragment { GpxDisplayItem item = adapter.getChild(groupPosition, childPosition); ch.setChecked(!ch.isChecked()); if (ch.isChecked()) { - selectedItems.add(item); + Set set = selectedItems.get(item.group.getType()); + if (set != null) { + set.add(item); + } else { + set = new LinkedHashSet<>(); + set.add(item); + selectedItems.put(item.group.getType(), set); + } } else { - selectedItems.remove(item); + Set set = selectedItems.get(item.group.getType()); + if (set != null) { + set.remove(item); + } } updateSelectionMode(actionMode); } else { @@ -876,13 +915,17 @@ public class TrackPointFragment extends OsmandExpandableListFragment { if (ch.isChecked()) { selectedGroups.add(groupPosition); if (items != null) { - selectedItems.addAll(items); + Set set = selectedItems.get(group.getType()); + if (set != null) { + set.addAll(items); + } else { + set = new LinkedHashSet<>(items); + selectedItems.put(group.getType(), set); + } } } else { selectedGroups.remove(groupPosition); - if (items != null) { - selectedItems.removeAll(items); - } + selectedItems.remove(group.getType()); } adapter.notifyDataSetInvalidated(); updateSelectionMode(actionMode); @@ -979,7 +1022,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item); if (selectionMode) { ch.setVisibility(View.VISIBLE); - ch.setChecked(selectedItems.contains(gpxItem)); + ch.setChecked(selectedItems.get(gpxItem.group.getType()) != null && selectedItems.get(gpxItem.group.getType()).contains(gpxItem)); row.findViewById(R.id.icon).setVisibility(View.GONE); options.setVisibility(View.GONE); ch.setOnClickListener(new View.OnClickListener() { @@ -987,9 +1030,19 @@ public class TrackPointFragment extends OsmandExpandableListFragment { @Override public void onClick(View v) { if (ch.isChecked()) { - selectedItems.add(gpxItem); + Set set = selectedItems.get(gpxItem.group.getType()); + if (set != null) { + set.add(gpxItem); + } else { + set = new LinkedHashSet<>(); + set.add(gpxItem); + selectedItems.put(gpxItem.group.getType(), set); + } } else { - selectedItems.remove(gpxItem); + Set set = selectedItems.get(gpxItem.group.getType()); + if (set != null) { + set.remove(gpxItem); + } } updateSelectionMode(actionMode); }