From a574a66ea8cb50ecd8315f96ac6486f6c167d12b Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 19 Sep 2017 18:40:53 +0300 Subject: [PATCH] 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