From 9c21024e810bca35c3181522a7ddb004d97a2912 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 19 Sep 2017 10:26:55 +0300 Subject: [PATCH 01/38] Fix item layout --- OsmAnd/res/layout/map_marker_item_new.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 0f4ddb6a42..da0e14678c 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -55,7 +55,6 @@ android:layout_height="28dp"> From bd8040420b5007a58f600f6743b7b022a0f7e1c3 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 19 Sep 2017 11:57:23 +0300 Subject: [PATCH 02/38] Refactor groups --- .../map_marker_item_show_hide_history.xml | 21 +++ OsmAnd/res/values/strings.xml | 2 + .../src/net/osmand/plus/MapMarkersHelper.java | 123 ++++++-------- .../plus/mapmarkers/MapMarkersGroup.java | 45 +++++ .../mapmarkers/MapMarkersGroupsFragment.java | 1 + .../adapters/MapMarkersGroupsAdapter.java | 157 +++++++++++++----- .../MapMarkersShowHideHistoryViewHolder.java | 16 ++ 7 files changed, 247 insertions(+), 118 deletions(-) create mode 100644 OsmAnd/res/layout/map_marker_item_show_hide_history.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersShowHideHistoryViewHolder.java diff --git a/OsmAnd/res/layout/map_marker_item_show_hide_history.xml b/OsmAnd/res/layout/map_marker_item_show_hide_history.xml new file mode 100644 index 0000000000..1d1f332ccf --- /dev/null +++ b/OsmAnd/res/layout/map_marker_item_show_hide_history.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 034ca5acff..ad814a51a3 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Show passed + Hide passed Remove from Map Markers Descendingly Ascendingly diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 1830656109..d4d3d42bc4 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -17,6 +17,7 @@ import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; +import net.osmand.plus.mapmarkers.MapMarkersGroup; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -251,7 +252,7 @@ public class MapMarkersHelper { checkAndFixActiveMarkersOrderIfNeeded(); List markersHistory = markersDbHelper.getMarkersHistory(); - sortHistoryMarkers(); + sortMarkers(markersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); mapMarkersHistory.addAll(markersHistory); if (!ctx.isApplicationInitializing()) { @@ -279,17 +280,31 @@ public class MapMarkersHelper { } } - public List getMarkersSortedByGroup() { - Map groupsMap = new LinkedHashMap<>(); - List noGroup = new ArrayList<>(); - for (MapMarker marker : mapMarkers) { + public List getMapMarkersGroups() { + List markers = new ArrayList<>(); + markers.addAll(mapMarkers); + markers.addAll(mapMarkersHistory); + + Map groupsMap = new LinkedHashMap<>(); + MapMarkersGroup noGroup = null; + for (MapMarker marker : markers) { String groupName = marker.groupName; if (groupName == null) { - noGroup.add(marker); + if (noGroup == null) { + noGroup = new MapMarkersGroup(); + noGroup.setCreationDate(marker.creationDate); + } + if (marker.history) { + noGroup.getHistoryMarkers().add(marker); + } else { + noGroup.getMapMarkers().add(marker); + } } else { - MapMarkerGroup group = groupsMap.get(groupName); + MapMarkersGroup group = groupsMap.get(groupName); if (group == null) { - group = new MapMarkerGroup(groupName, marker.creationDate); + group = new MapMarkersGroup(); + group.setName(groupName); + group.setCreationDate(marker.creationDate); groupsMap.put(groupName, group); } else { long markerCreationDate = marker.creationDate; @@ -297,26 +312,29 @@ public class MapMarkersHelper { group.setCreationDate(markerCreationDate); } } - group.getMapMarkers().add(marker); + if (marker.history) { + group.getHistoryMarkers().add(marker); + } else { + group.getMapMarkers().add(marker); + } } } - List groups = new ArrayList<>(groupsMap.values()); + List groups = new ArrayList<>(groupsMap.values()); sortGroups(groups); - List markers = new ArrayList<>(); - markers.addAll(noGroup); - for (MapMarkerGroup group : groups) { - markers.addAll(group.getMapMarkers()); + if (noGroup != null) { + sortMarkers(noGroup.getMapMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); + groups.add(0, noGroup); } - return markers; + return groups; } - private void sortGroups(List groups) { - Collections.sort(groups, new Comparator() { + private void sortGroups(List groups) { + Collections.sort(groups, new Comparator() { @Override - public int compare(MapMarkerGroup group1, MapMarkerGroup group2) { - long t1 = group1.creationDate; - long t2 = group2.creationDate; + public int compare(MapMarkersGroup group1, MapMarkersGroup group2) { + long t1 = group1.getCreationDate(); + long t2 = group2.getCreationDate(); if (t1 > t2) { return -1; } else if (t1 == t2) { @@ -328,24 +346,20 @@ public class MapMarkersHelper { }); } - private void sortHistoryMarkers() { - sortMarkers(true, null); - } - - private void sortMarkers(final boolean history, final OsmandSettings.MapMarkersOrderByMode orderByMode) { + private void sortMarkers(List markers, final boolean visited, final OsmandSettings.MapMarkersOrderByMode orderByMode) { final LatLon location = ctx.getSettings().getLastKnownMapLocation(); - Collections.sort(history ? mapMarkersHistory : mapMarkers, new Comparator() { + Collections.sort(markers, new Comparator() { @Override public int compare(MapMarker mapMarker1, MapMarker mapMarker2) { - if (history || orderByMode.isDateAddedDescending() || orderByMode.isDateAddedAscending()) { - long t1 = history ? mapMarker1.visitedDate : mapMarker1.creationDate; - long t2 = history ? mapMarker2.visitedDate : mapMarker2.creationDate; + if (orderByMode.isDateAddedDescending() || orderByMode.isDateAddedAscending()) { + long t1 = visited ? mapMarker1.visitedDate : mapMarker1.creationDate; + long t2 = visited ? mapMarker2.visitedDate : mapMarker2.creationDate; if (t1 > t2) { - return history || orderByMode.isDateAddedDescending() ? -1 : 1; + return orderByMode.isDateAddedDescending() ? -1 : 1; } else if (t1 == t2) { return 0; } else { - return history || orderByMode.isDateAddedDescending() ? 1 : -1; + return orderByMode.isDateAddedDescending() ? 1 : -1; } } else if (orderByMode.isDistanceDescending() || orderByMode.isDistanceAscending()) { int d1 = (int) MapUtils.getDistance(location, mapMarker1.getLatitude(), mapMarker1.getLongitude()); @@ -367,7 +381,7 @@ public class MapMarkersHelper { } public void orderMarkers(OsmandSettings.MapMarkersOrderByMode orderByMode) { - sortMarkers(false, orderByMode); + sortMarkers(getMapMarkers(), false, orderByMode); checkAndFixActiveMarkersOrderIfNeeded(); } @@ -501,7 +515,7 @@ public class MapMarkersHelper { marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE; mapMarkersHistory.add(marker); checkAndFixActiveMarkersOrderIfNeeded(); - sortHistoryMarkers(); + sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); refresh(); } } @@ -511,7 +525,7 @@ public class MapMarkersHelper { markersDbHelper.addMarker(marker); if (marker.history) { mapMarkersHistory.add(marker); - sortHistoryMarkers(); + sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); } else { mapMarkers.add(marker); checkAndFixActiveMarkersOrderIfNeeded(); @@ -527,7 +541,7 @@ public class MapMarkersHelper { marker.history = false; mapMarkers.add(position, marker); checkAndFixActiveMarkersOrderIfNeeded(); - sortHistoryMarkers(); + sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); refresh(); } } @@ -541,7 +555,7 @@ public class MapMarkersHelper { mapMarkers.add(marker); } checkAndFixActiveMarkersOrderIfNeeded(); - sortHistoryMarkers(); + sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); refresh(); } } @@ -623,7 +637,7 @@ public class MapMarkersHelper { } mapMarkersHistory.addAll(mapMarkers); mapMarkers.clear(); - sortHistoryMarkers(); + sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); refresh(); } @@ -855,39 +869,4 @@ public class MapMarkersHelper { } GPXUtilities.writeGpxFile(fout, file, ctx); } - - public static class MapMarkerGroup { - private String name; - private List mapMarkers = new ArrayList<>(); - private long creationDate; - - public MapMarkerGroup(String name, long creationDate) { - this.name = name; - this.creationDate = creationDate; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getMapMarkers() { - return mapMarkers; - } - - public void setMapMarkers(List mapMarkers) { - this.mapMarkers = mapMarkers; - } - - public long getCreationDate() { - return creationDate; - } - - public void setCreationDate(long creationDate) { - this.creationDate = creationDate; - } - } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java new file mode 100644 index 0000000000..3ba9536f91 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java @@ -0,0 +1,45 @@ +package net.osmand.plus.mapmarkers; + +import net.osmand.plus.MapMarkersHelper; + +import java.util.ArrayList; +import java.util.List; + +public class MapMarkersGroup { + private String name; + private List mapMarkers = new ArrayList<>(); + private List historyMarkers = new ArrayList<>(); + private long creationDate; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getMapMarkers() { + return mapMarkers; + } + + public void setMapMarkers(List mapMarkers) { + this.mapMarkers = mapMarkers; + } + + public List getHistoryMarkers() { + return historyMarkers; + } + + public void setHistoryMarkers(List historyMarkers) { + this.historyMarkers = historyMarkers; + } + + public long getCreationDate() { + return creationDate; + } + + public void setCreationDate(long creationDate) { + this.creationDate = creationDate; + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java index 6ef6cbd9fa..f689f14cc8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java @@ -43,6 +43,7 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL void updateAdapter() { if (adapter != null) { + adapter.createDisplayGroups(); adapter.notifyDataSetChanged(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 3d698fbae8..408223e920 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -11,6 +11,7 @@ import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapmarkers.MapMarkersGroup; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -23,6 +24,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter markersHistory = app.getMapMarkersHelper().getMarkersSortedByGroup(); + List groups = app.getMapMarkersHelper().getMapMarkersGroups(); - int previousDateHeader = -1; - String previousNameHeader = ""; - int monthsDisplayed = 0; + for (int i = 0; i < groups.size(); i++) { + MapMarkersGroup group = groups.get(i); + String markerGroupName = group.getName(); + if (markerGroupName == null) { + int previousDateHeader = -1; + int monthsDisplayed = 0; - Calendar currentDateCalendar = Calendar.getInstance(); - currentDateCalendar.setTimeInMillis(System.currentTimeMillis()); - int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR); - int currentMonth = currentDateCalendar.get(Calendar.MONTH); - int currentYear = currentDateCalendar.get(Calendar.YEAR); - Calendar markerCalendar = Calendar.getInstance(); - for (int i = 0; i < markersHistory.size(); i++) { - MapMarker marker = markersHistory.get(i); - markerCalendar.setTimeInMillis(marker.creationDate); - int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR); - int markerMonth = markerCalendar.get(Calendar.MONTH); - int markerYear = markerCalendar.get(Calendar.YEAR); - String markerGroupName = marker.groupName; - if (markerGroupName != null && markerGroupName.equals("")) { - markerGroupName = app.getString(R.string.shared_string_favorites); - } - if (markerGroupName == null && markerYear == currentYear) { - if (markerDay == currentDay && previousDateHeader != TODAY_HEADER) { - items.add(TODAY_HEADER); - previousDateHeader = TODAY_HEADER; - } else if (markerDay == currentDay - 1 && previousDateHeader != YESTERDAY_HEADER) { - items.add(YESTERDAY_HEADER); - previousDateHeader = YESTERDAY_HEADER; - } else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousDateHeader != LAST_SEVEN_DAYS_HEADER) { - items.add(LAST_SEVEN_DAYS_HEADER); - previousDateHeader = LAST_SEVEN_DAYS_HEADER; - } else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousDateHeader != markerMonth) { - items.add(markerMonth); - previousDateHeader = markerMonth; - monthsDisplayed += 1; - } else if (currentMonth - markerMonth >= 4 && previousDateHeader != THIS_YEAR_HEADER) { - items.add(THIS_YEAR_HEADER); - previousDateHeader = THIS_YEAR_HEADER; + Calendar currentDateCalendar = Calendar.getInstance(); + currentDateCalendar.setTimeInMillis(System.currentTimeMillis()); + int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR); + int currentMonth = currentDateCalendar.get(Calendar.MONTH); + int currentYear = currentDateCalendar.get(Calendar.YEAR); + Calendar markerCalendar = Calendar.getInstance(); + List groupMarkers = group.getMapMarkers(); + for (int j = 0; j < groupMarkers.size(); j++) { + MapMarker marker = groupMarkers.get(j); + markerCalendar.setTimeInMillis(marker.creationDate); + int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR); + int markerMonth = markerCalendar.get(Calendar.MONTH); + int markerYear = markerCalendar.get(Calendar.YEAR); + if (markerYear == currentYear) { + if (markerDay == currentDay && previousDateHeader != TODAY_HEADER) { + items.add(TODAY_HEADER); + previousDateHeader = TODAY_HEADER; + } else if (markerDay == currentDay - 1 && previousDateHeader != YESTERDAY_HEADER) { + items.add(YESTERDAY_HEADER); + previousDateHeader = YESTERDAY_HEADER; + } else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousDateHeader != LAST_SEVEN_DAYS_HEADER) { + items.add(LAST_SEVEN_DAYS_HEADER); + previousDateHeader = LAST_SEVEN_DAYS_HEADER; + } else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousDateHeader != markerMonth) { + items.add(markerMonth); + previousDateHeader = markerMonth; + monthsDisplayed += 1; + } else if (currentMonth - markerMonth >= 4 && previousDateHeader != THIS_YEAR_HEADER) { + items.add(THIS_YEAR_HEADER); + previousDateHeader = THIS_YEAR_HEADER; + } + } else if (previousDateHeader != markerYear) { + items.add(markerYear); + previousDateHeader = markerYear; + } + items.add(marker); + } + } else { + if (markerGroupName.equals("")) { + markerGroupName = app.getString(R.string.shared_string_favorites); } - } else if (markerGroupName == null && previousDateHeader != markerYear) { - items.add(markerYear); - previousDateHeader = markerYear; - } else if (markerGroupName != null && !previousNameHeader.equals(markerGroupName)) { items.add(markerGroupName); - previousNameHeader = markerGroupName; + items.addAll(group.getMapMarkers()); + if (group.getHistoryMarkers().size() > 0) { + ShowHideHistoryButton showHideHistoryButton = new ShowHideHistoryButton(); + showHideHistoryButton.setShowHistory(false); + showHideHistoryButton.setGroupName(markerGroupName); + showHideHistoryButton.setHistoryMarkers(group.getHistoryMarkers()); + items.add(showHideHistoryButton); + } } - items.add(marker); } } @@ -121,13 +135,16 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter historyMarkers; + + public boolean isShowHistory() { + return showHistory; + } + + public void setShowHistory(boolean showHistory) { + this.showHistory = showHistory; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public List getHistoryMarkers() { + return historyMarkers; + } + + public void setHistoryMarkers(List historyMarkers) { + this.historyMarkers = historyMarkers; + } + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersShowHideHistoryViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersShowHideHistoryViewHolder.java new file mode 100644 index 0000000000..9cc5be907d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersShowHideHistoryViewHolder.java @@ -0,0 +1,16 @@ +package net.osmand.plus.mapmarkers.adapters; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.TextView; + +import net.osmand.plus.R; + +public class MapMarkersShowHideHistoryViewHolder extends RecyclerView.ViewHolder { + final TextView title; + + public MapMarkersShowHideHistoryViewHolder(View itemView) { + super(itemView); + title = (TextView) itemView.findViewById(R.id.show_hide_history_title); + } +} From 8e93cc3e96f3901e4b259e38ca85960525f3ce4a Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 19 Sep 2017 12:42:02 +0300 Subject: [PATCH 03/38] Add gpx waypoints color syncing; change some logic in gpx points selection --- .../src/net/osmand/plus/MapMarkersHelper.java | 8 ++ .../plus/myplaces/TrackPointFragment.java | 115 +++++++++++++----- 2 files changed, 92 insertions(+), 31 deletions(-) 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); } From 79f2cedc218c824ac22c0d8f69df0f5ea0a8d488 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 19 Sep 2017 13:57:24 +0300 Subject: [PATCH 04/38] Show history in groups --- .../map_marker_item_show_hide_history.xml | 4 +-- .../adapters/MapMarkersGroupsAdapter.java | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_show_hide_history.xml b/OsmAnd/res/layout/map_marker_item_show_hide_history.xml index 1d1f332ccf..03b78d8051 100644 --- a/OsmAnd/res/layout/map_marker_item_show_hide_history.xml +++ b/OsmAnd/res/layout/map_marker_item_show_hide_history.xml @@ -9,8 +9,8 @@ historyMarkers = showHideHistoryButton.getHistoryMarkers(); + int pos = holder.getAdapterPosition(); + if (showHistory) { + showHideHistoryButton.setShowHistory(false); + notifyItemChanged(pos); + items.removeAll(historyMarkers); + notifyItemRangeRemoved(pos - historyMarkers.size(), historyMarkers.size()); + } else { + showHideHistoryButton.setShowHistory(true); + notifyItemChanged(pos); + items.addAll(pos, historyMarkers); + notifyItemRangeInserted(pos, historyMarkers.size()); + } + } + }); } } From 368695c56668db5a774698358cf21c0872d5084a Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 19 Sep 2017 16:19:52 +0300 Subject: [PATCH 05/38] Add to and revert from history in groups --- .../plus/mapmarkers/MapMarkersGroup.java | 30 +++++ .../adapters/MapMarkersGroupsAdapter.java | 121 ++++++++++++------ 2 files changed, 109 insertions(+), 42 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java index 3ba9536f91..fac92d8439 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java @@ -10,6 +10,7 @@ public class MapMarkersGroup { private List mapMarkers = new ArrayList<>(); private List historyMarkers = new ArrayList<>(); private long creationDate; + private ShowHideHistoryButton showHideHistoryButton; public String getName() { return name; @@ -42,4 +43,33 @@ public class MapMarkersGroup { public void setCreationDate(long creationDate) { this.creationDate = creationDate; } + + public ShowHideHistoryButton getShowHideHistoryButton() { + return showHideHistoryButton; + } + + public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) { + this.showHideHistoryButton = showHideHistoryButton; + } + + public static class ShowHideHistoryButton { + private boolean showHistory; + private MapMarkersGroup group; + + public boolean isShowHistory() { + return showHistory; + } + + public void setShowHistory(boolean showHistory) { + this.showHistory = showHistory; + } + + public MapMarkersGroup getGroup() { + return group; + } + + public void setGroup(MapMarkersGroup group) { + this.group = group; + } + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index d2b2cc2adb..9c02f89a02 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -33,6 +33,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter items = new ArrayList<>(); + private List groups; private boolean night; private int screenOrientation; private LatLon location; @@ -48,7 +49,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter groups = app.getMapMarkersHelper().getMapMarkersGroups(); + groups = app.getMapMarkersHelper().getMapMarkersGroups(); for (int i = 0; i < groups.size(); i++) { MapMarkersGroup group = groups.get(i); @@ -101,10 +102,10 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter 0) { - ShowHideHistoryButton showHideHistoryButton = new ShowHideHistoryButton(); + MapMarkersGroup.ShowHideHistoryButton showHideHistoryButton = new MapMarkersGroup.ShowHideHistoryButton(); showHideHistoryButton.setShowHistory(false); - showHideHistoryButton.setGroupName(markerGroupName); - showHideHistoryButton.setHistoryMarkers(group.getHistoryMarkers()); + showHideHistoryButton.setGroup(group); + group.setShowHideHistoryButton(showHideHistoryButton); items.add(showHideHistoryButton); } } @@ -149,7 +150,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter historyMarkers = showHideHistoryButton.getHistoryMarkers(); + List historyMarkers = showHideHistoryButton.getGroup().getHistoryMarkers(); int pos = holder.getAdapterPosition(); if (showHistory) { showHideHistoryButton.setShowHistory(false); - notifyItemChanged(pos); items.removeAll(historyMarkers); - notifyItemRangeRemoved(pos - historyMarkers.size(), historyMarkers.size()); } else { showHideHistoryButton.setShowHistory(true); - notifyItemChanged(pos); items.addAll(pos, historyMarkers); - notifyItemRangeInserted(pos, historyMarkers.size()); } + notifyDataSetChanged(); } }); } @@ -239,7 +275,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter historyMarkers; - - public boolean isShowHistory() { - return showHistory; + private MapMarkersGroup getMapMarkerGroupByName(String name) { + for (MapMarkersGroup group : groups) { + if (group.getName() != null && group.getName().equals(name)) { + return group; + } } + return null; + } - public void setShowHistory(boolean showHistory) { - this.showHistory = showHistory; - } + private void moveMarkerToHistoryInGroup(MapMarkersGroup group, MapMarker marker) { + group.getMapMarkers().remove(marker); + group.getHistoryMarkers().add(marker); + } - public String getGroupName() { - return groupName; - } + private void restoreMarkerFromHistoryInGroup(MapMarkersGroup group, MapMarker marker) { + group.getHistoryMarkers().remove(marker); + group.getMapMarkers().add(marker); + } - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - public List getHistoryMarkers() { - return historyMarkers; - } - - public void setHistoryMarkers(List historyMarkers) { - this.historyMarkers = historyMarkers; + private int getLastDisplayItemIndexOfGroup(MapMarkersGroup group) { + List markers = group.getMapMarkers(); + int index = -1; + for (MapMarker marker : markers) { + int markerIndex = items.indexOf(marker); + if (markerIndex > index) { + index = markerIndex; + } } + return index; } } From 316cd5177603f80830561d90804e0e08f6f3e93d Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 19 Sep 2017 16:33:09 +0300 Subject: [PATCH 06/38] Change logic for drawing arrows to the first two markers; add drawing of the lines to the first two markers --- .../src/net/osmand/plus/OsmandSettings.java | 3 + .../osmand/plus/views/MapMarkersLayer.java | 166 ++++-------------- 2 files changed, 42 insertions(+), 127 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index b533b3857e..3a2eeb4405 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -713,6 +713,9 @@ public class OsmandSettings { public final CommonPreference RULER_MODE = new EnumIntPreference<>("ruler_mode", RulerMode.FIRST, RulerMode.values()).makeGlobal(); + public final CommonPreference SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", true).makeGlobal(); + public final CommonPreference SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", true).makeGlobal(); + public final CommonPreference USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal(); public final CommonPreference MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal(); public final CommonPreference MAPILLARY_FILTER_USERNAME = new StringPreference("mapillary_filter_username", "").makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 8107ee7ba7..820ab2986b 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -8,13 +8,9 @@ import android.graphics.Path; import android.graphics.PointF; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; -import android.os.Handler; -import android.os.Message; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; -import android.view.GestureDetector; -import android.view.MotionEvent; import net.osmand.Location; import net.osmand.data.LatLon; @@ -23,7 +19,6 @@ import net.osmand.data.QuadPoint; import net.osmand.data.RotatedTileBox; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; -import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; @@ -39,8 +34,6 @@ import java.util.List; public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider { protected static final int DIST_TO_SHOW = 80; - protected static final long USE_FINGER_LOCATION_DELAY = 1000; - private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 6; private final MapActivity map; private OsmandMapTileView view; @@ -66,17 +59,11 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private Bitmap arrowToDestination; private float[] calculations = new float[2]; + private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine"); private Paint paint; private Path path; private List route = new ArrayList<>(); - private LatLon fingerLocation; - private boolean hasMoved; - private boolean moving; - private boolean useFingerLocation; - private GestureDetector longTapDetector; - private Handler handler; - private ContextMenuLayer contextMenuLayer; public MapMarkersLayer(MapActivity map) { @@ -190,50 +177,23 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi @Override public void initLayer(OsmandMapTileView view) { this.view = view; - handler = new Handler(); initUI(); - longTapDetector = new GestureDetector(view.getContext(), new GestureDetector.OnGestureListener() { - @Override - public boolean onDown(MotionEvent e) { - return false; - } - - @Override - public void onShowPress(MotionEvent e) { - - } - - @Override - public boolean onSingleTapUp(MotionEvent e) { - return false; - } - - @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - return false; - } - - @Override - public void onLongPress(MotionEvent e) { - cancelFingerAction(); - } - - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - return false; - } - }); } @Override public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { - widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom()); + Location myLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation(); + widgetsFactory.updateInfo(myLoc == null + ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom()); + OsmandSettings settings = map.getMyApplication().getSettings(); - if (tileBox.getZoom() < 3 || !map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) { + if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) { return; } + lineAttrs.updatePaints(view, nightMode, tileBox); + MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); if (route.size() > 0) { path.reset(); @@ -259,6 +219,17 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } List activeMapMarkers = markersHelper.getMapMarkers(); + + if (settings.SHOW_LINES_TO_FIRST_MARKERS.get()) { + int locX = myLoc == null ? tileBox.getCenterPixelX() : tileBox.getPixXFromLonNoRot(myLoc.getLongitude()); + int locY = myLoc == null ? tileBox.getCenterPixelY() : tileBox.getPixYFromLatNoRot(myLoc.getLatitude()); + for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) { + int markerX = tileBox.getPixXFromLonNoRot(activeMapMarkers.get(i).getLongitude()); + int markerY = tileBox.getPixYFromLatNoRot(activeMapMarkers.get(i).getLatitude()); + canvas.drawLine(locX, locY, markerX, markerY, lineAttrs.paint); + } + } + for (MapMarker marker : activeMapMarkers) { if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker) && !isInMotion(marker)) { @@ -273,34 +244,26 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } } - boolean show = useFingerLocation || - (map.getMyApplication().getSettings().MAP_MARKERS_MODE.get() == OsmandSettings.MapMarkersMode.WIDGETS - && map.getMyApplication().getSettings().SHOW_DESTINATION_ARROW.get()); - if (show) { - LatLon loc = fingerLocation; - if (!useFingerLocation) { - loc = tileBox.getCenterLatLon(); - } - if (loc != null) { - List mapMarkers = markersHelper.getMapMarkers(); - int i = 0; - for (MapMarker marker : mapMarkers) { - if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) { - canvas.save(); - net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), - marker.getLatitude(), marker.getLongitude(), calculations); - float bearing = calculations[1] - 90; - float radiusBearing = DIST_TO_SHOW * tileBox.getDensity(); - final QuadPoint cp = tileBox.getCenterPixelPoint(); - canvas.rotate(bearing, cp.x, cp.y); - canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity()); - canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex)); - canvas.restore(); - } - i++; - if (i > 1) { - break; - } + if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) { + LatLon loc = myLoc == null ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()); + List mapMarkers = markersHelper.getMapMarkers(); + int i = 0; + for (MapMarker marker : mapMarkers) { + if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) { + canvas.save(); + net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), + marker.getLatitude(), marker.getLongitude(), calculations); + float bearing = calculations[1] - 90; + float radiusBearing = DIST_TO_SHOW * tileBox.getDensity(); + final QuadPoint cp = tileBox.getCenterPixelPoint(); + canvas.rotate(bearing, cp.x, cp.y); + canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity()); + canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex)); + canvas.restore(); + } + i++; + if (i > 1) { + break; } } } @@ -354,57 +317,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi public void destroyLayer() { } - @Override - public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { - if (!longTapDetector.onTouchEvent(event)) { - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - float x = event.getX(); - float y = event.getY(); - fingerLocation = tileBox.getLatLonFromPixel(x, y); - hasMoved = false; - moving = true; - break; - - case MotionEvent.ACTION_MOVE: - if (!hasMoved) { - if (!handler.hasMessages(MAP_REFRESH_MESSAGE)) { - Message msg = Message.obtain(handler, new Runnable() { - @Override - public void run() { - handler.removeMessages(MAP_REFRESH_MESSAGE); - if (moving) { - if (!useFingerLocation) { - useFingerLocation = true; - map.refreshMap(); - } - } - } - }); - msg.what = MAP_REFRESH_MESSAGE; - handler.sendMessageDelayed(msg, USE_FINGER_LOCATION_DELAY); - } - hasMoved = true; - } - break; - - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: - cancelFingerAction(); - break; - } - } - return super.onTouchEvent(event, tileBox); - } - - private void cancelFingerAction() { - handler.removeMessages(MAP_REFRESH_MESSAGE); - useFingerLocation = false; - moving = false; - fingerLocation = null; - map.refreshMap(); - } - @Override public boolean drawInScreenPixels() { return false; From b5f826f886584ab3e60b87ceabdef7c62085095f Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 19 Sep 2017 17:56:03 +0300 Subject: [PATCH 07/38] Add settings and items to menu --- ...ker_show_direction_bottom_sheet_dialog.xml | 91 ++++++++++++++++--- OsmAnd/res/values/strings.xml | 2 + ...howDirectionBottomSheetDialogFragment.java | 42 ++++++++- 3 files changed, 118 insertions(+), 17 deletions(-) diff --git a/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml index 1e0030de66..27b9b86b1b 100644 --- a/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml @@ -115,6 +115,67 @@ + + + + + + + + + + + + + + + + + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:background="@null" + android:clickable="false" + android:focusable="false"/> + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:background="@null" + android:clickable="false" + android:focusable="false"/> + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:background="@null" + android:clickable="false" + android:focusable="false"/> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ad814a51a3..953168a80d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Show guide line + Show arrows on the map Show passed Hide passed Remove from Map Markers diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index 43148b2a13..73038dbba8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.mapmarkers; +import android.app.Activity; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; @@ -12,6 +13,7 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; +import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.TextView; @@ -19,6 +21,7 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -38,8 +41,9 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final OsmandSettings settings = getMyApplication().getSettings(); portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - night = !getMyApplication().getSettings().isLightContent(); + night = !settings.isLightContent(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container); @@ -47,7 +51,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); } - OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); + OsmandSettings.MapMarkersMode mode = settings.MAP_MARKERS_MODE.get(); highlightSelectedItem(mode, true); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { @@ -84,6 +88,32 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra ((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); } + CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch); + showArrowsToggle.setChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()); + mainView.findViewById(R.id.show_arrows_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + settings.SHOW_ARROWS_TO_FIRST_MARKERS.set(!settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()); + if (getMapActivity() != null) { + getMapActivity().refreshMap(); + } + dismiss(); + } + }); + + CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch); + showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get()); + mainView.findViewById(R.id.show_guide_line_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + settings.SHOW_LINES_TO_FIRST_MARKERS.set(!settings.SHOW_LINES_TO_FIRST_MARKERS.get()); + if (getMapActivity() != null) { + getMapActivity().refreshMap(); + } + dismiss(); + } + }); + ImageView topBarIcon = (ImageView) mainView.findViewById(R.id.top_bar_icon); topBarIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); topBarIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue)); @@ -157,6 +187,14 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra } } + private MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity != null) { + return (MapActivity) activity; + } + return null; + } + private void highlightSelectedItem(OsmandSettings.MapMarkersMode mode, boolean check) { int iconBgColor = check ? R.color.dashboard_blue : R.color.on_map_icon_color; int iconColor = check ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue; From a574a66ea8cb50ecd8315f96ac6486f6c167d12b Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 19 Sep 2017 18:40:53 +0300 Subject: [PATCH 08/38] Create group header --- OsmAnd/res/layout/map_marker_item_header.xml | 18 +- .../src/net/osmand/plus/MapMarkersHelper.java | 73 +---- .../plus/mapmarkers/MapMarkersGroup.java | 75 ----- .../adapters/MapMarkerHeaderViewHolder.java | 11 +- .../adapters/MapMarkersGroupsAdapter.java | 275 ++++++++++++++++-- .../adapters/MapMarkersHistoryAdapter.java | 2 +- 6 files changed, 284 insertions(+), 170 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java diff --git a/OsmAnd/res/layout/map_marker_item_header.xml b/OsmAnd/res/layout/map_marker_item_header.xml index 884449ea96..86463f5c64 100644 --- a/OsmAnd/res/layout/map_marker_item_header.xml +++ b/OsmAnd/res/layout/map_marker_item_header.xml @@ -14,13 +14,25 @@ android:orientation="horizontal" android:background="?attr/bg_color"> + + + + diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 47e91d76a8..3876fbcab8 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -17,7 +17,6 @@ import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; -import net.osmand.plus.mapmarkers.MapMarkersGroup; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -176,6 +175,10 @@ public class MapMarkersHelper { } } + public MarkersSyncGroup getGroup(String id) { + return markersDbHelper.getGroup(id); + } + public static class MarkersSyncGroup { public static final int FAVORITES_TYPE = 0; @@ -284,73 +287,7 @@ public class MapMarkersHelper { } } - public List getMapMarkersGroups() { - List markers = new ArrayList<>(); - markers.addAll(mapMarkers); - markers.addAll(mapMarkersHistory); - - Map groupsMap = new LinkedHashMap<>(); - MapMarkersGroup noGroup = null; - for (MapMarker marker : markers) { - String groupName = marker.groupName; - if (groupName == null) { - if (noGroup == null) { - noGroup = new MapMarkersGroup(); - noGroup.setCreationDate(marker.creationDate); - } - if (marker.history) { - noGroup.getHistoryMarkers().add(marker); - } else { - noGroup.getMapMarkers().add(marker); - } - } else { - MapMarkersGroup group = groupsMap.get(groupName); - if (group == null) { - group = new MapMarkersGroup(); - group.setName(groupName); - group.setCreationDate(marker.creationDate); - groupsMap.put(groupName, group); - } else { - long markerCreationDate = marker.creationDate; - if (markerCreationDate < group.getCreationDate()) { - group.setCreationDate(markerCreationDate); - } - } - if (marker.history) { - group.getHistoryMarkers().add(marker); - } else { - group.getMapMarkers().add(marker); - } - } - } - List groups = new ArrayList<>(groupsMap.values()); - sortGroups(groups); - - if (noGroup != null) { - sortMarkers(noGroup.getMapMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); - groups.add(0, noGroup); - } - return groups; - } - - private void sortGroups(List groups) { - Collections.sort(groups, new Comparator() { - @Override - public int compare(MapMarkersGroup group1, MapMarkersGroup group2) { - long t1 = group1.getCreationDate(); - long t2 = group2.getCreationDate(); - if (t1 > t2) { - return -1; - } else if (t1 == t2) { - return 0; - } else { - return 1; - } - } - }); - } - - private void sortMarkers(List markers, final boolean visited, final OsmandSettings.MapMarkersOrderByMode orderByMode) { + public void sortMarkers(List markers, final boolean visited, final OsmandSettings.MapMarkersOrderByMode orderByMode) { final LatLon location = ctx.getSettings().getLastKnownMapLocation(); Collections.sort(markers, new Comparator() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java deleted file mode 100644 index fac92d8439..0000000000 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java +++ /dev/null @@ -1,75 +0,0 @@ -package net.osmand.plus.mapmarkers; - -import net.osmand.plus.MapMarkersHelper; - -import java.util.ArrayList; -import java.util.List; - -public class MapMarkersGroup { - private String name; - private List mapMarkers = new ArrayList<>(); - private List historyMarkers = new ArrayList<>(); - private long creationDate; - private ShowHideHistoryButton showHideHistoryButton; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getMapMarkers() { - return mapMarkers; - } - - public void setMapMarkers(List mapMarkers) { - this.mapMarkers = mapMarkers; - } - - public List getHistoryMarkers() { - return historyMarkers; - } - - public void setHistoryMarkers(List historyMarkers) { - this.historyMarkers = historyMarkers; - } - - public long getCreationDate() { - return creationDate; - } - - public void setCreationDate(long creationDate) { - this.creationDate = creationDate; - } - - public ShowHideHistoryButton getShowHideHistoryButton() { - return showHideHistoryButton; - } - - public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) { - this.showHideHistoryButton = showHideHistoryButton; - } - - public static class ShowHideHistoryButton { - private boolean showHistory; - private MapMarkersGroup group; - - public boolean isShowHistory() { - return showHistory; - } - - public void setShowHistory(boolean showHistory) { - this.showHistory = showHistory; - } - - public MapMarkersGroup getGroup() { - return group; - } - - public void setGroup(MapMarkersGroup group) { - this.group = group; - } - } -} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java index 8f6f7ddcc4..ac556509bd 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java @@ -3,18 +3,23 @@ package net.osmand.plus.mapmarkers.adapters; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.TextView; import net.osmand.plus.R; public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder { - final TextView date; + final ImageView icon; + final View iconSpace; + final TextView title; final ImageButton optionsBtn; public MapMarkerHeaderViewHolder(View itemView) { super(itemView); - date = itemView.findViewById(R.id.date_title); - optionsBtn = itemView.findViewById(R.id.date_options_button); + icon = (ImageView) itemView.findViewById(R.id.icon); + iconSpace = itemView.findViewById(R.id.icon_space); + title = (TextView) itemView.findViewById(R.id.title); + optionsBtn = (ImageButton) itemView.findViewById(R.id.date_options_button); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 9c02f89a02..df26d5d1ac 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -7,18 +7,24 @@ import android.view.ViewGroup; import net.osmand.data.LatLon; import net.osmand.plus.IconsCache; +import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.dashboard.DashLocationFragment; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; import java.util.Date; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; +import java.util.Map; public class MapMarkersGroupsAdapter extends RecyclerView.Adapter { @@ -31,6 +37,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter items = new ArrayList<>(); private List groups; @@ -41,16 +48,15 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter 0) { - MapMarkersGroup.ShowHideHistoryButton showHideHistoryButton = new MapMarkersGroup.ShowHideHistoryButton(); + ShowHideHistoryButton showHideHistoryButton = new ShowHideHistoryButton(); showHideHistoryButton.setShowHistory(false); showHideHistoryButton.setGroup(group); group.setShowHideHistoryButton(showHideHistoryButton); @@ -112,6 +125,73 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter getMapMarkersGroups() { + List markers = new ArrayList<>(); + markers.addAll(app.getMapMarkersHelper().getMapMarkers()); + markers.addAll(app.getMapMarkersHelper().getMapMarkersHistory()); + + Map groupsMap = new LinkedHashMap<>(); + MapMarkersGroup noGroup = null; + for (MapMarker marker : markers) { + String groupName = marker.groupName; + if (groupName == null) { + if (noGroup == null) { + noGroup = new MapMarkersGroup(); + noGroup.setCreationDate(marker.creationDate); + } + if (marker.history) { + noGroup.getHistoryMarkers().add(marker); + } else { + noGroup.getMapMarkers().add(marker); + } + } else { + MapMarkersGroup group = groupsMap.get(groupName); + if (group == null) { + group = new MapMarkersGroup(); + group.setName(groupName); + group.setType(app.getMapMarkersHelper().getGroup(marker.groupKey).getType()); + group.setCreationDate(marker.creationDate); + groupsMap.put(groupName, group); + } else { + long markerCreationDate = marker.creationDate; + if (markerCreationDate < group.getCreationDate()) { + group.setCreationDate(markerCreationDate); + } + } + if (marker.history) { + group.getHistoryMarkers().add(marker); + } else { + group.getMapMarkers().add(marker); + } + } + } + List groups = new ArrayList<>(groupsMap.values()); + sortGroups(groups); + + if (noGroup != null) { + app.getMapMarkersHelper().sortMarkers(noGroup.getMapMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); + groups.add(0, noGroup); + } + return groups; + } + + private void sortGroups(List groups) { + Collections.sort(groups, new Comparator() { + @Override + public int compare(MapMarkersGroup group1, MapMarkersGroup group2) { + long t1 = group1.getCreationDate(); + long t2 = group2.getCreationDate(); + if (t1 > t2) { + return -1; + } else if (t1 == t2) { + return 0; + } else { + return 1; + } + } + }); + } + public void setLocation(LatLon location) { this.location = location; } @@ -157,7 +237,14 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter mapMarkers = new ArrayList<>(); + private List historyMarkers = new ArrayList<>(); + private long creationDate; + private ShowHideHistoryButton showHideHistoryButton; + + public String getName() { + return name; + } + + public GroupHeader getGroupHeader() { + return header; + } + + public void setGroupHeader(GroupHeader header) { + this.header = header; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public void setName(String name) { + this.name = name; + } + + public List getMapMarkers() { + return mapMarkers; + } + + public void setMapMarkers(List mapMarkers) { + this.mapMarkers = mapMarkers; + } + + public List getHistoryMarkers() { + return historyMarkers; + } + + public void setHistoryMarkers(List historyMarkers) { + this.historyMarkers = historyMarkers; + } + + public long getCreationDate() { + return creationDate; + } + + public void setCreationDate(long creationDate) { + this.creationDate = creationDate; + } + + public ShowHideHistoryButton getShowHideHistoryButton() { + return showHideHistoryButton; + } + + public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) { + this.showHideHistoryButton = showHideHistoryButton; + } + } + + private static class ShowHideHistoryButton { + private boolean showHistory; + private MapMarkersGroup group; + + public boolean isShowHistory() { + return showHistory; + } + + public void setShowHistory(boolean showHistory) { + this.showHistory = showHistory; + } + + public MapMarkersGroup getGroup() { + return group; + } + + public void setGroup(MapMarkersGroup group) { + this.group = group; + } + } + + private static class GroupHeader { + private String title; + private int activeMarkersCount; + private int historyMarkersCount; + private int iconRes; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getActiveMarkersCount() { + return activeMarkersCount; + } + + public void setActiveMarkersCount(int activeMarkersCount) { + this.activeMarkersCount = activeMarkersCount; + } + + public int getHistoryMarkersCount() { + return historyMarkersCount; + } + + public void setHistoryMarkersCount(int historyMarkersCount) { + this.historyMarkersCount = historyMarkersCount; + } + + public int getIconRes() { + return iconRes; + } + + public void setIconRes(int iconRes) { + this.iconRes = iconRes; + } + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index bb8e4d969c..c56e192052 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -160,7 +160,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter Date: Tue, 19 Sep 2017 19:00:43 +0300 Subject: [PATCH 09/38] Refactor groups adapter --- .../adapters/MapMarkersGroupsAdapter.java | 123 +++++++++--------- 1 file changed, 58 insertions(+), 65 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index df26d5d1ac..33dc6abfa8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -70,7 +70,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter groupMarkers = group.getMapMarkers(); + List groupMarkers = group.getActiveMarkers(); for (int j = 0; j < groupMarkers.size(); j++) { MapMarker marker = groupMarkers.get(j); markerCalendar.setTimeInMillis(marker.creationDate); @@ -106,14 +106,13 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter 0) { ShowHideHistoryButton showHideHistoryButton = new ShowHideHistoryButton(); showHideHistoryButton.setShowHistory(false); @@ -142,7 +141,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter markers = group.getMapMarkers(); + List markers = group.getActiveMarkers(); int index = -1; for (MapMarker marker : markers) { int markerIndex = items.indexOf(marker); @@ -442,7 +435,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter mapMarkers = new ArrayList<>(); + private List activeMarkers = new ArrayList<>(); private List historyMarkers = new ArrayList<>(); private long creationDate; private ShowHideHistoryButton showHideHistoryButton; @@ -451,6 +444,10 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter getActiveMarkers() { + return activeMarkers; } - public List getMapMarkers() { - return mapMarkers; - } - - public void setMapMarkers(List mapMarkers) { - this.mapMarkers = mapMarkers; + public void setActiveMarkers(List activeMarkers) { + this.activeMarkers = activeMarkers; } public List getHistoryMarkers() { @@ -526,17 +519,17 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter Date: Tue, 19 Sep 2017 19:01:12 +0300 Subject: [PATCH 10/38] Do not draw the line outside the screen --- .../osmand/plus/views/MapMarkersLayer.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 820ab2986b..fb8a4c30b3 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -31,6 +31,8 @@ import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import java.util.ArrayList; import java.util.List; +import gnu.trove.list.array.TIntArrayList; + public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider { protected static final int DIST_TO_SHOW = 80; @@ -64,6 +66,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private Path path; private List route = new ArrayList<>(); + private TIntArrayList tx = new TIntArrayList(); + private TIntArrayList ty = new TIntArrayList(); + private Path linePath = new Path(); + private ContextMenuLayer contextMenuLayer; public MapMarkersLayer(MapActivity map) { @@ -221,13 +227,27 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi List activeMapMarkers = markersHelper.getMapMarkers(); if (settings.SHOW_LINES_TO_FIRST_MARKERS.get()) { + linePath.reset(); + tx.clear(); + ty.clear(); int locX = myLoc == null ? tileBox.getCenterPixelX() : tileBox.getPixXFromLonNoRot(myLoc.getLongitude()); int locY = myLoc == null ? tileBox.getCenterPixelY() : tileBox.getPixYFromLatNoRot(myLoc.getLatitude()); for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) { int markerX = tileBox.getPixXFromLonNoRot(activeMapMarkers.get(i).getLongitude()); int markerY = tileBox.getPixYFromLatNoRot(activeMapMarkers.get(i).getLatitude()); - canvas.drawLine(locX, locY, markerX, markerY, lineAttrs.paint); + tx.add(markerX); + ty.add(markerY); + if (i == 0) { + linePath.moveTo(markerX, markerY); + linePath.lineTo(locX, locY); + tx.add(locX); + ty.add(locY); + } else { + linePath.lineTo(markerX, markerY); + } } + calculatePath(tileBox, tx, ty, linePath); + canvas.drawPath(linePath, lineAttrs.paint); } for (MapMarker marker : activeMapMarkers) { From a03cc63616f55382c924e9d4b0e590ebd0ef8812 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 20 Sep 2017 10:43:04 +0300 Subject: [PATCH 11/38] Extract default color from loop --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 3876fbcab8..74df197aeb 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -27,11 +27,9 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Locale; -import java.util.Map; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; @@ -396,8 +394,9 @@ public class MapMarkersHelper { } List gpxPoints = new LinkedList<>(gpx.getPoints()); + int defColor = ContextCompat.getColor(ctx, R.color.marker_red); for (WptPt pt : gpxPoints) { - group.setColor(pt.getColor(ContextCompat.getColor(ctx, R.color.marker_red))); + group.setColor(pt.getColor(defColor)); addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name); } From 949978734b9ee8ae2bf4221284bc3156d931a96e Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 20 Sep 2017 10:54:29 +0300 Subject: [PATCH 12/38] Disable focusability on switches --- ...fragment_marker_show_direction_bottom_sheet_dialog.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml index 27b9b86b1b..e758017d95 100644 --- a/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml @@ -140,7 +140,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|end" - android:clickable="false"/> + android:clickable="false" + android:focusable="false" + android:focusableInTouchMode="false"/> + android:clickable="false" + android:focusable="false" + android:focusableInTouchMode="false"/> Date: Wed, 20 Sep 2017 10:54:29 +0300 Subject: [PATCH 13/38] Disable focusability on switches --- ...gment_marker_show_direction_bottom_sheet_dialog.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml index 27b9b86b1b..d92053dc9c 100644 --- a/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml @@ -140,7 +140,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|end" - android:clickable="false"/> + android:background="@null" + android:clickable="false" + android:focusable="false" + android:focusableInTouchMode="false"/> + android:background="@null" + android:clickable="false" + android:focusable="false" + android:focusableInTouchMode="false"/> Date: Wed, 20 Sep 2017 12:27:48 +0300 Subject: [PATCH 14/38] Replace group with history markers in button --- .../adapters/MapMarkersGroupsAdapter.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 33dc6abfa8..1f4016779d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -116,7 +116,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter 0) { ShowHideHistoryButton showHideHistoryButton = new ShowHideHistoryButton(); showHideHistoryButton.setShowHistory(false); - showHideHistoryButton.setGroup(group); + showHideHistoryButton.setHistoryMarkers(group.getHistoryMarkers()); group.setShowHideHistoryButton(showHideHistoryButton); items.add(showHideHistoryButton); } @@ -277,7 +277,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter historyMarkers = showHideHistoryButton.getGroup().getHistoryMarkers(); + List historyMarkers = showHideHistoryButton.getHistoryMarkers(); int pos = holder.getAdapterPosition(); if (showHistory) { showHideHistoryButton.setShowHistory(false); @@ -499,7 +499,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter historyMarkers; public boolean isShowHistory() { return showHistory; @@ -509,12 +509,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter getHistoryMarkers() { + return historyMarkers; } - public void setGroup(MapMarkersGroup group) { - this.group = group; + public void setHistoryMarkers(List historyMarkers) { + this.historyMarkers = historyMarkers; } } From cbe5c3c20f7c6f4c030b24b6d5b3f59825f3ab3e Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Wed, 20 Sep 2017 12:35:04 +0300 Subject: [PATCH 15/38] Replace concat with plus --- .../plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 1f4016779d..dc65a4a251 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -336,10 +336,9 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter Date: Wed, 20 Sep 2017 12:36:39 +0300 Subject: [PATCH 16/38] Fix some colors for the night mode --- .../bottom_navigation_color_selector_dark.xml | 5 +++++ .../bottom_navigation_color_selector_light.xml | 5 +++++ OsmAnd/res/layout/fragment_map_markers_dialog.xml | 4 ++-- .../plus/mapmarkers/MapMarkersDialogFragment.java | 15 ++++++++++++--- .../adapters/MapMarkersActiveAdapter.java | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 OsmAnd/res/color/bottom_navigation_color_selector_dark.xml create mode 100644 OsmAnd/res/color/bottom_navigation_color_selector_light.xml diff --git a/OsmAnd/res/color/bottom_navigation_color_selector_dark.xml b/OsmAnd/res/color/bottom_navigation_color_selector_dark.xml new file mode 100644 index 0000000000..803c0606b2 --- /dev/null +++ b/OsmAnd/res/color/bottom_navigation_color_selector_dark.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/OsmAnd/res/color/bottom_navigation_color_selector_light.xml b/OsmAnd/res/color/bottom_navigation_color_selector_light.xml new file mode 100644 index 0000000000..d1537744a1 --- /dev/null +++ b/OsmAnd/res/color/bottom_navigation_color_selector_light.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml index d7b9dda1a9..6bc81c6b5e 100644 --- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -98,7 +98,7 @@ android:layout_height="wrap_content" android:background="?attr/bg_color" app:itemBackground="?attr/bg_color" - app:itemIconTint="@drawable/bottom_navigation_color_selector" - app:itemTextColor="@drawable/bottom_navigation_color_selector" + app:itemIconTint="@color/bottom_navigation_color_selector_light" + app:itemTextColor="@color/bottom_navigation_color_selector_light" app:menu="@menu/map_markers_bottom_navigation"/> diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 5b8dddc12d..300df40f42 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -24,9 +24,9 @@ import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashboardOnMap; -import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener; import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener; import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener; +import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener; import java.util.ArrayList; import java.util.Arrays; @@ -44,12 +44,14 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm private LockableViewPager viewPager; private TextView orderByModeTitle; + private boolean lightTheme; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); OsmandApplication app = getMyApplication(); - boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; - int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; + lightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + int themeId = lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); } @@ -95,6 +97,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.map_markers_toolbar); + if (!lightTheme) { + toolbar.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.actionbar_dark_color)); + } orderByModeTitle = toolbar.findViewById(R.id.order_by_mode_text); setOrderByMode(getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.get()); @@ -121,6 +126,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm viewPager.setAdapter(adapter); BottomNavigationView bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation); + if (!lightTheme) { + bottomNav.setItemIconTintList(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark)); + bottomNav.setItemTextColor(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark)); + } bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index d531c4d1f7..de5e198d43 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -96,7 +96,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Wed, 20 Sep 2017 13:09:52 +0300 Subject: [PATCH 17/38] Fix colors for menu item icons in dark theme --- .../OptionsBottomSheetDialogFragment.java | 17 ++++++++++++----- .../OrderByBottomSheetDialogFragment.java | 7 +++++++ .../ShowDirectionBottomSheetDialogFragment.java | 13 ++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java index 48063aef11..3e26135a91 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java @@ -1,7 +1,9 @@ package net.osmand.plus.mapmarkers; +import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -43,7 +45,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment } ((ImageView) mainView.findViewById(R.id.sort_by_icon)) - .setImageDrawable(getIcon(R.drawable.ic_sort_waypoint_dark, R.color.on_map_icon_color)); + .setImageDrawable(getContentIcon(R.drawable.ic_sort_waypoint_dark)); OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); ImageView showDirectionIcon = (ImageView) mainView.findViewById(R.id.show_direction_icon); int imageResId = 0; @@ -55,16 +57,16 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment imageResId = R.drawable.ic_action_device_widget; break; } - showDirectionIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); + showDirectionIcon.setBackgroundDrawable(getContentIcon(R.drawable.ic_action_device_top)); if (imageResId != 0) { showDirectionIcon.setImageDrawable(getIcon(imageResId, R.color.dashboard_blue)); } ((ImageView) mainView.findViewById(R.id.build_route_icon)) - .setImageDrawable(getIcon(R.drawable.map_directions, R.color.on_map_icon_color)); + .setImageDrawable(getContentIcon(R.drawable.map_directions)); ((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)) - .setImageDrawable(getIcon(R.drawable.ic_action_polygom_dark, R.color.on_map_icon_color)); + .setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); ((ImageView) mainView.findViewById(R.id.move_all_to_history_icon)) - .setImageDrawable(getIcon(R.drawable.ic_action_history2, R.color.on_map_icon_color)); + .setImageDrawable(getContentIcon(R.drawable.ic_action_history2)); ((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText(getMyApplication().getSettings().MAP_MARKERS_MODE.get().toHumanString(getActivity())); @@ -171,6 +173,11 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment } } + @Override + protected Drawable getContentIcon(@DrawableRes int id) { + return getIcon(id, getMyApplication().getSettings().isLightContent() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark); + } + interface MarkerOptionsFragmentListener { void sortByOnClick(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java index 168f9e281a..cd044f5ff6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java @@ -1,7 +1,9 @@ package net.osmand.plus.mapmarkers; +import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -121,6 +123,11 @@ public class OrderByBottomSheetDialogFragment extends BottomSheetDialogFragment } } + @Override + protected Drawable getContentIcon(@DrawableRes int id) { + return getIcon(id, settings.isLightContent() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark); + } + private View.OnClickListener orderByModeOnClickListener = new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index 73038dbba8..7c84e30f85 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -1,8 +1,10 @@ package net.osmand.plus.mapmarkers; import android.app.Activity; +import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.view.ContextThemeWrapper; @@ -116,14 +118,14 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra ImageView topBarIcon = (ImageView) mainView.findViewById(R.id.top_bar_icon); topBarIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); - topBarIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue)); + topBarIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_device_topbar)); ImageView widgetIcon = (ImageView) mainView.findViewById(R.id.widget_icon); widgetIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); - widgetIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_widget, R.color.dashboard_blue)); + widgetIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_device_widget)); ImageView noneIcon = (ImageView) mainView.findViewById(R.id.none_icon); - noneIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); + noneIcon.setBackgroundDrawable(getContentIcon(R.drawable.ic_action_device_top)); mainView.findViewById(R.id.top_bar_row).setOnClickListener(showDirectionOnClickListener); mainView.findViewById(R.id.widget_row).setOnClickListener(showDirectionOnClickListener); @@ -187,6 +189,11 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra } } + @Override + protected Drawable getContentIcon(@DrawableRes int id) { + return getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); + } + private MapActivity getMapActivity() { Activity activity = getActivity(); if (activity != null) { From d212fc24d384751d5892d269c3ea88f2003c9b8f Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Wed, 20 Sep 2017 13:13:20 +0300 Subject: [PATCH 18/38] Fix ui for groups --- OsmAnd/res/layout/map_marker_item_header.xml | 10 +++++++++- .../adapters/MapMarkerHeaderViewHolder.java | 4 ++++ .../adapters/MapMarkersGroupsAdapter.java | 17 ++++++++++------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_header.xml b/OsmAnd/res/layout/map_marker_item_header.xml index 86463f5c64..c3ac494423 100644 --- a/OsmAnd/res/layout/map_marker_item_header.xml +++ b/OsmAnd/res/layout/map_marker_item_header.xml @@ -6,7 +6,15 @@ android:layout_height="wrap_content" android:descendantFocusability="blocksDescendants"> - + + + position + 1 && getItemViewType(position + 1) == HEADER_TYPE) || lastItem) { itemViewHolder.divider.setVisibility(View.GONE); } else { - itemViewHolder.bottomShadow.setVisibility(View.GONE); itemViewHolder.divider.setVisibility(View.VISIBLE); } + itemViewHolder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE); LatLon markerLatLon = new LatLon(marker.getLatitude(), marker.getLongitude()); DashLocationFragment.updateLocationView(useCenter, location, @@ -346,6 +346,8 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter Date: Wed, 20 Sep 2017 13:27:03 +0300 Subject: [PATCH 19/38] Fix space with tab --- .../adapters/MapMarkersGroupsAdapter.java | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 82b2c164a6..ac65d38825 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -39,22 +39,22 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter items = new ArrayList<>(); + private List items = new ArrayList<>(); private List groups; - private boolean night; - private int screenOrientation; - private LatLon location; - private Float heading; - private boolean useCenter; + private boolean night; + private int screenOrientation; + private LatLon location; + private Float heading; + private boolean useCenter; - public MapMarkersGroupsAdapter(MapActivity mapActivity) { + public MapMarkersGroupsAdapter(MapActivity mapActivity) { this.mapActivity = mapActivity; app = mapActivity.getMyApplication(); - night = !mapActivity.getMyApplication().getSettings().isLightContent(); + night = !mapActivity.getMyApplication().getSettings().isLightContent(); createDisplayGroups(); - } + } - public void createDisplayGroups() { + public void createDisplayGroups() { items.clear(); groups = getMapMarkersGroups(); for (int i = 0; i < groups.size(); i++) { @@ -191,24 +191,24 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter Date: Wed, 20 Sep 2017 13:33:30 +0300 Subject: [PATCH 20/38] Add annotation --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 74df197aeb..a2d866ceec 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -173,6 +173,7 @@ public class MapMarkersHelper { } } + @Nullable public MarkersSyncGroup getGroup(String id) { return markersDbHelper.getGroup(id); } From 297b9fc08784233b40b451f9c964f83d6abb00f7 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 20 Sep 2017 13:35:50 +0300 Subject: [PATCH 21/38] Disable arrows and lines by default --- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 3a2eeb4405..34216131d9 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -713,8 +713,8 @@ public class OsmandSettings { public final CommonPreference RULER_MODE = new EnumIntPreference<>("ruler_mode", RulerMode.FIRST, RulerMode.values()).makeGlobal(); - public final CommonPreference SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", true).makeGlobal(); - public final CommonPreference SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", true).makeGlobal(); + public final CommonPreference SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", false).makeGlobal(); + public final CommonPreference SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", false).makeGlobal(); public final CommonPreference USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal(); public final CommonPreference MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal(); From a25b282df7f6aff5f85ad833617531e793c16658 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Wed, 20 Sep 2017 13:37:29 +0300 Subject: [PATCH 22/38] Fix updating groups in adapter --- .../net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java | 1 - .../plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java index f689f14cc8..6ef6cbd9fa 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java @@ -43,7 +43,6 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL void updateAdapter() { if (adapter != null) { - adapter.createDisplayGroups(); adapter.notifyDataSetChanged(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index ac65d38825..83b934685a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -54,8 +54,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter Date: Wed, 20 Sep 2017 13:43:09 +0300 Subject: [PATCH 23/38] Fix space with tab in groups fragment --- .../mapmarkers/MapMarkersGroupsFragment.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java index 6ef6cbd9fa..0b004edf13 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java @@ -22,43 +22,43 @@ import net.osmand.util.MapUtils; public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassListener, OsmAndLocationListener { - public static final String TAG = "MapMarkersGroupsFragment"; + public static final String TAG = "MapMarkersGroupsFragment"; - private MapMarkersGroupsAdapter adapter; + private MapMarkersGroupsAdapter adapter; private Float heading; private Location location; private boolean locationUpdateStarted; - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - final RecyclerView recyclerView = new RecyclerView(getContext()); - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - final MapActivity mapActivity = (MapActivity) getActivity(); + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + final RecyclerView recyclerView = new RecyclerView(getContext()); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + final MapActivity mapActivity = (MapActivity) getActivity(); - adapter = new MapMarkersGroupsAdapter(mapActivity); + adapter = new MapMarkersGroupsAdapter(mapActivity); recyclerView.setAdapter(adapter); - return recyclerView; - } + return recyclerView; + } - void updateAdapter() { - if (adapter != null) { - adapter.notifyDataSetChanged(); - } - } + void updateAdapter() { + if (adapter != null) { + adapter.notifyDataSetChanged(); + } + } - @Override - public void onResume() { - super.onResume(); - adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); - startLocationUpdate(); - } + @Override + public void onResume() { + super.onResume(); + adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); + startLocationUpdate(); + } - @Override - public void onPause() { - super.onPause(); - stopLocationUpdate(); - } + @Override + public void onPause() { + super.onPause(); + stopLocationUpdate(); + } void startLocationUpdate() { OsmandApplication app = getMyApplication(); From 3fd4f89c1d6713dab5b15f4d44d002ccb3da12ec Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 20 Sep 2017 13:48:14 +0300 Subject: [PATCH 24/38] Fix arrows direction when my location is on --- OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index fb8a4c30b3..e906d9feed 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -265,7 +265,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) { - LatLon loc = myLoc == null ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()); + LatLon loc = tileBox.getCenterLatLon(); List mapMarkers = markersHelper.getMapMarkers(); int i = 0; for (MapMarker marker : mapMarkers) { From 9b2eb3a4151b6a6e7f7ec1c6f399ab51dd16304a Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Wed, 20 Sep 2017 13:50:50 +0300 Subject: [PATCH 25/38] Fix NPE when getting sync group type --- .../mapmarkers/adapters/MapMarkersGroupsAdapter.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 83b934685a..7c137f7492 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -106,7 +106,10 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter activeMarkers = new ArrayList<>(); private List historyMarkers = new ArrayList<>(); private long creationDate; From accb0c7b9320927ab11850d4d88c05eb3a49286d Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 20 Sep 2017 14:00:17 +0300 Subject: [PATCH 26/38] Do not draw lines without my location --- OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index e906d9feed..ec93c52755 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -226,12 +226,12 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi List activeMapMarkers = markersHelper.getMapMarkers(); - if (settings.SHOW_LINES_TO_FIRST_MARKERS.get()) { + if (settings.SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) { linePath.reset(); tx.clear(); ty.clear(); - int locX = myLoc == null ? tileBox.getCenterPixelX() : tileBox.getPixXFromLonNoRot(myLoc.getLongitude()); - int locY = myLoc == null ? tileBox.getCenterPixelY() : tileBox.getPixYFromLatNoRot(myLoc.getLatitude()); + int locX = tileBox.getPixXFromLonNoRot(myLoc.getLongitude()); + int locY = tileBox.getPixYFromLatNoRot(myLoc.getLatitude()); for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) { int markerX = tileBox.getPixXFromLonNoRot(activeMapMarkers.get(i).getLongitude()); int markerY = tileBox.getPixYFromLatNoRot(activeMapMarkers.get(i).getLatitude()); From 01a40b6779d68850df3e07a947da88e29e1be6bd Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Wed, 20 Sep 2017 14:08:29 +0300 Subject: [PATCH 27/38] Paint group icon with group color --- .../adapters/MapMarkersGroupsAdapter.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 7c137f7492..4e7a01d39a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -112,6 +112,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter historyMarkers = new ArrayList<>(); private long creationDate; private ShowHideHistoryButton showHideHistoryButton; + private int color; public String getName() { return name; @@ -502,6 +505,14 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter Date: Wed, 20 Sep 2017 16:19:42 +0300 Subject: [PATCH 28/38] Save current location for 15 minutes --- .../src/net/osmand/plus/views/MapMarkersLayer.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index ec93c52755..526f398de8 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -35,6 +35,8 @@ import gnu.trove.list.array.TIntArrayList; public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider { + + private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 15; // 15 minutes protected static final int DIST_TO_SHOW = 80; private final MapActivity map; @@ -42,6 +44,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private MapMarkersWidgetsFactory widgetsFactory; + private Location myLoc; + private Paint bitmapPaint; private Bitmap markerBitmapBlue; private Bitmap markerBitmapGreen; @@ -189,7 +193,14 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi @Override public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { - Location myLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation(); + Location newloc = map.getMyApplication().getLocationProvider().getLastKnownLocation(); + if (newloc == null) { + if (myLoc != null && System.currentTimeMillis() - myLoc.getTime() > STALE_LOCATION_TIMEOUT) { + myLoc = null; + } + } else { + myLoc = newloc; + } widgetsFactory.updateInfo(myLoc == null ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom()); OsmandSettings settings = map.getMyApplication().getSettings(); From 1c9388a2c1b6739af04fd456bf89eed3e609279d Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 20 Sep 2017 18:12:07 +0300 Subject: [PATCH 29/38] Change logic for getting location --- .../osmand/plus/OsmAndLocationProvider.java | 28 +++++++++++++++++-- .../osmand/plus/views/MapControlsLayer.java | 2 +- .../osmand/plus/views/MapMarkersLayer.java | 12 +------- .../net/osmand/plus/views/OsmandMapLayer.java | 20 ------------- .../osmand/plus/views/PointLocationLayer.java | 7 ++--- 5 files changed, 31 insertions(+), 38 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index d07a2b40d4..ad96b84af6 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -38,6 +38,7 @@ import android.location.LocationManager; import android.os.Build; import android.os.Bundle; import android.provider.Settings; +import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AlertDialog; import android.util.Log; @@ -69,11 +70,14 @@ public class OsmAndLocationProvider implements SensorEventListener { private static final int GPS_DIST_REQUEST = 0; private static final int NOT_SWITCH_TO_NETWORK_WHEN_GPS_LOST_MS = 12000; - private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 60; // 60 minutes - public static final long STALE_LOCATION_TIMEOUT_FOR_ICON = 1000 * 60 * 5; // 5 minutes + private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 5; // 5 minutes + private static final long STALE_LOCATION_TIMEOUT_FOR_UI = 1000 * 60 * 15; // 15 minutes private static final int UPDATES_BEFORE_CHECK_LOCATION = 100; private int updatesCounter; + private int updatesCounterUi; + + private net.osmand.Location cachedLocation; private long lastTimeGPSLocationFixed = 0; private boolean gpsSignalLost; @@ -877,6 +881,26 @@ public class OsmAndLocationProvider implements SensorEventListener { return location; } + @Nullable + public net.osmand.Location getLastStaleKnownLocation() { + if (updatesCounterUi == 0) { + net.osmand.Location newLoc = getLastKnownLocation(); + if (newLoc == null) { + if (cachedLocation != null && System.currentTimeMillis() - cachedLocation.getTime() > STALE_LOCATION_TIMEOUT_FOR_UI) { + cachedLocation = null; + } + } else { + cachedLocation = newLoc; + } + } + if (updatesCounterUi == UPDATES_BEFORE_CHECK_LOCATION) { + updatesCounterUi = 0; + } else { + updatesCounterUi++; + } + return cachedLocation; + } + public void showNavigationInfo(TargetPoint pointToNavigate, Context uiActivity) { getNavigationInfo().show(pointToNavigate, getHeading(), uiActivity); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 50bb769fca..88dd4bf182 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -797,7 +797,7 @@ public class MapControlsLayer extends OsmandMapLayer { private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) { Location lastKnownLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); - boolean enabled = lastKnownLocation != null && !isLocationOutdated(lastKnownLocation); + boolean enabled = lastKnownLocation != null; boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation(); if (!enabled) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 526f398de8..b20504ac30 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -36,7 +36,6 @@ import gnu.trove.list.array.TIntArrayList; public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider { - private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 15; // 15 minutes protected static final int DIST_TO_SHOW = 80; private final MapActivity map; @@ -44,8 +43,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private MapMarkersWidgetsFactory widgetsFactory; - private Location myLoc; - private Paint bitmapPaint; private Bitmap markerBitmapBlue; private Bitmap markerBitmapGreen; @@ -193,14 +190,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi @Override public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { - Location newloc = map.getMyApplication().getLocationProvider().getLastKnownLocation(); - if (newloc == null) { - if (myLoc != null && System.currentTimeMillis() - myLoc.getTime() > STALE_LOCATION_TIMEOUT) { - myLoc = null; - } - } else { - myLoc = newloc; - } + Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation(); widgetsFactory.updateInfo(myLoc == null ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom()); OsmandSettings settings = map.getMyApplication().getSettings(); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index dc09eca433..0c2592cd07 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -16,13 +16,11 @@ import android.os.Build; import android.support.annotation.NonNull; import android.view.MotionEvent; -import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.QuadTree; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; -import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.render.OsmandRenderer; @@ -40,8 +38,6 @@ import gnu.trove.list.array.TIntArrayList; public abstract class OsmandMapLayer { - protected static final int UPDATES_BEFORE_CHECK_LOCATION = 40; - protected List fullObjectsLatLon; protected List smallObjectsLatLon; @@ -51,22 +47,6 @@ public abstract class OsmandMapLayer { TWO_POINTERS_ZOOM_OUT } - private int updatesCounter; - private boolean locationOutdated; - - boolean isLocationOutdated(Location location) { - if (location != null && updatesCounter == 0) { - locationOutdated = System.currentTimeMillis() - location.getTime() > - OsmAndLocationProvider.STALE_LOCATION_TIMEOUT_FOR_ICON; - } - if (updatesCounter == UPDATES_BEFORE_CHECK_LOCATION) { - updatesCounter = 0; - } else { - updatesCounter++; - } - return locationOutdated; - } - public boolean isMapGestureAllowed(MapGestureType type) { return true; } diff --git a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java index f66c05713f..860b0cc58f 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java @@ -64,8 +64,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay aroundArea.setAntiAlias(true); locationProvider = view.getApplication().getLocationProvider(); - updateIcons(view.getSettings().getApplicationMode(), false, - isLocationOutdated(locationProvider.getLastKnownLocation())); + updateIcons(view.getSettings().getApplicationMode(), false, locationProvider.getLastKnownLocation() == null); } @Override @@ -86,9 +85,9 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay } // draw boolean nm = nightMode != null && nightMode.isNightMode(); - Location lastKnownLocation = locationProvider.getLastKnownLocation(); + Location lastKnownLocation = locationProvider.getLastStaleKnownLocation(); updateIcons(view.getSettings().getApplicationMode(), nm, - isLocationOutdated(lastKnownLocation)); + view.getApplication().getLocationProvider().getLastKnownLocation() == null); if(lastKnownLocation == null || view == null){ return; } From cf6265201c6e0dc6e103b5daad0952249296a217 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 20 Sep 2017 18:27:14 +0300 Subject: [PATCH 30/38] Do not close the menu after changing the switch state --- .../ShowDirectionBottomSheetDialogFragment.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index 7c84e30f85..a7d10456db 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -90,29 +90,31 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra ((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); } - CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch); + final CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch); showArrowsToggle.setChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()); mainView.findViewById(R.id.show_arrows_row).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - settings.SHOW_ARROWS_TO_FIRST_MARKERS.set(!settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()); + boolean newState = !settings.SHOW_ARROWS_TO_FIRST_MARKERS.get(); + settings.SHOW_ARROWS_TO_FIRST_MARKERS.set(newState); + showArrowsToggle.setChecked(newState); if (getMapActivity() != null) { getMapActivity().refreshMap(); } - dismiss(); } }); - CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch); + final CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch); showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get()); mainView.findViewById(R.id.show_guide_line_row).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - settings.SHOW_LINES_TO_FIRST_MARKERS.set(!settings.SHOW_LINES_TO_FIRST_MARKERS.get()); + boolean newState = !settings.SHOW_LINES_TO_FIRST_MARKERS.get(); + settings.SHOW_LINES_TO_FIRST_MARKERS.set(newState); + showLinesToggle.setChecked(newState); if (getMapActivity() != null) { getMapActivity().refreshMap(); } - dismiss(); } }); From 53c64d553b3ecce379a3b191e47ab1763887b736 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 20 Sep 2017 18:48:28 +0300 Subject: [PATCH 31/38] Draw a line to marker with marker color --- .../osmand/plus/views/MapMarkersLayer.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index b20504ac30..556e90c20f 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -228,27 +228,26 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi List activeMapMarkers = markersHelper.getMapMarkers(); if (settings.SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) { - linePath.reset(); - tx.clear(); - ty.clear(); int locX = tileBox.getPixXFromLonNoRot(myLoc.getLongitude()); int locY = tileBox.getPixYFromLatNoRot(myLoc.getLatitude()); + int[] colors = MapMarker.getColors(map); for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) { - int markerX = tileBox.getPixXFromLonNoRot(activeMapMarkers.get(i).getLongitude()); - int markerY = tileBox.getPixYFromLatNoRot(activeMapMarkers.get(i).getLatitude()); + MapMarker marker = activeMapMarkers.get(i); + int markerX = tileBox.getPixXFromLonNoRot(marker.getLongitude()); + int markerY = tileBox.getPixYFromLatNoRot(marker.getLatitude()); + linePath.reset(); + tx.clear(); + ty.clear(); + linePath.moveTo(locX, locY); + linePath.lineTo(markerX, markerY); + tx.add(locX); + ty.add(locY); tx.add(markerX); ty.add(markerY); - if (i == 0) { - linePath.moveTo(markerX, markerY); - linePath.lineTo(locX, locY); - tx.add(locX); - ty.add(locY); - } else { - linePath.lineTo(markerX, markerY); - } + calculatePath(tileBox, tx, ty, linePath); + lineAttrs.paint.setColor(colors[marker.colorIndex]); + canvas.drawPath(linePath, lineAttrs.paint); } - calculatePath(tileBox, tx, ty, linePath); - canvas.drawPath(linePath, lineAttrs.paint); } for (MapMarker marker : activeMapMarkers) { From e29953acdeb1b1d5fc03657820bff00d9607e7fc Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 20 Sep 2017 18:58:21 +0300 Subject: [PATCH 32/38] Always give random color to markers --- .../src/net/osmand/plus/MapMarkersHelper.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index a2d866ceec..78fd2d5df8 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -15,7 +15,6 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -411,13 +410,10 @@ public class MapMarkersHelper { for (MapMarker marker : markers) { if (marker.id.equals(group.getId() + name)) { exists = true; - int colorIndex = MapMarker.getColorIndex(ctx, ColorDialogs.getNearestColor(group.getColor(), MapMarker.getColors(ctx))); - boolean updateColor = group.getColor() != -1 && marker.colorIndex != colorIndex; - if (!marker.history && (!marker.point.equals(latLon) || updateColor)) { + if (!marker.history && (!marker.point.equals(latLon))) { for (MapMarker m : mapMarkers) { if (m.id.equals(marker.id)) { m.point = latLon; - m.colorIndex = colorIndex; updateMapMarker(m, true); break; } @@ -634,8 +630,7 @@ public class MapMarkersHelper { private void addMarkers(List points, List historyNames, @Nullable MarkersSyncGroup group) { if (points.size() > 0) { - boolean randomColor = group == null || group.getColor() == -1; - int colorIndex = randomColor ? -1 : MapMarker.getColorIndex(ctx, ColorDialogs.getNearestColor(group.getColor(), MapMarker.getColors(ctx))); + int colorIndex = -1; for (int i = 0; i < points.size(); i++) { LatLon point = points.get(i); PointDescription historyName = historyNames.get(i); @@ -648,16 +643,14 @@ public class MapMarkersHelper { if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) { pointDescription.setName(PointDescription.getSearchAddressStr(ctx)); } - if (randomColor) { - if (colorIndex == -1) { - if (mapMarkers.size() > 0) { - colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; - } else { - colorIndex = 0; - } + if (colorIndex == -1) { + if (mapMarkers.size() > 0) { + colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } else { - colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; + colorIndex = 0; } + } else { + colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); From ea639ea08cfeacfe7c550f07d952b7d8122d28a5 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Wed, 20 Sep 2017 21:53:33 +0300 Subject: [PATCH 33/38] Refactor groups and highlight items in groups --- .../src/net/osmand/plus/MapMarkersHelper.java | 320 ++++++++++++++++ .../mapmarkers/MapMarkersGroupsFragment.java | 2 + .../adapters/MapMarkersGroupsAdapter.java | 347 ++++-------------- 3 files changed, 394 insertions(+), 275 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index a2d866ceec..2a38b8c96d 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -27,9 +27,11 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Locale; +import java.util.Map; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; @@ -38,6 +40,7 @@ public class MapMarkersHelper { private List mapMarkers = new LinkedList<>(); private List mapMarkersHistory = new LinkedList<>(); + private List mapMarkersGroups = new ArrayList<>(); private OsmandSettings settings; private List listeners = new ArrayList<>(); private OsmandApplication ctx; @@ -229,6 +232,7 @@ public class MapMarkersHelper { markersDbHelper = ctx.getMapMarkersDbHelper(); startFromMyLocation = settings.ROUTE_MAP_MARKERS_START_MY_LOC.get(); loadMarkers(); + createMapMarkersGroups(); } public boolean isStartFromMyLocation() { @@ -475,6 +479,7 @@ public class MapMarkersHelper { mapMarkers.add(marker); checkAndFixActiveMarkersOrderIfNeeded(); } + addMarkerToGroup(marker); refresh(); } } @@ -510,6 +515,7 @@ public class MapMarkersHelper { markersDbHelper.removeMarker(marker, true); mapMarkersHistory.remove(marker); refresh(); + removeMarkerFromGroup(marker); } } @@ -591,6 +597,7 @@ public class MapMarkersHelper { markersDbHelper.clearAllMarkersHistory(); mapMarkersHistory.clear(); refresh(); + removeHistoryMarkersFromGroups(); } public void addMarkersSyncGroup(MarkersSyncGroup group) { @@ -673,6 +680,7 @@ public class MapMarkersHelper { marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE; markersDbHelper.addMarker(marker); mapMarkers.add(marker); + addMarkerToGroup(marker); checkAndFixActiveMarkersOrderIfNeeded(); } } @@ -814,4 +822,316 @@ public class MapMarkersHelper { } GPXUtilities.writeGpxFile(fout, file, ctx); } + + private void removeHistoryMarkersFromGroups() { + for (MapMarkersGroup markersGroup : mapMarkersGroups) { + List activeMarkers = new ArrayList<>(); + for (MapMarker marker : markersGroup.getMarkers()) { + if (!marker.history) { + activeMarkers.add(marker); + } + } + markersGroup.setMarkers(activeMarkers); + updateShowHideHistoryButtonInGroup(markersGroup); + } + } + + private void updateShowHideHistoryButtonInGroup(MapMarkersGroup mapMarkersGroup) { + int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size(); + ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton(); + if (showHideHistoryButton != null && historyMarkersCount == 0) { + mapMarkersGroup.setShowHideHistoryButton(null); + } else if (historyMarkersCount > 0) { + showHideHistoryButton = new ShowHideHistoryButton(); + showHideHistoryButton.setShowHistory(false); + showHideHistoryButton.setMarkerGroup(mapMarkersGroup); + mapMarkersGroup.setShowHideHistoryButton(showHideHistoryButton); + } + } + + private void addMarkerToGroup(MapMarker marker) { + if (marker != null) { + MapMarkersGroup mapMarkersGroup = getMapMarkerGroupByName(marker.groupName); + if (mapMarkersGroup != null) { + mapMarkersGroup.getMarkers().add(marker); + updateShowHideHistoryButtonInGroup(mapMarkersGroup); + if (mapMarkersGroup.getName() == null) { + sortMarkers(mapMarkersGroup.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); + } + } else { + MapMarkersGroup group = createMapMarkerGroup(marker); + group.getMarkers().add(marker); + createHeaderAndHistoryButtonInGroup(group); + } + } + } + + private MapMarkersGroup createMapMarkerGroup(MapMarker marker) { + MapMarkersGroup group = new MapMarkersGroup(); + group.setName(marker.groupName); + MapMarkersHelper.MarkersSyncGroup syncGroup = getGroup(marker.groupKey); + if (syncGroup != null) { + group.setType(syncGroup.getType()); + } + group.setColor(MapMarker.getColorId(marker.colorIndex)); + group.setCreationDate(marker.creationDate); + mapMarkersGroups.add(group); + return group; + } + + private void createHeaderAndHistoryButtonInGroup(MapMarkersGroup group) { + String markerGroupName = group.getName(); + if (markerGroupName.equals("")) { + markerGroupName = ctx.getString(R.string.shared_string_favorites); + } + GroupHeader header = new GroupHeader(); + header.setGroupName(markerGroupName); + int type = group.getType(); + if (type != -1) { + header.setIconRes(type == MapMarkersHelper.MarkersSyncGroup.FAVORITES_TYPE ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_track_16); + } + header.setActiveMarkersCount(group.getActiveMarkers().size()); + header.setMarkersCount(group.getMarkers().size()); + header.setColor(group.getColor()); + group.setGroupHeader(header); + updateShowHideHistoryButtonInGroup(group); + } + + private void removeMarkerFromGroup(MapMarker marker) { + if (marker != null) { + MapMarkersGroup mapMarkersGroup = getMapMarkerGroupByName(marker.groupName); + if (mapMarkersGroup != null) { + mapMarkersGroup.getMarkers().remove(marker); + updateShowHideHistoryButtonInGroup(mapMarkersGroup); + } + } + } + + public List getMapMarkersGroups() { + return mapMarkersGroups; + } + + private void createMapMarkersGroups() { + List markers = new ArrayList<>(); + markers.addAll(mapMarkers); + markers.addAll(mapMarkersHistory); + + Map groupsMap = new LinkedHashMap<>(); + MapMarkersGroup noGroup = null; + for (MapMarker marker : markers) { + String groupName = marker.groupName; + if (groupName == null) { + if (noGroup == null) { + noGroup = new MapMarkersGroup(); + noGroup.setCreationDate(marker.creationDate); + } + noGroup.getMarkers().add(marker); + } else { + MapMarkersGroup group = groupsMap.get(groupName); + if (group == null) { + group = createMapMarkerGroup(marker); + groupsMap.put(groupName, group); + } else { + long markerCreationDate = marker.creationDate; + if (markerCreationDate < group.getCreationDate()) { + group.setCreationDate(markerCreationDate); + } + } + group.getMarkers().add(marker); + } + } + mapMarkersGroups = new ArrayList<>(groupsMap.values()); + sortGroups(mapMarkersGroups); + + for (MapMarkersGroup group : mapMarkersGroups) { + createHeaderAndHistoryButtonInGroup(group); + } + + if (noGroup != null) { + sortMarkers(noGroup.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); + mapMarkersGroups.add(0, noGroup); + } + } + + private void sortGroups(List groups) { + Collections.sort(groups, new Comparator() { + @Override + public int compare(MapMarkersGroup group1, MapMarkersGroup group2) { + long t1 = group1.getCreationDate(); + long t2 = group2.getCreationDate(); + if (t1 > t2) { + return -1; + } else if (t1 == t2) { + return 0; + } else { + return 1; + } + } + }); + } + + public MapMarkersGroup getMapMarkerGroupByName(String name) { + for (MapMarkersGroup group : mapMarkersGroups) { + if ((name == null && group.getName() == null) + || (group.getName() != null && group.getName().equals(name))) { + return group; + } + } + return null; + } + + public static class MapMarkersGroup { + private String name; + private GroupHeader header; + private int type = -1; + private List markers = new ArrayList<>(); + private long creationDate; + private ShowHideHistoryButton showHideHistoryButton; + private int color; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public GroupHeader getGroupHeader() { + return header; + } + + public void setGroupHeader(GroupHeader header) { + this.header = header; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public List getActiveMarkers() { + List activeMarkers = new ArrayList<>(); + for (MapMarker marker : markers) { + if (!marker.history) { + activeMarkers.add(marker); + } + } + return activeMarkers; + } + + public List getHistoryMarkers() { + List historyMarkers = new ArrayList<>(); + for (MapMarker marker : markers) { + if (marker.history) { + historyMarkers.add(marker); + } + } + return historyMarkers; + } + + public List getMarkers() { + return markers; + } + + public void setMarkers(List markers) { + this.markers = markers; + } + + public long getCreationDate() { + return creationDate; + } + + public void setCreationDate(long creationDate) { + this.creationDate = creationDate; + } + + public ShowHideHistoryButton getShowHideHistoryButton() { + return showHideHistoryButton; + } + + public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) { + this.showHideHistoryButton = showHideHistoryButton; + } + + public int getColor() { + return color; + } + + public void setColor(int color) { + this.color = color; + } + } + + public static class ShowHideHistoryButton { + private boolean showHistory; + private MapMarkersGroup group; + + public boolean isShowHistory() { + return showHistory; + } + + public void setShowHistory(boolean showHistory) { + this.showHistory = showHistory; + } + + public MapMarkersGroup getMapMarkerGroup() { + return group; + } + + public void setMarkerGroup(MapMarkersGroup group) { + this.group = group; + } + } + + public static class GroupHeader { + private String groupName; + private int activeMarkersCount; + private int markersCount; + private int iconRes; + private int color; + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public int getActiveMarkersCount() { + return activeMarkersCount; + } + + public void setActiveMarkersCount(int activeMarkersCount) { + this.activeMarkersCount = activeMarkersCount; + } + + public int getMarkersCount() { + return markersCount; + } + + public void setMarkersCount(int markersCount) { + this.markersCount = markersCount; + } + + public int getIconRes() { + return iconRes; + } + + public void setIconRes(int iconRes) { + this.iconRes = iconRes; + } + + public int getColor() { + return color; + } + + public void setColor(int color) { + this.color = color; + } + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java index 0b004edf13..c340f1dff7 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java @@ -43,6 +43,8 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL void updateAdapter() { if (adapter != null) { + adapter.createDisplayGroups(); + adapter.updateShowDirectionMarkers(); adapter.notifyDataSetChanged(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 4e7a01d39a..039a6651c2 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -1,14 +1,18 @@ package net.osmand.plus.mapmarkers.adapters; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import net.osmand.data.LatLon; import net.osmand.plus.IconsCache; -import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.MapMarkersHelper.MapMarkersGroup; +import net.osmand.plus.MapMarkersHelper.GroupHeader; +import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -18,13 +22,9 @@ import net.osmand.plus.dashboard.DashLocationFragment; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; import java.util.Date; -import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; -import java.util.Map; public class MapMarkersGroupsAdapter extends RecyclerView.Adapter { @@ -40,22 +40,32 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter items = new ArrayList<>(); - private List groups; private boolean night; private int screenOrientation; private LatLon location; private Float heading; private boolean useCenter; + private boolean showDirectionEnabled; + private List showDirectionMarkers; public MapMarkersGroupsAdapter(MapActivity mapActivity) { this.mapActivity = mapActivity; app = mapActivity.getMyApplication(); night = !mapActivity.getMyApplication().getSettings().isLightContent(); + updateShowDirectionMarkers(); createDisplayGroups(); } - private void createDisplayGroups() { - groups = getMapMarkersGroups(); + public void updateShowDirectionMarkers() { + showDirectionEnabled = app.getSettings().MAP_MARKERS_MODE.get() != OsmandSettings.MapMarkersMode.NONE;; + List mapMarkers = app.getMapMarkersHelper().getMapMarkers(); + int markersCount = mapMarkers.size(); + showDirectionMarkers = new ArrayList<>(mapMarkers.subList(0, markersCount > 0 ? markersCount > 1 ? 2 : 1 : 0)); + } + + public void createDisplayGroups() { + items.clear(); + List groups = app.getMapMarkersHelper().getMapMarkersGroups(); for (int i = 0; i < groups.size(); i++) { MapMarkersGroup group = groups.get(i); String markerGroupName = group.getName(); @@ -101,103 +111,21 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter 0) { - ShowHideHistoryButton showHideHistoryButton = new ShowHideHistoryButton(); - showHideHistoryButton.setShowHistory(false); - showHideHistoryButton.setHistoryMarkers(group.getHistoryMarkers()); - group.setShowHideHistoryButton(showHideHistoryButton); + ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton(); + if (showHideHistoryButton != null && showHideHistoryButton.isShowHistory()) { + items.addAll(group.getMarkers()); + } else { + items.addAll(group.getActiveMarkers()); + } + if (showHideHistoryButton != null) { items.add(showHideHistoryButton); } } } } - public List getMapMarkersGroups() { - List markers = new ArrayList<>(); - markers.addAll(app.getMapMarkersHelper().getMapMarkers()); - markers.addAll(app.getMapMarkersHelper().getMapMarkersHistory()); - - Map groupsMap = new LinkedHashMap<>(); - MapMarkersGroup noGroup = null; - for (MapMarker marker : markers) { - String groupName = marker.groupName; - if (groupName == null) { - if (noGroup == null) { - noGroup = new MapMarkersGroup(); - noGroup.setCreationDate(marker.creationDate); - } - if (marker.history) { - noGroup.getHistoryMarkers().add(marker); - } else { - noGroup.getActiveMarkers().add(marker); - } - } else { - MapMarkersGroup group = groupsMap.get(groupName); - if (group == null) { - group = new MapMarkersGroup(); - group.setName(groupName); - MapMarkersHelper.MarkersSyncGroup syncGroup = app.getMapMarkersHelper().getGroup(marker.groupKey); - if (syncGroup != null) { - group.setType(syncGroup.getType()); - } - group.setColor(MapMarker.getColorId(marker.colorIndex)); - group.setCreationDate(marker.creationDate); - groupsMap.put(groupName, group); - } else { - long markerCreationDate = marker.creationDate; - if (markerCreationDate < group.getCreationDate()) { - group.setCreationDate(markerCreationDate); - } - } - if (marker.history) { - group.getHistoryMarkers().add(marker); - } else { - group.getActiveMarkers().add(marker); - } - } - } - List groups = new ArrayList<>(groupsMap.values()); - sortGroups(groups); - - if (noGroup != null) { - app.getMapMarkersHelper().sortMarkers(noGroup.getActiveMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); - groups.add(0, noGroup); - } - return groups; - } - - private void sortGroups(List groups) { - Collections.sort(groups, new Comparator() { - @Override - public int compare(MapMarkersGroup group1, MapMarkersGroup group2) { - long t1 = group1.getCreationDate(); - long t2 = group2.getCreationDate(); - if (t1 > t2) { - return -1; - } else if (t1 == t2) { - return 0; - } else { - return 1; - } - } - }); - } - public void setLocation(LatLon location) { this.location = location; } @@ -237,12 +165,43 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter historyMarkers = showHideHistoryButton.getHistoryMarkers(); + List historyMarkers = showHideHistoryButton.getMapMarkerGroup().getHistoryMarkers(); int pos = holder.getAdapterPosition(); if (showHistory) { showHideHistoryButton.setShowHistory(false); @@ -408,26 +363,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter markers = group.getActiveMarkers(); int index = -1; @@ -437,150 +372,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter activeMarkers = new ArrayList<>(); - private List historyMarkers = new ArrayList<>(); - private long creationDate; - private ShowHideHistoryButton showHideHistoryButton; - private int color; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public GroupHeader getGroupHeader() { - return header; - } - - public void setGroupHeader(GroupHeader header) { - this.header = header; - } - - public int getType() { - return type; - } - - public void setType(int type) { - this.type = type; - } - - public List getActiveMarkers() { - return activeMarkers; - } - - public void setActiveMarkers(List activeMarkers) { - this.activeMarkers = activeMarkers; - } - - public List getHistoryMarkers() { - return historyMarkers; - } - - public void setHistoryMarkers(List historyMarkers) { - this.historyMarkers = historyMarkers; - } - - public long getCreationDate() { - return creationDate; - } - - public void setCreationDate(long creationDate) { - this.creationDate = creationDate; - } - - public ShowHideHistoryButton getShowHideHistoryButton() { - return showHideHistoryButton; - } - - public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) { - this.showHideHistoryButton = showHideHistoryButton; - } - - public int getColor() { - return color; - } - - public void setColor(int color) { - this.color = color; - } - } - - private static class ShowHideHistoryButton { - private boolean showHistory; - private List historyMarkers; - - public boolean isShowHistory() { - return showHistory; - } - - public void setShowHistory(boolean showHistory) { - this.showHistory = showHistory; - } - - public List getHistoryMarkers() { - return historyMarkers; - } - - public void setHistoryMarkers(List historyMarkers) { - this.historyMarkers = historyMarkers; - } - } - - private static class GroupHeader { - private String groupName; - private int activeMarkersCount; - private int historyMarkersCount; - private int iconRes; - private int color; - - public String getGroupName() { - return groupName; - } - - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - public int getActiveMarkersCount() { - return activeMarkersCount; - } - - public void setActiveMarkersCount(int activeMarkersCount) { - this.activeMarkersCount = activeMarkersCount; - } - - public int getHistoryMarkersCount() { - return historyMarkersCount; - } - - public void setHistoryMarkersCount(int historyMarkersCount) { - this.historyMarkersCount = historyMarkersCount; - } - - public int getIconRes() { - return iconRes; - } - - public void setIconRes(int iconRes) { - this.iconRes = iconRes; - } - - public int getColor() { - return color; - } - - public void setColor(int color) { - this.color = color; - } - } } From 426dcdce85df7809c7c59767ee2be1e1e7c4664a Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Thu, 21 Sep 2017 08:41:43 +0300 Subject: [PATCH 34/38] Revert spaces in groups --- OsmAnd/res/layout/map_marker_item_header.xml | 10 +--------- .../mapmarkers/adapters/MapMarkerHeaderViewHolder.java | 4 ---- .../mapmarkers/adapters/MapMarkersGroupsAdapter.java | 2 -- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_header.xml b/OsmAnd/res/layout/map_marker_item_header.xml index c3ac494423..86463f5c64 100644 --- a/OsmAnd/res/layout/map_marker_item_header.xml +++ b/OsmAnd/res/layout/map_marker_item_header.xml @@ -6,15 +6,7 @@ android:layout_height="wrap_content" android:descendantFocusability="blocksDescendants"> - - - + Date: Thu, 21 Sep 2017 08:50:48 +0300 Subject: [PATCH 35/38] Styling --- OsmAnd/res/layout/map_marker_item_show_hide_history.xml | 8 ++++++-- .../plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_show_hide_history.xml b/OsmAnd/res/layout/map_marker_item_show_hide_history.xml index 03b78d8051..2454538048 100644 --- a/OsmAnd/res/layout/map_marker_item_show_hide_history.xml +++ b/OsmAnd/res/layout/map_marker_item_show_hide_history.xml @@ -3,11 +3,12 @@ android:layout_width="match_parent" android:layout_height="48dp" xmlns:tools="http://schemas.android.com/tools" + xmlns:osmand="http://schemas.android.com/apk/res-auto" android:orientation="horizontal" android:background="?attr/bg_color" xmlns:android="http://schemas.android.com/apk/res/android"> - + tools:text="Show passed" + android:textSize="12sp" + osmand:typeface="@string/font_roboto_medium" + android:textColor="@color/dashboard_blue"/> \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 5ffc3da9f4..be684439a8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -298,7 +298,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter Date: Thu, 21 Sep 2017 08:59:23 +0300 Subject: [PATCH 36/38] Change type icon color --- .../plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index be684439a8..f1a1705dad 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -303,7 +303,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter Date: Thu, 21 Sep 2017 09:10:38 +0300 Subject: [PATCH 37/38] Add switch to disable groups --- OsmAnd/res/layout/map_marker_item_header.xml | 15 +++++++-------- .../adapters/MapMarkerHeaderViewHolder.java | 5 +++-- .../adapters/MapMarkersHistoryAdapter.java | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_header.xml b/OsmAnd/res/layout/map_marker_item_header.xml index 86463f5c64..bea554a14b 100644 --- a/OsmAnd/res/layout/map_marker_item_header.xml +++ b/OsmAnd/res/layout/map_marker_item_header.xml @@ -36,14 +36,13 @@ android:gravity="center_vertical" tools:text="Today"/> - + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java index ac556509bd..d8748a8786 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java @@ -1,6 +1,7 @@ package net.osmand.plus.mapmarkers.adapters; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SwitchCompat; import android.view.View; import android.widget.ImageButton; import android.widget.ImageView; @@ -13,13 +14,13 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder { final ImageView icon; final View iconSpace; final TextView title; - final ImageButton optionsBtn; + final SwitchCompat disableGroupSwitch; public MapMarkerHeaderViewHolder(View itemView) { super(itemView); icon = (ImageView) itemView.findViewById(R.id.icon); iconSpace = itemView.findViewById(R.id.icon_space); title = (TextView) itemView.findViewById(R.id.title); - optionsBtn = (ImageButton) itemView.findViewById(R.id.date_options_button); + disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index c56e192052..4941755174 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -160,6 +160,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter Date: Thu, 21 Sep 2017 09:47:49 +0300 Subject: [PATCH 38/38] Add disabling groups --- .../src/net/osmand/plus/MapMarkersHelper.java | 55 +++++-------------- .../adapters/MapMarkersGroupsAdapter.java | 30 ++++++---- 2 files changed, 34 insertions(+), 51 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 93f0103367..9c65a13f1b 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -873,19 +873,12 @@ public class MapMarkersHelper { } private void createHeaderAndHistoryButtonInGroup(MapMarkersGroup group) { - String markerGroupName = group.getName(); - if (markerGroupName.equals("")) { - markerGroupName = ctx.getString(R.string.shared_string_favorites); - } GroupHeader header = new GroupHeader(); - header.setGroupName(markerGroupName); int type = group.getType(); if (type != -1) { header.setIconRes(type == MapMarkersHelper.MarkersSyncGroup.FAVORITES_TYPE ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_track_16); } - header.setActiveMarkersCount(group.getActiveMarkers().size()); - header.setMarkersCount(group.getMarkers().size()); - header.setColor(group.getColor()); + header.setGroup(group); group.setGroupHeader(header); updateShowHideHistoryButtonInGroup(group); } @@ -981,6 +974,7 @@ public class MapMarkersHelper { private long creationDate; private ShowHideHistoryButton showHideHistoryButton; private int color; + private boolean disabled; public String getName() { return name; @@ -1057,6 +1051,14 @@ public class MapMarkersHelper { public void setColor(int color) { this.color = color; } + + public boolean isDisabled() { + return disabled; + } + + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } } public static class ShowHideHistoryButton { @@ -1081,35 +1083,8 @@ public class MapMarkersHelper { } public static class GroupHeader { - private String groupName; - private int activeMarkersCount; - private int markersCount; private int iconRes; - private int color; - - public String getGroupName() { - return groupName; - } - - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - public int getActiveMarkersCount() { - return activeMarkersCount; - } - - public void setActiveMarkersCount(int activeMarkersCount) { - this.activeMarkersCount = activeMarkersCount; - } - - public int getMarkersCount() { - return markersCount; - } - - public void setMarkersCount(int markersCount) { - this.markersCount = markersCount; - } + private MapMarkersGroup group; public int getIconRes() { return iconRes; @@ -1119,12 +1094,12 @@ public class MapMarkersHelper { this.iconRes = iconRes; } - public int getColor() { - return color; + public MapMarkersGroup getGroup() { + return group; } - public void setColor(int color) { - this.color = color; + public void setGroup(MapMarkersGroup group) { + this.group = group; } } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index f1a1705dad..c8c9d61aee 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -5,6 +5,7 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.CompoundButton; import android.widget.ImageView; import net.osmand.data.LatLon; @@ -249,13 +250,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter