From 7bca3f285052a95ab8115123e5dfc963e6837932 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 1 Sep 2017 14:48:42 +0300 Subject: [PATCH 1/6] Add creation date to markers; add color to markers from history --- OsmAnd/res/layout/map_marker_item_new.xml | 3 +- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 2 +- .../src/net/osmand/plus/MapMarkersHelper.java | 34 ++- .../src/net/osmand/plus/OsmandSettings.java | 275 ++++++++++++++++-- .../adapters/MapMarkersActiveAdapter.java | 2 + .../adapters/MapMarkersHistoryAdapter.java | 2 + 6 files changed, 281 insertions(+), 37 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index db101331d0..036c88f58e 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -78,7 +78,8 @@ android:text="•" android:textColor="?android:textColorSecondary" android:textSize="@dimen/default_sub_text_size" - android:visibility="gone"/> + android:visibility="gone" + tools:visibility="visible"/> desc = settings.getMapMarkersPointDescriptions(ips.size()); List colors = settings.getMapMarkersColors(ips.size()); List selections = settings.getMapMarkersSelections(ips.size()); + List creationDates = settings.getMapMarkersCreationDates(ips.size()); int colorIndex = 0; for (int i = 0; i < ips.size(); i++) { if (colors.size() > i) { @@ -176,15 +179,21 @@ public class MapMarkersHelper { } MapMarker mapMarker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, - selections.get(i), i); + selections.get(i), creationDates.get(i), i); mapMarkers.add(mapMarker); } ips = settings.getMapMarkersHistoryPoints(); desc = settings.getMapMarkersHistoryPointDescriptions(ips.size()); + colors = settings.getMapMarkersHistoryColors(ips.size()); + creationDates = settings.getMapMarkersHistoryCreationDates(ips.size()); for (int i = 0; i < ips.size(); i++) { + if (colors.size() > i) { + colorIndex = colors.get(i); + } MapMarker mapMarker = new MapMarker(ips.get(i), - PointDescription.deserializeFromString(desc.get(i), ips.get(i)), 0, false, i); + PointDescription.deserializeFromString(desc.get(i), ips.get(i)), + colorIndex, false, creationDates.get(i), i); mapMarker.history = true; mapMarkersHistory.add(mapMarker); } @@ -207,10 +216,10 @@ public class MapMarkersHelper { } if (history) { settings.updateMapMarkerHistory(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), - mapMarker.pointDescription, mapMarker.colorIndex); + mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.creationDate); } else { settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), - mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.selected); + mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.selected, mapMarker.creationDate); } updateMarker(mapMarker); } @@ -376,7 +385,7 @@ public class MapMarkersHelper { public void updateMapMarker(MapMarker marker, boolean refresh) { if (marker != null) { settings.updateMapMarker(marker.getLatitude(), marker.getLongitude(), - marker.pointDescription, marker.colorIndex, marker.selected); + marker.pointDescription, marker.colorIndex, marker.selected, marker.creationDate); if (refresh) { readFromSettings(); refresh(); @@ -387,7 +396,7 @@ public class MapMarkersHelper { public void moveMapMarker(@Nullable MapMarker marker, LatLon latLon) { if (marker != null) { settings.moveMapMarker(new LatLon(marker.getLatitude(), marker.getLongitude()), latLon, - marker.pointDescription, marker.colorIndex, marker.selected); + marker.pointDescription, marker.colorIndex, marker.selected, marker.creationDate); marker.point = new LatLon(latLon.getLatitude(), latLon.getLongitude()); readFromSettings(); refresh(); @@ -404,7 +413,8 @@ public class MapMarkersHelper { public void addMapMarkerHistory(MapMarker marker) { if (marker != null) { - settings.insertMapMarkerHistory(marker.getLatitude(), marker.getLongitude(), marker.pointDescription, marker.colorIndex, 0); + settings.insertMapMarkerHistory(marker.getLatitude(), marker.getLongitude(), + marker.pointDescription, marker.colorIndex, marker.creationDate, 0); readFromSettings(); refresh(); } @@ -424,25 +434,29 @@ public class MapMarkersHelper { List names = new ArrayList<>(markers.size()); List colors = new ArrayList<>(markers.size()); List selections = new ArrayList<>(markers.size()); + List creationDates = new ArrayList<>(markers.size()); for (MapMarker marker : markers) { ls.add(marker.point); names.add(PointDescription.serializeToString(marker.pointDescription)); colors.add(marker.colorIndex); selections.add(marker.selected); + creationDates.add(marker.creationDate); } - settings.saveMapMarkers(ls, names, colors, selections); + settings.saveMapMarkers(ls, names, colors, selections, creationDates); } if (markersHistory != null) { List ls = new ArrayList<>(markersHistory.size()); List names = new ArrayList<>(markersHistory.size()); List colors = new ArrayList<>(markersHistory.size()); + List creationDates = new ArrayList<>(markersHistory.size()); for (MapMarker marker : markersHistory) { ls.add(marker.point); names.add(PointDescription.serializeToString(marker.pointDescription)); colors.add(marker.colorIndex); + creationDates.add(marker.creationDate); } - settings.saveMapMarkersHistory(ls, names, colors); + settings.saveMapMarkersHistory(ls, names, colors, creationDates); } if (markers != null || markersHistory != null) { diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 8dcec70c60..6d98bfb771 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1783,8 +1783,11 @@ public class OsmandSettings { public final static String MAP_MARKERS_COLOR = "map_markers_color"; //$NON-NLS-1$ public final static String MAP_MARKERS_DESCRIPTION = "map_markers_description"; //$NON-NLS-1$ public final static String MAP_MARKERS_SELECTION = "map_markers_selection"; //$NON-NLS-1$ + public final static String MAP_MARKERS_CREATION_DATE = "map_markers_creation_date"; //$NON-NLS-1$ public final static String MAP_MARKERS_HISTORY_POINT = "map_markers_history_point"; //$NON-NLS-1$ + public final static String MAP_MARKERS_HISTORY_COLOR = "map_markers_history_color"; //$NON-NLS-1$ public final static String MAP_MARKERS_HISTORY_DESCRIPTION = "map_markers_history_description"; //$NON-NLS-1$ + public final static String MAP_MARKERS_HISTORY_CREATION_DATE = "map_markers_history_creation_date"; //$NON-NLS-1$ public final static int MAP_MARKERS_HISTORY_LIMIT = 30; private MapMarkersStorage mapMarkersStorage = new MapMarkersStorage(); private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage(); @@ -1896,6 +1899,7 @@ public class OsmandSettings { .remove(MAP_MARKERS_DESCRIPTION) .remove(MAP_MARKERS_COLOR) .remove(MAP_MARKERS_SELECTION) + .remove(MAP_MARKERS_CREATION_DATE) .commit(); } @@ -1903,6 +1907,8 @@ public class OsmandSettings { return settingsAPI.edit(globalPreferences) .remove(MAP_MARKERS_HISTORY_POINT) .remove(MAP_MARKERS_HISTORY_DESCRIPTION) + .remove(MAP_MARKERS_HISTORY_COLOR) + .remove(MAP_MARKERS_HISTORY_CREATION_DATE) .commit(); } @@ -1927,18 +1933,175 @@ public class OsmandSettings { private class MapMarkersHistoryStorage extends MapPointsStorage { + protected String colorsKey; + protected String creationDatesKey; + public MapMarkersHistoryStorage() { pointsKey = MAP_MARKERS_HISTORY_POINT; descriptionsKey = MAP_MARKERS_HISTORY_DESCRIPTION; + colorsKey = MAP_MARKERS_HISTORY_COLOR; + creationDatesKey = MAP_MARKERS_HISTORY_CREATION_DATE; + } + + public List getColors(int sz) { + List list = new ArrayList<>(); + String ip = settingsAPI.getString(globalPreferences, colorsKey, ""); + if (ip.trim().length() > 0) { + StringTokenizer tok = new StringTokenizer(ip, ","); + while (tok.hasMoreTokens()) { + String colorStr = tok.nextToken(); + list.add(Integer.parseInt(colorStr)); + } + } + while (list.size() > sz) { + list.remove(list.size() - 1); + } + int i = 0; + while (list.size() < sz) { + list.add(i % MapMarkersHelper.MAP_MARKERS_COLORS_COUNT); + i++; + } + return list; + } + + public List getCreationDates(int sz) { + List list = new ArrayList<>(); + String ip = settingsAPI.getString(globalPreferences, creationDatesKey, ""); + if (ip.trim().length() > 0) { + StringTokenizer tok = new StringTokenizer(ip, ","); + while (tok.hasMoreTokens()) { + String creationDateStr = tok.nextToken(); + list.add(Long.parseLong(creationDateStr)); + } + } + while (list.size() > sz) { + list.remove(list.size() - 1); + } + while (list.size() < sz) { + list.add(0L); + } + return list; + } + + public boolean savePoints(List ps, List ds, List cs, List cds) { + while (ps.size() > MAP_MARKERS_HISTORY_LIMIT) { + ps.remove(ps.size() - 1); + ds.remove(ds.size() - 1); + cs.remove(cs.size() - 1); + cds.remove(cds.size() - 1); + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < ps.size(); i++) { + if (i > 0) { + sb.append(","); + } + sb.append(((float) ps.get(i).getLatitude() + "")).append(",").append(((float) ps.get(i).getLongitude() + "")); + } + StringBuilder tb = new StringBuilder(); + for (int i = 0; i < ds.size(); i++) { + if (i > 0) { + tb.append("--"); + } + if (ds.get(i) == null) { + tb.append(""); + } else { + tb.append(ds.get(i)); + } + } + StringBuilder cb = new StringBuilder(); + for (int i = 0; i < cs.size(); i++) { + if (i > 0) { + cb.append(","); + } + cb.append(Integer.toString(cs.get(i))); + } + StringBuilder cdb = new StringBuilder(); + if (cds != null) { + for (int i = 0; i < cds.size(); i++) { + if (i > 0) { + cdb.append(","); + } + cdb.append(Long.toString(cds.get(i))); + } + } + return settingsAPI.edit(globalPreferences) + .putString(pointsKey, sb.toString()) + .putString(descriptionsKey, tb.toString()) + .putString(colorsKey, cb.toString()) + .putString(creationDatesKey, cdb.toString()) + .commit(); + } + + public boolean insertPoint(double latitude, double longitude, + PointDescription historyDescription, int colorIndex, + long creationDate, int index) { + List ps = getPoints(); + List ds = getPointDescriptions(ps.size()); + List cs = getColors(ps.size()); + List cds = getCreationDates(ps.size()); + ps.add(index, new LatLon(latitude, longitude)); + ds.add(index, PointDescription.serializeToString(historyDescription)); + cs.add(index, colorIndex); + cds.add(index, creationDate); + if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { + SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); + } + return savePoints(ps, ds, cs, cds); + } + + public boolean updatePoint(double latitude, double longitude, + PointDescription historyDescription, int colorIndex, + long creationDate) { + List ps = getPoints(); + List ds = getPointDescriptions(ps.size()); + List cs = getColors(ps.size()); + List cds = getCreationDates(ps.size()); + int index = ps.indexOf(new LatLon(latitude, longitude)); + if (index != -1) { + ds.set(index, PointDescription.serializeToString(historyDescription)); + if (cs.size() > index) { + cs.set(index, colorIndex); + } + if (cds.size() > index) { + cds.set(index, creationDate); + } + if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { + SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); + } + return savePoints(ps, ds, cs, cds); + } else { + return false; + } + } + + @Override + public boolean deletePoint(int index) { + List ps = getPoints(); + List ds = getPointDescriptions(ps.size()); + List cs = getColors(ps.size()); + List cds = getCreationDates(ps.size()); + ps.remove(index); + ds.remove(index); + cds.remove(index); + if (cs.size() > index) { + cs.remove(index); + } + return savePoints(ps, ds, cs, cds); } @Override public boolean savePoints(List ps, List ds) { - while (ps.size() > MAP_MARKERS_HISTORY_LIMIT) { - ps.remove(ps.size() - 1); - ds.remove(ds.size() - 1); - } - return super.savePoints(ps, ds); + return false; + } + + @Override + public boolean insertPoint(double latitude, double longitude, PointDescription historyDescription, int index) { + return false; + } + + @Override + public boolean updatePoint(double latitude, double longitude, PointDescription historyDescription) { + return false; } } @@ -1946,12 +2109,14 @@ public class OsmandSettings { protected String colorsKey; protected String selectionKey; + protected String creationDatesKey; public MapMarkersStorage() { pointsKey = MAP_MARKERS_POINT; descriptionsKey = MAP_MARKERS_DESCRIPTION; colorsKey = MAP_MARKERS_COLOR; selectionKey = MAP_MARKERS_SELECTION; + creationDatesKey = MAP_MARKERS_CREATION_DATE; } public List getColors(int sz) { @@ -1994,6 +2159,25 @@ public class OsmandSettings { return list; } + public List getCreationDates(int sz) { + List list = new ArrayList<>(); + String ip = settingsAPI.getString(globalPreferences, creationDatesKey, ""); + if (ip.trim().length() > 0) { + StringTokenizer tok = new StringTokenizer(ip, ","); + while (tok.hasMoreTokens()) { + String creationDateStr = tok.nextToken(); + list.add(Long.parseLong(creationDateStr)); + } + } + while (list.size() > sz) { + list.remove(list.size() - 1); + } + while (list.size() < sz) { + list.add(0L); + } + return list; + } + public boolean insertPoint(double latitude, double longitude, PointDescription historyDescription, int colorIndex, int pos, boolean selected, int index) { @@ -2001,14 +2185,16 @@ public class OsmandSettings { List ds = getPointDescriptions(ps.size()); List cs = getColors(ps.size()); List bs = getSelections(ps.size()); + List cds = getCreationDates(ps.size()); ps.add(index, new LatLon(latitude, longitude)); ds.add(index, PointDescription.serializeToString(historyDescription)); cs.add(index, colorIndex); bs.add(index, selected); + cds.add(index, System.currentTimeMillis()); if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); } - return savePoints(ps, ds, cs, bs); + return savePoints(ps, ds, cs, bs, cds); } public boolean insertPoints(double[] latitudes, double[] longitudes, @@ -2018,6 +2204,7 @@ public class OsmandSettings { List ds = getPointDescriptions(ps.size()); List cs = getColors(ps.size()); List bs = getSelections(ps.size()); + List cds = getCreationDates(ps.size()); for (int i = 0; i < latitudes.length; i++) { double latitude = latitudes[i]; double longitude = longitudes[i]; @@ -2029,20 +2216,22 @@ public class OsmandSettings { ds.add(index, PointDescription.serializeToString(historyDescription)); cs.add(index, colorIndex); bs.add(index, selected); + cds.add(index, System.currentTimeMillis()); if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); } } - return savePoints(ps, ds, cs, bs); + return savePoints(ps, ds, cs, bs, cds); } public boolean updatePoint(double latitude, double longitude, PointDescription historyDescription, int colorIndex, - boolean selected) { + boolean selected, long creationDate) { List ps = getPoints(); List ds = getPointDescriptions(ps.size()); List cs = getColors(ps.size()); List bs = getSelections(ps.size()); + List cds = getCreationDates(ps.size()); int index = ps.indexOf(new LatLon(latitude, longitude)); if (index != -1) { ds.set(index, PointDescription.serializeToString(historyDescription)); @@ -2052,10 +2241,13 @@ public class OsmandSettings { if (bs.size() > index) { bs.set(index, selected); } + if (cds.size() > index) { + cds.set(index, creationDate); + } if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); } - return savePoints(ps, ds, cs, bs); + return savePoints(ps, ds, cs, bs, cds); } else { return false; } @@ -2065,11 +2257,13 @@ public class OsmandSettings { LatLon latLonNew, PointDescription historyDescription, int colorIndex, - boolean selected) { + boolean selected, + long creationDate) { List ps = getPoints(); List ds = getPointDescriptions(ps.size()); List cs = getColors(ps.size()); List bs = getSelections(ps.size()); + List cds = getCreationDates(ps.size()); int index = ps.indexOf(latLonEx); if (index != -1) { if (ps.size() > index) { @@ -2082,12 +2276,15 @@ public class OsmandSettings { if (bs.size() > index) { bs.set(index, selected); } + if (cds.size() > index) { + cds.set(index, creationDate); + } if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { double lat = latLonNew.getLatitude(); double lon = latLonNew.getLongitude(); SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(lat, lon, historyDescription); } - return savePoints(ps, ds, cs, bs); + return savePoints(ps, ds, cs, bs, cds); } else { return false; } @@ -2099,19 +2296,21 @@ public class OsmandSettings { List ds = getPointDescriptions(ps.size()); List cs = getColors(ps.size()); List bs = getSelections(ps.size()); + List cds = getCreationDates(ps.size()); ps.remove(index); ds.remove(index); + cds.remove(index); if (cs.size() > index) { cs.remove(index); } if (bs.size() > index) { bs.remove(index); } - return savePoints(ps, ds, cs, bs); + return savePoints(ps, ds, cs, bs, cds); } public boolean savePoints(List ps, List ds, List cs, - List bs) { + List bs, List cds) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < ps.size(); i++) { if (i > 0) { @@ -2146,11 +2345,21 @@ public class OsmandSettings { bb.append(Boolean.toString(bs.get(i))); } } + StringBuilder cdb = new StringBuilder(); + if (cds != null) { + for (int i = 0; i < cds.size(); i++) { + if (i > 0) { + cdb.append(","); + } + cdb.append(Long.toString(cds.get(i))); + } + } return settingsAPI.edit(globalPreferences) .putString(pointsKey, sb.toString()) .putString(descriptionsKey, tb.toString()) .putString(colorsKey, cb.toString()) .putString(selectionKey, bb.toString()) + .putString(creationDatesKey, cdb.toString()) .commit(); } @@ -2344,6 +2553,10 @@ public class OsmandSettings { return mapMarkersStorage.getSelections(sz); } + public List getMapMarkersCreationDates(int sz) { + return mapMarkersStorage.getCreationDates(sz); + } + public List getMapMarkersPoints() { return mapMarkersStorage.getPoints(); } @@ -2363,24 +2576,27 @@ public class OsmandSettings { } public boolean updateMapMarker(double latitude, double longitude, - PointDescription historyDescription, int colorIndex, boolean selected) { - return mapMarkersStorage.updatePoint(latitude, longitude, historyDescription, colorIndex, selected); + PointDescription historyDescription, int colorIndex, boolean selected, + long creationDate) { + return mapMarkersStorage.updatePoint(latitude, longitude, historyDescription, colorIndex, selected, creationDate); } public boolean moveMapMarker(LatLon latLonEx, LatLon latLonNew, PointDescription historyDescription, int colorIndex, - boolean selected) { - return mapMarkersStorage.movePoint(latLonEx, latLonNew, historyDescription, colorIndex, selected); + boolean selected, + long creationDate) { + return mapMarkersStorage.movePoint(latLonEx, latLonNew, historyDescription, colorIndex, selected, creationDate); } public boolean deleteMapMarker(int index) { return mapMarkersStorage.deletePoint(index); } - public boolean saveMapMarkers(List ps, List ds, List cs, List bs) { - return mapMarkersStorage.savePoints(ps, ds, cs, bs); + public boolean saveMapMarkers(List ps, List ds, List cs, List bs, + List cds) { + return mapMarkersStorage.savePoints(ps, ds, cs, bs, cds); } @@ -2392,22 +2608,31 @@ public class OsmandSettings { return mapMarkersHistoryStorage.getPoints(); } + public List getMapMarkersHistoryCreationDates(int sz) { + return mapMarkersHistoryStorage.getCreationDates(sz); + } + + public List getMapMarkersHistoryColors(int sz) { + return mapMarkersHistoryStorage.getColors(sz); + } + public boolean insertMapMarkerHistory(double latitude, double longitude, - PointDescription historyDescription, int colorIndex, int index) { - return mapMarkersHistoryStorage.insertPoint(latitude, longitude, historyDescription, index); + PointDescription historyDescription, int colorIndex, + long creationDate, int index) { + return mapMarkersHistoryStorage.insertPoint(latitude, longitude, historyDescription, colorIndex, creationDate, index); } public boolean updateMapMarkerHistory(double latitude, double longitude, - PointDescription historyDescription, int colorIndex) { - return mapMarkersHistoryStorage.updatePoint(latitude, longitude, historyDescription); + PointDescription historyDescription, int colorIndex, long creationDate) { + return mapMarkersHistoryStorage.updatePoint(latitude, longitude, historyDescription, colorIndex, creationDate); } public boolean deleteMapMarkerHistory(int index) { return mapMarkersHistoryStorage.deletePoint(index); } - public boolean saveMapMarkersHistory(List ps, List ds, List cs) { - return mapMarkersHistoryStorage.savePoints(ps, ds); + public boolean saveMapMarkersHistory(List ps, List ds, List cs, List cds) { + return mapMarkersHistoryStorage.savePoints(ps, ds, cs, cds); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 83014d6132..8888476f7f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -87,6 +87,8 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Fri, 1 Sep 2017 17:07:52 +0300 Subject: [PATCH 2/6] Add possibility to move marker to history; add small changes --- OsmAnd/res/layout/map_marker_item_new.xml | 8 ++++---- .../plus/mapmarkers/MapMarkersActiveFragment.java | 6 ++++++ .../plus/mapmarkers/MapMarkersDialogFragment.java | 6 ++++++ .../plus/mapmarkers/MapMarkersHistoryFragment.java | 11 ++++++++++- .../mapmarkers/adapters/MapMarkerItemViewHolder.java | 4 ++-- .../mapmarkers/adapters/MapMarkersActiveAdapter.java | 12 ++++++++++++ .../adapters/MapMarkersHistoryAdapter.java | 2 -- 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 036c88f58e..7ae162e70d 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -102,12 +102,12 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|end" - android:layout_marginBottom="16dp" - android:layout_marginLeft="14dp" - android:layout_marginRight="14dp" - android:layout_marginTop="16dp" android:background="?attr/selectableItemBackground" android:focusableInTouchMode="true" + android:paddingBottom="16dp" + android:paddingLeft="14dp" + android:paddingRight="14dp" + android:paddingTop="16dp" tools:src="@drawable/ic_overflow_menu_white"/> diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index e6cb7502e1..3b2fb3d96d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -121,6 +121,12 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL return null; } + void updateAdapter() { + if (adapter != null) { + adapter.notifyDataSetChanged(); + } + } + private void updateLocationUi() { final MapActivity mapActivity = (MapActivity) getActivity(); if (mapActivity != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 0bdc11b5fb..99c05a9550 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -78,11 +78,17 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm switch (menuItem.getItemId()) { case R.id.action_active: ((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate(); + if (viewPager.getCurrentItem() != 0) { + ((MapMarkersActiveFragment) adapter.getItem(0)).updateAdapter(); + } viewPager.setCurrentItem(0); optionsButton.setVisibility(View.VISIBLE); return true; case R.id.action_history: ((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate(); + if (viewPager.getCurrentItem() != 1) { + ((MapMarkersHistoryFragment) adapter.getItem(1)).updateAdapter(); + } viewPager.setCurrentItem(1); optionsButton.setVisibility(View.GONE); return true; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index b84d42ba86..cb81e08396 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -14,6 +14,8 @@ import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter; public class MapMarkersHistoryFragment extends Fragment { + MapMarkersHistoryAdapter adapter; + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -21,8 +23,15 @@ public class MapMarkersHistoryFragment extends Fragment { recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); final MapActivity mapActivity = (MapActivity) getActivity(); - recyclerView.setAdapter(new MapMarkersHistoryAdapter(mapActivity.getMyApplication())); + adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication()); + recyclerView.setAdapter(adapter); return recyclerView; } + + void updateAdapter() { + if (adapter != null) { + adapter.notifyDataSetChanged(); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java index 8775a599f9..d3042e2090 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java @@ -17,7 +17,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { final TextView distance; final TextView point; final TextView description; - final ImageButton options; + final ImageButton optionsBtn; public MapMarkerItemViewHolder(View view) { super(view); @@ -28,6 +28,6 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { distance = (TextView) view.findViewById(R.id.map_marker_distance); point = (TextView) view.findViewById(R.id.map_marker_point_text_view); description = (TextView) view.findViewById(R.id.map_marker_description); - options = (ImageButton) view.findViewById(R.id.map_marker_options_button); + optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 8888476f7f..bf8e7d3f76 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -89,6 +89,18 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Fri, 1 Sep 2017 17:33:23 +0300 Subject: [PATCH 3/6] Show marker on map after click on history map markers list item --- .../mapmarkers/MapMarkersHistoryFragment.java | 15 ++++++++++++++ .../adapters/MapMarkersHistoryAdapter.java | 20 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index cb81e08396..f5ef8026e3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -2,6 +2,7 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -9,6 +10,8 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import net.osmand.data.PointDescription; +import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter; @@ -24,6 +27,18 @@ public class MapMarkersHistoryFragment extends Fragment { final MapActivity mapActivity = (MapActivity) getActivity(); adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication()); + adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() { + @Override + public void onItemClick(View view) { + int pos = recyclerView.indexOfChild(view); + MapMarker marker = adapter.getItem(pos); + mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), + 15, new PointDescription(PointDescription.POINT_TYPE_LOCATION, marker.getPointDescription(mapActivity).getName()), + false, null); + MapActivity.launchMapActivityMoveToTop(mapActivity); + ((DialogFragment) getParentFragment()).dismiss(); + } + }); recyclerView.setAdapter(adapter); return recyclerView; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index ee9b3bdd86..2a0f8816d1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -16,15 +16,26 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter markers; + private MapMarkersHistoryAdapterListener listener; public MapMarkersHistoryAdapter(OsmandApplication app) { this.app = app; markers = app.getMapMarkersHelper().getMapMarkersHistory(); } + public void setAdapterListener(MapMarkersHistoryAdapterListener listener) { + this.listener = listener; + } + @Override public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false); + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + listener.onItemClick(view); + } + }); return new MapMarkerItemViewHolder(view); } @@ -45,4 +56,13 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter Date: Fri, 1 Sep 2017 18:23:56 +0300 Subject: [PATCH 4/6] Add possibility to restore marker from history --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 6 ++++++ OsmAnd/src/net/osmand/plus/OsmandSettings.java | 12 ++++++------ .../adapters/MapMarkersHistoryAdapter.java | 14 +++++++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 25632fd823..ff4fab8f71 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -321,6 +321,12 @@ public class MapMarkersHelper { refresh(); } + public void addMapMarker(MapMarker marker) { + settings.insertMapMarker(marker.getLatitude(), marker.getLongitude(), marker.pointDescription, + marker.colorIndex, marker.selected, marker.creationDate, 0); + readFromSettings(); + } + public void addMapMarker(LatLon point, PointDescription historyName) { List points = new ArrayList<>(1); List historyNames = new ArrayList<>(1); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 6d98bfb771..f2f6b625a2 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -2179,8 +2179,8 @@ public class OsmandSettings { } public boolean insertPoint(double latitude, double longitude, - PointDescription historyDescription, int colorIndex, int pos, - boolean selected, int index) { + PointDescription historyDescription, int colorIndex, + boolean selected, long creationDate, int index) { List ps = getPoints(); List ds = getPointDescriptions(ps.size()); List cs = getColors(ps.size()); @@ -2190,7 +2190,7 @@ public class OsmandSettings { ds.add(index, PointDescription.serializeToString(historyDescription)); cs.add(index, colorIndex); bs.add(index, selected); - cds.add(index, System.currentTimeMillis()); + cds.add(index, creationDate == 0 ? System.currentTimeMillis() : creationDate); if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); } @@ -2562,10 +2562,10 @@ public class OsmandSettings { } public boolean insertMapMarker(double latitude, double longitude, - PointDescription historyDescription, int colorIndex, int pos, - boolean selected, int index) { + PointDescription historyDescription, int colorIndex, + boolean selected, long creationDate, int index) { return mapMarkersStorage.insertPoint(latitude, longitude, historyDescription, colorIndex, - index, selected, pos); + selected, creationDate, index); } public boolean insertMapMarkers(double[] latitudes, double[] longitudes, diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index 2a0f8816d1..90b1a4abb4 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -40,7 +40,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter Date: Fri, 1 Sep 2017 19:05:48 +0300 Subject: [PATCH 5/6] Undo for removing active marker in progress --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 4 ++-- .../adapters/MapMarkersActiveAdapter.java | 16 ++++++++++++++-- .../adapters/MapMarkersHistoryAdapter.java | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index ff4fab8f71..5b58d6e20e 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -321,9 +321,9 @@ public class MapMarkersHelper { refresh(); } - public void addMapMarker(MapMarker marker) { + public void addMapMarker(MapMarker marker, int index) { settings.insertMapMarker(marker.getLatitude(), marker.getLongitude(), marker.pointDescription, - marker.colorIndex, marker.selected, marker.creationDate, 0); + marker.colorIndex, marker.selected, marker.creationDate, index); readFromSettings(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index bf8e7d3f76..972996a1b1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -1,5 +1,6 @@ package net.osmand.plus.mapmarkers.adapters; +import android.support.design.widget.Snackbar; import android.support.v4.view.MotionEventCompat; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -93,8 +94,19 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Mon, 4 Sep 2017 10:47:12 +0300 Subject: [PATCH 6/6] Finish undo for active markers --- .../adapters/MapMarkersActiveAdapter.java | 21 ++++++++++++++----- .../adapters/MapMarkersHistoryAdapter.java | 3 +++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 972996a1b1..20cfc06e1a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -95,21 +95,32 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter