From c1365ddd114f35a04bdc5b98a5fea253901b4c20 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 1 Sep 2017 18:57:36 +0300 Subject: [PATCH 001/128] Add setting for speed --- OsmAnd/res/values/strings.xml | 2 + OsmAnd/res/xml/navigation_settings.xml | 133 +++++++++++------- .../src/net/osmand/plus/OsmandSettings.java | 3 + .../SettingsNavigationActivity.java | 2 + .../plus/base/MapViewTrackingUtilities.java | 25 +++- 5 files changed, 110 insertions(+), 55 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index f37e4d2c66..723210c7c8 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 --> + Speed for map to direction of movement + Specify speed when map should rotate to direction of movement instead of compass Move all to history Build route Show direction diff --git a/OsmAnd/res/xml/navigation_settings.xml b/OsmAnd/res/xml/navigation_settings.xml index 5463abb74c..e612541541 100644 --- a/OsmAnd/res/xml/navigation_settings.xml +++ b/OsmAnd/res/xml/navigation_settings.xml @@ -1,55 +1,92 @@ - + - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 8dcec70c60..e5d75dfccc 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -855,6 +855,9 @@ public class OsmandSettings { public final OsmandPreference SPEED_LIMIT_EXCEED = new FloatPreference("speed_limit_exceed", 5f).makeProfile(); + public final OsmandPreference SWITCH_TO_MAP_DIRECTION = + new FloatPreference("speed_for_map_to_direction_of_movement", 5f).makeProfile(); + // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference USE_TRACKBALL_FOR_MOVEMENTS = new BooleanPreference("use_trackball_for_movements", true).makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index eda15c2989..631977c461 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -202,12 +202,14 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { speedNames[i] = speedLimitsKm[i] + " " + getString(R.string.km_h); } registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm); + registerListPreference(settings.SWITCH_TO_MAP_DIRECTION, screen, speedNames, speedLimitsKm); } else { String[] speedNames = new String[speedLimitsKm.length]; for (int i =0; i 1) { mapView.setRotate(-val); } @@ -201,13 +203,17 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc zoom = autozoom(location); } int currentMapRotation = settings.ROTATE_MAP.get(); + float speedForDirectionOfMovement = settings.SWITCH_TO_MAP_DIRECTION.get(); + boolean smallSpeedForDirectionOfMovement = speedForDirectionOfMovement != 0 && isSmallSpeedForDirectionOfMovement(location, speedForDirectionOfMovement); boolean smallSpeedForCompass = isSmallSpeedForCompass(location); boolean smallSpeedForAnimation = isSmallSpeedForAnimation(location); // boolean virtualBearing = fMode && settings.SNAP_TO_ROAD.get(); showViewAngle = (!location.hasBearing() || smallSpeedForCompass) && (tb != null && tb.containsLatLon(location.getLatitude(), location.getLongitude())); if (currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING) { - if (location.hasBearing() && !smallSpeedForCompass) { + if (smallSpeedForDirectionOfMovement) { + showViewAngle = routePlanningMode; + } else if (location.hasBearing() && !smallSpeedForCompass) { // special case when bearing equals to zero (we don't change anything) if (location.getBearing() != 0f) { rotation = -location.getBearing(); @@ -216,7 +222,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc } else if(currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS) { showViewAngle = routePlanningMode; // disable compass rotation in that mode } - registerUnregisterSensor(location); + registerUnregisterSensor(location, smallSpeedForDirectionOfMovement); if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation && !movingToMyLocation && settings.WAKE_ON_VOICE_INT.get() == 0) { mapView.getAnimatedDraggingThread().startMoving( @@ -233,7 +239,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc } else if(location != null) { showViewAngle = (!location.hasBearing() || isSmallSpeedForCompass(location)) && (tb != null && tb.containsLatLon(location.getLatitude(), location.getLongitude())); - registerUnregisterSensor(location); + registerUnregisterSensor(location, false); } RoutingHelper routingHelper = app.getRoutingHelper(); followingMode = routingHelper.isFollowingMode(); @@ -252,6 +258,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc } } + public static boolean isSmallSpeedForDirectionOfMovement(Location location, float speedToDirectionOfMovement) { + return !location.hasSpeed() || location.getSpeed() < speedToDirectionOfMovement; + } + public static boolean isSmallSpeedForCompass(Location location) { return !location.hasSpeed() || location.getSpeed() < 0.5; } @@ -285,14 +295,15 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc && !settings.CENTER_POSITION_ON_MAP.get() ? OsmandSettings.BOTTOM_CONSTANT : OsmandSettings.CENTER_CONSTANT); } - registerUnregisterSensor(app.getLocationProvider().getLastKnownLocation()); + registerUnregisterSensor(app.getLocationProvider().getLastKnownLocation(), false); } - private void registerUnregisterSensor(net.osmand.Location location) { + private void registerUnregisterSensor(net.osmand.Location location, boolean smallSpeedForDirectionOfMovement) { int currentMapRotation = settings.ROTATE_MAP.get(); boolean registerCompassListener = ((showViewAngle || contextMenu != null) && location != null) - || (currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS && !routePlanningMode); + || (currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS && !routePlanningMode) + || (currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING && smallSpeedForDirectionOfMovement); // show point view only if gps enabled if(sensorRegistered != registerCompassListener) { app.getLocationProvider().registerOrUnregisterCompassListener(registerCompassListener); From d64627da07c2a1e165d41b03af47c4570a2952ab Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 4 Sep 2017 10:00:33 +0300 Subject: [PATCH 002/128] Make preference disabled by default --- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index e5d75dfccc..cdbf3d0ca2 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -856,7 +856,7 @@ public class OsmandSettings { new FloatPreference("speed_limit_exceed", 5f).makeProfile(); public final OsmandPreference SWITCH_TO_MAP_DIRECTION = - new FloatPreference("speed_for_map_to_direction_of_movement", 5f).makeProfile(); + new FloatPreference("speed_for_map_to_direction_of_movement", 0f).makeProfile(); // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference USE_TRACKBALL_FOR_MOVEMENTS = From 29d0916ec635bbfdc5c05094db57cca71c5edc08 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 4 Sep 2017 15:37:21 +0300 Subject: [PATCH 003/128] Show snackbar above the bottom navigation --- OsmAnd/res/layout/fragment_map_markers_dialog.xml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml index f07f3a3c15..861223957a 100644 --- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -47,10 +47,16 @@ android:layout_height="0dp" android:layout_weight="1"> - + + android:layout_height="wrap_content"> + + + Date: Mon, 4 Sep 2017 19:41:17 +0300 Subject: [PATCH 004/128] Create MapMarkersDbHelper --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 3 +- .../src/net/osmand/plus/MapMarkersHelper.java | 17 +- .../plus/mapmarkers/MapMarkersDbHelper.java | 169 ++++++++++++++++++ 3 files changed, 184 insertions(+), 5 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index cf1a3a30fd..25d340dffa 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -818,7 +818,8 @@ public class OsmandAidlApi { if (m.getOnlyName().equals(markerPrev.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { PointDescription pd = new PointDescription( PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : ""); - MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.creationDate, m.index); + MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, + m.creationDate, m.visitedDate, m.displayPlace, m.index); markersHelper.moveMapMarker(marker, latLonNew); refreshMap(); return true; diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 5b58d6e20e..b78865a949 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -6,6 +6,7 @@ import android.support.annotation.Nullable; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; +import net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace; import net.osmand.util.Algorithms; import java.util.ArrayList; @@ -36,9 +37,17 @@ public class MapMarkersHelper { public boolean selected; public int dist; public long creationDate; + public long visitedDate; + public DisplayPlace displayPlace; + + public enum DisplayPlace { + WIDGET, + TOPBAR + } public MapMarker(LatLon point, PointDescription name, int colorIndex, - boolean selected, long creationDate, int index) { + boolean selected, long creationDate, long visitedDate, + DisplayPlace displayPlace, int index) { this.point = point; this.pointDescription = name; this.colorIndex = colorIndex; @@ -179,7 +188,7 @@ public class MapMarkersHelper { } MapMarker mapMarker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, - selections.get(i), creationDates.get(i), i); + selections.get(i), creationDates.get(i), 0, DisplayPlace.WIDGET, i); mapMarkers.add(mapMarker); } @@ -193,7 +202,7 @@ public class MapMarkersHelper { } MapMarker mapMarker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), - colorIndex, false, creationDates.get(i), i); + colorIndex, false, creationDates.get(i), 0, DisplayPlace.WIDGET, i); mapMarker.history = true; mapMarkersHistory.add(mapMarker); } @@ -305,7 +314,7 @@ public class MapMarkersHelper { public void removeActiveMarkers() { cancelAddressRequests(); - for (int i = mapMarkers.size() - 1; i>= 0; i--) { + for (int i = mapMarkers.size() - 1; i >= 0; i--) { MapMarker marker = mapMarkers.get(i); addMapMarkerHistory(marker); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java new file mode 100644 index 0000000000..8bb21d44ca --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -0,0 +1,169 @@ +package net.osmand.plus.mapmarkers; + +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; +import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; + +import java.util.ArrayList; +import java.util.List; + +import static net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace.TOPBAR; +import static net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace.WIDGET; + +public class MapMarkersDbHelper { + + private static final int DB_VERSION = 1; + private static final String DB_NAME = "map_markers_db"; + + private static final String MARKERS_TABLE_NAME = "map_markers"; + private static final String MARKERS_COL_LAT = "marker_latitude"; + private static final String MARKERS_COL_LON = "marker_longitude"; + private static final String MARKERS_COL_DESCRIPTION = "marker_description"; + private static final String MARKERS_COL_ACTIVE = "marker_active"; + private static final String MARKERS_COL_ADDED = "marker_added"; + private static final String MARKERS_COL_VISITED = "marker_visited"; + private static final String MARKERS_COL_GROUP_KEY = "group_key"; + private static final String MARKERS_COL_COLOR = "marker_color"; + private static final String MARKERS_COL_DISPLAY_PLACE = "marker_display_place"; + private static final String MARKERS_COL_NEXT_KEY = "marker_next_key"; + + private static final String MARKERS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + + MARKERS_TABLE_NAME + " (" + + MARKERS_COL_LAT + " double, " + + MARKERS_COL_LON + " double, " + + MARKERS_COL_DESCRIPTION + " TEXT, " + + MARKERS_COL_ACTIVE + " int default 1, " + // 1 = true, 0 = false + MARKERS_COL_ADDED + " long, " + + MARKERS_COL_VISITED + " long, " + + MARKERS_COL_GROUP_KEY + " int, " + + MARKERS_COL_COLOR + " int, " + + MARKERS_COL_DISPLAY_PLACE + " int, " + + MARKERS_COL_NEXT_KEY + " int);"; + + private static final String MARKERS_TABLE_SELECT = "SELECT " + + MARKERS_COL_LAT + ", " + + MARKERS_COL_LON + ", " + + MARKERS_COL_DESCRIPTION + ", " + + MARKERS_COL_ACTIVE + ", " + + MARKERS_COL_ADDED + ", " + + MARKERS_COL_VISITED + ", " + + MARKERS_COL_GROUP_KEY + ", " + + MARKERS_COL_COLOR + ", " + + MARKERS_COL_DISPLAY_PLACE + ", " + + MARKERS_COL_NEXT_KEY + + " FROM " + MARKERS_TABLE_NAME; + + private static final String GROUPS_TABLE_NAME = "map_markers_groups"; + private static final String GROUPS_COL_NAME = "group_name"; + private static final String GROUPS_COL_TYPE = "group_type"; + private static final String GROUPS_COL_ADDED = "group_added"; + + private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + + GROUPS_TABLE_NAME + " (" + + GROUPS_COL_NAME + " TEXT, " + + GROUPS_COL_TYPE + " TEXT, " + + GROUPS_COL_ADDED + " long);"; + + private OsmandApplication context; + + public MapMarkersDbHelper(OsmandApplication context) { + this.context = context; + } + + private SQLiteConnection openConnection(boolean readonly) { + SQLiteConnection conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly); + int version = conn.getVersion(); + if (version == 0 || DB_VERSION != version) { + if (readonly) { + conn.close(); + conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false); + } + version = conn.getVersion(); + conn.setVersion(DB_VERSION); + if (version == 0) { + onCreate(conn); + } else { + onUpgrade(conn, version, DB_VERSION); + } + } + return conn; + } + + private void onCreate(SQLiteConnection db) { + db.execSQL(MARKERS_TABLE_CREATE); + db.execSQL(GROUPS_TABLE_CREATE); + //todo: load all existing markers + } + + private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) { + + } + + public boolean add(MapMarker marker) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + insert(marker, db); + } finally { + db.close(); + } + return true; + } + return false; + } + + private void insert(MapMarker marker, SQLiteConnection db) { + + } + + public List getMapMarkers() { + return getItems(true); + } + + public List getMapMarkersHistory() { + return getItems(false); + } + + private List getItems(boolean active) { + List result = new ArrayList<>(); + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?", + new String[]{String.valueOf(active ? 1 : 0)}); + if (query.moveToFirst()) { + do { + result.add(readItem(query)); + } while (query.moveToNext()); + } + query.close(); + } finally { + db.close(); + } + } + return result; + } + + private MapMarker readItem(SQLiteCursor query) { + double lat = query.getDouble(0); + double lon = query.getDouble(1); + String desc = query.getString(2); + boolean active = query.getInt(3) == 1; + long added = query.getLong(4); + long visited = query.getLong(5); + int groupKey = query.getInt(6); + int colorIndex = query.getInt(7); + int displayPlace = query.getInt(8); + int nextKey = query.getInt(9); + + LatLon latLon = new LatLon(lat, lon); + MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), + colorIndex, false, added, visited, displayPlace == 0 ? WIDGET : TOPBAR, 0); + marker.history = !active; + + return marker; + } +} From 802dbde613f3b33ed59e910f4e966e01b1f0d297 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 4 Sep 2017 22:58:51 +0300 Subject: [PATCH 005/128] Add some code --- .../src/net/osmand/plus/MapMarkersHelper.java | 2 + .../plus/mapmarkers/MapMarkersDbHelper.java | 68 +++++++++++++------ 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index b78865a949..3afc8d5cc7 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -29,6 +29,7 @@ public class MapMarkersHelper { } public static class MapMarker implements LocationPoint { + public int id; public LatLon point; private PointDescription pointDescription; public int colorIndex; @@ -39,6 +40,7 @@ public class MapMarkersHelper { public long creationDate; public long visitedDate; public DisplayPlace displayPlace; + public int nextKey; public enum DisplayPlace { WIDGET, diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 8bb21d44ca..ea2484fb81 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -1,5 +1,7 @@ package net.osmand.plus.mapmarkers; +import android.util.SparseArray; + import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.MapMarkersHelper.MapMarker; @@ -7,7 +9,6 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; -import java.util.ArrayList; import java.util.List; import static net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace.TOPBAR; @@ -19,6 +20,7 @@ public class MapMarkersDbHelper { private static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; + private static final String MARKERS_COL_ID = "_id"; private static final String MARKERS_COL_LAT = "marker_latitude"; private static final String MARKERS_COL_LON = "marker_longitude"; private static final String MARKERS_COL_DESCRIPTION = "marker_description"; @@ -35,7 +37,7 @@ public class MapMarkersDbHelper { MARKERS_COL_LAT + " double, " + MARKERS_COL_LON + " double, " + MARKERS_COL_DESCRIPTION + " TEXT, " + - MARKERS_COL_ACTIVE + " int default 1, " + // 1 = true, 0 = false + MARKERS_COL_ACTIVE + " int, " + // 1 = true, 0 = false MARKERS_COL_ADDED + " long, " + MARKERS_COL_VISITED + " long, " + MARKERS_COL_GROUP_KEY + " int, " + @@ -44,6 +46,7 @@ public class MapMarkersDbHelper { MARKERS_COL_NEXT_KEY + " int);"; private static final String MARKERS_TABLE_SELECT = "SELECT " + + MARKERS_COL_ID + ", " + MARKERS_COL_LAT + ", " + MARKERS_COL_LON + ", " + MARKERS_COL_DESCRIPTION + ", " + @@ -68,6 +71,8 @@ public class MapMarkersDbHelper { GROUPS_COL_ADDED + " long);"; private OsmandApplication context; + private List mapMarkers; + private List mapMarkersHistory; public MapMarkersDbHelper(OsmandApplication context) { this.context = context; @@ -106,7 +111,7 @@ public class MapMarkersDbHelper { SQLiteConnection db = openConnection(false); if (db != null) { try { - insert(marker, db); + insert(db, marker); } finally { db.close(); } @@ -115,54 +120,73 @@ public class MapMarkersDbHelper { return false; } - private void insert(MapMarker marker, SQLiteConnection db) { + private int insert(SQLiteConnection db, MapMarker marker) { + double lat = marker.getLatitude(); + double lon = marker.getLongitude(); + String descr = marker.getName(context); + int active = marker.history ? 0 : 1; + long added = System.currentTimeMillis(); + long visited = 0; + int groupKey = 0; + int colorIndex = marker.colorIndex; + int displayPlace = marker.displayPlace == WIDGET ? 0 : 1; + int next = marker.nextKey; + db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?", + new Object[]{lat, lon, descr, active, added, visited, groupKey, colorIndex, displayPlace, next == -1 ? null : next}); + return -1; } public List getMapMarkers() { - return getItems(true); + return mapMarkers; } public List getMapMarkersHistory() { - return getItems(false); + return mapMarkersHistory; } - private List getItems(boolean active) { - List result = new ArrayList<>(); + private void loadMapMarkers() { SQLiteConnection db = openConnection(true); + SparseArray markers = new SparseArray<>(); if (db != null) { try { - SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?", - new String[]{String.valueOf(active ? 1 : 0)}); + SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT, null); if (query.moveToFirst()) { do { - result.add(readItem(query)); + MapMarker marker = readItem(query); + markers.put(marker.id, marker); } while (query.moveToNext()); } query.close(); } finally { db.close(); } + for (int i = 0; i < markers.size(); i++) { + int key = markers.keyAt(i); + MapMarker marker = markers.get(key); + } } - return result; } private MapMarker readItem(SQLiteCursor query) { - double lat = query.getDouble(0); - double lon = query.getDouble(1); - String desc = query.getString(2); - boolean active = query.getInt(3) == 1; - long added = query.getLong(4); - long visited = query.getLong(5); - int groupKey = query.getInt(6); - int colorIndex = query.getInt(7); - int displayPlace = query.getInt(8); - int nextKey = query.getInt(9); + int id = query.getInt(0); + double lat = query.getDouble(1); + double lon = query.getDouble(2); + String desc = query.getString(3); + boolean active = query.getInt(4) == 1; + long added = query.getLong(5); + long visited = query.getLong(6); + int groupKey = query.getInt(7); + int colorIndex = query.getInt(8); + int displayPlace = query.getInt(9); + int nextKey = query.getInt(10); LatLon latLon = new LatLon(lat, lon); MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), colorIndex, false, added, visited, displayPlace == 0 ? WIDGET : TOPBAR, 0); marker.history = !active; + marker.nextKey = nextKey; + marker.id = id; return marker; } From bf2a7619fe56577bd27e2aea2d49dc879d83f19f Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 10:20:58 +0300 Subject: [PATCH 006/128] Change id for marker --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 2 +- .../osmand/plus/mapmarkers/MapMarkersDbHelper.java | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 3afc8d5cc7..e2827e0349 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -29,7 +29,7 @@ public class MapMarkersHelper { } public static class MapMarker implements LocationPoint { - public int id; + public long id; public LatLon point; private PointDescription pointDescription; public int colorIndex; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index ea2484fb81..8bd61107f2 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -1,6 +1,6 @@ package net.osmand.plus.mapmarkers; -import android.util.SparseArray; +import android.support.v4.util.LongSparseArray; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -20,7 +20,7 @@ public class MapMarkersDbHelper { private static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; - private static final String MARKERS_COL_ID = "_id"; + private static final String MARKERS_COL_ID = "marker_id"; private static final String MARKERS_COL_LAT = "marker_latitude"; private static final String MARKERS_COL_LON = "marker_longitude"; private static final String MARKERS_COL_DESCRIPTION = "marker_description"; @@ -34,6 +34,7 @@ public class MapMarkersDbHelper { private static final String MARKERS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + MARKERS_TABLE_NAME + " (" + + MARKERS_COL_ID + " long PRIMARY KEY, " + MARKERS_COL_LAT + " double, " + MARKERS_COL_LON + " double, " + MARKERS_COL_DESCRIPTION + " TEXT, " + @@ -147,7 +148,7 @@ public class MapMarkersDbHelper { private void loadMapMarkers() { SQLiteConnection db = openConnection(true); - SparseArray markers = new SparseArray<>(); + LongSparseArray markers = new LongSparseArray<>(); if (db != null) { try { SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT, null); @@ -162,14 +163,14 @@ public class MapMarkersDbHelper { db.close(); } for (int i = 0; i < markers.size(); i++) { - int key = markers.keyAt(i); + long key = markers.keyAt(i); MapMarker marker = markers.get(key); } } } private MapMarker readItem(SQLiteCursor query) { - int id = query.getInt(0); + long id = query.getLong(0); double lat = query.getDouble(1); double lon = query.getDouble(2); String desc = query.getString(3); From f84b94d8da22865450d5b52ecc695a049ef0eafc Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 10:23:24 +0300 Subject: [PATCH 007/128] Change key for next marker --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 2 +- .../src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index e2827e0349..2350fc45f9 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -40,7 +40,7 @@ public class MapMarkersHelper { public long creationDate; public long visitedDate; public DisplayPlace displayPlace; - public int nextKey; + public long nextKey; public enum DisplayPlace { WIDGET, diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 8bd61107f2..5be7441dc8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -44,7 +44,7 @@ public class MapMarkersDbHelper { MARKERS_COL_GROUP_KEY + " int, " + MARKERS_COL_COLOR + " int, " + MARKERS_COL_DISPLAY_PLACE + " int, " + - MARKERS_COL_NEXT_KEY + " int);"; + MARKERS_COL_NEXT_KEY + " long);"; private static final String MARKERS_TABLE_SELECT = "SELECT " + MARKERS_COL_ID + ", " + @@ -131,7 +131,7 @@ public class MapMarkersDbHelper { int groupKey = 0; int colorIndex = marker.colorIndex; int displayPlace = marker.displayPlace == WIDGET ? 0 : 1; - int next = marker.nextKey; + long next = marker.nextKey; db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?", new Object[]{lat, lon, descr, active, added, visited, groupKey, colorIndex, displayPlace, next == -1 ? null : next}); @@ -180,7 +180,7 @@ public class MapMarkersDbHelper { int groupKey = query.getInt(7); int colorIndex = query.getInt(8); int displayPlace = query.getInt(9); - int nextKey = query.getInt(10); + long nextKey = query.getLong(10); LatLon latLon = new LatLon(lat, lon); MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), From 2a6e03f7d7aeb0c2d744f694516efcb1d12ce78a Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 10:59:25 +0300 Subject: [PATCH 008/128] Add some code --- .../plus/mapmarkers/MapMarkersDbHelper.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 5be7441dc8..2074df59de 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -9,6 +9,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; +import java.util.LinkedList; import java.util.List; import static net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace.TOPBAR; @@ -72,8 +73,8 @@ public class MapMarkersDbHelper { GROUPS_COL_ADDED + " long);"; private OsmandApplication context; - private List mapMarkers; - private List mapMarkersHistory; + private List mapMarkers = new LinkedList<>(); + private List mapMarkersHistory = new LinkedList<>(); public MapMarkersDbHelper(OsmandApplication context) { this.context = context; @@ -112,7 +113,7 @@ public class MapMarkersDbHelper { SQLiteConnection db = openConnection(false); if (db != null) { try { - insert(db, marker); + insertLast(db, marker); } finally { db.close(); } @@ -121,21 +122,23 @@ public class MapMarkersDbHelper { return false; } - private int insert(SQLiteConnection db, MapMarker marker) { + private void insertLast(SQLiteConnection db, MapMarker marker) { + long currentTime = System.currentTimeMillis(); + marker.id = currentTime; double lat = marker.getLatitude(); double lon = marker.getLongitude(); - String descr = marker.getName(context); + String descr = marker.getName(context); //fixme int active = marker.history ? 0 : 1; - long added = System.currentTimeMillis(); long visited = 0; int groupKey = 0; int colorIndex = marker.colorIndex; int displayPlace = marker.displayPlace == WIDGET ? 0 : 1; - long next = marker.nextKey; - db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?", - new Object[]{lat, lon, descr, active, added, visited, groupKey, colorIndex, displayPlace, next == -1 ? null : next}); - return -1; + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, null}); + + db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, displayPlace, null}); } public List getMapMarkers() { From b02794fb1b646cab9a5b4865988724e57321ac62 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 13:38:16 +0300 Subject: [PATCH 009/128] Add some code --- .../plus/mapmarkers/MapMarkersDbHelper.java | 95 +++++++++++++++---- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 2074df59de..52bf567f90 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -1,5 +1,6 @@ package net.osmand.plus.mapmarkers; +import android.support.annotation.Nullable; import android.support.v4.util.LongSparseArray; import net.osmand.data.LatLon; @@ -11,6 +12,7 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import java.util.LinkedList; import java.util.List; +import java.util.Random; import static net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace.TOPBAR; import static net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace.WIDGET; @@ -72,9 +74,9 @@ public class MapMarkersDbHelper { GROUPS_COL_TYPE + " TEXT, " + GROUPS_COL_ADDED + " long);"; + private static final long TAIL_NEXT_VALUE = -1; + private OsmandApplication context; - private List mapMarkers = new LinkedList<>(); - private List mapMarkersHistory = new LinkedList<>(); public MapMarkersDbHelper(OsmandApplication context) { this.context = context; @@ -109,7 +111,25 @@ public class MapMarkersDbHelper { } - public boolean add(MapMarker marker) { + public void move(MapMarker moved, @Nullable MapMarker next) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{moved.nextKey, moved.id}); + + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{moved.id, next == null ? TAIL_NEXT_VALUE : next.id}); + + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_ID + " = ?", new Object[]{next == null ? TAIL_NEXT_VALUE : next.id, moved.id}); + } finally { + db.close(); + } + } + } + + public boolean addMapMarker(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -124,7 +144,7 @@ public class MapMarkersDbHelper { private void insertLast(SQLiteConnection db, MapMarker marker) { long currentTime = System.currentTimeMillis(); - marker.id = currentTime; + marker.id = Long.parseLong(String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100)); double lat = marker.getLatitude(); double lon = marker.getLongitude(); String descr = marker.getName(context); //fixme @@ -135,39 +155,76 @@ public class MapMarkersDbHelper { int displayPlace = marker.displayPlace == WIDGET ? 0 : 1; db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, null}); + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, TAIL_NEXT_VALUE}); db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, displayPlace, null}); + new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, displayPlace, TAIL_NEXT_VALUE}); } - public List getMapMarkers() { - return mapMarkers; + public void removeMapMarker(MapMarker marker) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.nextKey, marker.id}); + + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ? " + + "WHERE " + MARKERS_COL_ID + " = ?", new Object[]{0, marker.id}); + } finally { + db.close(); + } + } } public List getMapMarkersHistory() { - return mapMarkersHistory; - } - - private void loadMapMarkers() { + List markers = new LinkedList<>(); SQLiteConnection db = openConnection(true); - LongSparseArray markers = new LongSparseArray<>(); if (db != null) { try { - SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT, null); + SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?", + new String[]{String.valueOf(0)}); if (query.moveToFirst()) { do { - MapMarker marker = readItem(query); - markers.put(marker.id, marker); + markers.add(readItem(query)); } while (query.moveToNext()); } query.close(); } finally { db.close(); } - for (int i = 0; i < markers.size(); i++) { - long key = markers.keyAt(i); - MapMarker marker = markers.get(key); + } + return markers; + } + + public List getMapMarkers() { + List res = new LinkedList<>(); + LongSparseArray markers = new LongSparseArray<>(); + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?", + new String[]{String.valueOf(1)}); + if (query.moveToFirst()) { + do { + MapMarker marker = readItem(query); + markers.put(marker.nextKey, marker); + } while (query.moveToNext()); + } + query.close(); + } finally { + db.close(); + } + buildLinkedList(markers, res, markers.get(TAIL_NEXT_VALUE)); + } + return res; + } + + private void buildLinkedList(LongSparseArray markers, List res, MapMarker marker) { + if (marker != null) { + res.add(0, marker); + MapMarker prev = markers.get(marker.id); + if (prev != null) { + buildLinkedList(markers, res, prev); } } } From 2d7a4ac74fa10b299589ae92f2d726d9da6fd089 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 13:43:49 +0300 Subject: [PATCH 010/128] Reorder methods --- .../plus/mapmarkers/MapMarkersDbHelper.java | 148 +++++++++--------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 52bf567f90..49ae825deb 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -111,24 +111,6 @@ public class MapMarkersDbHelper { } - public void move(MapMarker moved, @Nullable MapMarker next) { - SQLiteConnection db = openConnection(false); - if (db != null) { - try { - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{moved.nextKey, moved.id}); - - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{moved.id, next == null ? TAIL_NEXT_VALUE : next.id}); - - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_ID + " = ?", new Object[]{next == null ? TAIL_NEXT_VALUE : next.id, moved.id}); - } finally { - db.close(); - } - } - } - public boolean addMapMarker(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { @@ -161,6 +143,80 @@ public class MapMarkersDbHelper { new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, displayPlace, TAIL_NEXT_VALUE}); } + public List getMapMarkers() { + List res = new LinkedList<>(); + LongSparseArray markers = new LongSparseArray<>(); + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?", + new String[]{String.valueOf(1)}); + if (query.moveToFirst()) { + do { + MapMarker marker = readItem(query); + markers.put(marker.nextKey, marker); + } while (query.moveToNext()); + } + query.close(); + } finally { + db.close(); + } + buildLinkedList(markers, res, markers.get(TAIL_NEXT_VALUE)); + } + return res; + } + + private MapMarker readItem(SQLiteCursor query) { + long id = query.getLong(0); + double lat = query.getDouble(1); + double lon = query.getDouble(2); + String desc = query.getString(3); + boolean active = query.getInt(4) == 1; + long added = query.getLong(5); + long visited = query.getLong(6); + int groupKey = query.getInt(7); + int colorIndex = query.getInt(8); + int displayPlace = query.getInt(9); + long nextKey = query.getLong(10); + + LatLon latLon = new LatLon(lat, lon); + MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), + colorIndex, false, added, visited, displayPlace == 0 ? WIDGET : TOPBAR, 0); + marker.history = !active; + marker.nextKey = nextKey; + marker.id = id; + + return marker; + } + + private void buildLinkedList(LongSparseArray markers, List res, MapMarker marker) { + if (marker != null) { + res.add(0, marker); + MapMarker prev = markers.get(marker.id); + if (prev != null) { + buildLinkedList(markers, res, prev); + } + } + } + + public void move(MapMarker moved, @Nullable MapMarker next) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{moved.nextKey, moved.id}); + + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{moved.id, next == null ? TAIL_NEXT_VALUE : next.id}); + + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_ID + " = ?", new Object[]{next == null ? TAIL_NEXT_VALUE : next.id, moved.id}); + } finally { + db.close(); + } + } + } + public void removeMapMarker(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { @@ -195,60 +251,4 @@ public class MapMarkersDbHelper { } return markers; } - - public List getMapMarkers() { - List res = new LinkedList<>(); - LongSparseArray markers = new LongSparseArray<>(); - SQLiteConnection db = openConnection(true); - if (db != null) { - try { - SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?", - new String[]{String.valueOf(1)}); - if (query.moveToFirst()) { - do { - MapMarker marker = readItem(query); - markers.put(marker.nextKey, marker); - } while (query.moveToNext()); - } - query.close(); - } finally { - db.close(); - } - buildLinkedList(markers, res, markers.get(TAIL_NEXT_VALUE)); - } - return res; - } - - private void buildLinkedList(LongSparseArray markers, List res, MapMarker marker) { - if (marker != null) { - res.add(0, marker); - MapMarker prev = markers.get(marker.id); - if (prev != null) { - buildLinkedList(markers, res, prev); - } - } - } - - private MapMarker readItem(SQLiteCursor query) { - long id = query.getLong(0); - double lat = query.getDouble(1); - double lon = query.getDouble(2); - String desc = query.getString(3); - boolean active = query.getInt(4) == 1; - long added = query.getLong(5); - long visited = query.getLong(6); - int groupKey = query.getInt(7); - int colorIndex = query.getInt(8); - int displayPlace = query.getInt(9); - long nextKey = query.getLong(10); - - LatLon latLon = new LatLon(lat, lon); - MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), - colorIndex, false, added, visited, displayPlace == 0 ? WIDGET : TOPBAR, 0); - marker.history = !active; - marker.nextKey = nextKey; - marker.id = id; - - return marker; - } } From f53590ef144594c86c5bda97c633fc6e8703f452 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 14:26:31 +0300 Subject: [PATCH 011/128] Add some code --- .../plus/mapmarkers/MapMarkersDbHelper.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 49ae825deb..9521e0dcef 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -199,7 +199,25 @@ public class MapMarkersDbHelper { } } - public void move(MapMarker moved, @Nullable MapMarker next) { + public void updateMapMarker(MapMarker marker) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + + MARKERS_COL_LAT + " = ?, " + + MARKERS_COL_LON + " = ?, " + + MARKERS_COL_DESCRIPTION + " = ?, " + + MARKERS_COL_COLOR + " = ? " + + "WHERE " + MARKERS_COL_ID + " = ?", + new Object[]{marker.getLatitude(), marker.getLongitude(), marker.getName(context), //fixme + marker.colorIndex, marker.id}); + } finally { + db.close(); + } + } + } + + public void moveMapMarker(MapMarker moved, @Nullable MapMarker next) { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -232,6 +250,24 @@ public class MapMarkersDbHelper { } } + public void restoreMarkerFromHistory(MapMarker marker) { + if (!marker.history) { + return; + } + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + + MARKERS_COL_ACTIVE + " = ?, " + + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_ID + " = ?", + new Object[]{1, getMapMarkers().get(0).id, marker.id}); + } finally { + db.close(); + } + } + } + public List getMapMarkersHistory() { List markers = new LinkedList<>(); SQLiteConnection db = openConnection(true); From 0a7e6d0db593be2a732b03478db85f8775d3df1f Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 14:38:57 +0300 Subject: [PATCH 012/128] Add some code --- .../plus/mapmarkers/MapMarkersDbHelper.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 9521e0dcef..f0728bd7a1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -250,7 +250,19 @@ public class MapMarkersDbHelper { } } - public void restoreMarkerFromHistory(MapMarker marker) { + public void removeAllActiveMapMarkers() { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ? " + + "WHERE " + MARKERS_COL_ACTIVE + " = ?", new Object[]{0, 1}); + } finally { + db.close(); + } + } + } + + public void restoreMapMarkerFromHistory(MapMarker marker) { if (!marker.history) { return; } @@ -287,4 +299,31 @@ public class MapMarkersDbHelper { } return markers; } + + public void removeMapMarkerHistory(MapMarker marker) { + if (!marker.history) { + return; + } + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ID + " = ?", + new Object[]{marker.id}); + } finally { + db.close(); + } + } + } + + public void removeAllMapMarkersHistory() { + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ACTIVE + " = ?", + new Object[]{0}); + } finally { + db.close(); + } + } + } } From 2501657467133b3550dc2f9d75c939deeaa2a005 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 15:10:53 +0300 Subject: [PATCH 013/128] Add some code --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 6 +- .../src/net/osmand/plus/MapMarkersHelper.java | 11 ++- .../plus/mapmarkers/MapMarkersDbHelper.java | 68 +++++++++++++++---- 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 25d340dffa..dea6f27adb 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -818,8 +818,10 @@ public class OsmandAidlApi { if (m.getOnlyName().equals(markerPrev.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { PointDescription pd = new PointDescription( PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : ""); - MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, - m.creationDate, m.visitedDate, m.displayPlace, m.index); + MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index); + marker.creationDate = m.creationDate; + marker.visitedDate = m.visitedDate; + marker.displayPlace = m.displayPlace; markersHelper.moveMapMarker(marker, latLonNew); refreshMap(); return true; diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 2350fc45f9..287422681b 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -6,7 +6,6 @@ import android.support.annotation.Nullable; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; -import net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace; import net.osmand.util.Algorithms; import java.util.ArrayList; @@ -48,13 +47,11 @@ public class MapMarkersHelper { } public MapMarker(LatLon point, PointDescription name, int colorIndex, - boolean selected, long creationDate, long visitedDate, - DisplayPlace displayPlace, int index) { + boolean selected, int index) { this.point = point; this.pointDescription = name; this.colorIndex = colorIndex; this.selected = selected; - this.creationDate = creationDate; this.index = index; } @@ -190,7 +187,8 @@ public class MapMarkersHelper { } MapMarker mapMarker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, - selections.get(i), creationDates.get(i), 0, DisplayPlace.WIDGET, i); + selections.get(i), i); + mapMarker.creationDate = creationDates.get(i); mapMarkers.add(mapMarker); } @@ -204,8 +202,9 @@ public class MapMarkersHelper { } MapMarker mapMarker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), - colorIndex, false, creationDates.get(i), 0, DisplayPlace.WIDGET, i); + colorIndex, false, i); mapMarker.history = true; + mapMarker.creationDate = creationDates.get(i); mapMarkersHistory.add(mapMarker); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index f0728bd7a1..a10041f5a8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -7,6 +7,7 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; @@ -74,9 +75,10 @@ public class MapMarkersDbHelper { GROUPS_COL_TYPE + " TEXT, " + GROUPS_COL_ADDED + " long);"; - private static final long TAIL_NEXT_VALUE = -1; + private static final int TAIL_NEXT_VALUE = 0; + private static final int HISTORY_NEXT_VALUE = -1; - private OsmandApplication context; + private final OsmandApplication context; public MapMarkersDbHelper(OsmandApplication context) { this.context = context; @@ -104,14 +106,47 @@ public class MapMarkersDbHelper { private void onCreate(SQLiteConnection db) { db.execSQL(MARKERS_TABLE_CREATE); db.execSQL(GROUPS_TABLE_CREATE); - //todo: load all existing markers + saveExistingMarkersToDb(); } private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) { } - public boolean addMapMarker(MapMarker marker) { + private void saveExistingMarkersToDb() { + OsmandSettings settings = context.getSettings(); + + List ips = settings.getMapMarkersPoints(); + List desc = settings.getMapMarkersPointDescriptions(ips.size()); + List colors = settings.getMapMarkersColors(ips.size()); + int colorIndex = 0; + for (int i = 0; i < ips.size(); i++) { + if (colors.size() > i) { + colorIndex = colors.get(i); + } + MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), + colorIndex, false, i); + marker.history = false; + marker.displayPlace = WIDGET; //fixme + addMapMarker(marker); + } + + ips = settings.getMapMarkersHistoryPoints(); + desc = settings.getMapMarkersHistoryPointDescriptions(ips.size()); + colors = settings.getMapMarkersHistoryColors(ips.size()); + for (int i = 0; i < ips.size(); i++) { + if (colors.size() > i) { + colorIndex = colors.get(i); + } + MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), + colorIndex, false, i); + marker.history = true; + marker.displayPlace = WIDGET; //fixme + addMapMarker(marker); + } + } + + public void addMapMarker(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -119,14 +154,13 @@ public class MapMarkersDbHelper { } finally { db.close(); } - return true; } - return false; } private void insertLast(SQLiteConnection db, MapMarker marker) { long currentTime = System.currentTimeMillis(); marker.id = Long.parseLong(String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100)); + marker.creationDate = currentTime; double lat = marker.getLatitude(); double lon = marker.getLongitude(); String descr = marker.getName(context); //fixme @@ -136,11 +170,14 @@ public class MapMarkersDbHelper { int colorIndex = marker.colorIndex; int displayPlace = marker.displayPlace == WIDGET ? 0 : 1; - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, TAIL_NEXT_VALUE}); + if (!marker.history) { + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, TAIL_NEXT_VALUE}); + } db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, displayPlace, TAIL_NEXT_VALUE}); + new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, displayPlace, + marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE}); } public List getMapMarkers() { @@ -181,7 +218,10 @@ public class MapMarkersDbHelper { LatLon latLon = new LatLon(lat, lon); MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), - colorIndex, false, added, visited, displayPlace == 0 ? WIDGET : TOPBAR, 0); + colorIndex, false, 0); + marker.creationDate = added; + marker.visitedDate = visited; + marker.displayPlace = displayPlace == 0 ? WIDGET : TOPBAR; marker.history = !active; marker.nextKey = nextKey; marker.id = id; @@ -239,11 +279,15 @@ public class MapMarkersDbHelper { SQLiteConnection db = openConnection(false); if (db != null) { try { + marker.visitedDate = System.currentTimeMillis(); + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.nextKey, marker.id}); - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ? " + - "WHERE " + MARKERS_COL_ID + " = ?", new Object[]{0, marker.id}); + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + + MARKERS_COL_ACTIVE + " = ? " + + MARKERS_COL_VISITED + " = ? " + + "WHERE " + MARKERS_COL_ID + " = ?", new Object[]{0, marker.visitedDate, marker.id}); } finally { db.close(); } From c1d0dfb383805b132691b134ae7d26853a3d9e77 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 17:07:45 +0300 Subject: [PATCH 014/128] Fix working with PointDescription --- .../osmand/plus/mapmarkers/MapMarkersDbHelper.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index a10041f5a8..df74c66d3c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -10,6 +10,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; +import net.osmand.plus.helpers.SearchHistoryHelper; import java.util.LinkedList; import java.util.List; @@ -163,13 +164,19 @@ public class MapMarkersDbHelper { marker.creationDate = currentTime; double lat = marker.getLatitude(); double lon = marker.getLongitude(); - String descr = marker.getName(context); //fixme + String descr = PointDescription.serializeToString(marker.getOriginalPointDescription()); int active = marker.history ? 0 : 1; long visited = 0; int groupKey = 0; int colorIndex = marker.colorIndex; int displayPlace = marker.displayPlace == WIDGET ? 0 : 1; + PointDescription pointDescription = marker.getOriginalPointDescription(); + if (pointDescription != null && !pointDescription.isSearchingAddress(context)) { + SearchHistoryHelper.getInstance(context) + .addNewItemToHistory(marker.getLatitude(), marker.getLongitude(), pointDescription); + } + if (!marker.history) { db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, TAIL_NEXT_VALUE}); @@ -243,14 +250,14 @@ public class MapMarkersDbHelper { SQLiteConnection db = openConnection(false); if (db != null) { try { + String descr = PointDescription.serializeToString(marker.getOriginalPointDescription()); db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_LAT + " = ?, " + MARKERS_COL_LON + " = ?, " + MARKERS_COL_DESCRIPTION + " = ?, " + MARKERS_COL_COLOR + " = ? " + "WHERE " + MARKERS_COL_ID + " = ?", - new Object[]{marker.getLatitude(), marker.getLongitude(), marker.getName(context), //fixme - marker.colorIndex, marker.id}); + new Object[]{marker.getLatitude(), marker.getLongitude(), descr, marker.colorIndex, marker.id}); } finally { db.close(); } From c073fc509a52f8d1979ec6f1ff4df3f308118527 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 17:55:43 +0300 Subject: [PATCH 015/128] Remove unnecessary enum --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 8 ++------ .../osmand/plus/mapmarkers/MapMarkersDbHelper.java | 12 ++++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 287422681b..4351ffce3e 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -6,6 +6,7 @@ import android.support.annotation.Nullable; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; +import net.osmand.plus.OsmandSettings.MapMarkersMode; import net.osmand.util.Algorithms; import java.util.ArrayList; @@ -38,14 +39,9 @@ public class MapMarkersHelper { public int dist; public long creationDate; public long visitedDate; - public DisplayPlace displayPlace; + public MapMarkersMode displayPlace; public long nextKey; - public enum DisplayPlace { - WIDGET, - TOPBAR - } - public MapMarker(LatLon point, PointDescription name, int colorIndex, boolean selected, int index) { this.point = point; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index df74c66d3c..1efa9231b5 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -16,8 +16,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Random; -import static net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace.TOPBAR; -import static net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace.WIDGET; +import static net.osmand.plus.OsmandSettings.MapMarkersMode.TOOLBAR; +import static net.osmand.plus.OsmandSettings.MapMarkersMode.WIDGETS; public class MapMarkersDbHelper { @@ -128,7 +128,7 @@ public class MapMarkersDbHelper { MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i); marker.history = false; - marker.displayPlace = WIDGET; //fixme + marker.displayPlace = WIDGETS; //fixme addMapMarker(marker); } @@ -142,7 +142,7 @@ public class MapMarkersDbHelper { MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i); marker.history = true; - marker.displayPlace = WIDGET; //fixme + marker.displayPlace = WIDGETS; //fixme addMapMarker(marker); } } @@ -169,7 +169,7 @@ public class MapMarkersDbHelper { long visited = 0; int groupKey = 0; int colorIndex = marker.colorIndex; - int displayPlace = marker.displayPlace == WIDGET ? 0 : 1; + int displayPlace = marker.displayPlace == WIDGETS ? 0 : 1; PointDescription pointDescription = marker.getOriginalPointDescription(); if (pointDescription != null && !pointDescription.isSearchingAddress(context)) { @@ -228,7 +228,7 @@ public class MapMarkersDbHelper { colorIndex, false, 0); marker.creationDate = added; marker.visitedDate = visited; - marker.displayPlace = displayPlace == 0 ? WIDGET : TOPBAR; + marker.displayPlace = displayPlace == 0 ? WIDGETS : TOOLBAR; marker.history = !active; marker.nextKey = nextKey; marker.id = id; From 38c382eec40888df5284e95147f4f6c1275da37a Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 18:09:26 +0300 Subject: [PATCH 016/128] Remove unnecessary field --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 1 - .../src/net/osmand/plus/MapMarkersHelper.java | 2 -- .../plus/mapmarkers/MapMarkersDbHelper.java | 17 +++-------------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index dea6f27adb..84f64f21dc 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -821,7 +821,6 @@ public class OsmandAidlApi { MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index); marker.creationDate = m.creationDate; marker.visitedDate = m.visitedDate; - marker.displayPlace = m.displayPlace; markersHelper.moveMapMarker(marker, latLonNew); refreshMap(); return true; diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 4351ffce3e..ebf5c04556 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -6,7 +6,6 @@ import android.support.annotation.Nullable; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; -import net.osmand.plus.OsmandSettings.MapMarkersMode; import net.osmand.util.Algorithms; import java.util.ArrayList; @@ -39,7 +38,6 @@ public class MapMarkersHelper { public int dist; public long creationDate; public long visitedDate; - public MapMarkersMode displayPlace; public long nextKey; public MapMarker(LatLon point, PointDescription name, int colorIndex, diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 1efa9231b5..8f008b2d2a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -16,9 +16,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Random; -import static net.osmand.plus.OsmandSettings.MapMarkersMode.TOOLBAR; -import static net.osmand.plus.OsmandSettings.MapMarkersMode.WIDGETS; - public class MapMarkersDbHelper { private static final int DB_VERSION = 1; @@ -34,7 +31,6 @@ public class MapMarkersDbHelper { private static final String MARKERS_COL_VISITED = "marker_visited"; private static final String MARKERS_COL_GROUP_KEY = "group_key"; private static final String MARKERS_COL_COLOR = "marker_color"; - private static final String MARKERS_COL_DISPLAY_PLACE = "marker_display_place"; private static final String MARKERS_COL_NEXT_KEY = "marker_next_key"; private static final String MARKERS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + @@ -48,7 +44,6 @@ public class MapMarkersDbHelper { MARKERS_COL_VISITED + " long, " + MARKERS_COL_GROUP_KEY + " int, " + MARKERS_COL_COLOR + " int, " + - MARKERS_COL_DISPLAY_PLACE + " int, " + MARKERS_COL_NEXT_KEY + " long);"; private static final String MARKERS_TABLE_SELECT = "SELECT " + @@ -61,7 +56,6 @@ public class MapMarkersDbHelper { MARKERS_COL_VISITED + ", " + MARKERS_COL_GROUP_KEY + ", " + MARKERS_COL_COLOR + ", " + - MARKERS_COL_DISPLAY_PLACE + ", " + MARKERS_COL_NEXT_KEY + " FROM " + MARKERS_TABLE_NAME; @@ -128,7 +122,6 @@ public class MapMarkersDbHelper { MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i); marker.history = false; - marker.displayPlace = WIDGETS; //fixme addMapMarker(marker); } @@ -142,7 +135,6 @@ public class MapMarkersDbHelper { MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i); marker.history = true; - marker.displayPlace = WIDGETS; //fixme addMapMarker(marker); } } @@ -169,7 +161,6 @@ public class MapMarkersDbHelper { long visited = 0; int groupKey = 0; int colorIndex = marker.colorIndex; - int displayPlace = marker.displayPlace == WIDGETS ? 0 : 1; PointDescription pointDescription = marker.getOriginalPointDescription(); if (pointDescription != null && !pointDescription.isSearchingAddress(context)) { @@ -182,8 +173,8 @@ public class MapMarkersDbHelper { "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, TAIL_NEXT_VALUE}); } - db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, displayPlace, + db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE}); } @@ -220,15 +211,13 @@ public class MapMarkersDbHelper { long visited = query.getLong(6); int groupKey = query.getInt(7); int colorIndex = query.getInt(8); - int displayPlace = query.getInt(9); - long nextKey = query.getLong(10); + long nextKey = query.getLong(9); LatLon latLon = new LatLon(lat, lon); MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), colorIndex, false, 0); marker.creationDate = added; marker.visitedDate = visited; - marker.displayPlace = displayPlace == 0 ? WIDGETS : TOOLBAR; marker.history = !active; marker.nextKey = nextKey; marker.id = id; From 88e1a1dc4b4e9811164aaec59430f197df11d99a Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 5 Sep 2017 18:30:16 +0300 Subject: [PATCH 017/128] Add MapMarkersDbHelper to OsmandApplication --- OsmAnd/src/net/osmand/plus/AppInitializer.java | 2 ++ OsmAnd/src/net/osmand/plus/OsmandApplication.java | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 48acbed4d9..a26bce255e 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -29,6 +29,7 @@ import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.liveupdates.LiveUpdatesHelper; +import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.monitoring.LiveMonitoringHelper; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.poi.PoiFiltersHelper; @@ -374,6 +375,7 @@ public class AppInitializer implements IProgress { app.geocodingLookupService = startupInit(new GeocodingLookupService(app), GeocodingLookupService.class); app.targetPointsHelper = startupInit(new TargetPointsHelper(app), TargetPointsHelper.class); app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class); + app.mapMarkersDbHelper = startupInit(new MapMarkersDbHelper(app), MapMarkersDbHelper.class); app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class); } diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index ca3046da0a..53b1938ad2 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -47,6 +47,7 @@ import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.inapp.InAppHelper; import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu; +import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.monitoring.LiveMonitoringHelper; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.render.RendererRegistry; @@ -107,6 +108,7 @@ public class OsmandApplication extends MultiDexApplication { LiveMonitoringHelper liveMonitoringHelper; TargetPointsHelper targetPointsHelper; MapMarkersHelper mapMarkersHelper; + MapMarkersDbHelper mapMarkersDbHelper; WaypointHelper waypointHelper; DownloadIndexesThread downloadIndexesThread; AvoidSpecificRoads avoidSpecificRoads; @@ -615,6 +617,10 @@ public class OsmandApplication extends MultiDexApplication { return mapMarkersHelper; } + public MapMarkersDbHelper getMapMarkersDbHelper() { + return mapMarkersDbHelper; + } + public void showShortToastMessage(final int msgId, final Object... args) { uiHandler.post(new Runnable() { @Override From c782b23cb919d73caf0d07126efa970beb7be1b8 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 6 Sep 2017 10:32:00 +0300 Subject: [PATCH 018/128] Reorder initialization --- OsmAnd/src/net/osmand/plus/AppInitializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index a26bce255e..e4d3563ac4 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -374,8 +374,8 @@ public class AppInitializer implements IProgress { app.rendererRegistry = startupInit(new RendererRegistry(app), RendererRegistry.class); app.geocodingLookupService = startupInit(new GeocodingLookupService(app), GeocodingLookupService.class); app.targetPointsHelper = startupInit(new TargetPointsHelper(app), TargetPointsHelper.class); - app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class); app.mapMarkersDbHelper = startupInit(new MapMarkersDbHelper(app), MapMarkersDbHelper.class); + app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class); app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class); } From b4e8e879015a945e251358761ebb9d1754c65244 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 6 Sep 2017 11:38:42 +0300 Subject: [PATCH 019/128] Rename methods --- .../plus/mapmarkers/MapMarkersDbHelper.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 8f008b2d2a..7f05f4e6ac 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -122,7 +122,7 @@ public class MapMarkersDbHelper { MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i); marker.history = false; - addMapMarker(marker); + addMarker(marker); } ips = settings.getMapMarkersHistoryPoints(); @@ -135,11 +135,11 @@ public class MapMarkersDbHelper { MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i); marker.history = true; - addMapMarker(marker); + addMarker(marker); } } - public void addMapMarker(MapMarker marker) { + public void addMarker(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -178,7 +178,7 @@ public class MapMarkersDbHelper { marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE}); } - public List getMapMarkers() { + public List getActiveMarkers() { List res = new LinkedList<>(); LongSparseArray markers = new LongSparseArray<>(); SQLiteConnection db = openConnection(true); @@ -235,7 +235,7 @@ public class MapMarkersDbHelper { } } - public void updateMapMarker(MapMarker marker) { + public void updateMarker(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -253,7 +253,7 @@ public class MapMarkersDbHelper { } } - public void moveMapMarker(MapMarker moved, @Nullable MapMarker next) { + public void changeActiveMarkerPosition(MapMarker moved, @Nullable MapMarker next) { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -271,7 +271,7 @@ public class MapMarkersDbHelper { } } - public void removeMapMarker(MapMarker marker) { + public void moveActiveMarkerToHistory(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -290,7 +290,7 @@ public class MapMarkersDbHelper { } } - public void removeAllActiveMapMarkers() { + public void moveAllActiveMarkersToHistory() { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -313,14 +313,14 @@ public class MapMarkersDbHelper { MARKERS_COL_ACTIVE + " = ?, " + MARKERS_COL_NEXT_KEY + " = ? " + "WHERE " + MARKERS_COL_ID + " = ?", - new Object[]{1, getMapMarkers().get(0).id, marker.id}); + new Object[]{1, getActiveMarkers().get(0).id, marker.id}); } finally { db.close(); } } } - public List getMapMarkersHistory() { + public List getMarkersHistory() { List markers = new LinkedList<>(); SQLiteConnection db = openConnection(true); if (db != null) { @@ -340,7 +340,7 @@ public class MapMarkersDbHelper { return markers; } - public void removeMapMarkerHistory(MapMarker marker) { + public void removeMarkerFromHistory(MapMarker marker) { if (!marker.history) { return; } @@ -355,7 +355,7 @@ public class MapMarkersDbHelper { } } - public void removeAllMapMarkersHistory() { + public void clearAllMarkersHistory() { SQLiteConnection db = openConnection(true); if (db != null) { try { From ec7ec1d57ba2fe652074bd3cec330d927096efd8 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 6 Sep 2017 12:33:52 +0300 Subject: [PATCH 020/128] Styling --- .../layout/fragment_map_markers_dialog.xml | 3 ++- OsmAnd/res/layout/map_marker_item_new.xml | 20 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml index 861223957a..00e5f1ba8d 100644 --- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -45,7 +45,8 @@ + android:layout_weight="1" + android:background="?attr/ctx_menu_info_view_bg"> - + android:descendantFocusability="blocksDescendants" + android:orientation="vertical"> @@ -91,7 +92,7 @@ android:ellipsize="end" android:maxLines="1" android:textColor="?android:textColorSecondary" - android:textSize="@dimen/default_sub_text_size" + android:textSize="@dimen/default_desc_text_size" tools:text="Amsterdam Weekend"/> @@ -115,9 +116,8 @@ - + From cafbf8a25fe7ff6837d6d6d4175bbe495223f804 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 6 Sep 2017 13:40:02 +0300 Subject: [PATCH 021/128] Migrate from settings to db in progress --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 2 +- .../src/net/osmand/plus/MapMarkersHelper.java | 166 +++++------------- .../controllers/MapMarkerMenuController.java | 4 +- .../plus/mapmarkers/MapMarkersDbHelper.java | 9 +- .../adapters/MapMarkersActiveAdapter.java | 16 +- .../adapters/MapMarkersHistoryAdapter.java | 5 +- .../mapwidgets/MapMarkersWidgetsFactory.java | 4 +- 7 files changed, 58 insertions(+), 148 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 84f64f21dc..3f734e0e5a 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -797,7 +797,7 @@ public class OsmandAidlApi { List mapMarkers = markersHelper.getMapMarkers(); for (MapMarker m : mapMarkers) { if (m.getOnlyName().equals(marker.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { - markersHelper.removeMapMarker(m); + markersHelper.moveMapMarkerToHistory(m); refreshMap(); return true; } diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index ebf5c04556..9f549dec40 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -6,6 +6,7 @@ import android.support.annotation.Nullable; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; +import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.util.Algorithms; import java.util.ArrayList; @@ -19,6 +20,7 @@ public class MapMarkersHelper { private OsmandSettings settings; private List listeners = new ArrayList<>(); private OsmandApplication ctx; + private MapMarkersDbHelper markersDbHelper; private boolean startFromMyLocation; public interface MapMarkerChangedListener { @@ -144,8 +146,9 @@ public class MapMarkersHelper { public MapMarkersHelper(OsmandApplication ctx) { this.ctx = ctx; settings = ctx.getSettings(); + markersDbHelper = ctx.getMapMarkersDbHelper(); startFromMyLocation = settings.ROUTE_MAP_MARKERS_START_MY_LOC.get(); - readFromSettings(); + loadMarkers(); } public boolean isStartFromMyLocation() { @@ -159,55 +162,25 @@ public class MapMarkersHelper { public void lookupAddressAll() { for (MapMarker mapMarker : mapMarkers) { - lookupAddress(mapMarker, false); + lookupAddress(mapMarker); } for (MapMarker mapMarker : mapMarkersHistory) { - lookupAddress(mapMarker, true); + lookupAddress(mapMarker); } } - private void readFromSettings() { + private void loadMarkers() { mapMarkers.clear(); mapMarkersHistory.clear(); - List ips = settings.getMapMarkersPoints(); - List 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) { - colorIndex = colors.get(i); - } - MapMarker mapMarker = new MapMarker(ips.get(i), - PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, - selections.get(i), i); - mapMarker.creationDate = creationDates.get(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)), - colorIndex, false, i); - mapMarker.history = true; - mapMarker.creationDate = creationDates.get(i); - mapMarkersHistory.add(mapMarker); - } + mapMarkers.addAll(markersDbHelper.getActiveMarkers()); + mapMarkersHistory.addAll(markersDbHelper.getMarkersHistory()); if (!ctx.isApplicationInitializing()) { lookupAddressAll(); } } - private void lookupAddress(final MapMarker mapMarker, final boolean history) { + private void lookupAddress(final MapMarker mapMarker) { if (mapMarker != null && mapMarker.pointDescription.isSearchingAddress(ctx)) { cancelPointAddressRequests(mapMarker.point); GeocodingLookupService.AddressLookupRequest lookupRequest = new GeocodingLookupService.AddressLookupRequest(mapMarker.point, new GeocodingLookupService.OnAddressLookupResult() { @@ -218,13 +191,7 @@ public class MapMarkersHelper { } else { mapMarker.pointDescription.setName(address); } - if (history) { - settings.updateMapMarkerHistory(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), - mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.creationDate); - } else { - settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), - mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.selected, mapMarker.creationDate); - } + markersDbHelper.updateMarker(mapMarker); updateMarker(mapMarker); } }, null); @@ -232,15 +199,27 @@ public class MapMarkersHelper { } } - public void removeMapMarker(int index) { - settings.deleteMapMarker(index); - MapMarker mapMarker = mapMarkers.remove(index); - cancelPointAddressRequests(mapMarker.point); - int ind = 0; - for (MapMarker marker : mapMarkers) { - marker.index = ind++; + public void moveMapMarkerToHistory(MapMarker marker) { + if (marker != null) { + marker.history = true; + markersDbHelper.moveMarkerToHistory(marker); + mapMarkers.remove(marker); + mapMarkersHistory.add(marker); + cancelPointAddressRequests(marker.point); + refresh(); + } + } + + public void restoreMarkerFromHistory(MapMarker marker, int position) { + if (marker != null) { + MapMarker next = position >= mapMarkers.size() ? null : mapMarkers.get(position); + marker.history = false; + mapMarkersHistory.remove(marker); + mapMarkers.add(position, marker); + markersDbHelper.restoreMapMarkerFromHistory(marker); + markersDbHelper.changeActiveMarkerPosition(marker, next); + refresh(); } - refresh(); } public List getMapMarkers() { @@ -309,28 +288,19 @@ public class MapMarkersHelper { public void removeActiveMarkers() { cancelAddressRequests(); - for (int i = mapMarkers.size() - 1; i >= 0; i--) { - MapMarker marker = mapMarkers.get(i); - addMapMarkerHistory(marker); - } - settings.clearActiveMapMarkers(); - readFromSettings(); + markersDbHelper.moveAllActiveMarkersToHistory(); + mapMarkers.clear(); + mapMarkersHistory = markersDbHelper.getMarkersHistory(); refresh(); } public void removeMarkersHistory() { cancelAddressRequests(); - settings.clearMapMarkersHistory(); - readFromSettings(); + markersDbHelper.clearAllMarkersHistory(); + mapMarkersHistory.clear(); refresh(); } - public void addMapMarker(MapMarker marker, int index) { - settings.insertMapMarker(marker.getLatitude(), marker.getLongitude(), marker.pointDescription, - marker.colorIndex, marker.selected, marker.creationDate, index); - readFromSettings(); - } - public void addMapMarker(LatLon point, PointDescription historyName) { List points = new ArrayList<>(1); List historyNames = new ArrayList<>(1); @@ -342,13 +312,6 @@ public class MapMarkersHelper { public void addMapMarkers(List points, List historyNames) { if (points.size() > 0) { int colorIndex = -1; - double[] latitudes = new double[points.size()]; - double[] longitudes = new double[points.size()]; - List pointDescriptions = new ArrayList<>(); - int[] colorIndexes = new int[points.size()]; - int[] positions = new int[points.size()]; - boolean[] selections = new boolean[points.size()]; - int[] indexes = new int[points.size()]; for (int i = 0; i < points.size(); i++) { LatLon point = points.get(i); PointDescription historyName = historyNames.get(i); @@ -371,33 +334,18 @@ public class MapMarkersHelper { colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } - latitudes[i] = point.getLatitude(); - longitudes[i] = point.getLongitude(); - pointDescriptions.add(pointDescription); - colorIndexes[i] = colorIndex; - positions[i] = -1 - i; - selections[i] = false; - indexes[i] = 0; + MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); + markersDbHelper.addMarker(marker); } - /* adding map marker to second topbar's row - if (sortedMapMarkers.size() > 0) { - MapMarker firstMarker = sortedMapMarkers.get(0); - settings.updateMapMarker(firstMarker.getLatitude(), firstMarker.getLongitude(), - firstMarker.pointDescription, firstMarker.colorIndex, -points.size(), firstMarker.selected); - } - */ - settings.insertMapMarkers(latitudes, longitudes, pointDescriptions, colorIndexes, positions, - selections, indexes); - readFromSettings(); + loadMarkers(); } } public void updateMapMarker(MapMarker marker, boolean refresh) { if (marker != null) { - settings.updateMapMarker(marker.getLatitude(), marker.getLongitude(), - marker.pointDescription, marker.colorIndex, marker.selected, marker.creationDate); + markersDbHelper.updateMarker(marker); if (refresh) { - readFromSettings(); + loadMarkers(); refresh(); } } @@ -405,35 +353,9 @@ 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.creationDate); marker.point = new LatLon(latLon.getLatitude(), latLon.getLongitude()); - readFromSettings(); - refresh(); - } - } - - public void removeMapMarker(MapMarker marker) { - if (marker != null) { - settings.deleteMapMarker(marker.index); - readFromSettings(); - refresh(); - } - } - - public void addMapMarkerHistory(MapMarker marker) { - if (marker != null) { - settings.insertMapMarkerHistory(marker.getLatitude(), marker.getLongitude(), - marker.pointDescription, marker.colorIndex, marker.creationDate, 0); - readFromSettings(); - refresh(); - } - } - - public void removeMapMarkerHistory(MapMarker marker) { - if (marker != null) { - settings.deleteMapMarkerHistory(marker.index); - readFromSettings(); + markersDbHelper.updateMarker(marker); + loadMarkers(); refresh(); } } @@ -470,7 +392,7 @@ public class MapMarkersHelper { } if (markers != null || markersHistory != null) { - readFromSettings(); + loadMarkers(); refresh(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java index 4e0bf8570f..875b8f0fdb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java @@ -10,7 +10,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.MapMarkerDialogHelper; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; -import net.osmand.plus.mapillary.MapillaryPlugin; import net.osmand.util.Algorithms; public class MapMarkerMenuController extends MenuController { @@ -25,8 +24,7 @@ public class MapMarkerMenuController extends MenuController { leftTitleButtonController = new TitleButtonController() { @Override public void buttonPressed() { - markersHelper.removeMapMarker(getMapMarker().index); - markersHelper.addMapMarkerHistory(getMapMarker()); + markersHelper.moveMapMarkerToHistory(getMapMarker()); getMapActivity().getContextMenu().close(); } }; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 7f05f4e6ac..0f06b5c028 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -227,7 +227,7 @@ public class MapMarkersDbHelper { private void buildLinkedList(LongSparseArray markers, List res, MapMarker marker) { if (marker != null) { - res.add(0, marker); + res.add(marker); MapMarker prev = markers.get(marker.id); if (prev != null) { buildLinkedList(markers, res, prev); @@ -271,7 +271,7 @@ public class MapMarkersDbHelper { } } - public void moveActiveMarkerToHistory(MapMarker marker) { + public void moveMarkerToHistory(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -281,7 +281,7 @@ public class MapMarkersDbHelper { "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.nextKey, marker.id}); db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + - MARKERS_COL_ACTIVE + " = ? " + + MARKERS_COL_ACTIVE + " = ?, " + MARKERS_COL_VISITED + " = ? " + "WHERE " + MARKERS_COL_ID + " = ?", new Object[]{0, marker.visitedDate, marker.id}); } finally { @@ -309,11 +309,12 @@ public class MapMarkersDbHelper { SQLiteConnection db = openConnection(false); if (db != null) { try { + List active = getActiveMarkers(); db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ?, " + MARKERS_COL_NEXT_KEY + " = ? " + "WHERE " + MARKERS_COL_ID + " = ?", - new Object[]{1, getActiveMarkers().get(0).id, marker.id}); + new Object[]{1, active.size() > 0 ? active.get(0).id : TAIL_NEXT_VALUE, marker.id}); } finally { db.close(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 20cfc06e1a..bafa9e7484 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -68,7 +68,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter index) { - MapMarker marker = helper.getMapMarkers().get(index); - helper.removeMapMarker(marker.index); - helper.addMapMarkerHistory(marker); + helper.moveMapMarkerToHistory(helper.getMapMarkers().get(index)); } } From f14f575ef1ff598eda40e5301d47209ead09cbe8 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 6 Sep 2017 16:11:05 +0300 Subject: [PATCH 022/128] Change passed and revert buttons --- .../drawable/marker_circle_background_light.xml | 7 +++++++ .../drawable/marker_circle_background_light_n.xml | 8 ++++++++ .../drawable/marker_circle_background_light_p.xml | 8 ++++++++ OsmAnd/res/layout/map_marker_item_new.xml | 14 ++++++-------- .../adapters/MapMarkersActiveAdapter.java | 2 +- .../adapters/MapMarkersHistoryAdapter.java | 2 +- 6 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 OsmAnd/res/drawable/marker_circle_background_light.xml create mode 100644 OsmAnd/res/drawable/marker_circle_background_light_n.xml create mode 100644 OsmAnd/res/drawable/marker_circle_background_light_p.xml diff --git a/OsmAnd/res/drawable/marker_circle_background_light.xml b/OsmAnd/res/drawable/marker_circle_background_light.xml new file mode 100644 index 0000000000..cd7fae2bff --- /dev/null +++ b/OsmAnd/res/drawable/marker_circle_background_light.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/marker_circle_background_light_n.xml b/OsmAnd/res/drawable/marker_circle_background_light_n.xml new file mode 100644 index 0000000000..135fceccb2 --- /dev/null +++ b/OsmAnd/res/drawable/marker_circle_background_light_n.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/marker_circle_background_light_p.xml b/OsmAnd/res/drawable/marker_circle_background_light_p.xml new file mode 100644 index 0000000000..180cf357ef --- /dev/null +++ b/OsmAnd/res/drawable/marker_circle_background_light_p.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index c5e6a51a66..bde4346136 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -100,16 +100,14 @@ + android:layout_marginLeft="16dp" + android:layout_marginRight="16dp" + tools:src="@drawable/ic_action_marker_passed"/> diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index bafa9e7484..2a3099367a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -90,7 +90,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Wed, 6 Sep 2017 18:16:08 +0300 Subject: [PATCH 023/128] Add some changes --- .../src/net/osmand/plus/MapMarkersHelper.java | 19 ++++++++++++------- .../mapmarkers/MapMarkersActiveFragment.java | 2 +- .../plus/mapmarkers/MapMarkersDbHelper.java | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 9f549dec40..5ddd5eeba2 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -201,23 +201,21 @@ public class MapMarkersHelper { public void moveMapMarkerToHistory(MapMarker marker) { if (marker != null) { - marker.history = true; + cancelPointAddressRequests(marker.point); markersDbHelper.moveMarkerToHistory(marker); mapMarkers.remove(marker); + marker.history = true; mapMarkersHistory.add(marker); - cancelPointAddressRequests(marker.point); refresh(); } } public void restoreMarkerFromHistory(MapMarker marker, int position) { if (marker != null) { - MapMarker next = position >= mapMarkers.size() ? null : mapMarkers.get(position); - marker.history = false; - mapMarkersHistory.remove(marker); - mapMarkers.add(position, marker); + MapMarker next = position == mapMarkers.size() ? null : mapMarkers.get(position); markersDbHelper.restoreMapMarkerFromHistory(marker); markersDbHelper.changeActiveMarkerPosition(marker, next); + loadMarkers(); refresh(); } } @@ -326,7 +324,7 @@ public class MapMarkersHelper { } if (colorIndex == -1) { if (mapMarkers.size() > 0) { - colorIndex = (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; + colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } else { colorIndex = 0; } @@ -360,6 +358,13 @@ public class MapMarkersHelper { } } + public void changeActiveMarkerPositionInDb(int currentPos) { + MapMarker moved = mapMarkers.get(currentPos); + markersDbHelper.changeActiveMarkerPosition(moved, + currentPos == mapMarkers.size() - 1 ? null : mapMarkers.get(currentPos + 1)); + loadMarkers(); + } + public void saveMapMarkers(List markers, List markersHistory) { if (markers != null) { List ls = new ArrayList<>(markers.size()); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 3b2fb3d96d..6a8da180ba 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -67,7 +67,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL public void onDragEnded(RecyclerView.ViewHolder holder) { toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { - mapActivity.getMyApplication().getMapMarkersHelper().saveMapMarkers(adapter.getItems(), null); + mapActivity.getMyApplication().getMapMarkersHelper().changeActiveMarkerPositionInDb(toPosition); } } }); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 0f06b5c028..aa4e828b58 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -227,7 +227,7 @@ public class MapMarkersDbHelper { private void buildLinkedList(LongSparseArray markers, List res, MapMarker marker) { if (marker != null) { - res.add(marker); + res.add(0, marker); MapMarker prev = markers.get(marker.id); if (prev != null) { buildLinkedList(markers, res, prev); From 1097262dfe37a362b68ca7d18081d1430a501d98 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 6 Sep 2017 18:34:57 +0300 Subject: [PATCH 024/128] Add show direction bottom sheet dialog --- .../bottom_navigation_color_selector.xml | 0 .../layout-land/fragment_measurement_tool.xml | 16 +- .../layout/close_measurement_tool_dialog.xml | 6 +- .../layout/fragment_map_markers_dialog.xml | 4 +- ...ent_marker_options_bottom_sheet_dialog.xml | 92 +++---- ...ker_show_direction_bottom_sheet_dialog.xml | 239 ++++++++++++++++++ .../res/layout/fragment_measurement_tool.xml | 16 +- .../fragment_options_bottom_sheet_dialog.xml | 96 +++---- ..._save_as_new_track_bottom_sheet_dialog.xml | 86 +++---- ...ment_selected_menu_bottom_sheet_dialog.xml | 84 +++--- ...gment_snap_to_road_bottom_sheet_dialog.xml | 24 +- .../res/layout/list_item_icon_and_title.xml | 16 +- OsmAnd/res/layout/save_gpx_dialog.xml | 24 +- OsmAnd/res/values-large/sizes.xml | 20 +- OsmAnd/res/values/sizes.xml | 20 +- OsmAnd/res/values/strings.xml | 2 + .../mapmarkers/MapMarkersActiveFragment.java | 2 +- .../mapmarkers/MapMarkersDialogFragment.java | 13 +- ...arkerOptionsBottomSheetDialogFragment.java | 9 +- ...howDirectionBottomSheetDialogFragment.java | 149 +++++++++++ .../OptionsBottomSheetDialogFragment.java | 2 +- ...veAsNewTrackBottomSheetDialogFragment.java | 2 +- ...electedPointBottomSheetDialogFragment.java | 2 +- 23 files changed, 664 insertions(+), 260 deletions(-) rename OsmAnd/res/{color => drawable}/bottom_navigation_color_selector.xml (100%) create mode 100644 OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java diff --git a/OsmAnd/res/color/bottom_navigation_color_selector.xml b/OsmAnd/res/drawable/bottom_navigation_color_selector.xml similarity index 100% rename from OsmAnd/res/color/bottom_navigation_color_selector.xml rename to OsmAnd/res/drawable/bottom_navigation_color_selector.xml diff --git a/OsmAnd/res/layout-land/fragment_measurement_tool.xml b/OsmAnd/res/layout-land/fragment_measurement_tool.xml index 9dd92bdcca..88782a4fb5 100644 --- a/OsmAnd/res/layout-land/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout-land/fragment_measurement_tool.xml @@ -46,10 +46,10 @@ android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_centerVertical="true" - android:layout_marginEnd="@dimen/measurement_tool_content_margin" - android:layout_marginLeft="@dimen/measurement_tool_content_margin" - android:layout_marginRight="@dimen/measurement_tool_content_margin" - android:layout_marginStart="@dimen/measurement_tool_content_margin" + android:layout_marginEnd="@dimen/bottom_sheet_content_margin" + android:layout_marginLeft="@dimen/bottom_sheet_content_margin" + android:layout_marginRight="@dimen/bottom_sheet_content_margin" + android:layout_marginStart="@dimen/bottom_sheet_content_margin" android:background="@null" tools:src="@drawable/ic_action_ruler"/> @@ -60,10 +60,10 @@ android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_centerVertical="true" - android:layout_marginEnd="@dimen/measurement_tool_content_margin" - android:layout_marginLeft="@dimen/measurement_tool_content_margin" - android:layout_marginRight="@dimen/measurement_tool_content_margin" - android:layout_marginStart="@dimen/measurement_tool_content_margin" + android:layout_marginEnd="@dimen/bottom_sheet_content_margin" + android:layout_marginLeft="@dimen/bottom_sheet_content_margin" + android:layout_marginRight="@dimen/bottom_sheet_content_margin" + android:layout_marginStart="@dimen/bottom_sheet_content_margin" android:background="@null" tools:src="@drawable/ic_action_arrow_down"/> diff --git a/OsmAnd/res/layout/close_measurement_tool_dialog.xml b/OsmAnd/res/layout/close_measurement_tool_dialog.xml index 6485e8582f..e1c823056a 100644 --- a/OsmAnd/res/layout/close_measurement_tool_dialog.xml +++ b/OsmAnd/res/layout/close_measurement_tool_dialog.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" - android:padding="@dimen/measurement_tool_content_padding"> + android:padding="@dimen/bottom_sheet_content_padding"> + android:layout_marginLeft="@dimen/bottom_sheet_content_margin" + android:layout_marginStart="@dimen/bottom_sheet_content_margin"/> \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml index 00e5f1ba8d..05173d51a0 100644 --- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -74,7 +74,7 @@ android:layout_height="wrap_content" android:background="?attr/bg_color" app:itemBackground="?attr/bg_color" - app:itemIconTint="@color/bottom_navigation_color_selector" - app:itemTextColor="@color/bottom_navigation_color_selector" + app:itemIconTint="@drawable/bottom_navigation_color_selector" + app:itemTextColor="@drawable/bottom_navigation_color_selector" app:menu="@menu/map_markers_bottom_navigation"/> diff --git a/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml index e77703ddfc..88ae0b8cc1 100644 --- a/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml @@ -21,12 +21,12 @@ @@ -34,21 +34,21 @@ + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index 57ddf558b8..6b5a3da674 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -41,10 +41,10 @@ android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_centerVertical="true" - android:layout_marginEnd="@dimen/measurement_tool_content_margin" - android:layout_marginLeft="@dimen/measurement_tool_content_margin" - android:layout_marginRight="@dimen/measurement_tool_content_margin" - android:layout_marginStart="@dimen/measurement_tool_content_margin" + android:layout_marginEnd="@dimen/bottom_sheet_content_margin" + android:layout_marginLeft="@dimen/bottom_sheet_content_margin" + android:layout_marginRight="@dimen/bottom_sheet_content_margin" + android:layout_marginStart="@dimen/bottom_sheet_content_margin" android:background="@null" tools:src="@drawable/ic_action_ruler"/> @@ -55,10 +55,10 @@ android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_centerVertical="true" - android:layout_marginEnd="@dimen/measurement_tool_content_margin" - android:layout_marginLeft="@dimen/measurement_tool_content_margin" - android:layout_marginRight="@dimen/measurement_tool_content_margin" - android:layout_marginStart="@dimen/measurement_tool_content_margin" + android:layout_marginEnd="@dimen/bottom_sheet_content_margin" + android:layout_marginLeft="@dimen/bottom_sheet_content_margin" + android:layout_marginRight="@dimen/bottom_sheet_content_margin" + android:layout_marginStart="@dimen/bottom_sheet_content_margin" android:background="@null" tools:src="@drawable/ic_action_arrow_down"/> diff --git a/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml index ed0730b8d2..4e1a338a84 100644 --- a/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml @@ -22,12 +22,12 @@ @@ -35,21 +35,21 @@ + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:paddingBottom="@dimen/bottom_sheet_content_padding_small"> @@ -46,16 +46,16 @@ android:id="@+id/images_row" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="16dp" + android:layout_marginBottom="@dimen/bottom_sheet_content_margin" android:orientation="horizontal"> @@ -84,10 +84,10 @@ @@ -118,21 +118,21 @@ + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:paddingBottom="@dimen/bottom_sheet_content_padding_small"> + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:paddingBottom="@dimen/bottom_sheet_content_padding_small"> @@ -50,7 +50,7 @@ + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:paddingEnd="@dimen/bottom_sheet_content_padding" + android:paddingLeft="@dimen/bottom_sheet_content_padding" + android:paddingRight="@dimen/bottom_sheet_content_padding" + android:paddingStart="@dimen/bottom_sheet_content_padding"> + android:padding="@dimen/bottom_sheet_content_padding"> + android:layout_marginLeft="@dimen/bottom_sheet_content_margin" + android:layout_marginStart="@dimen/bottom_sheet_content_margin"/> 90dp 96dp - 72dp + 72dp 540dp 30dp - 24dp - 12dp - 24dp - 12dp + 24dp + 12dp + 24dp + 12dp 12dp 18dp 6dp @@ -113,14 +113,14 @@ 12dp 12dp 54dp - 78dp - 66dp - 72dp - 36dp + 78dp + 66dp + 72dp + 36dp 11dp 12dp 96dp - 15dp + 15dp 84dp \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index aed0718f34..9ca00d5e8c 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -156,14 +156,14 @@ 60dp 64dp - 48dp + 48dp 360dp 20dp - 16dp - 8dp - 16dp - 8dp + 16dp + 8dp + 16dp + 8dp 8dp 12dp 4dp @@ -178,13 +178,13 @@ 8dp 8dp 36dp - 52dp - 44dp - 48dp - 24dp + 52dp + 44dp + 48dp + 24dp 7dp 8dp 64dp - 10dp + 10dp 56dp \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 7565a99cb9..0de4778165 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 --> + Widget + Top bar Move all to history Build route Show direction diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 3b2fb3d96d..969ea3b641 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -141,7 +141,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL adapter.setUseCenter(useCenter); adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude())); - adapter.setHeading(useCenter ? -mapActivity.getMapRotate() : heading); + adapter.setHeading(useCenter ? -mapActivity.getMapRotate() : heading != null ? heading : 99); adapter.notifyDataSetChanged(); } }); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 99c05a9550..24cdfac25b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -106,6 +106,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm private MarkerOptionsFragmentListener createMarkerOptionsFragmentListener() { return new MarkerOptionsFragmentListener() { + + final MapActivity mapActivity = getMapActivity(); + @Override public void sortByOnClick() { Toast.makeText(getContext(), "Sort by", Toast.LENGTH_SHORT).show(); @@ -113,7 +116,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void showDirectionOnClick() { - Toast.makeText(getContext(), "Show direction", Toast.LENGTH_SHORT).show(); + openShowDirectionMenu(mapActivity); } @Override @@ -133,6 +136,14 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm }; } + private void openShowDirectionMenu(MapActivity mapActivity) { + ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment(); + fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG); + } + + private MapActivity getMapActivity() { + return (MapActivity) getActivity(); + } public static boolean showInstance(@NonNull MapActivity mapActivity) { try { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java index 2bcf3d1325..5df7fc263f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.mapmarkers; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; +import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -32,10 +33,12 @@ public class MarkerOptionsBottomSheetDialogFragment extends BottomSheetDialogFra @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final View mainView = inflater.inflate(R.layout.fragment_marker_options_bottom_sheet_dialog, container); + final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_options_bottom_sheet_dialog, container); if (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, false, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); + AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); } ((ImageView) mainView.findViewById(R.id.sort_by_icon)) @@ -113,7 +116,7 @@ public class MarkerOptionsBottomSheetDialogFragment extends BottomSheetDialogFra final View scrollView = mainView.findViewById(R.id.marker_options_scroll_view); int scrollViewHeight = scrollView.getHeight(); int dividerHeight = AndroidUtils.dpToPx(getContext(), 1); - int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.measure_distance_bottom_sheet_cancel_button_height); + int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight; if (scrollViewHeight > spaceForScrollView) { scrollView.getLayoutParams().height = spaceForScrollView; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java new file mode 100644 index 0000000000..9a6407944b --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -0,0 +1,149 @@ +package net.osmand.plus.mapmarkers; + +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.view.Window; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.AndroidUtils; +import net.osmand.plus.R; +import net.osmand.plus.base.BottomSheetDialogFragment; +import net.osmand.plus.helpers.AndroidUiHelper; + +public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFragment { + + public final static String TAG = "ShowDirectionBottomSheetDialogFragment"; + + private ShowDirectionFragmentListener listener; + private boolean portrait; + + public void setListener(ShowDirectionFragmentListener listener) { + this.listener = listener; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + + final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container); + if (portrait) { + AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); + } + + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { + mainView.findViewById(R.id.images_row).setVisibility(View.GONE); + } else { + ImageView topBarImage = (ImageView) mainView.findViewById(R.id.top_bar_image); + ImageView widgetImage = (ImageView) mainView.findViewById(R.id.widget_image); + if (nightMode) { + topBarImage.setImageResource(R.drawable.img_help_markers_topbar_night); + widgetImage.setImageResource(R.drawable.img_help_markers_widgets_night); + } else { + topBarImage.setImageResource(R.drawable.img_help_markers_topbar_day); + widgetImage.setImageResource(R.drawable.img_help_markers_widgets_day); + } + + mainView.findViewById(R.id.top_bar_text).setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + return false; + } + }); + + mainView.findViewById(R.id.widget_text).setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + return false; + } + }); + } + + if (nightMode) { + ((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); + } + + 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)); + + 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)); + + ImageView noneIcon = (ImageView) mainView.findViewById(R.id.none_icon); + noneIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); + + mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + final int screenHeight = AndroidUtils.getScreenHeight(getActivity()); + final int statusBarHeight = AndroidUtils.getStatusBarHeight(getActivity()); + final int navBarHeight = AndroidUtils.getNavBarHeight(getActivity()); + + mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + final View scrollView = mainView.findViewById(R.id.marker_show_direction_scroll_view); + int scrollViewHeight = scrollView.getHeight(); + int dividerHeight = AndroidUtils.dpToPx(getContext(), 1); + int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); + int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight; + if (scrollViewHeight > spaceForScrollView) { + scrollView.getLayoutParams().height = spaceForScrollView; + scrollView.requestLayout(); + } + + if (!portrait) { + if (screenHeight - statusBarHeight - mainView.getHeight() + >= AndroidUtils.dpToPx(getActivity(), 8)) { + AndroidUtils.setBackground(getActivity(), mainView, false, + R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); + } else { + AndroidUtils.setBackground(getActivity(), mainView, false, + R.drawable.bg_bottom_sheet_sides_landscape_light, R.drawable.bg_bottom_sheet_sides_landscape_dark); + } + } + + ViewTreeObserver obs = mainView.getViewTreeObserver(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + obs.removeOnGlobalLayoutListener(this); + } else { + obs.removeGlobalOnLayoutListener(this); + } + } + }); + + return mainView; + } + + @Override + public void onStart() { + super.onStart(); + if (!portrait) { + final Window window = getDialog().getWindow(); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width); + window.setAttributes(params); + } + } + + interface ShowDirectionFragmentListener { + + } +} diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index 63b68e4191..81bb38aac4 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -141,7 +141,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment final View scrollView = mainView.findViewById(R.id.measure_options_scroll_view); int scrollViewHeight = scrollView.getHeight(); int dividerHeight = AndroidUtils.dpToPx(getContext(), 1); - int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.measure_distance_bottom_sheet_cancel_button_height); + int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight; if (scrollViewHeight > spaceForScrollView) { scrollView.getLayoutParams().height = spaceForScrollView; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index 568e083cbf..91e143c1eb 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -102,7 +102,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends BottomSheetDialogFr final View scrollView = mainView.findViewById(R.id.save_as_new_track_scroll_view); int scrollViewHeight = scrollView.getHeight(); int dividerHeight = AndroidUtils.dpToPx(getContext(), 1); - int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.measure_distance_bottom_sheet_cancel_button_height); + int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight; if (scrollViewHeight > spaceForScrollView) { scrollView.getLayoutParams().height = spaceForScrollView; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index 595f701073..b196f1410c 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -167,7 +167,7 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra final View scrollView = mainView.findViewById(R.id.selected_point_options_scroll_view); int scrollViewHeight = scrollView.getHeight(); int dividerHeight = AndroidUtils.dpToPx(getContext(), 1); - int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.measure_distance_bottom_sheet_cancel_button_height); + int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight; if (scrollViewHeight > spaceForScrollView) { scrollView.getLayoutParams().height = spaceForScrollView; From 0173c0b774dc8b6f8093450bf8b82a373d13beda Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 6 Sep 2017 18:54:53 +0300 Subject: [PATCH 025/128] Add shadow to action bar --- .../layout/fragment_map_markers_dialog.xml | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml index 05173d51a0..c7bcc91ff9 100644 --- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -6,41 +6,45 @@ android:layout_height="match_parent" android:orientation="vertical"> - + android:layout_height="@dimen/dashboard_map_toolbar"> - + android:layout_height="match_parent" + android:theme="?attr/actionBarStyle" + app:contentInsetLeft="54dp" + app:contentInsetStart="54dp"> - + android:gravity="center_vertical"> - - + - + + + + + + Date: Thu, 7 Sep 2017 10:41:11 +0300 Subject: [PATCH 026/128] Change some code --- .../src/net/osmand/plus/MapMarkersHelper.java | 17 ++++++++++++++--- .../net/osmand/plus/views/MapMarkersLayer.java | 11 +---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 5ddd5eeba2..5660ff5399 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -272,6 +272,7 @@ public class MapMarkersHelper { return list; } + //todo: rewrite with MapMarkersDbHelper public void reverseActiveMarkersOrder() { cancelAddressRequests(); @@ -358,13 +359,23 @@ public class MapMarkersHelper { } } - public void changeActiveMarkerPositionInDb(int currentPos) { - MapMarker moved = mapMarkers.get(currentPos); + public void changeActiveMarkerPositionInDb(int currentPosInMapMarkers) { + MapMarker moved = mapMarkers.get(currentPosInMapMarkers); markersDbHelper.changeActiveMarkerPosition(moved, - currentPos == mapMarkers.size() - 1 ? null : mapMarkers.get(currentPos + 1)); + currentPosInMapMarkers == mapMarkers.size() - 1 ? null : mapMarkers.get(currentPosInMapMarkers + 1)); loadMarkers(); } + public void moveMarkerToTop(MapMarker marker) { + int i = mapMarkers.indexOf(marker); + if (i != -1 && mapMarkers.size() > 1) { + mapMarkers.remove(i); + markersDbHelper.changeActiveMarkerPosition(marker, mapMarkers.get(0)); + loadMarkers(); + refresh(); + } + } + public void saveMapMarkers(List markers, List markersHistory) { if (markers != null) { List ls = new ArrayList<>(markers.size()); diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 296a8de611..8107ee7ba7 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -493,16 +493,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi @Override public void setSelectedObject(Object o) { if (o instanceof MapMarker) { - MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); - MapMarker marker = (MapMarker) o; - List mapMarkers = markersHelper.getMapMarkers(); - int i = mapMarkers.indexOf(marker); - if (i != -1) { - mapMarkers.remove(i); - mapMarkers.add(0, marker); - markersHelper.saveMapMarkers(mapMarkers, null); - marker.index = 0; - } + map.getMyApplication().getMapMarkersHelper().moveMarkerToTop((MapMarker) o); } } From b62f07a3f9ba2a47653225bd92ddd62a214c9c01 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 7 Sep 2017 11:07:55 +0300 Subject: [PATCH 027/128] Rewrite method reverseActiveMarkersOrder with MapMarkersDbHelper --- .../src/net/osmand/plus/MapMarkersHelper.java | 10 ++-------- .../plus/mapmarkers/MapMarkersDbHelper.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 5660ff5399..044de5d840 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -272,17 +272,11 @@ public class MapMarkersHelper { return list; } - //todo: rewrite with MapMarkersDbHelper public void reverseActiveMarkersOrder() { cancelAddressRequests(); - List markers = new ArrayList<>(mapMarkers.size()); - for (int i = mapMarkers.size() - 1; i >= 0; i--) { - MapMarker marker = mapMarkers.get(i); - markers.add(marker); - } - mapMarkers = markers; - saveMapMarkers(mapMarkers, null); + markersDbHelper.reverseActiveMarkersOrder(); + loadMarkers(); } public void removeActiveMarkers() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index aa4e828b58..03e2253f09 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -139,6 +139,14 @@ public class MapMarkersDbHelper { } } + public void reverseActiveMarkersOrder() { + List markers = getActiveMarkers(); + removeAllActiveMarkers(); + for (int i = markers.size() - 1; i >= 0; i--) { + addMarker(markers.get(i)); + } + } + public void addMarker(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { @@ -271,6 +279,18 @@ public class MapMarkersDbHelper { } } + private void removeAllActiveMarkers() { + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ACTIVE + " = ?", + new Object[]{1}); + } finally { + db.close(); + } + } + } + public void moveMarkerToHistory(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { From dfaeb353df911797146dc3a06d40f2e0986f87fc Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 7 Sep 2017 11:22:26 +0300 Subject: [PATCH 028/128] Fix passed and reorder buttons --- .../marker_circle_background_light_n_with_inset.xml | 7 +++++++ .../marker_circle_background_light_p_with_inset.xml | 9 +++++++++ ...xml => marker_circle_background_light_with_inset.xml} | 4 ++-- OsmAnd/res/layout/map_marker_item_new.xml | 8 +++----- 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 OsmAnd/res/drawable/marker_circle_background_light_n_with_inset.xml create mode 100644 OsmAnd/res/drawable/marker_circle_background_light_p_with_inset.xml rename OsmAnd/res/drawable/{marker_circle_background_light.xml => marker_circle_background_light_with_inset.xml} (77%) diff --git a/OsmAnd/res/drawable/marker_circle_background_light_n_with_inset.xml b/OsmAnd/res/drawable/marker_circle_background_light_n_with_inset.xml new file mode 100644 index 0000000000..b20f1f27f0 --- /dev/null +++ b/OsmAnd/res/drawable/marker_circle_background_light_n_with_inset.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/marker_circle_background_light_p_with_inset.xml b/OsmAnd/res/drawable/marker_circle_background_light_p_with_inset.xml new file mode 100644 index 0000000000..b843c16fe4 --- /dev/null +++ b/OsmAnd/res/drawable/marker_circle_background_light_p_with_inset.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/marker_circle_background_light.xml b/OsmAnd/res/drawable/marker_circle_background_light_with_inset.xml similarity index 77% rename from OsmAnd/res/drawable/marker_circle_background_light.xml rename to OsmAnd/res/drawable/marker_circle_background_light_with_inset.xml index cd7fae2bff..7e6b0f5772 100644 --- a/OsmAnd/res/drawable/marker_circle_background_light.xml +++ b/OsmAnd/res/drawable/marker_circle_background_light_with_inset.xml @@ -1,7 +1,7 @@ - - + + \ No newline at end of file diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index bde4346136..b2ef7bbcb1 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -100,13 +100,11 @@ From cb81896166a4167f89f1bb48347e1f11cf2d8240 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 7 Sep 2017 13:20:37 +0300 Subject: [PATCH 029/128] Hide snackbar when open history tab --- .../plus/mapmarkers/MapMarkersActiveFragment.java | 4 ++++ .../plus/mapmarkers/MapMarkersDialogFragment.java | 1 + .../mapmarkers/adapters/MapMarkersActiveAdapter.java | 12 ++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index bf621a7d60..7c5826cb1b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -127,6 +127,10 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL } } + void hideSnackbar() { + adapter.hideSnackbar(); + } + 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 24cdfac25b..389866ff7d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -88,6 +88,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm ((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate(); if (viewPager.getCurrentItem() != 1) { ((MapMarkersHistoryFragment) adapter.getItem(1)).updateAdapter(); + ((MapMarkersActiveFragment) adapter.getItem(0)).hideSnackbar(); } viewPager.setCurrentItem(1); optionsButton.setVisibility(View.GONE); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 2a3099367a..886b624511 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -24,6 +24,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter markers; private MapMarkersActiveAdapterListener listener; + private Snackbar snackbar; private LatLon location; private Float heading; @@ -103,14 +104,15 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Thu, 7 Sep 2017 14:14:20 +0300 Subject: [PATCH 030/128] Hide snackbar after reordering markers --- .../src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 7c5826cb1b..55a27727ae 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -67,6 +67,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL public void onDragEnded(RecyclerView.ViewHolder holder) { toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { + hideSnackbar(); mapActivity.getMyApplication().getMapMarkersHelper().changeActiveMarkerPositionInDb(toPosition); } } From 535188de5fcfd27ff767c6ec85b0e3e1cecf4a7e Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 7 Sep 2017 15:17:11 +0300 Subject: [PATCH 031/128] Fix bug --- .../src/net/osmand/plus/MapMarkersHelper.java | 4 +--- .../plus/mapmarkers/MapMarkersDbHelper.java | 17 +++++++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 044de5d840..d1a0ff686e 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -203,9 +203,7 @@ public class MapMarkersHelper { if (marker != null) { cancelPointAddressRequests(marker.point); markersDbHelper.moveMarkerToHistory(marker); - mapMarkers.remove(marker); - marker.history = true; - mapMarkersHistory.add(marker); + loadMarkers(); refresh(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 03e2253f09..d8d077e39e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -323,9 +323,6 @@ public class MapMarkersDbHelper { } public void restoreMapMarkerFromHistory(MapMarker marker) { - if (!marker.history) { - return; - } SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -333,8 +330,9 @@ public class MapMarkersDbHelper { db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ?, " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_ID + " = ?", - new Object[]{1, active.size() > 0 ? active.get(0).id : TAIL_NEXT_VALUE, marker.id}); + "WHERE " + MARKERS_COL_ID + " = ? " + + "AND " + MARKERS_COL_ACTIVE + " = ?", + new Object[]{1, active.size() > 0 ? active.get(0).id : TAIL_NEXT_VALUE, marker.id, 0}); } finally { db.close(); } @@ -362,14 +360,13 @@ public class MapMarkersDbHelper { } public void removeMarkerFromHistory(MapMarker marker) { - if (!marker.history) { - return; - } SQLiteConnection db = openConnection(true); if (db != null) { try { - db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ID + " = ?", - new Object[]{marker.id}); + db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + + " WHERE " + MARKERS_COL_ID + " = ?" + + " AND " + MARKERS_COL_ACTIVE + " = ?", + new Object[]{marker.id, 0}); } finally { db.close(); } From 2df51d08f1dd9026b25c59ca72c4ac0ea8fc3dd3 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 7 Sep 2017 17:50:55 +0300 Subject: [PATCH 032/128] Add functionality to "Move all to history" button --- .../src/net/osmand/plus/MapMarkersHelper.java | 3 ++- .../mapmarkers/MapMarkersActiveFragment.java | 6 ++++-- .../plus/mapmarkers/MapMarkersDbHelper.java | 7 +++++-- .../mapmarkers/MapMarkersDialogFragment.java | 21 ++++++++++++------- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index d1a0ff686e..4d967c08bf 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -281,7 +281,8 @@ public class MapMarkersHelper { cancelAddressRequests(); markersDbHelper.moveAllActiveMarkersToHistory(); mapMarkers.clear(); - mapMarkersHistory = markersDbHelper.getMarkersHistory(); + mapMarkersHistory.clear(); + mapMarkersHistory.addAll(markersDbHelper.getMarkersHistory()); refresh(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 55a27727ae..8490060ebe 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -129,12 +129,14 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL } void hideSnackbar() { - adapter.hideSnackbar(); + if (adapter != null) { + adapter.hideSnackbar(); + } } private void updateLocationUi() { final MapActivity mapActivity = (MapActivity) getActivity(); - if (mapActivity != null) { + if (mapActivity != null && adapter != null) { mapActivity.getMyApplication().runInUIThread(new Runnable() { @Override public void run() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index d8d077e39e..4c1de6d643 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -314,8 +314,11 @@ public class MapMarkersDbHelper { SQLiteConnection db = openConnection(false); if (db != null) { try { - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ? " + - "WHERE " + MARKERS_COL_ACTIVE + " = ?", new Object[]{0, 1}); + long visitedDate = System.currentTimeMillis(); + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + + MARKERS_COL_ACTIVE + " = ?, " + + MARKERS_COL_VISITED + " = ? " + + "WHERE " + MARKERS_COL_ACTIVE + " = ?", new Object[]{0, visitedDate, 1}); } finally { db.close(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 389866ff7d..87cb0ad019 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -28,6 +28,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm public static final String TAG = "MapMarkersDialogFragment"; + private MapMarkersActiveFragment activeFragment; + private MapMarkersHistoryFragment historyFragment; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -40,6 +43,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { + activeFragment = new MapMarkersActiveFragment(); + historyFragment = new MapMarkersHistoryFragment(); + FragmentManager fragmentManager = getChildFragmentManager(); Fragment markerOptionsFragment = fragmentManager.findFragmentByTag(MarkerOptionsBottomSheetDialogFragment.TAG); if (markerOptionsFragment != null) { @@ -77,18 +83,18 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_active: - ((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate(); + activeFragment.startLocationUpdate(); if (viewPager.getCurrentItem() != 0) { - ((MapMarkersActiveFragment) adapter.getItem(0)).updateAdapter(); + activeFragment.updateAdapter(); } viewPager.setCurrentItem(0); optionsButton.setVisibility(View.VISIBLE); return true; case R.id.action_history: - ((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate(); + activeFragment.stopLocationUpdate(); if (viewPager.getCurrentItem() != 1) { - ((MapMarkersHistoryFragment) adapter.getItem(1)).updateAdapter(); - ((MapMarkersActiveFragment) adapter.getItem(0)).hideSnackbar(); + historyFragment.updateAdapter(); + activeFragment.hideSnackbar(); } viewPager.setCurrentItem(1); optionsButton.setVisibility(View.GONE); @@ -132,7 +138,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void moveAllToHistoryOnClick() { - Toast.makeText(getContext(), "Move all to history", Toast.LENGTH_SHORT).show(); + mapActivity.getMyApplication().getMapMarkersHelper().removeActiveMarkers(); + activeFragment.updateAdapter(); } }; } @@ -165,7 +172,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm MapMarkersViewPagerAdapter(FragmentManager fm) { super(fm); - fragments = Arrays.asList(new MapMarkersActiveFragment(), new MapMarkersHistoryFragment()); + fragments = Arrays.asList(activeFragment, historyFragment); } @Override From 3a6d81bd521f14b3dd5ab0c772429d028e9884c4 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 7 Sep 2017 18:17:08 +0300 Subject: [PATCH 033/128] Add sort for history --- OsmAnd/res/layout/map_marker_item_date.xml | 38 ++++ OsmAnd/res/layout/map_marker_item_new.xml | 1 - OsmAnd/res/values/strings.xml | 4 + .../src/net/osmand/plus/MapMarkersHelper.java | 42 +++- .../mapmarkers/MapMarkersHistoryFragment.java | 51 ++++- .../adapters/MapMarkerDateViewHolder.java | 20 ++ .../adapters/MapMarkersHistoryAdapter.java | 180 ++++++++++++++---- 7 files changed, 292 insertions(+), 44 deletions(-) create mode 100644 OsmAnd/res/layout/map_marker_item_date.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerDateViewHolder.java diff --git a/OsmAnd/res/layout/map_marker_item_date.xml b/OsmAnd/res/layout/map_marker_item_date.xml new file mode 100644 index 0000000000..4061e951ec --- /dev/null +++ b/OsmAnd/res/layout/map_marker_item_date.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index b2ef7bbcb1..1edd0e5cf1 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -102,7 +102,6 @@ android:id="@+id/map_marker_options_button" android:layout_width="56dp" android:layout_height="56dp" - android:layout_gravity="center_vertical|end" android:background="@drawable/marker_circle_background_light_with_inset" android:focusableInTouchMode="true" tools:src="@drawable/ic_action_marker_passed"/> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 0de4778165..185a71c4a0 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,10 @@ 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 --> + Today + Yesterday + Last 7 days + This year Widget Top bar Move all to history diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 044de5d840..efce422fb0 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -10,6 +10,8 @@ import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.util.Algorithms; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; public class MapMarkersHelper { @@ -172,14 +174,50 @@ public class MapMarkersHelper { private void loadMarkers() { mapMarkers.clear(); mapMarkersHistory.clear(); - mapMarkers.addAll(markersDbHelper.getActiveMarkers()); - mapMarkersHistory.addAll(markersDbHelper.getMarkersHistory()); + + List activeMarkers = markersDbHelper.getActiveMarkers(); + sortActiveMarkers(activeMarkers); + mapMarkers.addAll(activeMarkers); + + List markersHistory = markersDbHelper.getMarkersHistory(); + sortHistoryMarkers(markersHistory); + mapMarkersHistory.addAll(markersHistory); if (!ctx.isApplicationInitializing()) { lookupAddressAll(); } } + private void sortActiveMarkers(List markers) { + Collections.sort(markers, new Comparator() { + @Override + public int compare(MapMarker mapMarker1, MapMarker mapMarker2) { + if (mapMarker1.creationDate > mapMarker2.creationDate) { + return -1; + } else if (mapMarker1.creationDate == mapMarker2.creationDate) { + return 0; + } else { + return 1; + } + } + }); + } + + private void sortHistoryMarkers(List markers) { + Collections.sort(markers, new Comparator() { + @Override + public int compare(MapMarker mapMarker1, MapMarker mapMarker2) { + if (mapMarker1.visitedDate > mapMarker2.visitedDate) { + return -1; + } else if (mapMarker1.visitedDate == mapMarker2.visitedDate) { + return 0; + } else { + return 1; + } + } + }); + } + private void lookupAddress(final MapMarker mapMarker) { if (mapMarker != null && mapMarker.pointDescription.isSearchingAddress(ctx)) { cancelPointAddressRequests(mapMarker.point); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index f5ef8026e3..c393d5840d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -11,17 +11,28 @@ import android.view.View; import android.view.ViewGroup; import net.osmand.data.PointDescription; +import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter; -public class MapMarkersHistoryFragment extends Fragment { +public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHelper.MapMarkerChangedListener { MapMarkersHistoryAdapter adapter; + OsmandApplication app; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + app = getMyApplication(); + } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + app = getMyApplication(); + final RecyclerView recyclerView = new RecyclerView(getContext()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); final MapActivity mapActivity = (MapActivity) getActivity(); @@ -31,22 +42,48 @@ public class MapMarkersHistoryFragment extends Fragment { @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(); + Object item = adapter.getItem(pos); + if (item instanceof MapMarker) { + MapMarker marker = (MapMarker) item; + 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); + app.getMapMarkersHelper().addListener(this); + return recyclerView; } + @Override + public void onDestroy() { + app.getMapMarkersHelper().removeListener(this); + super.onDestroy(); + } + void updateAdapter() { + adapter.createHeaders(); if (adapter != null) { adapter.notifyDataSetChanged(); } } + + public OsmandApplication getMyApplication() { + return (OsmandApplication)getActivity().getApplication(); + } + + @Override + public void onMapMarkerChanged(MapMarker mapMarker) { + updateAdapter(); + } + + @Override + public void onMapMarkersChanged() { + updateAdapter(); + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerDateViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerDateViewHolder.java new file mode 100644 index 0000000000..7347d46604 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerDateViewHolder.java @@ -0,0 +1,20 @@ +package net.osmand.plus.mapmarkers.adapters; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.ImageButton; +import android.widget.TextView; + +import net.osmand.plus.R; + +public class MapMarkerDateViewHolder extends RecyclerView.ViewHolder { + + final TextView date; + final ImageButton optionsBtn; + + public MapMarkerDateViewHolder(View itemView) { + super(itemView); + date = itemView.findViewById(R.id.date_title); + optionsBtn = itemView.findViewById(R.id.date_options_button); + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index e48b8705a2..16725b548c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -10,17 +10,87 @@ import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import java.text.DateFormatSymbols; +import java.util.ArrayList; +import java.util.Calendar; import java.util.List; -public class MapMarkersHistoryAdapter extends RecyclerView.Adapter { +public class MapMarkersHistoryAdapter extends RecyclerView.Adapter { + + private static final int DATE_TYPE = 1; + private static final int MARKER_TYPE = 2; + + private static final int TODAY_HEADER = 56; + private static final int YESTERDAY_HEADER = 57; + private static final int LAST_SEVEN_DAYS_HEADER = 58; + private static final int THIS_YEAR_HEADER = 59; private OsmandApplication app; - private List markers; + private List items = new ArrayList<>(); private MapMarkersHistoryAdapterListener listener; public MapMarkersHistoryAdapter(OsmandApplication app) { this.app = app; - markers = app.getMapMarkersHelper().getMapMarkersHistory(); + createHeaders(); + } + + public void createHeaders() { + items.clear(); + + List markersHistory = app.getMapMarkersHelper().getMapMarkersHistory(); + + int previousHeader = -1; + int monthsDisplayed = 0; + + Calendar currentDateCalendar = Calendar.getInstance(); + currentDateCalendar.setTimeInMillis(System.currentTimeMillis()); + int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR); + 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.visitedDate); + 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) { + if (previousHeader != TODAY_HEADER) { + items.add(TODAY_HEADER); + previousHeader = TODAY_HEADER; + } + items.add(marker); + } else if (markerDay == currentDay - 1) { + if (previousHeader != YESTERDAY_HEADER) { + items.add(YESTERDAY_HEADER); + previousHeader = YESTERDAY_HEADER; + } + items.add(marker); + } else if (currentDay - 7 >= markerDay && markerYear != 1970) { + if (previousHeader != LAST_SEVEN_DAYS_HEADER) { + items.add(LAST_SEVEN_DAYS_HEADER); + previousHeader = LAST_SEVEN_DAYS_HEADER; + } + items.add(marker); + } else { + if (previousHeader != markerMonth && monthsDisplayed < 3) { + items.add(markerMonth); + previousHeader = markerMonth; + monthsDisplayed += 1; + } else if (previousHeader != markerMonth && previousHeader != THIS_YEAR_HEADER) { + items.add(THIS_YEAR_HEADER); + previousHeader = THIS_YEAR_HEADER; + } + items.add(marker); + } + } else { + if (previousHeader != markerYear) { + items.add(markerYear); + previousHeader = markerYear; + } + items.add(marker); + } + } } public void setAdapterListener(MapMarkersHistoryAdapterListener listener) { @@ -28,53 +98,95 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter Date: Thu, 7 Sep 2017 18:18:10 +0300 Subject: [PATCH 034/128] Fix action bar --- OsmAnd/res/layout/fragment_map_markers_dialog.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml index c7bcc91ff9..47150f34f8 100644 --- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -14,7 +14,6 @@ android:id="@+id/map_markers_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" - android:theme="?attr/actionBarStyle" app:contentInsetLeft="54dp" app:contentInsetStart="54dp"> From cc13112c63710db3d70555d302220b7c045449bf Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 7 Sep 2017 18:30:47 +0300 Subject: [PATCH 035/128] Fix back to active icon --- .../plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index 16725b548c..e532eae4d1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -131,7 +131,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter Date: Thu, 7 Sep 2017 18:36:37 +0300 Subject: [PATCH 036/128] Fix issue with fragments --- .../mapmarkers/MapMarkersDialogFragment.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 87cb0ad019..abd1ade119 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -43,8 +43,20 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { - activeFragment = new MapMarkersActiveFragment(); - historyFragment = new MapMarkersHistoryFragment(); + List fragments = getChildFragmentManager().getFragments(); + for (Fragment fragment : fragments) { + if (fragment instanceof MapMarkersActiveFragment) { + activeFragment = (MapMarkersActiveFragment) fragment; + } else if (fragment instanceof MapMarkersHistoryFragment) { + historyFragment = (MapMarkersHistoryFragment) fragment; + } + } + if (activeFragment == null) { + activeFragment = new MapMarkersActiveFragment(); + } + if (historyFragment == null) { + historyFragment = new MapMarkersHistoryFragment(); + } FragmentManager fragmentManager = getChildFragmentManager(); Fragment markerOptionsFragment = fragmentManager.findFragmentByTag(MarkerOptionsBottomSheetDialogFragment.TAG); From 4ba50ff806a4f9f907951148945bf028af2610ae Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 7 Sep 2017 18:51:04 +0300 Subject: [PATCH 037/128] Rename setting --- OsmAnd/res/values/strings.xml | 4 ++-- OsmAnd/res/xml/navigation_settings.xml | 4 ++-- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 2 +- .../osmand/plus/activities/SettingsNavigationActivity.java | 4 ++-- OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index fc287e5aef..73a65c3ff7 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,8 +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 --> - Speed for map to direction of movement - Specify speed when map should rotate to direction of movement instead of compass + Map orientation change in accordance with speed + Use built in compass instead of direction of movement to determine map orientation at low speed Move all to history Build route Show direction diff --git a/OsmAnd/res/xml/navigation_settings.xml b/OsmAnd/res/xml/navigation_settings.xml index e612541541..47eefe9ade 100644 --- a/OsmAnd/res/xml/navigation_settings.xml +++ b/OsmAnd/res/xml/navigation_settings.xml @@ -63,8 +63,8 @@ android:title="@string/speed_limit_exceed"/> + android:summary="@string/map_orientation_change_in_accordance_with_speed_descr" + android:title="@string/map_orientation_change_in_accordance_with_speed"/> diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index af670182bb..29a0d165b5 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -855,7 +855,7 @@ public class OsmandSettings { public final OsmandPreference SPEED_LIMIT_EXCEED = new FloatPreference("speed_limit_exceed", 5f).makeProfile(); - public final OsmandPreference SWITCH_TO_MAP_DIRECTION = + public final OsmandPreference SWITCH_MAP_DIRECTION_TO_COMPASS = new FloatPreference("speed_for_map_to_direction_of_movement", 0f).makeProfile(); // this value string is synchronized with settings_pref.xml preference name diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 631977c461..7978fe9b15 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -202,14 +202,14 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { speedNames[i] = speedLimitsKm[i] + " " + getString(R.string.km_h); } registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm); - registerListPreference(settings.SWITCH_TO_MAP_DIRECTION, screen, speedNames, speedLimitsKm); + registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS, screen, speedNames, speedLimitsKm); } else { String[] speedNames = new String[speedLimitsKm.length]; for (int i =0; i 1) { @@ -203,7 +203,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc zoom = autozoom(location); } int currentMapRotation = settings.ROTATE_MAP.get(); - float speedForDirectionOfMovement = settings.SWITCH_TO_MAP_DIRECTION.get(); + float speedForDirectionOfMovement = settings.SWITCH_MAP_DIRECTION_TO_COMPASS.get(); boolean smallSpeedForDirectionOfMovement = speedForDirectionOfMovement != 0 && isSmallSpeedForDirectionOfMovement(location, speedForDirectionOfMovement); boolean smallSpeedForCompass = isSmallSpeedForCompass(location); boolean smallSpeedForAnimation = isSmallSpeedForAnimation(location); From 30a966af0b9697370fd6f20efc8e4be82cbb5ebe Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 8 Sep 2017 10:03:42 +0300 Subject: [PATCH 038/128] Fix history header --- .../plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index e532eae4d1..ec43cd4f9f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -53,7 +53,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter Date: Fri, 8 Sep 2017 10:06:57 +0300 Subject: [PATCH 039/128] Fix displaying headers --- .../plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index ec43cd4f9f..400509580c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -155,7 +155,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter Date: Fri, 8 Sep 2017 10:21:38 +0300 Subject: [PATCH 040/128] Fix NPE in child fragments --- .../plus/mapmarkers/MapMarkersDialogFragment.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index abd1ade119..be0150a73d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -44,11 +44,13 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { List fragments = getChildFragmentManager().getFragments(); - for (Fragment fragment : fragments) { - if (fragment instanceof MapMarkersActiveFragment) { - activeFragment = (MapMarkersActiveFragment) fragment; - } else if (fragment instanceof MapMarkersHistoryFragment) { - historyFragment = (MapMarkersHistoryFragment) fragment; + if (fragments != null) { + for (Fragment fragment : fragments) { + if (fragment instanceof MapMarkersActiveFragment) { + activeFragment = (MapMarkersActiveFragment) fragment; + } else if (fragment instanceof MapMarkersHistoryFragment) { + historyFragment = (MapMarkersHistoryFragment) fragment; + } } } if (activeFragment == null) { From d77fc5109bc7ab642959f31cb48fbbf0505f3648 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 8 Sep 2017 11:17:52 +0300 Subject: [PATCH 041/128] Divide selected points to groups --- .../activities/FavoritesTreeFragment.java | 107 +++++++++++++----- 1 file changed, 78 insertions(+), 29 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index d038d93105..3103115549 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -80,7 +80,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { private OsmandApplication app; private boolean selectionMode = false; - private Set favoritesSelected = new LinkedHashSet<>(); + private LinkedHashMap> favoritesSelected = new LinkedHashMap<>(); private Set groupsToDelete = new LinkedHashSet<>(); private ActionMode actionMode; Drawable arrowImage; @@ -127,7 +127,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { @Override protected String doInBackground(Void... params) { - helper.delete(groupsToDelete, favoritesSelected); + helper.delete(groupsToDelete, getSelectedFavorites()); favoritesSelected.clear(); groupsToDelete.clear(); return getString(R.string.favourites_delete_multiple_succesful); @@ -206,14 +206,35 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { initListExpandedState(); } + private int getSelectedFavoritesCount() { + int count = 0; + for (Set set : favoritesSelected.values()) { + if (set != null) { + count += set.size(); + } + } + return count; + } + + private Set getSelectedFavorites() { + Set result = new LinkedHashSet<>(); + for (Set set : favoritesSelected.values()) { + if (set != null) { + result.addAll(set); + } + } + return result; + } + public void reloadData() { favouritesAdapter.synchronizeGroups(); favouritesAdapter.notifyDataSetInvalidated(); } private void updateSelectionMode(ActionMode m) { - if (favoritesSelected.size() > 0) { - m.setTitle(favoritesSelected.size() + " " + getMyApplication().getString(R.string.shared_string_selected_lowercase)); + int size = getSelectedFavoritesCount(); + if (size > 0) { + m.setTitle(size + " " + getMyApplication().getString(R.string.shared_string_selected_lowercase)); } else { m.setTitle(""); } @@ -224,11 +245,22 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { if (selectionMode) { CheckBox ch = (CheckBox) v.findViewById(R.id.toggle_item); FavouritePoint model = favouritesAdapter.getChild(groupPosition, childPosition); + FavoriteGroup group = favouritesAdapter.getGroup(groupPosition); ch.setChecked(!ch.isChecked()); if (ch.isChecked()) { - favoritesSelected.add(model); + Set set = favoritesSelected.get(group.name); + if (set != null) { + set.add(model); + } else { + set = new LinkedHashSet<>(); + set.add(model); + favoritesSelected.put(group.name, set); + } } else { - favoritesSelected.remove(model); + Set set = favoritesSelected.get(group.name); + if (set != null) { + set.remove(model); + } } updateSelectionMode(actionMode); } else { @@ -308,14 +340,14 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { public void showProgressBar() { OsmandActionBarActivity activity = getActionBarActivity(); - if(activity != null) { + if (activity != null) { activity.setSupportProgressBarIndeterminateVisibility(true); } } public void hideProgressBar() { OsmandActionBarActivity activity = getActionBarActivity(); - if(activity != null) { + if (activity != null) { activity.setSupportProgressBarIndeterminateVisibility(false); } } @@ -366,12 +398,13 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { } private void selectMapMarkersImpl() { - if(!favoritesSelected.isEmpty()) { + if (getSelectedFavoritesCount() > 0) { if (getSettings().USE_MAP_MARKERS.get()) { MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); - List points = new ArrayList<>(favoritesSelected.size()); - List names = new ArrayList<>(favoritesSelected.size()); - for (FavouritePoint fp : favoritesSelected) { + int size = getSelectedFavoritesCount(); + List points = new ArrayList<>(size); + List names = new ArrayList<>(size); + for (FavouritePoint fp : getSelectedFavorites()) { points.add(new LatLon(fp.getLatitude(), fp.getLongitude())); names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName())); } @@ -379,7 +412,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { MapActivity.launchMapActivityMoveToTop(getActivity()); } else { final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper(); - for (FavouritePoint fp : favoritesSelected) { + for (FavouritePoint fp : getSelectedFavorites()) { targetPointsHelper.navigateToPoint(new LatLon(fp.getLatitude(), fp.getLongitude()), false, targetPointsHelper.getIntermediatePoints().size() + 1, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, fp.getName())); @@ -441,10 +474,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { } private void deleteFavoritesAction() { - if (groupsToDelete.size() + favoritesSelected.size() > 0) { + int size = getSelectedFavoritesCount(); + if (groupsToDelete.size() + size > 0) { AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); - b.setMessage(getString(R.string.favorite_delete_multiple, favoritesSelected.size(), groupsToDelete.size())); + b.setMessage(getString(R.string.favorite_delete_multiple, size, groupsToDelete.size())); b.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -458,18 +492,18 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { b.show(); } } - + private StringBuilder generateHtmlPrint(List groups) { StringBuilder html = new StringBuilder(); html.append("

My Favorites

"); for (FavoriteGroup group : groups) { - html.append("

"+group.name+"

"); - for(FavouritePoint fp : group.points) { - String url = "geo:"+((float)fp.getLatitude())+","+((float)fp.getLongitude())+"?m="+fp.getName(); + html.append("

" + group.name + "

"); + for (FavouritePoint fp : group.points) { + String url = "geo:" + ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "?m=" + fp.getName(); html.append("

" + fp.getName() + " - " + "geo:" + ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "
"); - - if(!Algorithms.isEmpty(fp.getDescription())) { + + if (!Algorithms.isEmpty(fp.getDescription())) { html.append(": " + fp.getDescription()); } html.append("

"); @@ -521,7 +555,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { @Override protected void onPostExecute(Void res) { hideProgressBar(); - if(getActivity() == null) { + if (getActivity() == null) { // user quit application return; } @@ -763,13 +797,17 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { if (ch.isChecked()) { groupsToDelete.add(model); if (fvs != null) { - favoritesSelected.addAll(fvs); + Set set = favoritesSelected.get(model.name); + if (set != null) { + set.addAll(model.points); + } else { + set = new LinkedHashSet<>(model.points); + favoritesSelected.put(model.name, set); + } } } else { groupsToDelete.remove(model); - if (fvs != null) { - favoritesSelected.removeAll(fvs); - } + favoritesSelected.remove(model.name); } favouritesAdapter.notifyDataSetInvalidated(); updateSelectionMode(actionMode); @@ -820,6 +858,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon); final FavouritePoint model = getChild(groupPosition, childPosition); + final FavoriteGroup group = getGroup(groupPosition); boolean visible = model.isVisible(); row.setTag(model); @@ -864,16 +903,26 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item); if (selectionMode) { ch.setVisibility(View.VISIBLE); - ch.setChecked(favoritesSelected.contains(model)); + ch.setChecked(favoritesSelected.get(group.name) != null && favoritesSelected.get(group.name).contains(model)); row.findViewById(R.id.favourite_icon).setVisibility(View.GONE); ch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (ch.isChecked()) { - favoritesSelected.add(model); + Set set = favoritesSelected.get(group.name); + if (set != null) { + set.add(model); + } else { + set = new LinkedHashSet<>(); + set.add(model); + favoritesSelected.put(group.name, set); + } } else { - favoritesSelected.remove(model); + Set set = favoritesSelected.get(group.name); + if (set != null) { + set.remove(model); + } } updateSelectionMode(actionMode); } From 09223033c72d230d0da996a089f05c04826250f7 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 8 Sep 2017 11:21:15 +0300 Subject: [PATCH 042/128] Localize headers --- .../adapters/MapMarkersHistoryAdapter.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index 400509580c..bad2cd7fff 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -10,10 +10,12 @@ import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import java.text.DateFormatSymbols; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; import java.util.List; +import java.util.Locale; public class MapMarkersHistoryAdapter extends RecyclerView.Adapter { @@ -37,6 +39,22 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter markersHistory = app.getMapMarkersHelper().getMapMarkersHistory(); int previousHeader = -1; @@ -186,7 +204,10 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter Date: Fri, 8 Sep 2017 11:34:41 +0300 Subject: [PATCH 043/128] Fix color --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index dc8925b055..a03627a3bd 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -356,7 +356,7 @@ public class MapMarkersHelper { } if (colorIndex == -1) { if (mapMarkers.size() > 0) { - colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; + colorIndex = (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } else { colorIndex = 0; } From bbc7ff9ea0cb69df2bbbef15cd282ee8a8c8f76d Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 8 Sep 2017 11:35:29 +0300 Subject: [PATCH 044/128] Fix headers --- .../mapmarkers/adapters/MapMarkersHistoryAdapter.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index bad2cd7fff..0562b1cc37 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -90,12 +90,15 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter Date: Fri, 8 Sep 2017 11:48:02 +0300 Subject: [PATCH 045/128] Fix old markers headers --- .../plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index 0562b1cc37..631c414925 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -71,7 +71,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter= markerDay && markerYear != 1970) { + } else if (currentDay - 7 >= markerDay) { if (previousHeader != LAST_SEVEN_DAYS_HEADER) { items.add(LAST_SEVEN_DAYS_HEADER); previousHeader = LAST_SEVEN_DAYS_HEADER; From a5fbace3327283696ffbb744c916d273bc2ea7a0 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 8 Sep 2017 12:34:27 +0300 Subject: [PATCH 046/128] Fix date for existing markers --- .../plus/mapmarkers/MapMarkersDbHelper.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 4c1de6d643..c9aa1b0da5 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -12,6 +12,7 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.helpers.SearchHistoryHelper; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.Random; @@ -122,7 +123,7 @@ public class MapMarkersDbHelper { MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i); marker.history = false; - addMarker(marker); + addMarker(marker, true); } ips = settings.getMapMarkersHistoryPoints(); @@ -135,7 +136,7 @@ public class MapMarkersDbHelper { MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i); marker.history = true; - addMarker(marker); + addMarker(marker, true); } } @@ -148,25 +149,36 @@ public class MapMarkersDbHelper { } public void addMarker(MapMarker marker) { + addMarker(marker, false); + } + + private void addMarker(MapMarker marker, boolean saveExisting) { SQLiteConnection db = openConnection(false); if (db != null) { try { - insertLast(db, marker); + insertLast(db, marker, saveExisting); } finally { db.close(); } } } - private void insertLast(SQLiteConnection db, MapMarker marker) { - long currentTime = System.currentTimeMillis(); + private void insertLast(SQLiteConnection db, MapMarker marker, boolean saveExisting) { + long currentTime; + if (saveExisting) { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MONTH, -1); + currentTime = cal.getTimeInMillis(); + } else { + currentTime = System.currentTimeMillis(); + } marker.id = Long.parseLong(String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100)); marker.creationDate = currentTime; double lat = marker.getLatitude(); double lon = marker.getLongitude(); String descr = PointDescription.serializeToString(marker.getOriginalPointDescription()); int active = marker.history ? 0 : 1; - long visited = 0; + long visited = saveExisting ? currentTime : 0; int groupKey = 0; int colorIndex = marker.colorIndex; From 3dd513c1e18e508cb1aa70022537dfb8cb809e10 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 8 Sep 2017 12:40:41 +0300 Subject: [PATCH 047/128] Add on click listeners in show direction menu --- .../ShowDirectionBottomSheetDialogFragment.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index 9a6407944b..f057cfc319 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -61,6 +61,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra return false; } }); + topBarImage.setOnClickListener(topBarOnClickListener); mainView.findViewById(R.id.widget_text).setOnTouchListener(new View.OnTouchListener() { @Override @@ -68,6 +69,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra return false; } }); + widgetImage.setOnClickListener(widgetOnClickListener); } if (nightMode) { @@ -143,6 +145,21 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra } } + private View.OnClickListener topBarOnClickListener = new View.OnClickListener() { + + @Override + public void onClick(View view) { + + } + }; + + private View.OnClickListener widgetOnClickListener = new View.OnClickListener() { + @Override + public void onClick(View view) { + + } + }; + interface ShowDirectionFragmentListener { } From 61fb2ab0babb9fa0bb96ca20ba135dd897f5c30a Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 8 Sep 2017 13:16:18 +0300 Subject: [PATCH 048/128] Fix old markers --- .../plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index 631c414925..228f777004 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -63,6 +63,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter= markerDay) { + } else if (currentDay - 7 >= markerDay && currentMonth == markerMonth) { if (previousHeader != LAST_SEVEN_DAYS_HEADER) { items.add(LAST_SEVEN_DAYS_HEADER); previousHeader = LAST_SEVEN_DAYS_HEADER; From a86ea5118bad81a95e4ed6d27dd61cfefe936f9a Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 8 Sep 2017 13:23:16 +0300 Subject: [PATCH 049/128] Fix sorting --- .../src/net/osmand/plus/MapMarkersHelper.java | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index a03627a3bd..787db38093 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -176,11 +176,10 @@ public class MapMarkersHelper { mapMarkersHistory.clear(); List activeMarkers = markersDbHelper.getActiveMarkers(); - sortActiveMarkers(activeMarkers); mapMarkers.addAll(activeMarkers); List markersHistory = markersDbHelper.getMarkersHistory(); - sortHistoryMarkers(markersHistory); + sortMarkers(markersHistory, true); mapMarkersHistory.addAll(markersHistory); if (!ctx.isApplicationInitializing()) { @@ -188,28 +187,22 @@ public class MapMarkersHelper { } } - private void sortActiveMarkers(List markers) { + private void sortMarkers(List markers, final boolean history) { Collections.sort(markers, new Comparator() { @Override public int compare(MapMarker mapMarker1, MapMarker mapMarker2) { - if (mapMarker1.creationDate > mapMarker2.creationDate) { - return -1; - } else if (mapMarker1.creationDate == mapMarker2.creationDate) { - return 0; + long firstMarkerDate; + long secondMarkerDate; + if (history) { + firstMarkerDate = mapMarker1.visitedDate; + secondMarkerDate = mapMarker2.visitedDate; } else { - return 1; + firstMarkerDate = mapMarker1.creationDate; + secondMarkerDate = mapMarker2.creationDate; } - } - }); - } - - private void sortHistoryMarkers(List markers) { - Collections.sort(markers, new Comparator() { - @Override - public int compare(MapMarker mapMarker1, MapMarker mapMarker2) { - if (mapMarker1.visitedDate > mapMarker2.visitedDate) { + if (firstMarkerDate > secondMarkerDate) { return -1; - } else if (mapMarker1.visitedDate == mapMarker2.visitedDate) { + } else if (firstMarkerDate == secondMarkerDate) { return 0; } else { return 1; From 2b264697add8c211e237940b9a4746aab20b9c7f Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 8 Sep 2017 14:13:03 +0300 Subject: [PATCH 050/128] Make show direction menu work --- .../mapmarkers/MapMarkersDialogFragment.java | 22 +++++++++-- ...arkerOptionsBottomSheetDialogFragment.java | 2 +- ...howDirectionBottomSheetDialogFragment.java | 38 +++++++++++++------ .../views/mapwidgets/MapWidgetRegistry.java | 24 +++++++----- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index be0150a73d..e66348ef5a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -19,6 +19,7 @@ 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.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener; import net.osmand.plus.mapmarkers.MarkerOptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener; import java.util.Arrays; @@ -65,6 +66,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm if (markerOptionsFragment != null) { ((MarkerOptionsBottomSheetDialogFragment) markerOptionsFragment).setListener(createMarkerOptionsFragmentListener()); } + Fragment showDirectionFragment = fragmentManager.findFragmentByTag(ShowDirectionBottomSheetDialogFragment.TAG); + if (showDirectionFragment != null) { + ((ShowDirectionBottomSheetDialogFragment) showDirectionFragment).setListener(createShowDirectionFragmentListener()); + } View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); @@ -137,7 +142,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void showDirectionOnClick() { - openShowDirectionMenu(mapActivity); + ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment(); + fragment.setListener(createShowDirectionFragmentListener()); + fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG); } @Override @@ -158,9 +165,16 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm }; } - private void openShowDirectionMenu(MapActivity mapActivity) { - ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment(); - fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG); + private ShowDirectionFragmentListener createShowDirectionFragmentListener() { + return new ShowDirectionFragmentListener() { + + final MapActivity mapActivity = getMapActivity(); + + @Override + public void onMapMarkersModeChanged() { + mapActivity.getMapLayers().getMapWidgetRegistry().updateMapMarkersMode(mapActivity); + } + }; } private MapActivity getMapActivity() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java index 5df7fc263f..8ef1ab8531 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java @@ -52,7 +52,7 @@ public class MarkerOptionsBottomSheetDialogFragment extends BottomSheetDialogFra ((ImageView) mainView.findViewById(R.id.move_all_to_history_icon)) .setImageDrawable(getIcon(R.drawable.ic_action_history2, R.color.on_map_icon_color)); - ((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText("Top bar"); + ((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText(getMyApplication().getSettings().MAP_MARKERS_MODE.get().toHumanString(getActivity())); mainView.findViewById(R.id.sort_by_row).setOnClickListener(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 f057cfc319..1b84f0974d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -15,6 +15,7 @@ import android.widget.ImageView; import android.widget.TextView; import net.osmand.AndroidUtils; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -61,7 +62,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra return false; } }); - topBarImage.setOnClickListener(topBarOnClickListener); + topBarImage.setOnClickListener(showDirectionOnClickListener); mainView.findViewById(R.id.widget_text).setOnTouchListener(new View.OnTouchListener() { @Override @@ -69,7 +70,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra return false; } }); - widgetImage.setOnClickListener(widgetOnClickListener); + widgetImage.setOnClickListener(showDirectionOnClickListener); } if (nightMode) { @@ -87,6 +88,10 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra ImageView noneIcon = (ImageView) mainView.findViewById(R.id.none_icon); noneIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); + mainView.findViewById(R.id.top_bar_row).setOnClickListener(showDirectionOnClickListener); + mainView.findViewById(R.id.widget_row).setOnClickListener(showDirectionOnClickListener); + mainView.findViewById(R.id.none_row).setOnClickListener(showDirectionOnClickListener); + mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -145,22 +150,31 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra } } - private View.OnClickListener topBarOnClickListener = new View.OnClickListener() { + private View.OnClickListener showDirectionOnClickListener = new View.OnClickListener() { @Override public void onClick(View view) { - - } - }; - - private View.OnClickListener widgetOnClickListener = new View.OnClickListener() { - @Override - public void onClick(View view) { - + switch (view.getId()) { + case R.id.top_bar_image: + case R.id.top_bar_row: + getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.TOOLBAR); + break; + case R.id.widget_image: + case R.id.widget_row: + getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.WIDGETS); + break; + case R.id.none_row: + getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.NONE); + break; + } + if (listener != null) { + listener.onMapMarkersModeChanged(); + } + dismiss(); } }; interface ShowDirectionFragmentListener { - + void onMapMarkersModeChanged(); } } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index 64316febc4..db172d577f 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -345,16 +345,7 @@ public class MapWidgetRegistry { @Override public void onClick(DialogInterface dialog, int which) { settings.MAP_MARKERS_MODE.set(MapMarkersMode.values()[which]); - for (MapWidgetRegInfo info : rightWidgetSet) { - if ("map_marker_1st".equals(info.key) || "map_marker_2nd".equals(info.key)) { - setVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets(), false); - } - } - MapInfoLayer mil = map.getMapLayers().getMapInfoLayer(); - if (mil != null) { - mil.recreateControls(); - } - map.refreshMap(); + updateMapMarkersMode(map); dialog.dismiss(); cm.getItem(pos).setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map)); ad.notifyDataSetChanged(); @@ -367,6 +358,19 @@ public class MapWidgetRegistry { } } + public void updateMapMarkersMode(MapActivity mapActivity) { + for (MapWidgetRegInfo info : rightWidgetSet) { + if ("map_marker_1st".equals(info.key) || "map_marker_2nd".equals(info.key)) { + setVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets(), false); + } + } + MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer(); + if (mil != null) { + mil.recreateControls(); + } + mapActivity.refreshMap(); + } + private void addControlId(final MapActivity map, ContextMenuAdapter cm, @StringRes int stringId, OsmandPreference pref) { cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(stringId, map) From c42d8b8114fb9eb13a251d204bf17b989a3fe561 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 8 Sep 2017 14:33:10 +0300 Subject: [PATCH 051/128] Add some code --- .../src/net/osmand/plus/MapMarkersHelper.java | 20 +++--- .../plus/mapmarkers/MapMarkersDbHelper.java | 61 ++++++++++++++++--- 2 files changed, 62 insertions(+), 19 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 787db38093..87a11c53e7 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -43,6 +43,7 @@ public class MapMarkersHelper { public long creationDate; public long visitedDate; public long nextKey; + public long groupKey = -1; public MapMarker(LatLon point, PointDescription name, int colorIndex, boolean selected, int index) { @@ -191,15 +192,8 @@ public class MapMarkersHelper { Collections.sort(markers, new Comparator() { @Override public int compare(MapMarker mapMarker1, MapMarker mapMarker2) { - long firstMarkerDate; - long secondMarkerDate; - if (history) { - firstMarkerDate = mapMarker1.visitedDate; - secondMarkerDate = mapMarker2.visitedDate; - } else { - firstMarkerDate = mapMarker1.creationDate; - secondMarkerDate = mapMarker2.creationDate; - } + long firstMarkerDate = history ? mapMarker1.visitedDate : mapMarker1.creationDate; + long secondMarkerDate = history ? mapMarker2.visitedDate : mapMarker2.creationDate; if (firstMarkerDate > secondMarkerDate) { return -1; } else if (firstMarkerDate == secondMarkerDate) { @@ -230,6 +224,14 @@ public class MapMarkersHelper { } } + public long createGroupIfNeeded(String name) { + return markersDbHelper.createGroupIfNeeded(name); + } + + public String getGroupName(long id) { + return markersDbHelper.getGroupName(id); + } + public void moveMapMarkerToHistory(MapMarker marker) { if (marker != null) { cancelPointAddressRequests(marker.point); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index c9aa1b0da5..910ad1ca51 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -43,7 +43,7 @@ public class MapMarkersDbHelper { MARKERS_COL_ACTIVE + " int, " + // 1 = true, 0 = false MARKERS_COL_ADDED + " long, " + MARKERS_COL_VISITED + " long, " + - MARKERS_COL_GROUP_KEY + " int, " + + MARKERS_COL_GROUP_KEY + " long, " + MARKERS_COL_COLOR + " int, " + MARKERS_COL_NEXT_KEY + " long);"; @@ -61,15 +61,18 @@ public class MapMarkersDbHelper { " FROM " + MARKERS_TABLE_NAME; private static final String GROUPS_TABLE_NAME = "map_markers_groups"; + private static final String GROUPS_COL_ID = "group_id"; private static final String GROUPS_COL_NAME = "group_name"; - private static final String GROUPS_COL_TYPE = "group_type"; - private static final String GROUPS_COL_ADDED = "group_added"; private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + GROUPS_TABLE_NAME + " (" + - GROUPS_COL_NAME + " TEXT, " + - GROUPS_COL_TYPE + " TEXT, " + - GROUPS_COL_ADDED + " long);"; + GROUPS_COL_ID + " long PRIMARY KEY, " + + GROUPS_COL_NAME + " TEXT);"; + + private static final String GROUPS_TABLE_SELECT = "SELECT " + + GROUPS_COL_ID + ", " + + GROUPS_COL_NAME + + " FROM " + GROUPS_TABLE_NAME; private static final int TAIL_NEXT_VALUE = 0; private static final int HISTORY_NEXT_VALUE = -1; @@ -148,6 +151,26 @@ public class MapMarkersDbHelper { } } + public long createGroupIfNeeded(String name) { + long res = -1; + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_NAME + " = ?", + new String[]{name}); + if (query.moveToFirst()) { + res = query.getLong(0); + } else { + res = Long.parseLong(String.valueOf(System.currentTimeMillis()) + String.valueOf(new Random().nextInt(900) + 100)); + db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?)", new Object[]{res, name}); + } + } finally { + db.close(); + } + } + return res; + } + public void addMarker(MapMarker marker) { addMarker(marker, false); } @@ -179,7 +202,7 @@ public class MapMarkersDbHelper { String descr = PointDescription.serializeToString(marker.getOriginalPointDescription()); int active = marker.history ? 0 : 1; long visited = saveExisting ? currentTime : 0; - int groupKey = 0; + long groupKey = marker.groupKey; int colorIndex = marker.colorIndex; PointDescription pointDescription = marker.getOriginalPointDescription(); @@ -198,6 +221,23 @@ public class MapMarkersDbHelper { marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE}); } + public String getGroupName(long id) { + String res = ""; + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_ID + " = ?", + new String[]{String.valueOf(id)}); + if (query.moveToFirst()) { + res = query.getString(1); + } + } finally { + db.close(); + } + } + return res; + } + public List getActiveMarkers() { List res = new LinkedList<>(); LongSparseArray markers = new LongSparseArray<>(); @@ -229,18 +269,19 @@ public class MapMarkersDbHelper { boolean active = query.getInt(4) == 1; long added = query.getLong(5); long visited = query.getLong(6); - int groupKey = query.getInt(7); + long groupKey = query.getInt(7); int colorIndex = query.getInt(8); long nextKey = query.getLong(9); LatLon latLon = new LatLon(lat, lon); MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), colorIndex, false, 0); + marker.id = id; + marker.history = !active; marker.creationDate = added; marker.visitedDate = visited; - marker.history = !active; + marker.groupKey = groupKey; marker.nextKey = nextKey; - marker.id = id; return marker; } From 63131b6abb4a186bec7dba80640cd20044f3f365 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 8 Sep 2017 15:09:03 +0300 Subject: [PATCH 052/128] Change some methods --- .../src/net/osmand/plus/MapMarkersHelper.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 87a11c53e7..4e08dc1ea3 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -327,14 +327,18 @@ public class MapMarkersHelper { } public void addMapMarker(LatLon point, PointDescription historyName) { - List points = new ArrayList<>(1); - List historyNames = new ArrayList<>(1); - points.add(point); - historyNames.add(historyName); - addMapMarkers(points, historyNames); + addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null); + } + + public void addMapMarkers(List points, List historyNames, List groups) { + addMarkers(points, historyNames, groups); } public void addMapMarkers(List points, List historyNames) { + addMarkers(points, historyNames, null); + } + + private void addMarkers(List points, List historyNames, @Nullable List groups) { if (points.size() > 0) { int colorIndex = -1; for (int i = 0; i < points.size(); i++) { @@ -360,6 +364,9 @@ public class MapMarkersHelper { } MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); + if (groups != null) { + marker.groupKey = markersDbHelper.createGroupIfNeeded(groups.get(i)); + } markersDbHelper.addMarker(marker); } loadMarkers(); From c5a053605759968995dfa46b9f4cec46e60a5f3e Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 8 Sep 2017 15:29:45 +0300 Subject: [PATCH 053/128] Change method --- .../plus/activities/FavoritesTreeFragment.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 3103115549..7c0f7817b6 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -404,11 +404,15 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { int size = getSelectedFavoritesCount(); List points = new ArrayList<>(size); List names = new ArrayList<>(size); - for (FavouritePoint fp : getSelectedFavorites()) { - points.add(new LatLon(fp.getLatitude(), fp.getLongitude())); - names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName())); + List groups = new ArrayList<>(size); + for (Map.Entry> entry : favoritesSelected.entrySet()) { + for (FavouritePoint fp : entry.getValue()) { + points.add(new LatLon(fp.getLatitude(), fp.getLongitude())); + names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName())); + groups.add(entry.getKey()); + } } - markersHelper.addMapMarkers(points, names); + markersHelper.addMapMarkers(points, names, groups); MapActivity.launchMapActivityMoveToTop(getActivity()); } else { final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper(); From a30b123b898df91b0334a6cea46f49d9e168344a Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 8 Sep 2017 15:59:29 +0300 Subject: [PATCH 054/128] Add history marker menu --- ...ent_marker_history_bottom_sheet_dialog.xml | 160 ++++++++++++++++++ ...ment_selected_menu_bottom_sheet_dialog.xml | 4 +- OsmAnd/res/values-large/sizes.xml | 2 +- OsmAnd/res/values/sizes.xml | 2 +- OsmAnd/res/values/strings.xml | 1 + ...ryMarkerMenuBottomSheetDialogFragment.java | 112 ++++++++++++ .../mapmarkers/MapMarkersHistoryFragment.java | 9 +- 7 files changed, 280 insertions(+), 10 deletions(-) create mode 100644 OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java diff --git a/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml new file mode 100644 index 0000000000..f1db780f6e --- /dev/null +++ b/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml index e62de7e2dc..828941f378 100644 --- a/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml @@ -20,8 +20,8 @@ 12dp 96dp 15dp - 84dp + 84dp \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 9ca00d5e8c..8ff94dfbef 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -186,5 +186,5 @@ 8dp 64dp 10dp - 56dp + 56dp \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 185a71c4a0..1e08479d0b 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 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 --> + Make active Today Yesterday Last 7 days diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java new file mode 100644 index 0000000000..fd309ce2df --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -0,0 +1,112 @@ +package net.osmand.plus.mapmarkers; + +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.view.Window; +import android.view.WindowManager; +import android.widget.ImageView; + +import net.osmand.AndroidUtils; +import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.R; +import net.osmand.plus.base.BottomSheetDialogFragment; +import net.osmand.plus.helpers.AndroidUiHelper; + +public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialogFragment { + + public final static String TAG = "HistoryMarkerMenuBottomSheetDialogFragment"; + + private HistoryMarkerMenuFragmentListener listener; + private boolean portrait; + private MapMarker marker; + + public void setListener(HistoryMarkerMenuFragmentListener listener) { + this.listener = listener; + } + + public void setMarker(MapMarker marker) { + this.marker = marker; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + + final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_history_bottom_sheet_dialog, container); + if (portrait) { + AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); + } + ((ImageView) mainView.findViewById(R.id.make_active_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_reset_to_default_dark)); + ((ImageView) mainView.findViewById(R.id.delete_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_delete_dark)); + + mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + final int screenHeight = AndroidUtils.getScreenHeight(getActivity()); + final int statusBarHeight = AndroidUtils.getStatusBarHeight(getActivity()); + final int navBarHeight = AndroidUtils.getNavBarHeight(getActivity()); + + mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + final View scrollView = mainView.findViewById(R.id.history_marker_scroll_view); + int scrollViewHeight = scrollView.getHeight(); + int dividerHeight = AndroidUtils.dpToPx(getContext(), 1); + int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); + int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight; + if (scrollViewHeight > spaceForScrollView) { + scrollView.getLayoutParams().height = spaceForScrollView; + scrollView.requestLayout(); + } + + if (!portrait) { + if (screenHeight - statusBarHeight - mainView.getHeight() + >= AndroidUtils.dpToPx(getActivity(), 8)) { + AndroidUtils.setBackground(getActivity(), mainView, false, + R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); + } else { + AndroidUtils.setBackground(getActivity(), mainView, false, + R.drawable.bg_bottom_sheet_sides_landscape_light, R.drawable.bg_bottom_sheet_sides_landscape_dark); + } + } + + ViewTreeObserver obs = mainView.getViewTreeObserver(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + obs.removeOnGlobalLayoutListener(this); + } else { + obs.removeGlobalOnLayoutListener(this); + } + } + }); + + return mainView; + } + + @Override + public void onStart() { + super.onStart(); + if (!portrait) { + final Window window = getDialog().getWindow(); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width); + window.setAttributes(params); + } + } + + interface HistoryMarkerMenuFragmentListener { + + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index c393d5840d..9bb0410e4f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -44,12 +44,9 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel int pos = recyclerView.indexOfChild(view); Object item = adapter.getItem(pos); if (item instanceof MapMarker) { - MapMarker marker = (MapMarker) item; - 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(); + HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment(); + fragment.setMarker((MapMarker) item); + fragment.show(mapActivity.getSupportFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG); } } }); From a1b9e6791ed9c19321b7a5c4e02f8c878de3123b Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 8 Sep 2017 16:12:59 +0300 Subject: [PATCH 055/128] Fix small issues --- OsmAnd/res/layout/map_marker_item_new.xml | 4 +++- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 2 +- OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java | 2 +- .../plus/mapmarkers/adapters/MapMarkersActiveAdapter.java | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 1edd0e5cf1..a74186b4e6 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -9,8 +9,8 @@ android:orientation="vertical"> diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 4e08dc1ea3..41db924c59 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -355,7 +355,7 @@ public class MapMarkersHelper { } if (colorIndex == -1) { if (mapMarkers.size() > 0) { - colorIndex = (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; + colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } else { colorIndex = 0; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 910ad1ca51..f5c798bcb4 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -269,7 +269,7 @@ public class MapMarkersDbHelper { boolean active = query.getInt(4) == 1; long added = query.getLong(5); long visited = query.getLong(6); - long groupKey = query.getInt(7); + long groupKey = query.getLong(7); int colorIndex = query.getInt(8); long nextKey = query.getLong(9); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 886b624511..31f02bf711 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -89,7 +89,9 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Fri, 8 Sep 2017 16:41:20 +0300 Subject: [PATCH 056/128] Fix small issue with Favorites --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 1 + .../osmand/plus/mapmarkers/MapMarkersDbHelper.java | 3 ++- .../adapters/MapMarkersActiveAdapter.java | 13 ++++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 41db924c59..d0d0acb1a4 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -228,6 +228,7 @@ public class MapMarkersHelper { return markersDbHelper.createGroupIfNeeded(name); } + @Nullable public String getGroupName(long id) { return markersDbHelper.getGroupName(id); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index f5c798bcb4..2e309fc19e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -221,8 +221,9 @@ public class MapMarkersDbHelper { marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE}); } + @Nullable public String getGroupName(long id) { - String res = ""; + String res = null; SQLiteConnection db = openConnection(true); if (db != null) { try { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 31f02bf711..872a70e7e6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -89,9 +89,16 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Fri, 8 Sep 2017 16:46:04 +0300 Subject: [PATCH 057/128] Show info from marker in menu --- .../HistoryMarkerMenuBottomSheetDialogFragment.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index fd309ce2df..5925434216 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -11,10 +11,12 @@ import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; +import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -37,6 +39,7 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + MapActivity mapActivity = (MapActivity) getActivity(); portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; @@ -45,6 +48,14 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo if (portrait) { AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); } + + if (marker != null) { + int color = MapMarker.getColorId(marker.colorIndex); + ((ImageView) mainView.findViewById(R.id.map_marker_icon)).setImageDrawable(getIcon(R.drawable.ic_action_flag_dark, color)); + ((TextView) mainView.findViewById(R.id.map_marker_title)).setText(marker.getName(mapActivity)); + ((TextView) mainView.findViewById(R.id.map_marker_passed_info)).setText(String.valueOf(marker.visitedDate)); + } + ((ImageView) mainView.findViewById(R.id.make_active_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_reset_to_default_dark)); ((ImageView) mainView.findViewById(R.id.delete_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_delete_dark)); From d5639abfd607809d075a7f94b3018203337e4b2e Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 8 Sep 2017 16:53:31 +0300 Subject: [PATCH 058/128] Add some code --- OsmAnd/res/layout/map_marker_item_new.xml | 2 +- .../src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index a74186b4e6..e9e1b0548a 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -46,7 +46,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="end" - android:maxLines="2" + android:maxLines="1" android:textColor="?android:textColorPrimary" android:textSize="@dimen/default_list_text_size" tools:text="Van Gogh Museum"/> diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 2e309fc19e..d630600cc3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -19,7 +19,7 @@ import java.util.Random; public class MapMarkersDbHelper { - private static final int DB_VERSION = 1; + private static final int DB_VERSION = 2; private static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; @@ -109,7 +109,9 @@ public class MapMarkersDbHelper { } private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) { - + db.execSQL("DROP TABLE " + MARKERS_TABLE_NAME); + db.execSQL("DROP TABLE " + GROUPS_TABLE_NAME); + onCreate(db); } private void saveExistingMarkersToDb() { From 196fd7c1b5c47760fa2b0d13208acc80b31e7a4c Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 8 Sep 2017 16:57:09 +0300 Subject: [PATCH 059/128] Add some code --- OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index d630600cc3..c942cfd40b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -109,8 +109,8 @@ public class MapMarkersDbHelper { } private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) { - db.execSQL("DROP TABLE " + MARKERS_TABLE_NAME); - db.execSQL("DROP TABLE " + GROUPS_TABLE_NAME); + db.execSQL("DROP TABLE IF EXISTS " + MARKERS_TABLE_NAME); + db.execSQL("DROP TABLE IF EXISTS " + GROUPS_TABLE_NAME); onCreate(db); } From 9f3cde1b9a7a6e076e387bace814a749cf6a572e Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 9 Sep 2017 15:44:50 +0300 Subject: [PATCH 060/128] Fix history marker menu on rotation --- ...ryMarkerMenuBottomSheetDialogFragment.java | 24 +++++++++---------- .../mapmarkers/MapMarkersHistoryFragment.java | 7 +++++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index 5925434216..e06fca76c9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -16,7 +16,6 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -24,22 +23,20 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo public final static String TAG = "HistoryMarkerMenuBottomSheetDialogFragment"; + public static final String MARKER_NAME = "marker_name"; + public static final String MARKER_COLOR_INDEX = "marker_color_index"; + public static final String MARKER_VISITED_DATE = "marker_visited_date"; + private HistoryMarkerMenuFragmentListener listener; private boolean portrait; - private MapMarker marker; public void setListener(HistoryMarkerMenuFragmentListener listener) { this.listener = listener; } - public void setMarker(MapMarker marker) { - this.marker = marker; - } - @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - MapActivity mapActivity = (MapActivity) getActivity(); portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; @@ -49,11 +46,14 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); } - if (marker != null) { - int color = MapMarker.getColorId(marker.colorIndex); - ((ImageView) mainView.findViewById(R.id.map_marker_icon)).setImageDrawable(getIcon(R.drawable.ic_action_flag_dark, color)); - ((TextView) mainView.findViewById(R.id.map_marker_title)).setText(marker.getName(mapActivity)); - ((TextView) mainView.findViewById(R.id.map_marker_passed_info)).setText(String.valueOf(marker.visitedDate)); + Bundle arguments = getArguments(); + if (arguments != null) { + String markerName = arguments.getString(MARKER_NAME, ""); + int markerColorIndex = arguments.getInt(MARKER_COLOR_INDEX, 0); + long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE, 0); + ((TextView) mainView.findViewById(R.id.map_marker_title)).setText(markerName); + ((ImageView) mainView.findViewById(R.id.map_marker_icon)).setImageDrawable(getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(markerColorIndex))); + ((TextView) mainView.findViewById(R.id.map_marker_passed_info)).setText(String.valueOf(markerVisitedDate)); } ((ImageView) mainView.findViewById(R.id.make_active_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_reset_to_default_dark)); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 9bb0410e4f..738b52ce77 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -44,8 +44,13 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel int pos = recyclerView.indexOfChild(view); Object item = adapter.getItem(pos); if (item instanceof MapMarker) { + MapMarker marker = (MapMarker) item; HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment(); - fragment.setMarker((MapMarker) item); + Bundle arguments = new Bundle(); + arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity)); + arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex); + arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate); + fragment.setArguments(arguments); fragment.show(mapActivity.getSupportFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG); } } From 2bb38e3122909fb1ee6656394f9b5667d6d697e9 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 9 Sep 2017 16:24:55 +0300 Subject: [PATCH 061/128] Make history marker menu work --- ...ryMarkerMenuBottomSheetDialogFragment.java | 30 ++++++++++++++++--- .../mapmarkers/MapMarkersHistoryFragment.java | 27 ++++++++++++++++- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index e06fca76c9..972a44e2bc 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -23,6 +23,7 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo public final static String TAG = "HistoryMarkerMenuBottomSheetDialogFragment"; + public static final String MARKER_POSITION = "marker_position"; public static final String MARKER_NAME = "marker_name"; public static final String MARKER_COLOR_INDEX = "marker_color_index"; public static final String MARKER_VISITED_DATE = "marker_visited_date"; @@ -48,12 +49,32 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo Bundle arguments = getArguments(); if (arguments != null) { - String markerName = arguments.getString(MARKER_NAME, ""); - int markerColorIndex = arguments.getInt(MARKER_COLOR_INDEX, 0); - long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE, 0); + final int pos = arguments.getInt(MARKER_POSITION); + String markerName = arguments.getString(MARKER_NAME); + int markerColorIndex = arguments.getInt(MARKER_COLOR_INDEX); + long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE); ((TextView) mainView.findViewById(R.id.map_marker_title)).setText(markerName); ((ImageView) mainView.findViewById(R.id.map_marker_icon)).setImageDrawable(getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(markerColorIndex))); ((TextView) mainView.findViewById(R.id.map_marker_passed_info)).setText(String.valueOf(markerVisitedDate)); + + mainView.findViewById(R.id.make_active_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.onMakeMarkerActive(pos); + } + dismiss(); + } + }); + mainView.findViewById(R.id.delete_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.onDeleteMarker(pos); + } + dismiss(); + } + }); } ((ImageView) mainView.findViewById(R.id.make_active_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_reset_to_default_dark)); @@ -118,6 +139,7 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo } interface HistoryMarkerMenuFragmentListener { - + void onMakeMarkerActive(int pos); + void onDeleteMarker(int pos); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 738b52ce77..b906f2448b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -32,10 +32,15 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { app = getMyApplication(); + final MapActivity mapActivity = (MapActivity) getActivity(); + + Fragment historyMarkerMenuFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG); + if (historyMarkerMenuFragment != null) { + ((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener()); + } final RecyclerView recyclerView = new RecyclerView(getContext()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - final MapActivity mapActivity = (MapActivity) getActivity(); adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication()); adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() { @@ -47,10 +52,12 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel MapMarker marker = (MapMarker) item; HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment(); Bundle arguments = new Bundle(); + arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos); arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity)); arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex); arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate); fragment.setArguments(arguments); + fragment.setListener(createHistoryMarkerMenuListener()); fragment.show(mapActivity.getSupportFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG); } } @@ -62,6 +69,24 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel return recyclerView; } + private HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener createHistoryMarkerMenuListener() { + return new HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener() { + @Override + public void onMakeMarkerActive(int pos) { + Object item = adapter.getItem(pos); + if (item instanceof MapMarker) { + app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0); + adapter.notifyItemRemoved(pos); + } + } + + @Override + public void onDeleteMarker(int pos) { + + } + }; + } + @Override public void onDestroy() { app.getMapMarkersHelper().removeListener(this); From 276a03735ccd1fe048e3626a1de30e25cd5d4aa7 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 9 Sep 2017 19:08:24 +0300 Subject: [PATCH 062/128] Format date --- .../HistoryMarkerMenuBottomSheetDialogFragment.java | 6 +++++- .../plus/mapmarkers/adapters/MapMarkersActiveAdapter.java | 5 ++++- .../plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index 972a44e2bc..6d751f9138 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -19,6 +19,10 @@ import net.osmand.plus.R; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialogFragment { public final static String TAG = "HistoryMarkerMenuBottomSheetDialogFragment"; @@ -55,7 +59,7 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE); ((TextView) mainView.findViewById(R.id.map_marker_title)).setText(markerName); ((ImageView) mainView.findViewById(R.id.map_marker_icon)).setImageDrawable(getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(markerColorIndex))); - ((TextView) mainView.findViewById(R.id.map_marker_passed_info)).setText(String.valueOf(markerVisitedDate)); + ((TextView) mainView.findViewById(R.id.map_marker_passed_info)).setText(getString(R.string.passed, new SimpleDateFormat("MMM dd", Locale.getDefault()).format(new Date(markerVisitedDate)))); mainView.findViewById(R.id.make_active_row).setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 872a70e7e6..1eabc58101 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -15,8 +15,11 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashLocationFragment; +import java.text.SimpleDateFormat; import java.util.Collections; +import java.util.Date; import java.util.List; +import java.util.Locale; public class MapMarkersActiveAdapter extends RecyclerView.Adapter implements MapMarkersItemTouchHelperCallback.ItemTouchHelperAdapter { @@ -96,7 +99,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Sat, 9 Sep 2017 19:13:13 +0300 Subject: [PATCH 063/128] Add passed string to resources --- OsmAnd/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 1e08479d0b..b32760d7ba 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 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 --> + Passed: %1$s Make active Today Yesterday From fbcf727a25fca705b215ab8ebb20f99660c62482 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 9 Sep 2017 20:30:05 +0300 Subject: [PATCH 064/128] Fix headers in history --- .../adapters/MapMarkersHistoryAdapter.java | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index 27eb64382c..4eb319e47b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -39,22 +39,6 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter markersHistory = app.getMapMarkersHelper().getMapMarkersHistory(); int previousHeader = -1; @@ -85,13 +69,13 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter= markerDay && currentMonth == markerMonth) { + } else if (currentDay - markerDay <= 8) { if (previousHeader != LAST_SEVEN_DAYS_HEADER) { items.add(LAST_SEVEN_DAYS_HEADER); previousHeader = LAST_SEVEN_DAYS_HEADER; } items.add(marker); - } else if (monthsDisplayed < 3) { + } else if (monthsDisplayed < 3 || currentMonth - 3 == markerMonth) { if (previousHeader != markerMonth) { items.add(markerMonth); previousHeader = markerMonth; From 5df52cd5ed57fe43654fe4dd660a0d7833bdda70 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 9 Sep 2017 20:57:44 +0300 Subject: [PATCH 065/128] Backup markers --- OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java | 6 ++++-- .../src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java b/OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java index 32b3b91122..791dc15c0e 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java +++ b/OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java @@ -6,6 +6,8 @@ import android.app.backup.BackupAgentHelper; import android.app.backup.FileBackupHelper; import android.app.backup.SharedPreferencesBackupHelper; +import net.osmand.plus.mapmarkers.MapMarkersDbHelper; + /** * Requires android API from android-8 */ @@ -25,7 +27,7 @@ public class OsmandBackupAgent extends BackupAgentHelper { SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, prefs); addHelper("osmand.settings", helper); - FileBackupHelper fileBackupHelper = new FileBackupHelper(this, FavouritesDbHelper.FILE_TO_BACKUP); - addHelper(FavouritesDbHelper.FILE_TO_BACKUP, fileBackupHelper); + FileBackupHelper fileBackupHelper = new FileBackupHelper(this, FavouritesDbHelper.FILE_TO_BACKUP, "../databases/" + MapMarkersDbHelper.DB_NAME); + addHelper("osmand.files", fileBackupHelper); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index c942cfd40b..f3e0cb8a94 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -20,7 +20,7 @@ import java.util.Random; public class MapMarkersDbHelper { private static final int DB_VERSION = 2; - private static final String DB_NAME = "map_markers_db"; + public static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; private static final String MARKERS_COL_ID = "marker_id"; From f166ecf4369806ba15a1fa94f0e66a0a69d28b02 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 10 Sep 2017 00:10:55 +0300 Subject: [PATCH 066/128] Increase MapMarkers_DB_VERSION --- OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index f3e0cb8a94..370e7d4615 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -19,7 +19,7 @@ import java.util.Random; public class MapMarkersDbHelper { - private static final int DB_VERSION = 2; + private static final int DB_VERSION = 3; public static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; From b88bed8e013b3a954cc8299354e56425d9113f0a Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Mon, 11 Sep 2017 00:44:49 +0300 Subject: [PATCH 067/128] Improve create headers algorithm --- .../adapters/MapMarkersHistoryAdapter.java | 57 +++++++------------ 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index 4eb319e47b..0ec789cef0 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -57,45 +57,28 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter= 2 && currentDay - markerDay <= 8 && previousHeader != LAST_SEVEN_DAYS_HEADER) { + items.add(LAST_SEVEN_DAYS_HEADER); + previousHeader = LAST_SEVEN_DAYS_HEADER; + } else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousHeader != markerMonth) { + items.add(markerMonth); + previousHeader = markerMonth; + monthsDisplayed += 1; + } else if (currentMonth - markerMonth >= 4 && previousHeader != THIS_YEAR_HEADER) { + items.add(THIS_YEAR_HEADER); + previousHeader = THIS_YEAR_HEADER; } - } else { - if (previousHeader != markerYear) { - items.add(markerYear); - previousHeader = markerYear; - } - items.add(marker); + } else if (previousHeader != markerYear) { + items.add(markerYear); + previousHeader = markerYear; } + items.add(marker); } } From 1810e5fcbf5fc1acb317f6976c7a5133ca199b20 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Mon, 11 Sep 2017 00:58:45 +0300 Subject: [PATCH 068/128] Fix recycler view positions --- .../net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java | 2 +- .../net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 8490060ebe..0472875d9e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -49,7 +49,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL @Override public void onItemClick(View view) { - int pos = recyclerView.indexOfChild(view); + int pos = recyclerView.getChildAdapterPosition(view); MapMarker marker = adapter.getItem(pos); mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), 15, marker.getPointDescription(mapActivity), true, marker); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index b906f2448b..f2c8b76d1b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -46,7 +46,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() { @Override public void onItemClick(View view) { - int pos = recyclerView.indexOfChild(view); + int pos = recyclerView.getChildAdapterPosition(view); Object item = adapter.getItem(pos); if (item instanceof MapMarker) { MapMarker marker = (MapMarker) item; From aa64fcd47a0ae6019aadd81ce9c93b009cde8d54 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 10:31:01 +0300 Subject: [PATCH 069/128] Add delete action to history menu --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 8 ++++++++ .../osmand/plus/mapmarkers/MapMarkersHistoryFragment.java | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index d0d0acb1a4..3a15cb8ef1 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -252,6 +252,14 @@ public class MapMarkersHelper { } } + public void removeMarkerFromHistory(MapMarker marker) { + if (marker != null) { + markersDbHelper.removeMarkerFromHistory(marker); + loadMarkers(); + refresh(); + } + } + public List getMapMarkers() { return mapMarkers; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index f2c8b76d1b..3ad7f41f8f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -82,7 +82,11 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel @Override public void onDeleteMarker(int pos) { - + Object item = adapter.getItem(pos); + if (item instanceof MapMarker) { + app.getMapMarkersHelper().removeMarkerFromHistory((MapMarker) item); + adapter.notifyItemRemoved(pos); + } } }; } From b8c1d890255ac6212f908375282e54e9ce099840 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 13:04:40 +0300 Subject: [PATCH 070/128] Add swipe to history --- .../mapmarkers/MapMarkersHistoryFragment.java | 76 +++++++++++++++++-- 1 file changed, 70 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 3ad7f41f8f..a169fbe04c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -1,26 +1,36 @@ package net.osmand.plus.mapmarkers; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; import android.os.Bundle; import android.support.annotation.Nullable; -import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.helper.ItemTouchHelper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import net.osmand.data.PointDescription; import net.osmand.plus.MapMarkersHelper; 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.adapters.MapMarkerDateViewHolder; import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter; public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHelper.MapMarkerChangedListener { - MapMarkersHistoryAdapter adapter; - OsmandApplication app; + private MapMarkersHistoryAdapter adapter; + private OsmandApplication app; + private Paint backgroundPaint = new Paint(); + private Paint iconPaint = new Paint(); @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -31,8 +41,10 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - app = getMyApplication(); + final boolean night = !app.getSettings().isLightContent(); final MapActivity mapActivity = (MapActivity) getActivity(); + backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light)); + iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), night ? 0 : R.color.icon_color), PorterDuff.Mode.SRC_IN)); Fragment historyMarkerMenuFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG); if (historyMarkerMenuFragment != null) { @@ -42,6 +54,58 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel final RecyclerView recyclerView = new RecyclerView(getContext()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { + private float iconMarginSides = getResources().getDimension(R.dimen.list_content_padding); + private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark); + private Bitmap resetBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_reset_to_default_dark); + + @Override + public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { + return false; + } + + @Override + public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { + if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { + View itemView = viewHolder.itemView; + if (dX > 0) { + c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint); + float iconMarginTop = ((float) itemView.getHeight() - (float) deleteBitmap.getHeight()) / 2; + c.drawBitmap(deleteBitmap, itemView.getLeft() + iconMarginSides,itemView.getTop() + iconMarginTop, iconPaint); + } else { + c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint); + float iconMarginTop = ((float) itemView.getHeight() - (float) resetBitmap.getHeight()) / 2; + c.drawBitmap(resetBitmap, itemView.getRight() - resetBitmap.getWidth() - iconMarginSides, itemView.getTop() + iconMarginTop, iconPaint); + } + } + super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); + } + + @Override + public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { + if (viewHolder instanceof MapMarkerDateViewHolder) { + return 0; + } + return super.getSwipeDirs(recyclerView, viewHolder); + } + + @Override + public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { + int pos = viewHolder.getAdapterPosition(); + Object item = adapter.getItem(pos); + if (item instanceof MapMarker) { + if (direction == ItemTouchHelper.LEFT) { + app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0); + } else { + app.getMapMarkersHelper().removeMarkerFromHistory((MapMarker) item); + } + adapter.notifyItemRemoved(pos); + } + } + }; + ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); + itemTouchHelper.attachToRecyclerView(recyclerView); + adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication()); adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() { @Override @@ -105,7 +169,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel } public OsmandApplication getMyApplication() { - return (OsmandApplication)getActivity().getApplication(); + return (OsmandApplication) getActivity().getApplication(); } @Override From be41613c8c3bd255ba10cfd7c32f5a37ae7aba1d Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 11 Sep 2017 13:17:13 +0300 Subject: [PATCH 071/128] Delete marker with deleting favorite; fix small issues --- .../net/osmand/plus/FavouritesDbHelper.java | 85 ++++++++++--------- .../src/net/osmand/plus/MapMarkersHelper.java | 10 ++- .../plus/mapmarkers/MapMarkersDbHelper.java | 54 ++++++++++++ 3 files changed, 107 insertions(+), 42 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 5d9e0db424..63daababa7 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -33,7 +33,7 @@ public class FavouritesDbHelper { private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(FavouritesDbHelper.class); - + public static final String FILE_TO_SAVE = "favourites.gpx"; //$NON-NLS-1$ public static final String BACKUP_FOLDER = "backup"; //$NON-NLS-1$ public static final int BACKUP_CNT = 20; //$NON-NLS-1$ @@ -45,23 +45,23 @@ public class FavouritesDbHelper { private final OsmandApplication context; protected static final String HIDDEN = "HIDDEN"; private static final String DELIMETER = "__"; - + public FavouritesDbHelper(OsmandApplication context) { this.context = context; } - + public static class FavoriteGroup { public String name; public boolean visible = true; public int color; public List points = new ArrayList(); } - + public void loadFavorites() { flatGroups.clear(); favoriteGroups.clear(); - + File internalFile = getInternalFile(); if(!internalFile.exists()) { File dbPath = context.getDatabasePath(FAVOURITE_DB_NAME); @@ -76,7 +76,7 @@ public class FavouritesDbHelper { loadGPXFile(internalFile, points); loadGPXFile(getExternalFile(), extPoints); boolean changed = merge(extPoints, points); - + for(FavouritePoint pns : points.values()) { FavoriteGroup group = getOrCreateGroup(pns, 0); group.points.add(pns); @@ -87,7 +87,7 @@ public class FavouritesDbHelper { saveCurrentPointsIntoFile(); } favouritesUpdated(); - + } private void favouritesUpdated(){ @@ -110,13 +110,18 @@ public class FavouritesDbHelper { private File getInternalFile() { return context.getFileStreamPath(FILE_TO_BACKUP); } - + public void delete(Set groupsToDelete, Set favoritesSelected) { + MapMarkersHelper markersHelper = context.getMapMarkersHelper(); if (favoritesSelected != null) { for (FavouritePoint p : favoritesSelected) { FavoriteGroup group = flatGroups.get(p.getCategory()); if (group != null) { group.points.remove(p); + long groupId = markersHelper.getGroupId(group.name); + if (groupId != -1) { + markersHelper.removeMarker(p.getLatitude(), p.getLongitude(), groupId); + } } cachedFavoritePoints.remove(p); } @@ -130,7 +135,7 @@ public class FavouritesDbHelper { } saveCurrentPointsIntoFile(); } - + public boolean deleteFavourite(FavouritePoint p) { return deleteFavourite(p, true); } @@ -148,7 +153,7 @@ public class FavouritesDbHelper { } return true; } - + public boolean addFavourite(FavouritePoint p) { return addFavourite(p, true); } @@ -172,7 +177,7 @@ public class FavouritesDbHelper { return true; } - + public static AlertDialog.Builder checkDuplicates(FavouritePoint p, FavouritesDbHelper fdb, Context uiContext) { boolean emoticons = false; String index = ""; @@ -266,7 +271,7 @@ public class FavouritesDbHelper { saveCurrentPointsIntoFile(); return true; } - + public boolean editFavourite(FavouritePoint p, double lat, double lon) { p.setLatitude(lat); @@ -274,7 +279,7 @@ public class FavouritesDbHelper { saveCurrentPointsIntoFile(); return true; } - + public void saveCurrentPointsIntoFile() { try { Map deletedInMemory = new LinkedHashMap(); @@ -289,7 +294,7 @@ public class FavouritesDbHelper { log.error(e.getMessage(), e); } } - + private void backup(File backupFile, File externalFile) { try { File f = new File(backupFile.getParentFile(), backupFile.getName()); @@ -338,7 +343,7 @@ public class FavouritesDbHelper { } - + public boolean deleteGroup(FavoriteGroup group) { boolean remove = favoriteGroups.remove(group); if (remove) { @@ -352,7 +357,7 @@ public class FavouritesDbHelper { public File getExternalFile() { return new File(context.getAppPath(null), FILE_TO_SAVE); } - + public File getBackupFile() { File fld = new File(context.getAppPath(null), BACKUP_FOLDER); if(!fld.exists()) { @@ -378,17 +383,17 @@ public class FavouritesDbHelper { } return firstModified; } - + public String saveFile(List favoritePoints, File f) { GPXFile gpx = asGpxFile(favoritePoints); return GPXUtilities.writeGpxFile(f, gpx, context); } - + public GPXFile asGpxFile() { return asGpxFile(cachedFavoritePoints); } - + private GPXFile asGpxFile(List favoritePoints) { GPXFile gpx = new GPXFile(); for (FavouritePoint p : favoritePoints) { @@ -413,7 +418,7 @@ public class FavouritesDbHelper { return gpx; } - + public void addEmptyCategory(String name) { addEmptyCategory(name, 0, true); } @@ -434,7 +439,7 @@ public class FavouritesDbHelper { public List getFavouritePoints() { return cachedFavoritePoints; } - + public List getVisibleFavouritePoints() { List fp = new ArrayList<>(); for(FavouritePoint p : cachedFavoritePoints) { @@ -444,7 +449,7 @@ public class FavouritesDbHelper { } return fp; } - + public List getFavoriteGroups() { return favoriteGroups; @@ -488,8 +493,8 @@ public class FavouritesDbHelper { return null; } - - + + public void recalculateCachedFavPoints(){ ArrayList temp = new ArrayList(); for(FavoriteGroup f : favoriteGroups){ @@ -497,7 +502,7 @@ public class FavouritesDbHelper { } cachedFavoritePoints = temp; } - + public void sortAll() { final Collator collator = Collator.getInstance(); collator.setStrength(Collator.SECONDARY); @@ -550,7 +555,7 @@ public class FavouritesDbHelper { }; return favoritesComparator; } - + private boolean loadGPXFile(File file, Map points) { if(!file.exists()) { @@ -583,21 +588,21 @@ public class FavouritesDbHelper { } return true; } - + public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) { if(color != 0 && group.color != color) { FavoriteGroup gr = flatGroups.get(group.name); group.color = color; for(FavouritePoint p : gr.points) { p.setColor(color); - } + } } if(group.visible != visible) { FavoriteGroup gr = flatGroups.get(group.name); group.visible = visible; for(FavouritePoint p : gr.points) { p.setVisible(visible); - } + } } if (!group.name.equals(newName)) { FavoriteGroup gr = flatGroups.remove(group.name); @@ -643,7 +648,7 @@ public class FavouritesDbHelper { return group; } - + /// Deprecated sqlite db private static final int DATABASE_VERSION = 2; public static final String FAVOURITE_DB_NAME = "favourite"; //$NON-NLS-1$ @@ -656,8 +661,8 @@ public class FavouritesDbHelper { FAVOURITE_COL_NAME + " TEXT, " + FAVOURITE_COL_CATEGORY + " TEXT, " + //$NON-NLS-1$ //$NON-NLS-2$ FAVOURITE_COL_LAT + " double, " + FAVOURITE_COL_LON + " double);"; //$NON-NLS-1$ //$NON-NLS-2$ private SQLiteConnection conn; - - + + private SQLiteConnection openConnection(boolean readonly) { conn = context.getSQLiteAPI().getOrCreateDatabase(FAVOURITE_DB_NAME, readonly); if (conn.getVersion() == 0 || DATABASE_VERSION != conn.getVersion()) { @@ -674,7 +679,7 @@ public class FavouritesDbHelper { } return conn; } - + public void onCreate(SQLiteConnection db) { db.execSQL(FAVOURITE_TABLE_CREATE); } @@ -685,7 +690,7 @@ public class FavouritesDbHelper { db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET category = ?", new Object[] { "" }); //$NON-NLS-1$ //$NON-NLS-2$ } } - + private void loadAndCheckDatabasePoints(){ if (favoriteGroups == null) { SQLiteConnection db = openConnection(true); @@ -715,13 +720,13 @@ public class FavouritesDbHelper { query.close(); } finally { db.close(); - } + } sortAll(); } recalculateCachedFavPoints(); } } - + public boolean deleteFavouriteDB(FavouritePoint p) { SQLiteConnection db = openConnection(false); if (db != null) { @@ -771,8 +776,8 @@ public class FavouritesDbHelper { } return false; } - - + + public boolean editFavouriteNameDB(FavouritePoint p, String newName, String category) { SQLiteConnection db = openConnection(false); @@ -801,14 +806,14 @@ public class FavouritesDbHelper { } return false; } - + public boolean editFavouriteDB(FavouritePoint p, double lat, double lon) { SQLiteConnection db = openConnection(false); if (db != null) { try { db.execSQL( - "UPDATE " + FAVOURITE_TABLE_NAME + " SET latitude = ?, longitude = ? WHERE " + whereNameLatLon(), new Object[] { lat, lon, p.getName(), p.getLatitude(), p.getLongitude() }); //$NON-NLS-1$ //$NON-NLS-2$ + "UPDATE " + FAVOURITE_TABLE_NAME + " SET latitude = ?, longitude = ? WHERE " + whereNameLatLon(), new Object[] { lat, lon, p.getName(), p.getLatitude(), p.getLongitude() }); //$NON-NLS-1$ //$NON-NLS-2$ p.setLatitude(lat); p.setLongitude(lon); saveCurrentPointsIntoFile(); diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 3a15cb8ef1..2874c708a5 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -224,8 +224,14 @@ public class MapMarkersHelper { } } - public long createGroupIfNeeded(String name) { - return markersDbHelper.createGroupIfNeeded(name); + public long getGroupId(String name) { + return markersDbHelper.getGroupId(name); + } + + public void removeMarker(double lat, double lon, long groupId) { + markersDbHelper.removeMarker(lat, lon, groupId); + loadMarkers(); + refresh(); } @Nullable diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 370e7d4615..4be7f32a70 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -166,6 +166,7 @@ public class MapMarkersDbHelper { res = Long.parseLong(String.valueOf(System.currentTimeMillis()) + String.valueOf(new Random().nextInt(900) + 100)); db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?)", new Object[]{res, name}); } + query.close(); } finally { db.close(); } @@ -223,6 +224,26 @@ public class MapMarkersDbHelper { marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE}); } + public long getGroupId(String name) { + long res = -1; + if (name != null) { + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_NAME + " = ?", + new String[]{name}); + if (query.moveToFirst()) { + res = query.getLong(0); + } + query.close(); + } finally { + db.close(); + } + } + } + return res; + } + @Nullable public String getGroupName(long id) { String res = null; @@ -234,6 +255,7 @@ public class MapMarkersDbHelper { if (query.moveToFirst()) { res = query.getString(1); } + query.close(); } finally { db.close(); } @@ -347,6 +369,38 @@ public class MapMarkersDbHelper { } } + public void removeMarker(double lat, double lon, long groupId) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + MapMarker marker = null; + SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + + MARKERS_COL_LAT + " = ? AND " + + MARKERS_COL_LON + " = ? AND " + + MARKERS_COL_GROUP_KEY + " = ?", + new String[]{String.valueOf(lat), String.valueOf(lon), String.valueOf(groupId)}); + if (query.moveToFirst()) { + marker = readItem(query); + } + query.close(); + + if (marker != null) { + if (marker.history) { + removeMarkerFromHistory(marker); + } else { + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.nextKey, marker.id}); + + db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ID + " = ?", + new Object[]{marker.id}); + } + } + } finally { + db.close(); + } + } + } + public void moveMarkerToHistory(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { From 56a6a8b81f58f02807e578d87af17bbceddc1f86 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 13:18:55 +0300 Subject: [PATCH 072/128] Fix paints --- .../plus/mapmarkers/MapMarkersHistoryFragment.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index a169fbe04c..c63dea999b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -43,8 +43,16 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final boolean night = !app.getSettings().isLightContent(); final MapActivity mapActivity = (MapActivity) getActivity(); + backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light)); - iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), night ? 0 : R.color.icon_color), PorterDuff.Mode.SRC_IN)); + backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE); + backgroundPaint.setAntiAlias(true); + if (!night) { + iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), R.color.icon_color), PorterDuff.Mode.SRC_IN)); + } + iconPaint.setAntiAlias(true); + iconPaint.setFilterBitmap(true); + iconPaint.setDither(true); Fragment historyMarkerMenuFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG); if (historyMarkerMenuFragment != null) { From 2b8ade482aafb2c131cdaedaebd766f512f8f41c Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 14:32:31 +0300 Subject: [PATCH 073/128] Add text to swipe --- .../mapmarkers/MapMarkersHistoryFragment.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index c63dea999b..142482c851 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -6,6 +6,7 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; +import android.graphics.Rect; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; @@ -31,6 +32,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel private OsmandApplication app; private Paint backgroundPaint = new Paint(); private Paint iconPaint = new Paint(); + private Paint textPaint = new Paint(); @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -53,6 +55,18 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel iconPaint.setAntiAlias(true); iconPaint.setFilterBitmap(true); iconPaint.setDither(true); + textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size)); + textPaint.setFakeBoldText(true); + textPaint.setColor(ContextCompat.getColor(getActivity(), R.color.dashboard_subheader_text_light)); + textPaint.setAntiAlias(true); + + final String delStr = getString(R.string.shared_string_delete).toUpperCase(); + final String activateStr = getString(R.string.local_index_mi_restore).toUpperCase(); + Rect bounds = new Rect(); + + textPaint.getTextBounds(activateStr, 0, activateStr.length(), bounds); + final int activateStrWidth = bounds.width(); + final int textHeight = bounds.height(); Fragment historyMarkerMenuFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG); if (historyMarkerMenuFragment != null) { @@ -63,7 +77,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { - private float iconMarginSides = getResources().getDimension(R.dimen.list_content_padding); + private float marginSides = getResources().getDimension(R.dimen.list_content_padding); private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark); private Bitmap resetBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_reset_to_default_dark); @@ -76,14 +90,17 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { View itemView = viewHolder.itemView; + float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2; if (dX > 0) { c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint); float iconMarginTop = ((float) itemView.getHeight() - (float) deleteBitmap.getHeight()) / 2; - c.drawBitmap(deleteBitmap, itemView.getLeft() + iconMarginSides,itemView.getTop() + iconMarginTop, iconPaint); + c.drawBitmap(deleteBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint); + c.drawText(delStr, itemView.getLeft() + 2 * marginSides + deleteBitmap.getWidth(), itemView.getTop() + textMarginTop + textHeight, textPaint); } else { c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint); float iconMarginTop = ((float) itemView.getHeight() - (float) resetBitmap.getHeight()) / 2; - c.drawBitmap(resetBitmap, itemView.getRight() - resetBitmap.getWidth() - iconMarginSides, itemView.getTop() + iconMarginTop, iconPaint); + c.drawBitmap(resetBitmap, itemView.getRight() - resetBitmap.getWidth() - marginSides, itemView.getTop() + iconMarginTop, iconPaint); + c.drawText(activateStr, itemView.getRight() - resetBitmap.getWidth() - 2 * marginSides - activateStrWidth, itemView.getTop() + textMarginTop + textHeight, textPaint); } } super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); From f5859e50197f7114cb6bfdcfc5293fccbcb4d497 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 14:45:05 +0300 Subject: [PATCH 074/128] Save markers to gpx --- .../src/net/osmand/plus/MapMarkersHelper.java | 30 +++++++++++++++++++ .../mapmarkers/MapMarkersDialogFragment.java | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 2874c708a5..fdc1edde1d 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -2,17 +2,23 @@ package net.osmand.plus; import android.content.Context; import android.support.annotation.Nullable; +import android.text.format.DateFormat; +import net.osmand.IndexConstants; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.util.Algorithms; +import java.io.File; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.List; +import java.util.Locale; public class MapMarkersHelper { public static final int MAP_MARKERS_COLORS_COUNT = 7; @@ -503,4 +509,28 @@ public class MapMarkersHelper { ctx.getGeocodingLookupService().cancel(latLon); } } + + public void generateGpx() { + final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers"); + if (!dir.exists()) { + dir.mkdirs(); + } + Date date = new Date(); + String fileName = DateFormat.format("yyyy-MM-dd", date).toString() + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(date); + File fout = new File(dir, fileName + ".gpx"); + int ind = 1; + while (fout.exists()) { + fout = new File(dir, fileName + "_" + (++ind) + ".gpx"); + } + GPXUtilities.GPXFile file = new GPXUtilities.GPXFile(); + for (MapMarker marker : markersDbHelper.getActiveMarkers()) { + GPXUtilities.WptPt wpt = new GPXUtilities.WptPt(); + wpt.lat = marker.getLatitude(); + wpt.lon = marker.getLongitude(); + wpt.setColor(ctx.getResources().getColor(MapMarker.getColorId(marker.colorIndex))); + wpt.name = marker.getOnlyName(); + file.points.add(wpt); + } + GPXUtilities.writeGpxFile(fout, file, ctx); + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index e66348ef5a..73e09665da 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -154,7 +154,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void saveAsNewTrackOnClick() { - Toast.makeText(getContext(), "Save as new track", Toast.LENGTH_SHORT).show(); + mapActivity.getMyApplication().getMapMarkersHelper().generateGpx(); } @Override From 701db4df63e675abe319ff04cd97db04f6acdde7 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 15:01:16 +0300 Subject: [PATCH 075/128] Add build route --- .../net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 73e09665da..4e30eb5f65 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -19,6 +19,7 @@ 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.dashboard.DashboardOnMap; import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener; import net.osmand.plus.mapmarkers.MarkerOptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener; @@ -149,7 +150,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void buildRouteOnClick() { - Toast.makeText(getContext(), "Build route", Toast.LENGTH_SHORT).show(); + mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS_SELECTION); + dismiss(); } @Override From afc32a880e045c576498ddefcc0e3eff697a654a Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 15:09:00 +0300 Subject: [PATCH 076/128] Remove old markers from drawer --- .../osmand/plus/activities/MapActivityActions.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 8187f17f61..92f0a4aa9a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -614,18 +614,6 @@ public class MapActivityActions implements DialogProvider { }).createItem()); if (settings.USE_MAP_MARKERS.get()) { optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.map_markers, mapActivity) - .setIcon(R.drawable.ic_action_flag_dark) - .setListener(new ContextMenuAdapter.ItemClickListener() { - @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - app.logEvent(mapActivity, "drawer_markers_open"); - MapActivity.clearPrevActivityIntent(); - mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.MAP_MARKERS); - return false; - } - }).createItem()); - - optionsMenuHelper.addItem(new ItemBuilder().setTitle("New map markers") .setIcon(R.drawable.ic_action_flag_dark) .setListener(new ContextMenuAdapter.ItemClickListener() { @Override From 78bec6ec55344638377e2307e9eb448409b561fd Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 15:49:04 +0300 Subject: [PATCH 077/128] Hide icon when swiping --- .../mapmarkers/MapMarkersHistoryFragment.java | 21 +++++++++++++++---- .../adapters/MapMarkerItemViewHolder.java | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 142482c851..c46c6e0656 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -14,6 +14,7 @@ import android.support.v4.content.ContextCompat; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -24,6 +25,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapmarkers.adapters.MapMarkerDateViewHolder; +import net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder; import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter; public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHelper.MapMarkerChangedListener { @@ -81,6 +83,17 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark); private Bitmap resetBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_reset_to_default_dark); + @Override + public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { + if (viewHolder instanceof MapMarkerDateViewHolder) { + return 0; + } + if (viewHolder instanceof MapMarkerItemViewHolder) { + ((MapMarkerItemViewHolder) viewHolder).setOptionsButtonVisibility(View.GONE); + } + return super.getSwipeDirs(recyclerView, viewHolder); + } + @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; @@ -107,11 +120,11 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel } @Override - public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { - if (viewHolder instanceof MapMarkerDateViewHolder) { - return 0; + public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { + if (viewHolder instanceof MapMarkerItemViewHolder) { + ((MapMarkerItemViewHolder) viewHolder).setOptionsButtonVisibility(View.VISIBLE); } - return super.getSwipeDirs(recyclerView, viewHolder); + super.clearView(recyclerView, viewHolder); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java index d3042e2090..7f63f34b7b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java @@ -30,4 +30,8 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { description = (TextView) view.findViewById(R.id.map_marker_description); optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button); } + + public void setOptionsButtonVisibility(int visibility) { + optionsBtn.setVisibility(visibility); + } } From 10f3918f7f1513d462cbd68e6d72aa96c27931e8 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 16:00:22 +0300 Subject: [PATCH 078/128] Swipe styling --- .../mapmarkers/MapMarkersHistoryFragment.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index c46c6e0656..2a3dc6eba3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -51,15 +51,11 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light)); backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE); backgroundPaint.setAntiAlias(true); - if (!night) { - iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), R.color.icon_color), PorterDuff.Mode.SRC_IN)); - } iconPaint.setAntiAlias(true); iconPaint.setFilterBitmap(true); iconPaint.setDither(true); textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size)); textPaint.setFakeBoldText(true); - textPaint.setColor(ContextCompat.getColor(getActivity(), R.color.dashboard_subheader_text_light)); textPaint.setAntiAlias(true); final String delStr = getString(R.string.shared_string_delete).toUpperCase(); @@ -103,6 +99,19 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { View itemView = viewHolder.itemView; + int colorIcon; + int colorText; + if (Math.abs(dX) > itemView.getWidth() / 2) { + colorIcon = R.color.map_widget_blue; + colorText = R.color.map_widget_blue; + } else { + colorIcon = night ? 0 : R.color.icon_color; + colorText = R.color.dashboard_subheader_text_light; + } + if (colorIcon != 0) { + iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), colorIcon), PorterDuff.Mode.SRC_IN)); + } + textPaint.setColor(ContextCompat.getColor(getActivity(), colorText)); float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2; if (dX > 0) { c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint); From f5b8b41633ae26452503e8a59386721e169364ad Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 17:10:19 +0300 Subject: [PATCH 079/128] Style history menu --- .../fragment_marker_history_bottom_sheet_dialog.xml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml index f1db780f6e..c88241cab7 100644 --- a/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + xmlns:osmand="http://schemas.android.com/apk/res-auto" android:background="?attr/bg_color" android:orientation="vertical"> @@ -50,10 +51,13 @@ android:layout_height="wrap_content" android:maxLines="1" android:ellipsize="end" + android:textStyle="bold" + android:textSize="@dimen/default_list_text_size" android:textAppearance="@style/TextAppearance.ListItemTitle" tools:text="Bloemstraat 179"/> - @@ -81,6 +85,7 @@ android:background="?attr/selectableItemBackground" android:gravity="center_vertical" android:minHeight="@dimen/bottom_sheet_list_item_height" + android:layout_marginTop="@dimen/bottom_sheet_content_margin_small" android:paddingEnd="@dimen/bottom_sheet_content_padding" android:paddingLeft="@dimen/bottom_sheet_content_padding" android:paddingRight="@dimen/bottom_sheet_content_padding" From 03018fd5387003f32014907a454b9643f7c5cfa6 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 17:11:12 +0300 Subject: [PATCH 080/128] Style history menu --- .../res/layout/fragment_marker_history_bottom_sheet_dialog.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml index c88241cab7..24d9579995 100644 --- a/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml @@ -64,7 +64,6 @@ android:layout_gravity="center_vertical" android:ellipsize="end" android:maxLines="1" - android:textAppearance="@style/TextAppearance.ListItemTitle" android:textColor="?android:textColorSecondary" android:textSize="@dimen/default_sub_text_size" tools:text="Passed: July 28"/> From 962d732aa66f2a1c89e0e23b018376e4c79b997b Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 11 Sep 2017 19:15:49 +0300 Subject: [PATCH 081/128] Add fixes and improvements --- .../net/osmand/plus/FavouritesDbHelper.java | 5 - .../src/net/osmand/plus/MapMarkersHelper.java | 122 +++++++++++------- .../plus/helpers/MapMarkerDialogHelper.java | 2 +- .../mapmarkers/MapMarkersActiveFragment.java | 2 +- .../plus/mapmarkers/MapMarkersDbHelper.java | 107 ++++++--------- .../mapmarkers/MapMarkersDialogFragment.java | 2 +- 6 files changed, 123 insertions(+), 117 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 63daababa7..f250942298 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -112,16 +112,11 @@ public class FavouritesDbHelper { } public void delete(Set groupsToDelete, Set favoritesSelected) { - MapMarkersHelper markersHelper = context.getMapMarkersHelper(); if (favoritesSelected != null) { for (FavouritePoint p : favoritesSelected) { FavoriteGroup group = flatGroups.get(p.getCategory()); if (group != null) { group.points.remove(p); - long groupId = markersHelper.getGroupId(group.name); - if (groupId != -1) { - markersHelper.removeMarker(p.getLatitude(), p.getLongitude(), groupId); - } } cachedFavoritePoints.remove(p); } diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index fdc1edde1d..b51e67e727 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -17,14 +17,15 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.LinkedList; import java.util.List; import java.util.Locale; public class MapMarkersHelper { public static final int MAP_MARKERS_COLORS_COUNT = 7; - private List mapMarkers = new ArrayList<>(); - private List mapMarkersHistory = new ArrayList<>(); + private List mapMarkers = new LinkedList<>(); + private List mapMarkersHistory = new LinkedList<>(); private OsmandSettings settings; private List listeners = new ArrayList<>(); private OsmandApplication ctx; @@ -38,7 +39,7 @@ public class MapMarkersHelper { } public static class MapMarker implements LocationPoint { - public long id; + public String id; public LatLon point; private PointDescription pointDescription; public int colorIndex; @@ -48,8 +49,9 @@ public class MapMarkersHelper { public int dist; public long creationDate; public long visitedDate; - public long nextKey; + public String nextKey; public long groupKey = -1; + public String groupName; public MapMarker(LatLon point, PointDescription name, int colorIndex, boolean selected, int index) { @@ -194,6 +196,26 @@ public class MapMarkersHelper { } } + public void checkAndFixActiveMarkersOrderIfNeeded() { + if (!mapMarkers.isEmpty()) { + if (mapMarkers.size() > 1) { + for (int i = 0; i < mapMarkers.size() - 1; i++) { + MapMarker first = mapMarkers.get(i); + MapMarker second = mapMarkers.get(i + 1); + if (!first.nextKey.equals(second.id)) { + markersDbHelper.changeActiveMarkerPosition(first, second); + first.nextKey = second.id; + } + } + } + + MapMarker tail = mapMarkers.get(mapMarkers.size() - 1); + if (!tail.nextKey.equals(MapMarkersDbHelper.TAIL_NEXT_VALUE)) { + markersDbHelper.changeActiveMarkerPosition(tail, null); + } + } + } + private void sortMarkers(List markers, final boolean history) { Collections.sort(markers, new Comparator() { @Override @@ -214,18 +236,19 @@ public class MapMarkersHelper { private void lookupAddress(final MapMarker mapMarker) { if (mapMarker != null && mapMarker.pointDescription.isSearchingAddress(ctx)) { cancelPointAddressRequests(mapMarker.point); - GeocodingLookupService.AddressLookupRequest lookupRequest = new GeocodingLookupService.AddressLookupRequest(mapMarker.point, new GeocodingLookupService.OnAddressLookupResult() { - @Override - public void geocodingDone(String address) { - if (Algorithms.isEmpty(address)) { - mapMarker.pointDescription.setName(PointDescription.getAddressNotFoundStr(ctx)); - } else { - mapMarker.pointDescription.setName(address); - } - markersDbHelper.updateMarker(mapMarker); - updateMarker(mapMarker); - } - }, null); + GeocodingLookupService.AddressLookupRequest lookupRequest = + new GeocodingLookupService.AddressLookupRequest(mapMarker.point, new GeocodingLookupService.OnAddressLookupResult() { + @Override + public void geocodingDone(String address) { + if (Algorithms.isEmpty(address)) { + mapMarker.pointDescription.setName(PointDescription.getAddressNotFoundStr(ctx)); + } else { + mapMarker.pointDescription.setName(address); + } + markersDbHelper.updateMarker(mapMarker); + updateMarker(mapMarker); + } + }, null); ctx.getGeocodingLookupService().lookupAddress(lookupRequest); } } @@ -234,11 +257,11 @@ public class MapMarkersHelper { return markersDbHelper.getGroupId(name); } - public void removeMarker(double lat, double lon, long groupId) { - markersDbHelper.removeMarker(lat, lon, groupId); - loadMarkers(); - refresh(); - } +// public void removeMarker(double lat, double lon, long groupId) { +// markersDbHelper.removeMarker(lat, lon, groupId); +// loadMarkers(); +// refresh(); +// } @Nullable public String getGroupName(long id) { @@ -249,17 +272,24 @@ public class MapMarkersHelper { if (marker != null) { cancelPointAddressRequests(marker.point); markersDbHelper.moveMarkerToHistory(marker); - loadMarkers(); + mapMarkers.remove(marker); + marker.history = true; + marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE; + mapMarkersHistory.add(marker); + checkAndFixActiveMarkersOrderIfNeeded(); + sortMarkers(mapMarkersHistory, true); refresh(); } } public void restoreMarkerFromHistory(MapMarker marker, int position) { if (marker != null) { - MapMarker next = position == mapMarkers.size() ? null : mapMarkers.get(position); markersDbHelper.restoreMapMarkerFromHistory(marker); - markersDbHelper.changeActiveMarkerPosition(marker, next); - loadMarkers(); + mapMarkersHistory.remove(marker); + marker.history = false; + mapMarkers.add(position, marker); + checkAndFixActiveMarkersOrderIfNeeded(); + sortMarkers(mapMarkersHistory, true); refresh(); } } @@ -267,7 +297,7 @@ public class MapMarkersHelper { public void removeMarkerFromHistory(MapMarker marker) { if (marker != null) { markersDbHelper.removeMarkerFromHistory(marker); - loadMarkers(); + mapMarkersHistory.remove(marker); refresh(); } } @@ -326,17 +356,20 @@ public class MapMarkersHelper { public void reverseActiveMarkersOrder() { cancelAddressRequests(); - - markersDbHelper.reverseActiveMarkersOrder(); - loadMarkers(); + Collections.reverse(mapMarkers); + checkAndFixActiveMarkersOrderIfNeeded(); } - public void removeActiveMarkers() { + public void moveAllActiveMarkersToHistory() { cancelAddressRequests(); markersDbHelper.moveAllActiveMarkersToHistory(); + for (MapMarker marker : mapMarkers) { + marker.history = true; + marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE; + } + mapMarkersHistory.addAll(mapMarkers); mapMarkers.clear(); - mapMarkersHistory.clear(); - mapMarkersHistory.addAll(markersDbHelper.getMarkersHistory()); + sortMarkers(mapMarkersHistory, true); refresh(); } @@ -388,9 +421,12 @@ public class MapMarkersHelper { if (groups != null) { marker.groupKey = markersDbHelper.createGroupIfNeeded(groups.get(i)); } + marker.history = false; + marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE; markersDbHelper.addMarker(marker); + mapMarkers.add(marker); + checkAndFixActiveMarkersOrderIfNeeded(); } - loadMarkers(); } } @@ -406,26 +442,24 @@ public class MapMarkersHelper { public void moveMapMarker(@Nullable MapMarker marker, LatLon latLon) { if (marker != null) { - marker.point = new LatLon(latLon.getLatitude(), latLon.getLongitude()); + LatLon point = new LatLon(latLon.getLatitude(), latLon.getLongitude()); + int index = mapMarkers.indexOf(marker); + if (index != -1) { + mapMarkers.get(index).point = point; + } + marker.point = point; markersDbHelper.updateMarker(marker); - loadMarkers(); + checkAndFixActiveMarkersOrderIfNeeded(); refresh(); } } - public void changeActiveMarkerPositionInDb(int currentPosInMapMarkers) { - MapMarker moved = mapMarkers.get(currentPosInMapMarkers); - markersDbHelper.changeActiveMarkerPosition(moved, - currentPosInMapMarkers == mapMarkers.size() - 1 ? null : mapMarkers.get(currentPosInMapMarkers + 1)); - loadMarkers(); - } - public void moveMarkerToTop(MapMarker marker) { int i = mapMarkers.indexOf(marker); if (i != -1 && mapMarkers.size() > 1) { mapMarkers.remove(i); - markersDbHelper.changeActiveMarkerPosition(marker, mapMarkers.get(0)); - loadMarkers(); + mapMarkers.add(0, marker); + checkAndFixActiveMarkersOrderIfNeeded(); refresh(); } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java index 35823dfcba..4b88b2089b 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java @@ -354,7 +354,7 @@ public class MapMarkerDialogHelper { @Override public void onClick(DialogInterface dialog, int which) { listAdapter.notifyDataSetInvalidated(); - markersHelper.removeActiveMarkers(); + markersHelper.moveAllActiveMarkersToHistory(); if (markersHelper.getMapMarkersHistory().size() == 0) { mapActivity.getDashboard().hideDashboard(); } else if (helperCallbacks != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 0472875d9e..cde730ea9c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -68,7 +68,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { hideSnackbar(); - mapActivity.getMyApplication().getMapMarkersHelper().changeActiveMarkerPositionInDb(toPosition); + mapActivity.getMyApplication().getMapMarkersHelper().checkAndFixActiveMarkersOrderIfNeeded(); } } }); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 4be7f32a70..0e6714b1b5 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -1,7 +1,6 @@ package net.osmand.plus.mapmarkers; import android.support.annotation.Nullable; -import android.support.v4.util.LongSparseArray; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -13,39 +12,43 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.helpers.SearchHistoryHelper; import java.util.Calendar; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Random; public class MapMarkersDbHelper { - private static final int DB_VERSION = 3; + private static final int DB_VERSION = 4; public static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; private static final String MARKERS_COL_ID = "marker_id"; - private static final String MARKERS_COL_LAT = "marker_latitude"; - private static final String MARKERS_COL_LON = "marker_longitude"; + private static final String MARKERS_COL_LAT = "marker_lat"; + private static final String MARKERS_COL_LON = "marker_lon"; private static final String MARKERS_COL_DESCRIPTION = "marker_description"; private static final String MARKERS_COL_ACTIVE = "marker_active"; private static final String MARKERS_COL_ADDED = "marker_added"; private static final String MARKERS_COL_VISITED = "marker_visited"; + private static final String MARKERS_COL_GROUP_NAME = "group_name"; private static final String MARKERS_COL_GROUP_KEY = "group_key"; private static final String MARKERS_COL_COLOR = "marker_color"; private static final String MARKERS_COL_NEXT_KEY = "marker_next_key"; private static final String MARKERS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + MARKERS_TABLE_NAME + " (" + - MARKERS_COL_ID + " long PRIMARY KEY, " + + MARKERS_COL_ID + " TEXT PRIMARY KEY, " + MARKERS_COL_LAT + " double, " + MARKERS_COL_LON + " double, " + MARKERS_COL_DESCRIPTION + " TEXT, " + MARKERS_COL_ACTIVE + " int, " + // 1 = true, 0 = false MARKERS_COL_ADDED + " long, " + MARKERS_COL_VISITED + " long, " + + MARKERS_COL_GROUP_NAME + " TEXT, " + MARKERS_COL_GROUP_KEY + " long, " + MARKERS_COL_COLOR + " int, " + - MARKERS_COL_NEXT_KEY + " long);"; + MARKERS_COL_NEXT_KEY + " TEXT);"; private static final String MARKERS_TABLE_SELECT = "SELECT " + MARKERS_COL_ID + ", " + @@ -55,6 +58,7 @@ public class MapMarkersDbHelper { MARKERS_COL_ACTIVE + ", " + MARKERS_COL_ADDED + ", " + MARKERS_COL_VISITED + ", " + + MARKERS_COL_GROUP_NAME + ", " + MARKERS_COL_GROUP_KEY + ", " + MARKERS_COL_COLOR + ", " + MARKERS_COL_NEXT_KEY + @@ -74,8 +78,8 @@ public class MapMarkersDbHelper { GROUPS_COL_NAME + " FROM " + GROUPS_TABLE_NAME; - private static final int TAIL_NEXT_VALUE = 0; - private static final int HISTORY_NEXT_VALUE = -1; + public static final String TAIL_NEXT_VALUE = "tail_next"; + public static final String HISTORY_NEXT_VALUE = "history_next"; private final OsmandApplication context; @@ -145,14 +149,6 @@ public class MapMarkersDbHelper { } } - public void reverseActiveMarkersOrder() { - List markers = getActiveMarkers(); - removeAllActiveMarkers(); - for (int i = markers.size() - 1; i >= 0; i--) { - addMarker(markers.get(i)); - } - } - public long createGroupIfNeeded(String name) { long res = -1; SQLiteConnection db = openConnection(false); @@ -198,15 +194,11 @@ public class MapMarkersDbHelper { } else { currentTime = System.currentTimeMillis(); } - marker.id = Long.parseLong(String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100)); + marker.id = String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100); marker.creationDate = currentTime; - double lat = marker.getLatitude(); - double lon = marker.getLongitude(); String descr = PointDescription.serializeToString(marker.getOriginalPointDescription()); int active = marker.history ? 0 : 1; long visited = saveExisting ? currentTime : 0; - long groupKey = marker.groupKey; - int colorIndex = marker.colorIndex; PointDescription pointDescription = marker.getOriginalPointDescription(); if (pointDescription != null && !pointDescription.isSearchingAddress(context)) { @@ -219,8 +211,9 @@ public class MapMarkersDbHelper { "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, TAIL_NEXT_VALUE}); } - db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, + db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + new Object[]{marker.id, marker.getLatitude(), marker.getLongitude(), descr, active, + currentTime, visited, marker.groupName, marker.groupKey, marker.colorIndex, marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE}); } @@ -265,7 +258,7 @@ public class MapMarkersDbHelper { public List getActiveMarkers() { List res = new LinkedList<>(); - LongSparseArray markers = new LongSparseArray<>(); + HashMap markers = new LinkedHashMap<>(); SQLiteConnection db = openConnection(true); if (db != null) { try { @@ -274,29 +267,30 @@ public class MapMarkersDbHelper { if (query.moveToFirst()) { do { MapMarker marker = readItem(query); - markers.put(marker.nextKey, marker); + markers.put(marker.id, marker); } while (query.moveToNext()); } query.close(); } finally { db.close(); } - buildLinkedList(markers, res, markers.get(TAIL_NEXT_VALUE)); + buildLinkedList(markers, res); } return res; } private MapMarker readItem(SQLiteCursor query) { - long id = query.getLong(0); + String id = query.getString(0); double lat = query.getDouble(1); double lon = query.getDouble(2); String desc = query.getString(3); boolean active = query.getInt(4) == 1; long added = query.getLong(5); long visited = query.getLong(6); - long groupKey = query.getLong(7); - int colorIndex = query.getInt(8); - long nextKey = query.getLong(9); + String groupName = query.getString(7); + long groupKey = query.getLong(8); + int colorIndex = query.getInt(9); + String nextKey = query.getString(10); LatLon latLon = new LatLon(lat, lon); MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), @@ -305,19 +299,23 @@ public class MapMarkersDbHelper { marker.history = !active; marker.creationDate = added; marker.visitedDate = visited; + marker.groupName = groupName; marker.groupKey = groupKey; marker.nextKey = nextKey; return marker; } - private void buildLinkedList(LongSparseArray markers, List res, MapMarker marker) { - if (marker != null) { - res.add(0, marker); - MapMarker prev = markers.get(marker.id); - if (prev != null) { - buildLinkedList(markers, res, prev); + private void buildLinkedList(HashMap markers, List res) { + if (!markers.isEmpty()) { + for (MapMarker marker : markers.values()) { + if (!markers.keySet().contains(marker.nextKey)) { + res.add(0, marker); + markers.remove(marker.id); + break; + } } + buildLinkedList(markers, res); } } @@ -343,12 +341,6 @@ public class MapMarkersDbHelper { SQLiteConnection db = openConnection(false); if (db != null) { try { - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{moved.nextKey, moved.id}); - - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{moved.id, next == null ? TAIL_NEXT_VALUE : next.id}); - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + "WHERE " + MARKERS_COL_ID + " = ?", new Object[]{next == null ? TAIL_NEXT_VALUE : next.id, moved.id}); } finally { @@ -357,18 +349,6 @@ public class MapMarkersDbHelper { } } - private void removeAllActiveMarkers() { - SQLiteConnection db = openConnection(true); - if (db != null) { - try { - db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ACTIVE + " = ?", - new Object[]{1}); - } finally { - db.close(); - } - } - } - public void removeMarker(double lat, double lon, long groupId) { SQLiteConnection db = openConnection(false); if (db != null) { @@ -407,13 +387,11 @@ public class MapMarkersDbHelper { try { marker.visitedDate = System.currentTimeMillis(); - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.nextKey, marker.id}); - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ?, " + - MARKERS_COL_VISITED + " = ? " + - "WHERE " + MARKERS_COL_ID + " = ?", new Object[]{0, marker.visitedDate, marker.id}); + MARKERS_COL_VISITED + " = ?, " + + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_ID + " = ?", new Object[]{0, marker.visitedDate, HISTORY_NEXT_VALUE, marker.id}); } finally { db.close(); } @@ -427,8 +405,9 @@ public class MapMarkersDbHelper { long visitedDate = System.currentTimeMillis(); db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ?, " + - MARKERS_COL_VISITED + " = ? " + - "WHERE " + MARKERS_COL_ACTIVE + " = ?", new Object[]{0, visitedDate, 1}); + MARKERS_COL_VISITED + " = ?, " + + MARKERS_COL_NEXT_KEY + " = ? " + + "WHERE " + MARKERS_COL_ACTIVE + " = ?", new Object[]{0, visitedDate, HISTORY_NEXT_VALUE, 1}); } finally { db.close(); } @@ -439,13 +418,11 @@ public class MapMarkersDbHelper { SQLiteConnection db = openConnection(false); if (db != null) { try { - List active = getActiveMarkers(); db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + - MARKERS_COL_ACTIVE + " = ?, " + - MARKERS_COL_NEXT_KEY + " = ? " + + MARKERS_COL_ACTIVE + " = ? " + "WHERE " + MARKERS_COL_ID + " = ? " + "AND " + MARKERS_COL_ACTIVE + " = ?", - new Object[]{1, active.size() > 0 ? active.get(0).id : TAIL_NEXT_VALUE, marker.id, 0}); + new Object[]{1, marker.id, 0}); } finally { db.close(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 4e30eb5f65..cf570549c9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -161,7 +161,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void moveAllToHistoryOnClick() { - mapActivity.getMyApplication().getMapMarkersHelper().removeActiveMarkers(); + mapActivity.getMyApplication().getMapMarkersHelper().moveAllActiveMarkersToHistory(); activeFragment.updateAdapter(); } }; From dbe9d66e8dae11f1c58517efc26e59ccd9461baf Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Sep 2017 19:26:51 +0300 Subject: [PATCH 082/128] Highlight first two items in active --- ...ker_circle_background_light_with_inset.xml | 2 +- .../marker_circle_background_on_map_n.xml | 8 ++ ..._circle_background_on_map_n_with_inset.xml | 7 ++ ...er_circle_background_on_map_with_inset.xml | 5 + ...t_p.xml => marker_circle_background_p.xml} | 2 +- ...marker_circle_background_p_with_inset.xml} | 2 +- OsmAnd/res/layout/map_marker_item_on_map.xml | 113 ++++++++++++++++++ OsmAnd/res/values/colors.xml | 2 + .../MapMarkerItemOnMapViewHolder.java | 31 +++++ .../adapters/MapMarkersActiveAdapter.java | 45 +++++-- 10 files changed, 206 insertions(+), 11 deletions(-) create mode 100644 OsmAnd/res/drawable/marker_circle_background_on_map_n.xml create mode 100644 OsmAnd/res/drawable/marker_circle_background_on_map_n_with_inset.xml create mode 100644 OsmAnd/res/drawable/marker_circle_background_on_map_with_inset.xml rename OsmAnd/res/drawable/{marker_circle_background_light_p.xml => marker_circle_background_p.xml} (75%) rename OsmAnd/res/drawable/{marker_circle_background_light_p_with_inset.xml => marker_circle_background_p_with_inset.xml} (78%) create mode 100644 OsmAnd/res/layout/map_marker_item_on_map.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemOnMapViewHolder.java diff --git a/OsmAnd/res/drawable/marker_circle_background_light_with_inset.xml b/OsmAnd/res/drawable/marker_circle_background_light_with_inset.xml index 7e6b0f5772..9028ba95f8 100644 --- a/OsmAnd/res/drawable/marker_circle_background_light_with_inset.xml +++ b/OsmAnd/res/drawable/marker_circle_background_light_with_inset.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/OsmAnd/res/drawable/marker_circle_background_on_map_n.xml b/OsmAnd/res/drawable/marker_circle_background_on_map_n.xml new file mode 100644 index 0000000000..c9a69c97ff --- /dev/null +++ b/OsmAnd/res/drawable/marker_circle_background_on_map_n.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/marker_circle_background_on_map_n_with_inset.xml b/OsmAnd/res/drawable/marker_circle_background_on_map_n_with_inset.xml new file mode 100644 index 0000000000..e9ab9f1da0 --- /dev/null +++ b/OsmAnd/res/drawable/marker_circle_background_on_map_n_with_inset.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/marker_circle_background_on_map_with_inset.xml b/OsmAnd/res/drawable/marker_circle_background_on_map_with_inset.xml new file mode 100644 index 0000000000..c8a1ec15a5 --- /dev/null +++ b/OsmAnd/res/drawable/marker_circle_background_on_map_with_inset.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/marker_circle_background_light_p.xml b/OsmAnd/res/drawable/marker_circle_background_p.xml similarity index 75% rename from OsmAnd/res/drawable/marker_circle_background_light_p.xml rename to OsmAnd/res/drawable/marker_circle_background_p.xml index 180cf357ef..66ed549f5f 100644 --- a/OsmAnd/res/drawable/marker_circle_background_light_p.xml +++ b/OsmAnd/res/drawable/marker_circle_background_p.xml @@ -4,5 +4,5 @@ android:shape="oval"> + android:color="@color/map_widget_blue"/> \ No newline at end of file diff --git a/OsmAnd/res/drawable/marker_circle_background_light_p_with_inset.xml b/OsmAnd/res/drawable/marker_circle_background_p_with_inset.xml similarity index 78% rename from OsmAnd/res/drawable/marker_circle_background_light_p_with_inset.xml rename to OsmAnd/res/drawable/marker_circle_background_p_with_inset.xml index b843c16fe4..87a731b9d6 100644 --- a/OsmAnd/res/drawable/marker_circle_background_light_p_with_inset.xml +++ b/OsmAnd/res/drawable/marker_circle_background_p_with_inset.xml @@ -1,6 +1,6 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index 12872af5b5..a4d52ec974 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -258,5 +258,7 @@ #101821 #46bd2a + #0d464a + #17828a \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemOnMapViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemOnMapViewHolder.java new file mode 100644 index 0000000000..c252b5ec97 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemOnMapViewHolder.java @@ -0,0 +1,31 @@ +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 MapMarkerItemOnMapViewHolder extends MapMarkerItemViewHolder { + + final ImageView iconDirection; + final ImageView iconReorder; + final TextView title; + final TextView distance; + final TextView point; + final TextView description; + final ImageButton optionsBtn; + + public MapMarkerItemOnMapViewHolder(View view) { + super(view); + iconDirection = (ImageView) view.findViewById(R.id.map_marker_direction_icon); + iconReorder = (ImageView) view.findViewById(R.id.map_marker_reorder_icon); + title = (TextView) view.findViewById(R.id.map_marker_title); + 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); + 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 1eabc58101..08cab33ea2 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -24,6 +24,9 @@ import java.util.Locale; public class MapMarkersActiveAdapter extends RecyclerView.Adapter implements MapMarkersItemTouchHelperCallback.ItemTouchHelperAdapter { + private static final int ON_MAP_TYPE = 1; + private static final int GENERAL_TYPE = 2; + private MapActivity mapActivity; private List markers; private MapMarkersActiveAdapterListener listener; @@ -60,15 +63,23 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Tue, 12 Sep 2017 10:42:39 +0300 Subject: [PATCH 083/128] Improve method --- OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 0e6714b1b5..35e301c287 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -308,12 +308,14 @@ public class MapMarkersDbHelper { private void buildLinkedList(HashMap markers, List res) { if (!markers.isEmpty()) { + int count = 1; for (MapMarker marker : markers.values()) { - if (!markers.keySet().contains(marker.nextKey)) { + if (!markers.keySet().contains(marker.nextKey) || count == markers.size()) { res.add(0, marker); markers.remove(marker.id); break; } + count++; } buildLinkedList(markers, res); } From 9e050f207ca166f8c1c9f7846d4bbe8e3ed81a94 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 12 Sep 2017 11:59:14 +0300 Subject: [PATCH 084/128] Add method call --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 1 + .../osmand/plus/activities/EditFavoriteGroupDialogFragment.java | 1 + 2 files changed, 2 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index b51e67e727..29fbf20a58 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -186,6 +186,7 @@ public class MapMarkersHelper { List activeMarkers = markersDbHelper.getActiveMarkers(); mapMarkers.addAll(activeMarkers); + checkAndFixActiveMarkersOrderIfNeeded(); List markersHistory = markersDbHelper.getMarkersHistory(); sortMarkers(markersHistory, true); diff --git a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java index af747429e6..22d3327d4c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java @@ -181,6 +181,7 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment { addToMarkersView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + // add to map markers MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); List points = new ArrayList<>(group.points.size()); List names = new ArrayList<>(group.points.size()); From d61b2a9e8245fea3d5a7b7639e9d66a86e8848c9 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 12 Sep 2017 13:36:35 +0300 Subject: [PATCH 085/128] Add some changes --- .../src/net/osmand/plus/MapMarkersHelper.java | 17 +-- .../EditFavoriteGroupDialogFragment.java | 1 - .../plus/mapmarkers/MapMarkersDbHelper.java | 100 +----------------- .../adapters/MapMarkersActiveAdapter.java | 3 +- 4 files changed, 8 insertions(+), 113 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 29fbf20a58..e0e4675989 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -50,7 +50,7 @@ public class MapMarkersHelper { public long creationDate; public long visitedDate; public String nextKey; - public long groupKey = -1; + public String groupKey; public String groupName; public MapMarker(LatLon point, PointDescription name, int colorIndex, @@ -254,19 +254,8 @@ public class MapMarkersHelper { } } - public long getGroupId(String name) { - return markersDbHelper.getGroupId(name); - } + public void addGroupToSync(String id, String name) { -// public void removeMarker(double lat, double lon, long groupId) { -// markersDbHelper.removeMarker(lat, lon, groupId); -// loadMarkers(); -// refresh(); -// } - - @Nullable - public String getGroupName(long id) { - return markersDbHelper.getGroupName(id); } public void moveMapMarkerToHistory(MapMarker marker) { @@ -420,7 +409,7 @@ public class MapMarkersHelper { MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); if (groups != null) { - marker.groupKey = markersDbHelper.createGroupIfNeeded(groups.get(i)); +// marker.groupKey = markersDbHelper.createGroupIfNeeded(groups.get(i)); } marker.history = false; marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE; diff --git a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java index 22d3327d4c..af747429e6 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java @@ -181,7 +181,6 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment { addToMarkersView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - // add to map markers MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); List points = new ArrayList<>(group.points.size()); List names = new ArrayList<>(group.points.size()); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 35e301c287..d7f5572e79 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -20,7 +20,7 @@ import java.util.Random; public class MapMarkersDbHelper { - private static final int DB_VERSION = 4; + private static final int DB_VERSION = 5; public static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; @@ -46,7 +46,7 @@ public class MapMarkersDbHelper { MARKERS_COL_ADDED + " long, " + MARKERS_COL_VISITED + " long, " + MARKERS_COL_GROUP_NAME + " TEXT, " + - MARKERS_COL_GROUP_KEY + " long, " + + MARKERS_COL_GROUP_KEY + " TEXT, " + MARKERS_COL_COLOR + " int, " + MARKERS_COL_NEXT_KEY + " TEXT);"; @@ -70,7 +70,7 @@ public class MapMarkersDbHelper { private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + GROUPS_TABLE_NAME + " (" + - GROUPS_COL_ID + " long PRIMARY KEY, " + + GROUPS_COL_ID + " TEXT PRIMARY KEY, " + GROUPS_COL_NAME + " TEXT);"; private static final String GROUPS_TABLE_SELECT = "SELECT " + @@ -149,27 +149,6 @@ public class MapMarkersDbHelper { } } - public long createGroupIfNeeded(String name) { - long res = -1; - SQLiteConnection db = openConnection(false); - if (db != null) { - try { - SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_NAME + " = ?", - new String[]{name}); - if (query.moveToFirst()) { - res = query.getLong(0); - } else { - res = Long.parseLong(String.valueOf(System.currentTimeMillis()) + String.valueOf(new Random().nextInt(900) + 100)); - db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?)", new Object[]{res, name}); - } - query.close(); - } finally { - db.close(); - } - } - return res; - } - public void addMarker(MapMarker marker) { addMarker(marker, false); } @@ -217,45 +196,6 @@ public class MapMarkersDbHelper { marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE}); } - public long getGroupId(String name) { - long res = -1; - if (name != null) { - SQLiteConnection db = openConnection(true); - if (db != null) { - try { - SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_NAME + " = ?", - new String[]{name}); - if (query.moveToFirst()) { - res = query.getLong(0); - } - query.close(); - } finally { - db.close(); - } - } - } - return res; - } - - @Nullable - public String getGroupName(long id) { - String res = null; - SQLiteConnection db = openConnection(true); - if (db != null) { - try { - SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_ID + " = ?", - new String[]{String.valueOf(id)}); - if (query.moveToFirst()) { - res = query.getString(1); - } - query.close(); - } finally { - db.close(); - } - } - return res; - } - public List getActiveMarkers() { List res = new LinkedList<>(); HashMap markers = new LinkedHashMap<>(); @@ -288,7 +228,7 @@ public class MapMarkersDbHelper { long added = query.getLong(5); long visited = query.getLong(6); String groupName = query.getString(7); - long groupKey = query.getLong(8); + String groupKey = query.getString(8); int colorIndex = query.getInt(9); String nextKey = query.getString(10); @@ -351,38 +291,6 @@ public class MapMarkersDbHelper { } } - public void removeMarker(double lat, double lon, long groupId) { - SQLiteConnection db = openConnection(false); - if (db != null) { - try { - MapMarker marker = null; - SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + - MARKERS_COL_LAT + " = ? AND " + - MARKERS_COL_LON + " = ? AND " + - MARKERS_COL_GROUP_KEY + " = ?", - new String[]{String.valueOf(lat), String.valueOf(lon), String.valueOf(groupId)}); - if (query.moveToFirst()) { - marker = readItem(query); - } - query.close(); - - if (marker != null) { - if (marker.history) { - removeMarkerFromHistory(marker); - } else { - db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.nextKey, marker.id}); - - db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ID + " = ?", - new Object[]{marker.id}); - } - } - } finally { - db.close(); - } - } - } - public void moveMarkerToHistory(MapMarker marker) { SQLiteConnection db = openConnection(false); if (db != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 08cab33ea2..1401f5c4c3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -114,8 +114,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Tue, 12 Sep 2017 15:54:17 +0300 Subject: [PATCH 086/128] Change adding markers from favorites --- .../src/net/osmand/plus/MapMarkersHelper.java | 45 +++++++++++++--- .../EditFavoriteGroupDialogFragment.java | 3 +- .../activities/FavoritesTreeFragment.java | 18 ++++--- .../plus/mapmarkers/MapMarkersDbHelper.java | 51 +++++++++++++++++-- 4 files changed, 100 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index e0e4675989..e39a68c11e 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -1,6 +1,7 @@ package net.osmand.plus; import android.content.Context; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.format.DateFormat; @@ -154,6 +155,34 @@ public class MapMarkersHelper { } } + public static class MarkersSyncGroup { + + public static final int FAVORITES_TYPE = 0; + public static final int GPX_TYPE = 1; + + private String id; + private String name; + private int type; + + public MarkersSyncGroup(@NonNull String id, @NonNull String name, int type) { + this.id = id; + this.name = name; + this.type = type; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public int getType() { + return type; + } + } + public MapMarkersHelper(OsmandApplication ctx) { this.ctx = ctx; settings = ctx.getSettings(); @@ -254,7 +283,7 @@ public class MapMarkersHelper { } } - public void addGroupToSync(String id, String name) { + public void syncGroup(MarkersSyncGroup group) { } @@ -374,15 +403,15 @@ public class MapMarkersHelper { addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null); } - public void addMapMarkers(List points, List historyNames, List groups) { - addMarkers(points, historyNames, groups); + public void addMapMarkers(List points, List historyNames, @Nullable MarkersSyncGroup group) { + addMarkers(points, historyNames, group); } public void addMapMarkers(List points, List historyNames) { addMarkers(points, historyNames, null); } - private void addMarkers(List points, List historyNames, @Nullable List groups) { + private void addMarkers(List points, List historyNames, @Nullable MarkersSyncGroup group) { if (points.size() > 0) { int colorIndex = -1; for (int i = 0; i < points.size(); i++) { @@ -408,8 +437,12 @@ public class MapMarkersHelper { } MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); - if (groups != null) { -// marker.groupKey = markersDbHelper.createGroupIfNeeded(groups.get(i)); + if (group != null) { + if (markersDbHelper.getGroup(group.getId()) == null) { + markersDbHelper.addGroup(group.getId(), group.getName(), group.getType()); + } + marker.id = group.getId() + marker.getName(ctx); + marker.groupName = group.getName(); } marker.history = false; marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE; diff --git a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java index af747429e6..ce4bc97295 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java @@ -30,6 +30,7 @@ import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper; +import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.base.BottomSheetDialogFragment; @@ -188,7 +189,7 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment { points.add(new LatLon(fp.getLatitude(), fp.getLongitude())); names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName())); } - markersHelper.addMapMarkers(points, names); + markersHelper.addMapMarkers(points, names, new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE)); dismiss(); MapActivity.launchMapActivityMoveToTop(getActivity()); } diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 7c0f7817b6..1ee398d73d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -36,6 +36,7 @@ import net.osmand.data.PointDescription; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.MapMarkersHelper; +import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -57,6 +58,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -401,18 +403,22 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { if (getSelectedFavoritesCount() > 0) { if (getSettings().USE_MAP_MARKERS.get()) { MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); - int size = getSelectedFavoritesCount(); - List points = new ArrayList<>(size); - List names = new ArrayList<>(size); - List groups = new ArrayList<>(size); + List points = new LinkedList<>(); + List names = new LinkedList<>(); for (Map.Entry> entry : favoritesSelected.entrySet()) { + MarkersSyncGroup syncGr = null; + FavoriteGroup favGr = helper.getGroup(entry.getKey()); + if (entry.getValue().size() == favGr.points.size()) { + syncGr = new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE); + } for (FavouritePoint fp : entry.getValue()) { points.add(new LatLon(fp.getLatitude(), fp.getLongitude())); names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName())); - groups.add(entry.getKey()); } + markersHelper.addMapMarkers(points, names, syncGr); + points.clear(); + names.clear(); } - markersHelper.addMapMarkers(points, names, groups); MapActivity.launchMapActivityMoveToTop(getActivity()); } else { final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index d7f5572e79..f6be7c00ec 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -5,6 +5,7 @@ import android.support.annotation.Nullable; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; @@ -20,7 +21,7 @@ import java.util.Random; public class MapMarkersDbHelper { - private static final int DB_VERSION = 5; + private static final int DB_VERSION = 6; public static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; @@ -67,15 +68,18 @@ public class MapMarkersDbHelper { private static final String GROUPS_TABLE_NAME = "map_markers_groups"; private static final String GROUPS_COL_ID = "group_id"; private static final String GROUPS_COL_NAME = "group_name"; + private static final String GROUPS_COL_TYPE = "group_type"; private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + GROUPS_TABLE_NAME + " (" + GROUPS_COL_ID + " TEXT PRIMARY KEY, " + - GROUPS_COL_NAME + " TEXT);"; + GROUPS_COL_NAME + " TEXT, " + + GROUPS_COL_TYPE + " int);"; private static final String GROUPS_TABLE_SELECT = "SELECT " + GROUPS_COL_ID + ", " + - GROUPS_COL_NAME + + GROUPS_COL_NAME + ", " + + GROUPS_COL_TYPE + " FROM " + GROUPS_TABLE_NAME; public static final String TAIL_NEXT_VALUE = "tail_next"; @@ -149,6 +153,43 @@ public class MapMarkersDbHelper { } } + public void addGroup(String id, String name, int type) { + SQLiteConnection db = openConnection(false); + if (db != null) { + try { + db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?)", new Object[]{id, name, type}); + } finally { + db.close(); + } + } + } + + @Nullable + public MarkersSyncGroup getGroup(String id) { + MarkersSyncGroup res = null; + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_ID + " = ?", new String[]{id}); + if (query.moveToFirst()) { + res = readSyncGroup(query); + } + query.close(); + } finally { + db.close(); + } + } + return res; + } + + private MarkersSyncGroup readSyncGroup(SQLiteCursor query) { + String id = query.getString(0); + String name = query.getString(1); + int type = query.getInt(2); + + return new MarkersSyncGroup(id, name, type); + } + public void addMarker(MapMarker marker) { addMarker(marker, false); } @@ -173,7 +214,9 @@ public class MapMarkersDbHelper { } else { currentTime = System.currentTimeMillis(); } - marker.id = String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100); + if (marker.id == null) { + marker.id = String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100); + } marker.creationDate = currentTime; String descr = PointDescription.serializeToString(marker.getOriginalPointDescription()); int active = marker.history ? 0 : 1; From 3f5420e423856ad3118e354bfec77fd49e1e08b3 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 12 Sep 2017 16:55:33 +0300 Subject: [PATCH 087/128] Change adding markers from gpx track --- .../osmand/plus/myplaces/TrackPointFragment.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 54ceae5c4c..07315990ce 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -44,6 +44,7 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper; +import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -607,7 +608,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment { names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, i.name)); } } - markersHelper.addMapMarkers(points, names); + File gpx = getGpxDataItem().getFile(); + MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE); + markersHelper.addMapMarkers(points, names, syncGroup); MapActivity.launchMapActivityMoveToTop(getActivity()); } else { final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper(); @@ -626,6 +629,14 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } } + private String trimExtension(String src) { + int index = src.lastIndexOf('.'); + if (index != -1) { + return src.substring(0, index); + } + return src; + } + private void enterFavoritesMode() { actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() { From 9e088e6575063bac5707aaca33b9f47c612c5e47 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 12 Sep 2017 18:43:51 +0300 Subject: [PATCH 088/128] Change reorder highlight --- OsmAnd/res/layout/map_marker_item_new.xml | 7 +-- OsmAnd/res/layout/map_marker_item_on_map.xml | 2 +- OsmAnd/res/values/colors.xml | 2 +- .../mapmarkers/MapMarkersActiveFragment.java | 2 + .../adapters/MapMarkerItemViewHolder.java | 2 + .../adapters/MapMarkersActiveAdapter.java | 43 +++++++------------ 6 files changed, 25 insertions(+), 33 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index e9e1b0548a..49bb2f36f8 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/bg_color" + tools:background="?attr/bg_color" android:descendantFocusability="blocksDescendants" android:orientation="vertical"> @@ -47,7 +47,7 @@ android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="1" - android:textColor="?android:textColorPrimary" + tools:textColor="?android:textColorPrimary" android:textSize="@dimen/default_list_text_size" tools:text="Van Gogh Museum"/> @@ -111,10 +111,11 @@ + tools:background="?attr/dashboard_divider"/> diff --git a/OsmAnd/res/layout/map_marker_item_on_map.xml b/OsmAnd/res/layout/map_marker_item_on_map.xml index b33b5469c5..94a6134200 100644 --- a/OsmAnd/res/layout/map_marker_item_on_map.xml +++ b/OsmAnd/res/layout/map_marker_item_on_map.xml @@ -108,6 +108,6 @@ android:layout_height="1dp" android:layout_marginLeft="56dp" android:layout_marginStart="56dp" - android:background="@color/map_markers_divider_color"/> + android:background="@color/map_markers_on_map_divider_color"/> \ No newline at end of file diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index a4d52ec974..a646c6aab6 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -258,7 +258,7 @@ #101821 #46bd2a - #0d464a + #0d464a #17828a \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index cde730ea9c..5634d61157 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -70,6 +70,8 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL hideSnackbar(); mapActivity.getMyApplication().getMapMarkersHelper().checkAndFixActiveMarkersOrderIfNeeded(); } + adapter.notifyItemChanged(fromPosition); + adapter.notifyItemChanged(toPosition); } }); recyclerView.setAdapter(adapter); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java index 7f63f34b7b..38a93d9bc6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java @@ -18,6 +18,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { final TextView point; final TextView description; final ImageButton optionsBtn; + final View divider; public MapMarkerItemViewHolder(View view) { super(view); @@ -29,6 +30,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { point = (TextView) view.findViewById(R.id.map_marker_point_text_view); description = (TextView) view.findViewById(R.id.map_marker_description); optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button); + divider = view.findViewById(R.id.divider); } public void setOptionsButtonVisibility(int visibility) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 08cab33ea2..1633721fd3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -1,6 +1,7 @@ package net.osmand.plus.mapmarkers.adapters; import android.support.design.widget.Snackbar; +import android.support.v4.content.ContextCompat; import android.support.v4.view.MotionEventCompat; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -24,9 +25,6 @@ import java.util.Locale; public class MapMarkersActiveAdapter extends RecyclerView.Adapter implements MapMarkersItemTouchHelperCallback.ItemTouchHelperAdapter { - private static final int ON_MAP_TYPE = 1; - private static final int GENERAL_TYPE = 2; - private MapActivity mapActivity; private List markers; private MapMarkersActiveAdapterListener listener; @@ -36,10 +34,12 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Wed, 13 Sep 2017 10:02:52 +0300 Subject: [PATCH 089/128] Fix highlight reorder --- OsmAnd/res/layout/map_marker_item_new.xml | 6 +++--- .../osmand/plus/mapmarkers/MapMarkersActiveFragment.java | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 49bb2f36f8..e45f5be595 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - tools:background="?attr/bg_color" + android:background="?attr/bg_color" android:descendantFocusability="blocksDescendants" android:orientation="vertical"> @@ -47,7 +47,7 @@ android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="1" - tools:textColor="?android:textColorPrimary" + android:textColor="?android:textColorPrimary" android:textSize="@dimen/default_list_text_size" tools:text="Van Gogh Museum"/> @@ -116,6 +116,6 @@ android:layout_height="1dp" android:layout_marginLeft="56dp" android:layout_marginStart="56dp" - tools:background="?attr/dashboard_divider"/> + android:background="?attr/dashboard_divider"/> diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 5634d61157..199c76a01b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -69,9 +69,8 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { hideSnackbar(); mapActivity.getMyApplication().getMapMarkersHelper().checkAndFixActiveMarkersOrderIfNeeded(); + adapter.notifyDataSetChanged(); } - adapter.notifyItemChanged(fromPosition); - adapter.notifyItemChanged(toPosition); } }); recyclerView.setAdapter(adapter); From 904168403b380fd87c46f36f37cd763e9bde6a90 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 13 Sep 2017 10:07:22 +0300 Subject: [PATCH 090/128] Remove unnecessary code to highlight --- .../plus/mapmarkers/adapters/MapMarkersActiveAdapter.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 36deb4f72b..cfbc1eedc1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -90,10 +90,6 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Wed, 13 Sep 2017 10:08:22 +0300 Subject: [PATCH 091/128] Remove unnecessary files to highlight --- OsmAnd/res/layout/map_marker_item_on_map.xml | 113 ------------------ .../MapMarkerItemOnMapViewHolder.java | 31 ----- 2 files changed, 144 deletions(-) delete mode 100644 OsmAnd/res/layout/map_marker_item_on_map.xml delete mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemOnMapViewHolder.java diff --git a/OsmAnd/res/layout/map_marker_item_on_map.xml b/OsmAnd/res/layout/map_marker_item_on_map.xml deleted file mode 100644 index 94a6134200..0000000000 --- a/OsmAnd/res/layout/map_marker_item_on_map.xml +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemOnMapViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemOnMapViewHolder.java deleted file mode 100644 index c252b5ec97..0000000000 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemOnMapViewHolder.java +++ /dev/null @@ -1,31 +0,0 @@ -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 MapMarkerItemOnMapViewHolder extends MapMarkerItemViewHolder { - - final ImageView iconDirection; - final ImageView iconReorder; - final TextView title; - final TextView distance; - final TextView point; - final TextView description; - final ImageButton optionsBtn; - - public MapMarkerItemOnMapViewHolder(View view) { - super(view); - iconDirection = (ImageView) view.findViewById(R.id.map_marker_direction_icon); - iconReorder = (ImageView) view.findViewById(R.id.map_marker_reorder_icon); - title = (TextView) view.findViewById(R.id.map_marker_title); - 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); - optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button); - } -} From ab180a69765dce7e3060275cdf2a790a6dc99e08 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 13 Sep 2017 10:47:15 +0300 Subject: [PATCH 092/128] Highlight styling --- OsmAnd/res/layout/map_marker_item_new.xml | 4 ++- .../plus/dashboard/DashLocationFragment.java | 8 ++++- .../adapters/MapMarkerItemViewHolder.java | 4 +++ .../adapters/MapMarkersActiveAdapter.java | 33 +++++++++++++++---- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index e45f5be595..4a4a7f3912 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -60,6 +60,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:layout_marginRight="4dp" + android:layout_marginEnd="4dp" tools:src="@drawable/ic_direction_arrow"/> diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java index 3f13b90922..474a6638bc 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java @@ -120,6 +120,12 @@ public abstract class DashLocationFragment extends DashBaseFragment { public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h, ImageView arrow, int arrowResId, TextView txt, LatLon toLoc, int screenOrientation, OsmandApplication app, Context ctx, boolean paint) { + updateLocationView(useCenter, fromLoc, h, arrow, arrowResId, 0, txt, toLoc, screenOrientation, app, ctx, paint); + } + + public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h, + ImageView arrow, int arrowResId, int color, TextView txt, LatLon toLoc, + int screenOrientation, OsmandApplication app, Context ctx, boolean paint) { float[] mes = new float[2]; if (fromLoc != null && toLoc != null) { Location.distanceBetween(toLoc.getLatitude(), toLoc.getLongitude(), fromLoc.getLatitude(), fromLoc.getLongitude(), mes); @@ -136,7 +142,7 @@ public abstract class DashLocationFragment extends DashBaseFragment { } else { dd = (DirectionDrawable) arrow.getDrawable(); } - dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_myloc_distance); + dd.setImage(arrowResId, color == 0 ? useCenter ? R.color.color_distance : R.color.color_myloc_distance : color); if (fromLoc == null || h == null || toLoc == null) { dd.setAngle(0); } else { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java index 38a93d9bc6..8c94023a17 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java @@ -36,4 +36,8 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { public void setOptionsButtonVisibility(int visibility) { optionsBtn.setVisibility(visibility); } + + public void setIconDirectionVisibility(int visibility) { + iconDirection.setVisibility(visibility); + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index cfbc1eedc1..20f656fcc9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -8,6 +8,7 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import net.osmand.data.LatLon; import net.osmand.plus.IconsCache; @@ -79,20 +80,40 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Wed, 13 Sep 2017 12:49:16 +0300 Subject: [PATCH 093/128] Highlight selected item in show direction menu --- ...ker_show_direction_bottom_sheet_dialog.xml | 46 ++++++++++-- OsmAnd/res/layout/map_hud_widget.xml | 2 +- OsmAnd/res/values/colors.xml | 1 + ...howDirectionBottomSheetDialogFragment.java | 71 ++++++++++++++++--- 4 files changed, 106 insertions(+), 14 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 b577b2c2d2..6e667ee0b3 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 @@ -68,7 +68,7 @@ tools:src="@drawable/img_help_trip_route_points_night"/> + + + + + + diff --git a/OsmAnd/res/layout/map_hud_widget.xml b/OsmAnd/res/layout/map_hud_widget.xml index 22b7c90d05..77299a4eb9 100644 --- a/OsmAnd/res/layout/map_hud_widget.xml +++ b/OsmAnd/res/layout/map_hud_widget.xml @@ -74,7 +74,7 @@ android:textSize="@dimen/map_widget_text_size" /> #46bd2a #0d464a #17828a + #f2f4ff \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index 1b84f0974d..4c2d249e3c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.mapmarkers; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -12,6 +13,7 @@ import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; +import android.widget.RadioButton; import android.widget.TextView; import net.osmand.AndroidUtils; @@ -26,6 +28,8 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra private ShowDirectionFragmentListener listener; private boolean portrait; + private View mainView; + private boolean night; public void setListener(ShowDirectionFragmentListener listener) { this.listener = listener; @@ -35,20 +39,23 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + night = !getMyApplication().getSettings().isLightContent(); + final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container); + mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container); if (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); + 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(); + highlightSelectedItem(mode, true); + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { mainView.findViewById(R.id.images_row).setVisibility(View.GONE); } else { ImageView topBarImage = (ImageView) mainView.findViewById(R.id.top_bar_image); ImageView widgetImage = (ImageView) mainView.findViewById(R.id.widget_image); - if (nightMode) { + if (night) { topBarImage.setImageResource(R.drawable.img_help_markers_topbar_night); widgetImage.setImageResource(R.drawable.img_help_markers_widgets_night); } else { @@ -56,7 +63,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra widgetImage.setImageResource(R.drawable.img_help_markers_widgets_day); } - mainView.findViewById(R.id.top_bar_text).setOnTouchListener(new View.OnTouchListener() { + mainView.findViewById(R.id.top_bar_image_text).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return false; @@ -64,7 +71,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra }); topBarImage.setOnClickListener(showDirectionOnClickListener); - mainView.findViewById(R.id.widget_text).setOnTouchListener(new View.OnTouchListener() { + mainView.findViewById(R.id.widget_image_text).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return false; @@ -73,7 +80,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra widgetImage.setOnClickListener(showDirectionOnClickListener); } - if (nightMode) { + if (night) { ((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); } @@ -150,21 +157,69 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra } } + 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; + int textColor = ContextCompat.getColor(getContext(), check ? R.color.dashboard_blue : night ? R.color.color_white : R.color.color_black); + switch (mode) { + case TOOLBAR: + ((RadioButton) mainView.findViewById(R.id.top_bar_radio_button)).setChecked(check); + ImageView topBarIcon = (ImageView) mainView.findViewById(R.id.top_bar_icon); + if (check) { + mainView.findViewById(R.id.top_bar_row).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.show_direction_menu_selected_item_bg)); + } else { + mainView.findViewById(R.id.top_bar_row).setBackgroundResource(0); + } + ((TextView) mainView.findViewById(R.id.top_bar_text)).setTextColor(textColor); + topBarIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, iconBgColor)); + topBarIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_topbar, iconColor)); + break; + case WIDGETS: + ((RadioButton) mainView.findViewById(R.id.widget_radio_button)).setChecked(check); + ImageView widgetIcon = (ImageView) mainView.findViewById(R.id.widget_icon); + if (check) { + mainView.findViewById(R.id.widget_row).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.show_direction_menu_selected_item_bg)); + } else { + mainView.findViewById(R.id.widget_row).setBackgroundResource(0); + } + ((TextView) mainView.findViewById(R.id.widget_text)).setTextColor(textColor); + widgetIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, iconBgColor)); + widgetIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_widget, iconColor)); + break; + case NONE: + ((RadioButton) mainView.findViewById(R.id.none_radio_button)).setChecked(check); + ImageView noneIcon = (ImageView) mainView.findViewById(R.id.none_icon); + if (check) { + mainView.findViewById(R.id.none_row).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.show_direction_menu_selected_item_bg)); + } else { + mainView.findViewById(R.id.none_row).setBackgroundResource(0); + } + ((TextView) mainView.findViewById(R.id.none_text)).setTextColor(textColor); + noneIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, iconBgColor)); + break; + } + } + private View.OnClickListener showDirectionOnClickListener = new View.OnClickListener() { @Override public void onClick(View view) { + OsmandSettings.MapMarkersMode previousMode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); + highlightSelectedItem(previousMode, false); switch (view.getId()) { case R.id.top_bar_image: case R.id.top_bar_row: getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.TOOLBAR); + highlightSelectedItem(OsmandSettings.MapMarkersMode.TOOLBAR, true); break; case R.id.widget_image: case R.id.widget_row: getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.WIDGETS); + highlightSelectedItem(OsmandSettings.MapMarkersMode.WIDGETS, true); break; case R.id.none_row: getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.NONE); + highlightSelectedItem(OsmandSettings.MapMarkersMode.NONE, true); break; } if (listener != null) { From f4206e0a838bbbc012b48abbafeb9b96efb8a51c Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 13 Sep 2017 13:40:11 +0300 Subject: [PATCH 094/128] Fix text widget --- OsmAnd/res/layout/map_hud_widget.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/res/layout/map_hud_widget.xml b/OsmAnd/res/layout/map_hud_widget.xml index 77299a4eb9..22b7c90d05 100644 --- a/OsmAnd/res/layout/map_hud_widget.xml +++ b/OsmAnd/res/layout/map_hud_widget.xml @@ -74,7 +74,7 @@ android:textSize="@dimen/map_widget_text_size" /> Date: Wed, 13 Sep 2017 14:39:10 +0300 Subject: [PATCH 095/128] Fix hiding icon --- .../plus/mapmarkers/MapMarkersHistoryFragment.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 2a3dc6eba3..5541e4f5f6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -78,15 +78,13 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel private float marginSides = getResources().getDimension(R.dimen.list_content_padding); private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark); private Bitmap resetBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_reset_to_default_dark); + private boolean iconHidden; @Override public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { if (viewHolder instanceof MapMarkerDateViewHolder) { return 0; } - if (viewHolder instanceof MapMarkerItemViewHolder) { - ((MapMarkerItemViewHolder) viewHolder).setOptionsButtonVisibility(View.GONE); - } return super.getSwipeDirs(recyclerView, viewHolder); } @@ -97,7 +95,11 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { - if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { + if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) { + if (!iconHidden && isCurrentlyActive) { + ((MapMarkerItemViewHolder) viewHolder).setOptionsButtonVisibility(View.GONE); + iconHidden = true; + } View itemView = viewHolder.itemView; int colorIcon; int colorText; @@ -132,6 +134,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { if (viewHolder instanceof MapMarkerItemViewHolder) { ((MapMarkerItemViewHolder) viewHolder).setOptionsButtonVisibility(View.VISIBLE); + iconHidden = false; } super.clearView(recyclerView, viewHolder); } From 56ebb8b33c32a019014c045459a6717b0382bce9 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 13 Sep 2017 14:49:49 +0300 Subject: [PATCH 096/128] Fix highlight first two items --- .../plus/mapmarkers/adapters/MapMarkersActiveAdapter.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 20f656fcc9..65d74932cc 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -147,6 +147,9 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter 1) { + notifyItemChanged(1); + } snackbar = Snackbar.make(holder.itemView, R.string.item_removed, Snackbar.LENGTH_LONG) .setAction(R.string.shared_string_undo, new View.OnClickListener() { @@ -154,6 +157,9 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter 2) { + notifyItemChanged(2); + } } }); snackbar.show(); From e21014a9dcda5b34ce5291336f60f97f50ae39b6 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 13 Sep 2017 15:37:42 +0300 Subject: [PATCH 097/128] Add undo for swipe in history --- .../src/net/osmand/plus/MapMarkersHelper.java | 14 ++++++++++ .../mapmarkers/MapMarkersDialogFragment.java | 1 + .../mapmarkers/MapMarkersHistoryFragment.java | 26 ++++++++++++++++--- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index e39a68c11e..74b56dc966 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -301,6 +301,20 @@ public class MapMarkersHelper { } } + public void addMarker(MapMarker marker) { + if (marker != null) { + markersDbHelper.addMarker(marker); + if (marker.history) { + mapMarkersHistory.add(marker); + sortMarkers(mapMarkersHistory, true); + } else { + mapMarkers.add(marker); + checkAndFixActiveMarkersOrderIfNeeded(); + } + refresh(); + } + } + public void restoreMarkerFromHistory(MapMarker marker, int position) { if (marker != null) { markersDbHelper.restoreMapMarkerFromHistory(marker); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index cf570549c9..06028476be 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -106,6 +106,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm activeFragment.startLocationUpdate(); if (viewPager.getCurrentItem() != 0) { activeFragment.updateAdapter(); + historyFragment.hideSnackbar(); } viewPager.setCurrentItem(0); optionsButton.setVisibility(View.VISIBLE); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 5541e4f5f6..32c98aadda 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -9,12 +9,12 @@ import android.graphics.PorterDuffColorFilter; import android.graphics.Rect; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -35,6 +35,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel private Paint backgroundPaint = new Paint(); private Paint iconPaint = new Paint(); private Paint textPaint = new Paint(); + private Snackbar snackbar; @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -140,16 +141,29 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel } @Override - public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { - int pos = viewHolder.getAdapterPosition(); + public void onSwiped(RecyclerView.ViewHolder viewHolder, final int direction) { + final int pos = viewHolder.getAdapterPosition(); Object item = adapter.getItem(pos); if (item instanceof MapMarker) { + final MapMarker marker = (MapMarker) item; if (direction == ItemTouchHelper.LEFT) { app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0); } else { app.getMapMarkersHelper().removeMarkerFromHistory((MapMarker) item); } adapter.notifyItemRemoved(pos); + snackbar = Snackbar.make(viewHolder.itemView, R.string.item_removed, Snackbar.LENGTH_LONG) + .setAction(R.string.shared_string_undo, new View.OnClickListener() { + @Override + public void onClick(View view) { + if (direction == ItemTouchHelper.LEFT) { + app.getMapMarkersHelper().moveMapMarkerToHistory(marker); + } else { + app.getMapMarkersHelper().addMarker(marker); + } + } + }); + snackbar.show(); } } }; @@ -183,6 +197,12 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel return recyclerView; } + void hideSnackbar() { + if (snackbar != null && snackbar.isShown()) { + snackbar.dismiss(); + } + } + private HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener createHistoryMarkerMenuListener() { return new HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener() { @Override From f211b18a6c5c42a70f3994b9fa98e3b7949642b0 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 13 Sep 2017 16:41:31 +0300 Subject: [PATCH 098/128] Add shadow --- OsmAnd/res/layout/map_marker_item_new.xml | 207 ++++++++++-------- .../adapters/MapMarkerItemViewHolder.java | 8 + .../adapters/MapMarkersActiveAdapter.java | 4 +- .../adapters/MapMarkersHistoryAdapter.java | 5 + 4 files changed, 130 insertions(+), 94 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 4a4a7f3912..db8346170e 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -4,120 +4,143 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/bg_color" android:descendantFocusability="blocksDescendants" android:orientation="vertical"> - - - - + android:layout_height="wrap_content"> + android:layout_width="match_parent" + android:layout_height="56dp" + android:background="?attr/selectableItemBackground"> - + android:layout_gravity="center_vertical" + android:paddingBottom="16dp" + android:paddingLeft="16dp" + android:paddingStart="16dp" + android:paddingTop="16dp" + android:tint="?attr/secondary_icon_color" + tools:src="@drawable/ic_action_reorder"/> + + - - + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_weight="1" + android:orientation="vertical"> - - - - + android:textColor="?android:textColorPrimary" + android:textSize="@dimen/default_list_text_size" + tools:text="Van Gogh Museum"/> + + + + + + + + + + + + + + - + - + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java index 8c94023a17..66b138d20c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java @@ -10,6 +10,7 @@ import net.osmand.plus.R; public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { + final View mainLayout; final ImageView iconDirection; final ImageView iconReorder; final ImageView icon; @@ -19,9 +20,11 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { final TextView description; final ImageButton optionsBtn; final View divider; + final View bottomShadow; public MapMarkerItemViewHolder(View view) { super(view); + mainLayout = view.findViewById(R.id.main_layout); iconDirection = (ImageView) view.findViewById(R.id.map_marker_direction_icon); iconReorder = (ImageView) view.findViewById(R.id.map_marker_reorder_icon); icon = (ImageView) view.findViewById(R.id.map_marker_icon); @@ -31,6 +34,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { description = (TextView) view.findViewById(R.id.map_marker_description); optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button); divider = view.findViewById(R.id.divider); + bottomShadow = view.findViewById(R.id.bottom_shadow); } public void setOptionsButtonVisibility(int visibility) { @@ -40,4 +44,8 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { public void setIconDirectionVisibility(int visibility) { iconDirection.setVisibility(visibility); } + + public void setBottomShadowVisibility(int visibility) { + bottomShadow.setVisibility(visibility); + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 65d74932cc..b77f9de136 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -88,7 +88,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Wed, 13 Sep 2017 18:16:24 +0300 Subject: [PATCH 099/128] Styling --- ...ent_marker_options_bottom_sheet_dialog.xml | 4 +-- OsmAnd/res/layout/map_marker_item_date.xml | 8 +++--- OsmAnd/res/layout/map_marker_item_new.xml | 28 ++++++++++++------- OsmAnd/res/values/strings.xml | 1 - ...arkerOptionsBottomSheetDialogFragment.java | 18 ++++++++++-- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml index 88ae0b8cc1..d5fd81800e 100644 --- a/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml @@ -27,7 +27,7 @@ android:paddingLeft="@dimen/bottom_sheet_content_padding" android:paddingRight="@dimen/bottom_sheet_content_padding" android:paddingStart="@dimen/bottom_sheet_content_padding" - android:text="@string/marker_options" + android:text="@string/shared_string_options" android:textAppearance="@style/TextAppearance.ListItemTitle" osmand:typeface="@string/font_roboto_medium"/> @@ -78,7 +78,7 @@ android:layout_gravity="center_vertical" android:layout_marginEnd="@dimen/bottom_sheet_icon_margin" android:layout_marginRight="@dimen/bottom_sheet_icon_margin" - tools:src="@drawable/ic_sort_waypoint_dark"/> + tools:background="@drawable/ic_action_device_top"/> @@ -18,7 +18,7 @@ android:id="@+id/date_title" android:layout_width="0dp" android:layout_weight="1" - android:layout_height="56dp" + android:layout_height="match_parent" android:paddingLeft="16dp" android:paddingStart="16dp" android:gravity="center_vertical" @@ -26,8 +26,8 @@ - + android:layout_height="28dp"> + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index b32760d7ba..dea93cc727 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -21,7 +21,6 @@ Build route Show direction Sort by - Marker options Do not use animations Disables animations in the app Keep showing on map diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java index 8ef1ab8531..0415556cea 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerOptionsBottomSheetDialogFragment.java @@ -14,6 +14,7 @@ import android.widget.ImageView; import android.widget.TextView; import net.osmand.AndroidUtils; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -43,8 +44,21 @@ public class MarkerOptionsBottomSheetDialogFragment extends BottomSheetDialogFra ((ImageView) mainView.findViewById(R.id.sort_by_icon)) .setImageDrawable(getIcon(R.drawable.ic_sort_waypoint_dark, R.color.on_map_icon_color)); - ((ImageView) mainView.findViewById(R.id.show_direction_icon)) - .setImageDrawable(getIcon(R.drawable.ic_sort_waypoint_dark, R.color.on_map_icon_color)); + OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); + ImageView showDirectionIcon = (ImageView) mainView.findViewById(R.id.show_direction_icon); + int imageResId = 0; + switch (mode) { + case TOOLBAR: + imageResId = R.drawable.ic_action_device_topbar; + break; + case WIDGETS: + imageResId = R.drawable.ic_action_device_widget; + break; + } + showDirectionIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); + 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)); ((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)) From d4acaad1872f920ba6eec5aa2bd4036bf1f52a0a Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 13 Sep 2017 19:42:05 +0300 Subject: [PATCH 100/128] Add sync --- .../src/net/osmand/plus/AppInitializer.java | 1 + .../net/osmand/plus/FavouritesDbHelper.java | 129 +++++++++--------- .../src/net/osmand/plus/MapMarkersHelper.java | 82 +++++++++-- .../EditFavoriteGroupDialogFragment.java | 4 +- .../activities/FavoritesTreeFragment.java | 4 +- .../plus/mapmarkers/MapMarkersDbHelper.java | 82 ++++++++++- .../plus/myplaces/TrackPointFragment.java | 1 + 7 files changed, 221 insertions(+), 82 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index e4d3563ac4..ec14837769 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -501,6 +501,7 @@ public class AppInitializer implements IProgress { startBgTime = System.currentTimeMillis(); app.favorites.loadFavorites(); notifyEvent(InitEvents.FAVORITES_INITIALIZED); + app.mapMarkersHelper.syncAllGroups(); // init poi types before indexes and before POI initPoiTypes(); notifyEvent(InitEvents.POI_TYPES_INITIALIZED); diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index f250942298..4213b31847 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -7,6 +7,7 @@ import net.osmand.PlatformUtil; import net.osmand.data.FavouritePoint; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.util.Algorithms; @@ -20,6 +21,7 @@ import java.text.Collator; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -63,9 +65,9 @@ public class FavouritesDbHelper { favoriteGroups.clear(); File internalFile = getInternalFile(); - if(!internalFile.exists()) { + if (!internalFile.exists()) { File dbPath = context.getDatabasePath(FAVOURITE_DB_NAME); - if(dbPath.exists()) { + if (dbPath.exists()) { loadAndCheckDatabasePoints(); saveCurrentPointsIntoFile(); } @@ -77,27 +79,27 @@ public class FavouritesDbHelper { loadGPXFile(getExternalFile(), extPoints); boolean changed = merge(extPoints, points); - for(FavouritePoint pns : points.values()) { + for (FavouritePoint pns : points.values()) { FavoriteGroup group = getOrCreateGroup(pns, 0); group.points.add(pns); } sortAll(); recalculateCachedFavPoints(); - if(changed) { + if (changed) { saveCurrentPointsIntoFile(); } favouritesUpdated(); } - private void favouritesUpdated(){ + private void favouritesUpdated() { } private boolean merge(Map source, Map destination) { boolean changed = false; - for(String ks : source.keySet()) { - if(!destination.containsKey(ks)) { + for (String ks : source.keySet()) { + if (!destination.containsKey(ks)) { changed = true; destination.put(ks, source.get(ks)); } @@ -106,26 +108,31 @@ public class FavouritesDbHelper { } - private File getInternalFile() { return context.getFileStreamPath(FILE_TO_BACKUP); } public void delete(Set groupsToDelete, Set favoritesSelected) { if (favoritesSelected != null) { + Set groupsToSync = new HashSet<>(); for (FavouritePoint p : favoritesSelected) { FavoriteGroup group = flatGroups.get(p.getCategory()); if (group != null) { group.points.remove(p); + groupsToSync.add(group); } cachedFavoritePoints.remove(p); } + for (FavoriteGroup gr : groupsToSync) { + context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE)); + } } if (groupsToDelete != null) { for (FavoriteGroup g : groupsToDelete) { flatGroups.remove(g.name); favoriteGroups.remove(g); cachedFavoritePoints.removeAll(g.points); + context.getMapMarkersHelper().removeMarkersSyncGroup(g.name); } } saveCurrentPointsIntoFile(); @@ -140,6 +147,7 @@ public class FavouritesDbHelper { FavoriteGroup group = flatGroups.get(p.getCategory()); if (group != null) { group.points.remove(p); + context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE)); } cachedFavoritePoints.remove(p); } @@ -169,6 +177,7 @@ public class FavouritesDbHelper { sortAll(); saveCurrentPointsIntoFile(); } + context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE)); return true; } @@ -201,7 +210,7 @@ public class FavouritesDbHelper { } } } - if ((index.length() > 0 || emoticons) ) { + if ((index.length() > 0 || emoticons)) { AlertDialog.Builder builder = new AlertDialog.Builder(uiContext); builder.setTitle(R.string.fav_point_dublicate); if (emoticons) { @@ -215,7 +224,7 @@ public class FavouritesDbHelper { return null; } - public static String checkEmoticons(String name){ + public static String checkEmoticons(String name) { char[] chars = name.toCharArray(); int index; char ch1; @@ -225,16 +234,15 @@ public class FavouritesDbHelper { StringBuilder builder = new StringBuilder(); while (index < chars.length) { ch1 = chars[index]; - if ((int)ch1 == 0xD83C) { - ch2 = chars[index+1]; - if ((int)ch2 >= 0xDF00 && (int)ch2 <= 0xDFFF) { + if ((int) ch1 == 0xD83C) { + ch2 = chars[index + 1]; + if ((int) ch2 >= 0xDF00 && (int) ch2 <= 0xDFFF) { index += 2; continue; } - } - else if ((int)ch1 == 0xD83D) { - ch2 = chars[index+1]; - if ((int)ch2 >= 0xDC00 && (int)ch2 <= 0xDDFF) { + } else if ((int) ch1 == 0xD83D) { + ch2 = chars[index + 1]; + if ((int) ch2 >= 0xDC00 && (int) ch2 <= 0xDDFF) { index += 2; continue; } @@ -264,14 +272,15 @@ public class FavouritesDbHelper { } sortAll(); saveCurrentPointsIntoFile(); + context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE)); return true; } - public boolean editFavourite(FavouritePoint p, double lat, double lon) { p.setLatitude(lat); p.setLongitude(lon); saveCurrentPointsIntoFile(); + context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE)); return true; } @@ -279,7 +288,7 @@ public class FavouritesDbHelper { try { Map deletedInMemory = new LinkedHashMap(); loadGPXFile(getInternalFile(), deletedInMemory); - for(FavouritePoint fp : cachedFavoritePoints) { + for (FavouritePoint fp : cachedFavoritePoints) { deletedInMemory.remove(getKey(fp)); } saveFile(cachedFavoritePoints, getInternalFile()); @@ -312,18 +321,17 @@ public class FavouritesDbHelper { } - private String saveExternalFile(Set deleted) { Map all = new LinkedHashMap(); loadGPXFile(getExternalFile(), all); List favoritePoints = new ArrayList(cachedFavoritePoints); - if(deleted != null) { - for(String key : deleted) { + if (deleted != null) { + for (String key : deleted) { all.remove(key); } } // remove already existing in memory - for(FavouritePoint p : favoritePoints) { + for (FavouritePoint p : favoritePoints) { all.remove(getKey(p)); } // save favoritePoints from memory in order to update existing @@ -332,18 +340,16 @@ public class FavouritesDbHelper { } - private String getKey(FavouritePoint p) { return p.getName() + DELIMETER + p.getCategory(); } - - public boolean deleteGroup(FavoriteGroup group) { boolean remove = favoriteGroups.remove(group); if (remove) { flatGroups.remove(group.name); saveCurrentPointsIntoFile(); + context.getMapMarkersHelper().removeMarkersSyncGroup(group.name); return true; } return false; @@ -355,26 +361,26 @@ public class FavouritesDbHelper { public File getBackupFile() { File fld = new File(context.getAppPath(null), BACKUP_FOLDER); - if(!fld.exists()) { + if (!fld.exists()) { fld.mkdirs(); } int back = 1; String backPrefix = "" + back; File firstModified = null; long firstModifiedMin = System.currentTimeMillis(); - while(back <= BACKUP_CNT) { + while (back <= BACKUP_CNT) { backPrefix = "" + back; - if(back < 10) { - backPrefix = "0"+backPrefix; + if (back < 10) { + backPrefix = "0" + backPrefix; } - File bak = new File(fld, "favourites_bak_" + backPrefix +".gpx.bz2"); + File bak = new File(fld, "favourites_bak_" + backPrefix + ".gpx.bz2"); if (!bak.exists()) { return bak; } else if (bak.lastModified() < firstModifiedMin) { firstModified = bak; firstModifiedMin = bak.lastModified(); } - back ++; + back++; } return firstModified; } @@ -395,10 +401,10 @@ public class FavouritesDbHelper { WptPt pt = new WptPt(); pt.lat = p.getLatitude(); pt.lon = p.getLongitude(); - if(!p.isVisible()) { + if (!p.isVisible()) { pt.getExtensionsToWrite().put(HIDDEN, "true"); } - if(p.getColor() != 0) { + if (p.getColor() != 0) { pt.setColor(p.getColor()); } pt.name = p.getName(); @@ -437,8 +443,8 @@ public class FavouritesDbHelper { public List getVisibleFavouritePoints() { List fp = new ArrayList<>(); - for(FavouritePoint p : cachedFavoritePoints) { - if(p.isVisible()) { + for (FavouritePoint p : cachedFavoritePoints) { + if (p.isVisible()) { fp.add(p); } } @@ -476,7 +482,7 @@ public class FavouritesDbHelper { } } - private FavouritePoint findFavoriteByAllProperties(String category, String name, double lat, double lon){ + private FavouritePoint findFavoriteByAllProperties(String category, String name, double lat, double lon) { if (flatGroups.containsKey(category)) { FavoriteGroup fg = flatGroups.get(category); for (FavouritePoint fv : fg.points) { @@ -489,10 +495,9 @@ public class FavouritesDbHelper { } - - public void recalculateCachedFavPoints(){ + public void recalculateCachedFavPoints() { ArrayList temp = new ArrayList(); - for(FavoriteGroup f : favoriteGroups){ + for (FavoriteGroup f : favoriteGroups) { temp.addAll(f.points); } cachedFavoritePoints = temp; @@ -553,7 +558,7 @@ public class FavouritesDbHelper { private boolean loadGPXFile(File file, Map points) { - if(!file.exists()) { + if (!file.exists()) { return false; } GPXFile res = GPXUtilities.loadGPXFile(context, file); @@ -584,18 +589,19 @@ public class FavouritesDbHelper { return true; } + //todo public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) { - if(color != 0 && group.color != color) { + if (color != 0 && group.color != color) { FavoriteGroup gr = flatGroups.get(group.name); group.color = color; - for(FavouritePoint p : gr.points) { + for (FavouritePoint p : gr.points) { p.setColor(color); } } - if(group.visible != visible) { + if (group.visible != visible) { FavoriteGroup gr = flatGroups.get(group.name); group.visible = visible; - for(FavouritePoint p : gr.points) { + for (FavouritePoint p : gr.points) { p.setVisible(visible); } } @@ -604,15 +610,15 @@ public class FavouritesDbHelper { gr.name = newName; FavoriteGroup renamedGroup = flatGroups.get(gr.name); boolean existing = renamedGroup != null; - if(renamedGroup == null) { + if (renamedGroup == null) { renamedGroup = gr; flatGroups.put(gr.name, gr); } else { favoriteGroups.remove(gr); } - for(FavouritePoint p : gr.points) { + for (FavouritePoint p : gr.points) { p.setCategory(newName); - if(existing) { + if (existing) { renamedGroup.points.add(p); } } @@ -680,13 +686,13 @@ public class FavouritesDbHelper { } public void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) { - if(oldVersion == 1){ - db.execSQL("ALTER TABLE " + FAVOURITE_TABLE_NAME + " ADD " + FAVOURITE_COL_CATEGORY + " text"); - db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET category = ?", new Object[] { "" }); //$NON-NLS-1$ //$NON-NLS-2$ + if (oldVersion == 1) { + db.execSQL("ALTER TABLE " + FAVOURITE_TABLE_NAME + " ADD " + FAVOURITE_COL_CATEGORY + " text"); + db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET category = ?", new Object[]{""}); //$NON-NLS-1$ //$NON-NLS-2$ } } - private void loadAndCheckDatabasePoints(){ + private void loadAndCheckDatabasePoints() { if (favoriteGroups == null) { SQLiteConnection db = openConnection(true); if (db != null) { @@ -727,17 +733,17 @@ public class FavouritesDbHelper { if (db != null) { try { db.execSQL( - "DELETE FROM " + FAVOURITE_TABLE_NAME + " WHERE category = ? AND " + whereNameLatLon(), new Object[] { p.getCategory(), p.getName(), p.getLatitude(), p.getLongitude() }); //$NON-NLS-1$ //$NON-NLS-2$ + "DELETE FROM " + FAVOURITE_TABLE_NAME + " WHERE category = ? AND " + whereNameLatLon(), new Object[]{p.getCategory(), p.getName(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$ FavouritePoint fp = findFavoriteByAllProperties(p.getCategory(), p.getName(), p.getLatitude(), p.getLongitude()); if (fp != null) { FavoriteGroup group = flatGroups.get(p.getCategory()); - if(group != null) { + if (group != null) { group.points.remove(fp); } cachedFavoritePoints.remove(fp); } saveCurrentPointsIntoFile(); - } finally{ + } finally { db.close(); } return true; @@ -747,7 +753,7 @@ public class FavouritesDbHelper { public boolean addFavouriteDB(FavouritePoint p) { - if(p.getName().equals("") && flatGroups.containsKey(p.getCategory())){ + if (p.getName().equals("") && flatGroups.containsKey(p.getCategory())) { return true; } SQLiteConnection db = openConnection(false); @@ -755,8 +761,8 @@ public class FavouritesDbHelper { try { db.execSQL( "INSERT INTO " + FAVOURITE_TABLE_NAME + " (" + FAVOURITE_COL_NAME + ", " + FAVOURITE_COL_CATEGORY + ", " - + FAVOURITE_COL_LAT + ", " + FAVOURITE_COL_LON + ")" + " VALUES (?, ?, ?, ?)", new Object[] { p.getName(), p.getCategory(), p.getLatitude(), p.getLongitude() }); //$NON-NLS-1$ //$NON-NLS-2$ - FavoriteGroup group = getOrCreateGroup(p, 0); + + FAVOURITE_COL_LAT + ", " + FAVOURITE_COL_LON + ")" + " VALUES (?, ?, ?, ?)", new Object[]{p.getName(), p.getCategory(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$ + FavoriteGroup group = getOrCreateGroup(p, 0); if (!p.getName().equals("")) { p.setVisible(group.visible); p.setColor(group.color); @@ -773,14 +779,13 @@ public class FavouritesDbHelper { } - public boolean editFavouriteNameDB(FavouritePoint p, String newName, String category) { SQLiteConnection db = openConnection(false); if (db != null) { try { String oldCategory = p.getCategory(); db.execSQL( - "UPDATE " + FAVOURITE_TABLE_NAME + " SET " + FAVOURITE_COL_NAME + " = ?, " + FAVOURITE_COL_CATEGORY + "= ? WHERE " + whereNameLatLon(), new Object[] { newName, category, p.getName(), p.getLatitude(), p.getLongitude() }); //$NON-NLS-1$ //$NON-NLS-2$ + "UPDATE " + FAVOURITE_TABLE_NAME + " SET " + FAVOURITE_COL_NAME + " = ?, " + FAVOURITE_COL_CATEGORY + "= ? WHERE " + whereNameLatLon(), new Object[]{newName, category, p.getName(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$ p.setName(newName); p.setCategory(category); if (!oldCategory.equals(category)) { @@ -808,7 +813,7 @@ public class FavouritesDbHelper { if (db != null) { try { db.execSQL( - "UPDATE " + FAVOURITE_TABLE_NAME + " SET latitude = ?, longitude = ? WHERE " + whereNameLatLon(), new Object[] { lat, lon, p.getName(), p.getLatitude(), p.getLongitude() }); //$NON-NLS-1$ //$NON-NLS-2$ + "UPDATE " + FAVOURITE_TABLE_NAME + " SET latitude = ?, longitude = ? WHERE " + whereNameLatLon(), new Object[]{lat, lon, p.getName(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$ p.setLatitude(lat); p.setLongitude(lon); saveCurrentPointsIntoFile(); @@ -826,6 +831,4 @@ public class FavouritesDbHelper { } - - } diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 74b56dc966..037030610a 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -6,6 +6,7 @@ import android.support.annotation.Nullable; import android.text.format.DateFormat; import net.osmand.IndexConstants; +import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; @@ -22,6 +23,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; +import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; + public class MapMarkersHelper { public static final int MAP_MARKERS_COLORS_COUNT = 7; @@ -64,7 +67,7 @@ public class MapMarkersHelper { } public PointDescription getPointDescription(Context ctx) { - return new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, ctx.getString(R.string.map_marker), + return new PointDescription(POINT_TYPE_MAP_MARKER, ctx.getString(R.string.map_marker), getOnlyName()); } @@ -283,8 +286,52 @@ public class MapMarkersHelper { } } - public void syncGroup(MarkersSyncGroup group) { + public void syncAllGroups() { + List groups = markersDbHelper.getAllGroups(); + for (MarkersSyncGroup gr : groups) { + syncGroup(gr); + } + } + public void syncGroup(MarkersSyncGroup group) { + if (markersDbHelper.getGroup(group.getId()) == null) { + return; + } + List dbMarkers = markersDbHelper.getMarkersFromGroup(group); + + if (group.getType() == MarkersSyncGroup.FAVORITES_TYPE) { + List favPoints = ctx.getFavorites().getGroup(group.name).points; + for (FavouritePoint fp : favPoints) { + LatLon fpLatLon = new LatLon(fp.getLatitude(), fp.getLongitude()); + boolean exists = false; + + for (MapMarker marker : dbMarkers) { + if (marker.point.equals(fpLatLon) && marker.getName(ctx).equals(fp.getName(ctx))) { + exists = true; + dbMarkers.remove(marker); + break; + } + } + + if (!exists) { + addMarkers(Collections.singletonList(fpLatLon), + Collections.singletonList(new PointDescription(POINT_TYPE_MAP_MARKER, fp.getName())), group); + } + } + + if (!dbMarkers.isEmpty()) { + for (MapMarker marker : dbMarkers) { + if (!marker.history) { + markersDbHelper.removeMarker(marker, false); + mapMarkers.remove(marker); + checkAndFixActiveMarkersOrderIfNeeded(); + refresh(); + } + } + } + } else { + + } } public void moveMapMarkerToHistory(MapMarker marker) { @@ -329,7 +376,7 @@ public class MapMarkersHelper { public void removeMarkerFromHistory(MapMarker marker) { if (marker != null) { - markersDbHelper.removeMarkerFromHistory(marker); + markersDbHelper.removeMarker(marker, true); mapMarkersHistory.remove(marker); refresh(); } @@ -395,8 +442,10 @@ public class MapMarkersHelper { public void moveAllActiveMarkersToHistory() { cancelAddressRequests(); - markersDbHelper.moveAllActiveMarkersToHistory(); + long timestamp = System.currentTimeMillis(); + markersDbHelper.moveAllActiveMarkersToHistory(timestamp); for (MapMarker marker : mapMarkers) { + marker.visitedDate = timestamp; marker.history = true; marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE; } @@ -413,6 +462,20 @@ public class MapMarkersHelper { refresh(); } + public void addMarkersSyncGroup(MarkersSyncGroup group) { + if (group != null) { + if (markersDbHelper.getGroup(group.getId()) == null) { + markersDbHelper.addGroup(group.getId(), group.getName(), group.getType()); + } + } + } + + public void removeMarkersSyncGroup(String id) { + if (id != null) { + markersDbHelper.removeMarkersSyncGroup(id); + } + } + public void addMapMarker(LatLon point, PointDescription historyName) { addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null); } @@ -421,10 +484,6 @@ public class MapMarkersHelper { addMarkers(points, historyNames, group); } - public void addMapMarkers(List points, List historyNames) { - addMarkers(points, historyNames, null); - } - private void addMarkers(List points, List historyNames, @Nullable MarkersSyncGroup group) { if (points.size() > 0) { int colorIndex = -1; @@ -452,11 +511,12 @@ public class MapMarkersHelper { MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); if (group != null) { - if (markersDbHelper.getGroup(group.getId()) == null) { - markersDbHelper.addGroup(group.getId(), group.getName(), group.getType()); + marker.id = group.getId() + marker.getName(ctx) + marker.getLatitude() + marker.getLongitude(); + if (markersDbHelper.getMarker(marker.id) != null) { + continue; } - marker.id = group.getId() + marker.getName(ctx); marker.groupName = group.getName(); + marker.groupKey = group.getId(); } marker.history = false; marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE; diff --git a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java index ce4bc97295..722c0bf019 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java @@ -189,7 +189,9 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment { points.add(new LatLon(fp.getLatitude(), fp.getLongitude())); names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName())); } - markersHelper.addMapMarkers(points, names, new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE)); + MarkersSyncGroup syncGroup = new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE); + markersHelper.addMarkersSyncGroup(syncGroup); + markersHelper.addMapMarkers(points, names, syncGroup); dismiss(); MapActivity.launchMapActivityMoveToTop(getActivity()); } diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 1ee398d73d..e187024fd6 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -406,10 +406,10 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { List points = new LinkedList<>(); List names = new LinkedList<>(); for (Map.Entry> entry : favoritesSelected.entrySet()) { - MarkersSyncGroup syncGr = null; FavoriteGroup favGr = helper.getGroup(entry.getKey()); + MarkersSyncGroup syncGr = new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE); if (entry.getValue().size() == favGr.points.size()) { - syncGr = new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE); + markersHelper.addMarkersSyncGroup(syncGr); } for (FavouritePoint fp : entry.getValue()) { points.add(new LatLon(fp.getLatitude(), fp.getLongitude())); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index f6be7c00ec..9a6c779fdd 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -164,6 +164,25 @@ public class MapMarkersDbHelper { } } + public List getAllGroups() { + List res = new LinkedList<>(); + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT, null); + if (query.moveToFirst()) { + do { + res.add(readSyncGroup(query)); + } while (query.moveToNext()); + } + query.close(); + } finally { + db.close(); + } + } + return res; + } + @Nullable public MarkersSyncGroup getGroup(String id) { MarkersSyncGroup res = null; @@ -190,6 +209,22 @@ public class MapMarkersDbHelper { return new MarkersSyncGroup(id, name, type); } + public void removeMarkersSyncGroup(String id) { + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + + " WHERE " + MARKERS_COL_GROUP_KEY + " = ?" + + " AND " + MARKERS_COL_ACTIVE + " = ?", + new Object[]{id, 1}); + + db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_ID + " = ?", new Object[]{id}); + } finally { + db.close(); + } + } + } + public void addMarker(MapMarker marker) { addMarker(marker, false); } @@ -239,6 +274,44 @@ public class MapMarkersDbHelper { marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE}); } + public List getMarkersFromGroup(MarkersSyncGroup group) { + List res = new LinkedList<>(); + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_GROUP_KEY + " = ?", + new String[]{group.getId()}); + if (query.moveToFirst()) { + do { + res.add(readItem(query)); + } while (query.moveToNext()); + } + query.close(); + } finally { + db.close(); + } + } + return res; + } + + @Nullable + public MapMarker getMarker(String id) { + MapMarker res = null; + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ID + " = ?", new String[]{id}); + if (query.moveToFirst()) { + res = readItem(query); + } + query.close(); + } finally { + db.close(); + } + } + return res; + } + public List getActiveMarkers() { List res = new LinkedList<>(); HashMap markers = new LinkedHashMap<>(); @@ -351,16 +424,15 @@ public class MapMarkersDbHelper { } } - public void moveAllActiveMarkersToHistory() { + public void moveAllActiveMarkersToHistory(long timestamp) { SQLiteConnection db = openConnection(false); if (db != null) { try { - long visitedDate = System.currentTimeMillis(); db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ?, " + MARKERS_COL_VISITED + " = ?, " + MARKERS_COL_NEXT_KEY + " = ? " + - "WHERE " + MARKERS_COL_ACTIVE + " = ?", new Object[]{0, visitedDate, HISTORY_NEXT_VALUE, 1}); + "WHERE " + MARKERS_COL_ACTIVE + " = ?", new Object[]{0, timestamp, HISTORY_NEXT_VALUE, 1}); } finally { db.close(); } @@ -402,14 +474,14 @@ public class MapMarkersDbHelper { return markers; } - public void removeMarkerFromHistory(MapMarker marker) { + public void removeMarker(MapMarker marker, boolean history) { SQLiteConnection db = openConnection(true); if (db != null) { try { db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ID + " = ?" + " AND " + MARKERS_COL_ACTIVE + " = ?", - new Object[]{marker.id, 0}); + new Object[]{marker.id, history ? 0 : 1}); } finally { db.close(); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 07315990ce..9e135db20b 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -610,6 +610,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } File gpx = getGpxDataItem().getFile(); MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE); + markersHelper.addMarkersSyncGroup(syncGroup); markersHelper.addMapMarkers(points, names, syncGroup); MapActivity.launchMapActivityMoveToTop(getActivity()); } else { From 11eb486144dd3f61eb877755ea3969f84eb8f614 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Thu, 14 Sep 2017 09:58:35 +0300 Subject: [PATCH 101/128] Add groups tab --- .../menu/map_markers_bottom_navigation.xml | 5 ++ OsmAnd/res/values/strings.xml | 1 + .../mapmarkers/MapMarkersDialogFragment.java | 22 ++++++-- .../mapmarkers/MapMarkersGroupsFragment.java | 37 ++++++++++++++ .../adapters/MapMarkersGroupsAdapter.java | 51 +++++++++++++++++++ 5 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java diff --git a/OsmAnd/res/menu/map_markers_bottom_navigation.xml b/OsmAnd/res/menu/map_markers_bottom_navigation.xml index 5751b155b0..23cd570d73 100644 --- a/OsmAnd/res/menu/map_markers_bottom_navigation.xml +++ b/OsmAnd/res/menu/map_markers_bottom_navigation.xml @@ -5,6 +5,11 @@ android:icon="@drawable/ic_map" android:title="@string/osm_live_active"/> + + + Groups Passed: %1$s Make active Today diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 06028476be..ccc2005fa0 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -31,6 +31,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm public static final String TAG = "MapMarkersDialogFragment"; private MapMarkersActiveFragment activeFragment; + private MapMarkersGroupsFragment groupsFragment; private MapMarkersHistoryFragment historyFragment; @Override @@ -50,6 +51,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm for (Fragment fragment : fragments) { if (fragment instanceof MapMarkersActiveFragment) { activeFragment = (MapMarkersActiveFragment) fragment; + } else if (fragment instanceof MapMarkersGroupsFragment) { + groupsFragment = (MapMarkersGroupsFragment) fragment; } else if (fragment instanceof MapMarkersHistoryFragment) { historyFragment = (MapMarkersHistoryFragment) fragment; } @@ -58,6 +61,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm if (activeFragment == null) { activeFragment = new MapMarkersActiveFragment(); } + if (groupsFragment == null) { + groupsFragment = new MapMarkersGroupsFragment(); + } if (historyFragment == null) { historyFragment = new MapMarkersHistoryFragment(); } @@ -111,13 +117,23 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm viewPager.setCurrentItem(0); optionsButton.setVisibility(View.VISIBLE); return true; - case R.id.action_history: + case R.id.action_groups: activeFragment.stopLocationUpdate(); if (viewPager.getCurrentItem() != 1) { + groupsFragment.updateAdapter(); + activeFragment.hideSnackbar(); + historyFragment.hideSnackbar(); + } + viewPager.setCurrentItem(1); + optionsButton.setVisibility(View.GONE); + return true; + case R.id.action_history: + activeFragment.stopLocationUpdate(); + if (viewPager.getCurrentItem() != 2) { historyFragment.updateAdapter(); activeFragment.hideSnackbar(); } - viewPager.setCurrentItem(1); + viewPager.setCurrentItem(2); optionsButton.setVisibility(View.GONE); return true; } @@ -203,7 +219,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm MapMarkersViewPagerAdapter(FragmentManager fm) { super(fm); - fragments = Arrays.asList(activeFragment, historyFragment); + fragments = Arrays.asList(activeFragment, groupsFragment, historyFragment); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java new file mode 100644 index 0000000000..328575d030 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java @@ -0,0 +1,37 @@ +package net.osmand.plus.mapmarkers; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapmarkers.adapters.MapMarkersGroupsAdapter; + +public class MapMarkersGroupsFragment extends Fragment { + + public static final String TAG = "MapMarkersGroupsFragment"; + + private MapMarkersGroupsAdapter adapter; + + @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); + return recyclerView; + } + + void updateAdapter() { + if (adapter != null) { + adapter.notifyDataSetChanged(); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java new file mode 100644 index 0000000000..1aebc80531 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -0,0 +1,51 @@ +package net.osmand.plus.mapmarkers.adapters; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.osmand.plus.IconsCache; +import net.osmand.plus.MapMarkersHelper; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; + +import java.util.List; + +public class MapMarkersGroupsAdapter extends RecyclerView.Adapter { + + private MapActivity mapActivity; + private List markers; + private boolean night; + + public MapMarkersGroupsAdapter(MapActivity mapActivity) { + this.mapActivity = mapActivity; + markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers(); + night = !mapActivity.getMyApplication().getSettings().isLightContent(); + } + + @Override + public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false); + return new MapMarkerItemViewHolder(view); + } + + @Override + public void onBindViewHolder(MapMarkerItemViewHolder mapMarkerItemViewHolder, int i) { + IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); + MapMarkersHelper.MapMarker marker = markers.get(i); + } + + @Override + public int getItemCount() { + return markers.size(); + } + + public MapMarkersHelper.MapMarker getItem(int position) { + return markers.get(position); + } + + public List getItems() { + return markers; + } +} From 6f7e2cb380b6c77c668555b25c5e83b3804311e6 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Thu, 14 Sep 2017 10:00:51 +0300 Subject: [PATCH 102/128] Rename active --- OsmAnd/res/menu/map_markers_bottom_navigation.xml | 2 +- OsmAnd/res/values/strings.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/menu/map_markers_bottom_navigation.xml b/OsmAnd/res/menu/map_markers_bottom_navigation.xml index 23cd570d73..dc64fd4edd 100644 --- a/OsmAnd/res/menu/map_markers_bottom_navigation.xml +++ b/OsmAnd/res/menu/map_markers_bottom_navigation.xml @@ -3,7 +3,7 @@ + android:title="@string/shared_string_list"/> + List Groups Passed: %1$s Make active From ff46f495092a6383eef5b464524979688cde2b55 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Thu, 14 Sep 2017 10:44:36 +0300 Subject: [PATCH 103/128] Fix history fragment --- .../net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 32c98aadda..761dcb24f9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -232,8 +232,8 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel } void updateAdapter() { - adapter.createHeaders(); if (adapter != null) { + adapter.createHeaders(); adapter.notifyDataSetChanged(); } } From 8b6255142ed0effc1d3c758c5a01ea79847fb484 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Thu, 14 Sep 2017 11:21:15 +0300 Subject: [PATCH 104/128] Change groups icon --- OsmAnd/res/menu/map_markers_bottom_navigation.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/res/menu/map_markers_bottom_navigation.xml b/OsmAnd/res/menu/map_markers_bottom_navigation.xml index dc64fd4edd..4764258e39 100644 --- a/OsmAnd/res/menu/map_markers_bottom_navigation.xml +++ b/OsmAnd/res/menu/map_markers_bottom_navigation.xml @@ -7,7 +7,7 @@ Date: Thu, 14 Sep 2017 11:51:52 +0300 Subject: [PATCH 105/128] Fix small issues --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 14 +++++++++++--- .../osmand/plus/mapmarkers/MapMarkersDbHelper.java | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 037030610a..6ce78edacd 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -306,8 +306,17 @@ public class MapMarkersHelper { boolean exists = false; for (MapMarker marker : dbMarkers) { - if (marker.point.equals(fpLatLon) && marker.getName(ctx).equals(fp.getName(ctx))) { + if (marker.id.equals(group.getId() + fp.getName(ctx))) { exists = true; + if (!marker.history && !marker.point.equals(fpLatLon)) { + for (MapMarker m : mapMarkers) { + if (m.id.equals(marker.id)) { + m.point = fpLatLon; + updateMapMarker(m, true); + break; + } + } + } dbMarkers.remove(marker); break; } @@ -511,7 +520,7 @@ public class MapMarkersHelper { MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); if (group != null) { - marker.id = group.getId() + marker.getName(ctx) + marker.getLatitude() + marker.getLongitude(); + marker.id = group.getId() + marker.getName(ctx); if (markersDbHelper.getMarker(marker.id) != null) { continue; } @@ -531,7 +540,6 @@ public class MapMarkersHelper { if (marker != null) { markersDbHelper.updateMarker(marker); if (refresh) { - loadMarkers(); refresh(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 9a6c779fdd..a6804667bb 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -21,7 +21,7 @@ import java.util.Random; public class MapMarkersDbHelper { - private static final int DB_VERSION = 6; + private static final int DB_VERSION = 1; public static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; From e3a9622ad1096107f9819f3b2959d0d3ce55420c Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Thu, 14 Sep 2017 12:02:38 +0300 Subject: [PATCH 106/128] Add shadow to active markers --- .../plus/mapmarkers/adapters/MapMarkersActiveAdapter.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index b77f9de136..0664134d02 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -113,6 +113,11 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Thu, 14 Sep 2017 13:30:32 +0300 Subject: [PATCH 107/128] Fix action bar --- OsmAnd/res/layout/fragment_map_markers_dialog.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml index 47150f34f8..2d3f7b246f 100644 --- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -4,6 +4,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:osmand="http://schemas.android.com/tools" android:orientation="vertical"> - + osmand:typeface="@string/font_roboto_medium" + android:textSize="@dimen/dialog_header_text_size"/> Date: Thu, 14 Sep 2017 13:38:21 +0300 Subject: [PATCH 108/128] Fix reorder button style --- OsmAnd/res/layout/map_marker_item_new.xml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 3a0be98732..e1e632651f 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -21,13 +21,10 @@ @@ -36,8 +33,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:layout_marginLeft="16dp" android:layout_marginRight="16dp" + android:layout_marginEnd="16dp" tools:src="@drawable/ic_action_flag_dark"/> Date: Thu, 14 Sep 2017 13:40:24 +0300 Subject: [PATCH 109/128] Revert reorder button --- OsmAnd/res/layout/map_marker_item_new.xml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index e1e632651f..3a0be98732 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -21,10 +21,13 @@ @@ -33,8 +36,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:layout_marginLeft="16dp" android:layout_marginRight="16dp" - android:layout_marginEnd="16dp" tools:src="@drawable/ic_action_flag_dark"/> Date: Thu, 14 Sep 2017 13:44:11 +0300 Subject: [PATCH 110/128] Fix reorder button style --- OsmAnd/res/layout/map_marker_item_new.xml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 3a0be98732..f2f0929c85 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -21,13 +21,10 @@ From 82b0a08ff4ecddd88629e22792b5805b0d249e4e Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 14 Sep 2017 14:05:34 +0300 Subject: [PATCH 111/128] Fix space before second row --- OsmAnd/res/layout/map_marker_item_new.xml | 14 ++++++++++---- .../adapters/MapMarkerItemViewHolder.java | 9 +++++++++ .../adapters/MapMarkersHistoryAdapter.java | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index f2f0929c85..a4013fc42b 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -80,12 +80,15 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:layout_marginRight="4dp" - android:layout_marginEnd="4dp" android:maxLines="1" android:textSize="@dimen/default_desc_text_size" tools:text="213 m"/> + + + + Date: Thu, 14 Sep 2017 14:13:58 +0300 Subject: [PATCH 112/128] Fix divider --- .../plus/mapmarkers/adapters/MapMarkerItemViewHolder.java | 4 ++++ .../plus/mapmarkers/adapters/MapMarkersActiveAdapter.java | 2 ++ .../plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java | 2 ++ 3 files changed, 8 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java index a7f2493a80..385c8c1944 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java @@ -57,4 +57,8 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { leftPointSpace.setVisibility(visibility); rightPointSpace.setVisibility(visibility); } + + public void setDividerVisibility(int visibility) { + divider.setVisibility(visibility); + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 0664134d02..996bc4de8e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -115,8 +115,10 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Thu, 14 Sep 2017 14:33:12 +0300 Subject: [PATCH 113/128] Fix shadow --- OsmAnd/res/layout/map_marker_item_new.xml | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index a4013fc42b..824de91705 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -139,19 +139,9 @@ - - - - - - - + From 29a4b67e431c4df2d234a1050e29b5b632e1ae41 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 14 Sep 2017 14:33:27 +0300 Subject: [PATCH 114/128] Add sync after changing favorite group name --- .../net/osmand/plus/FavouritesDbHelper.java | 9 +++++++-- .../src/net/osmand/plus/MapMarkersHelper.java | 18 +++++++++++++++++- .../plus/mapmarkers/MapMarkersDbHelper.java | 17 +++++++++++++---- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 4213b31847..60d9370b72 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -132,7 +132,7 @@ public class FavouritesDbHelper { flatGroups.remove(g.name); favoriteGroups.remove(g); cachedFavoritePoints.removeAll(g.points); - context.getMapMarkersHelper().removeMarkersSyncGroup(g.name); + context.getMapMarkersHelper().removeMarkersSyncGroup(g.name, true); } } saveCurrentPointsIntoFile(); @@ -349,7 +349,7 @@ public class FavouritesDbHelper { if (remove) { flatGroups.remove(group.name); saveCurrentPointsIntoFile(); - context.getMapMarkersHelper().removeMarkersSyncGroup(group.name); + context.getMapMarkersHelper().removeMarkersSyncGroup(group.name, true); return true; } return false; @@ -591,6 +591,7 @@ public class FavouritesDbHelper { //todo public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) { + MapMarkersHelper markersHelper = context.getMapMarkersHelper(); if (color != 0 && group.color != color) { FavoriteGroup gr = flatGroups.get(group.name); group.color = color; @@ -607,6 +608,7 @@ public class FavouritesDbHelper { } if (!group.name.equals(newName)) { FavoriteGroup gr = flatGroups.remove(group.name); + markersHelper.removeMarkersSyncGroup(group.name, true); gr.name = newName; FavoriteGroup renamedGroup = flatGroups.get(gr.name); boolean existing = renamedGroup != null; @@ -622,6 +624,9 @@ public class FavouritesDbHelper { renamedGroup.points.add(p); } } + MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE); + markersHelper.addMarkersSyncGroup(syncGroup); + markersHelper.syncGroup(syncGroup); } saveCurrentPointsIntoFile(); } diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 6ce78edacd..e686cebb4b 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -479,9 +480,24 @@ public class MapMarkersHelper { } } - public void removeMarkersSyncGroup(String id) { + public void removeMarkersSyncGroup(String id, boolean removeActiveMarkers) { if (id != null) { markersDbHelper.removeMarkersSyncGroup(id); + if (removeActiveMarkers) { + removeActiveMarkersFromSyncGroup(id); + } + } + } + + public void removeActiveMarkersFromSyncGroup(String syncGroupId) { + if (syncGroupId != null) { + markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId); + for (Iterator iterator = mapMarkers.iterator(); iterator.hasNext(); ) { + if (iterator.next().groupKey.equals(syncGroupId)) { + iterator.remove(); + } + } + checkAndFixActiveMarkersOrderIfNeeded(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index a6804667bb..939e1732c3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -21,7 +21,7 @@ import java.util.Random; public class MapMarkersDbHelper { - private static final int DB_VERSION = 1; + private static final int DB_VERSION = 2; public static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; @@ -210,15 +210,24 @@ public class MapMarkersDbHelper { } public void removeMarkersSyncGroup(String id) { + SQLiteConnection db = openConnection(true); + if (db != null) { + try { + db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_ID + " = ?", new Object[]{id}); + } finally { + db.close(); + } + } + } + + public void removeActiveMarkersFromSyncGroup(String syncGroupId) { SQLiteConnection db = openConnection(true); if (db != null) { try { db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_GROUP_KEY + " = ?" + " AND " + MARKERS_COL_ACTIVE + " = ?", - new Object[]{id, 1}); - - db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_ID + " = ?", new Object[]{id}); + new Object[]{syncGroupId, 1}); } finally { db.close(); } From a1ccfd34daeb6a11570b9e3f8866ca8665aafee6 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 14 Sep 2017 14:50:28 +0300 Subject: [PATCH 115/128] Change snackbar strings --- OsmAnd/res/values/strings.xml | 2 ++ .../osmand/plus/mapmarkers/MapMarkersHistoryFragment.java | 5 ++++- .../plus/mapmarkers/adapters/MapMarkersActiveAdapter.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index c2441b85ee..dc3b7be809 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 --> + Marker moved to History + Marker moved to Active List Groups Passed: %1$s diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 761dcb24f9..3fd44c7534 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -146,13 +146,16 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel Object item = adapter.getItem(pos); if (item instanceof MapMarker) { final MapMarker marker = (MapMarker) item; + int snackbarStringRes; if (direction == ItemTouchHelper.LEFT) { app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0); + snackbarStringRes = R.string.marker_moved_to_active; } else { app.getMapMarkersHelper().removeMarkerFromHistory((MapMarker) item); + snackbarStringRes = R.string.item_removed; } adapter.notifyItemRemoved(pos); - snackbar = Snackbar.make(viewHolder.itemView, R.string.item_removed, Snackbar.LENGTH_LONG) + snackbar = Snackbar.make(viewHolder.itemView, snackbarStringRes, Snackbar.LENGTH_LONG) .setAction(R.string.shared_string_undo, new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 996bc4de8e..8446d3e132 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -158,7 +158,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Thu, 14 Sep 2017 15:12:53 +0300 Subject: [PATCH 116/128] Hide markers with favorites --- OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java | 1 + OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 60d9370b72..7f03710b68 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -605,6 +605,7 @@ public class FavouritesDbHelper { for (FavouritePoint p : gr.points) { p.setVisible(visible); } + markersHelper.syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE)); } if (!group.name.equals(newName)) { FavoriteGroup gr = flatGroups.remove(group.name); diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index e686cebb4b..19a8477bec 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -301,7 +301,12 @@ public class MapMarkersHelper { List dbMarkers = markersDbHelper.getMarkersFromGroup(group); if (group.getType() == MarkersSyncGroup.FAVORITES_TYPE) { - List favPoints = ctx.getFavorites().getGroup(group.name).points; + FavouritesDbHelper.FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.name); + if (!favGroup.visible) { + removeActiveMarkersFromSyncGroup(group.id); + return; + } + List favPoints = favGroup.points; for (FavouritePoint fp : favPoints) { LatLon fpLatLon = new LatLon(fp.getLatitude(), fp.getLongitude()); boolean exists = false; @@ -498,6 +503,7 @@ public class MapMarkersHelper { } } checkAndFixActiveMarkersOrderIfNeeded(); + refresh(); } } From 299d9f4e75252c10c4224acfc7f58f504917d985 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 14 Sep 2017 17:02:39 +0300 Subject: [PATCH 117/128] Remove unnecessary comment --- OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 7f03710b68..6ab73a355f 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -589,7 +589,6 @@ public class FavouritesDbHelper { return true; } - //todo public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) { MapMarkersHelper markersHelper = context.getMapMarkersHelper(); if (color != 0 && group.color != color) { From c05b64ec419248f0f07334e8e787ccb17f9e87ee Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 14 Sep 2017 17:36:11 +0300 Subject: [PATCH 118/128] Add small fix --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 3f734e0e5a..96674888da 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -819,6 +819,7 @@ public class OsmandAidlApi { PointDescription pd = new PointDescription( PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : ""); MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index); + marker.id = m.id; marker.creationDate = m.creationDate; marker.visitedDate = m.visitedDate; markersHelper.moveMapMarker(marker, latLonNew); From 1328261c508e92b2bc872c556c574714a9cba49a Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 14 Sep 2017 17:36:44 +0300 Subject: [PATCH 119/128] Fix shadow when doing undo --- .../plus/mapmarkers/adapters/MapMarkersActiveAdapter.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 8446d3e132..769c5c45d3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -156,6 +156,8 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter 1) { notifyItemChanged(1); + } else if (position == getItemCount()) { + notifyItemChanged(position - 1); } snackbar = Snackbar.make(holder.itemView, mapActivity.getString(R.string.marker_moved_to_history), Snackbar.LENGTH_LONG) @@ -166,6 +168,8 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter 2) { notifyItemChanged(2); + } else if (position == getItemCount() - 1) { + notifyItemChanged(position - 1); } } }); From c25febe9ebb11a4a2b2e31107ca2024ff05d4426 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 14 Sep 2017 17:51:54 +0300 Subject: [PATCH 120/128] Change snack bar action color --- .../net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java | 4 ++++ .../plus/mapmarkers/adapters/MapMarkersActiveAdapter.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 3fd44c7534..eb0e41d54b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -18,6 +18,7 @@ import android.support.v7.widget.helper.ItemTouchHelper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; @@ -166,6 +167,9 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel } } }); + View snackBarView = snackbar.getView(); + TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action); + tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark)); snackbar.show(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 769c5c45d3..b98f2d345e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -9,6 +9,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.TextView; import net.osmand.data.LatLon; import net.osmand.plus.IconsCache; @@ -173,6 +174,9 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Thu, 14 Sep 2017 18:32:20 +0300 Subject: [PATCH 121/128] Add snackbar for move all to history --- OsmAnd/res/values/strings.xml | 1 + .../src/net/osmand/plus/MapMarkersHelper.java | 14 +++++++++ .../mapmarkers/MapMarkersDialogFragment.java | 29 +++++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index dc3b7be809..3cebacd24b 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 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 --> + All markers moved to History Marker moved to History Marker moved to Active List diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 19a8477bec..82720e9ef2 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -389,6 +389,20 @@ public class MapMarkersHelper { } } + public void restoreMarkersFromHistory(List markers) { + if (markers != null) { + for (MapMarker marker : markers) { + markersDbHelper.restoreMapMarkerFromHistory(marker); + mapMarkersHistory.remove(marker); + marker.history = false; + mapMarkers.add(marker); + } + checkAndFixActiveMarkersOrderIfNeeded(); + sortMarkers(mapMarkersHistory, true); + refresh(); + } + } + public void removeMarkerFromHistory(MapMarker marker) { if (marker != null) { markersDbHelper.removeMarker(marker, true); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index ccc2005fa0..14852d01ba 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -4,17 +4,23 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.BottomNavigationView; +import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.content.ContextCompat; +import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; +import android.support.v7.widget.helper.ItemTouchHelper; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import android.widget.Toast; import net.osmand.plus.LockableViewPager; +import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -23,8 +29,10 @@ import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener; import net.osmand.plus.mapmarkers.MarkerOptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragment { @@ -34,6 +42,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm private MapMarkersGroupsFragment groupsFragment; private MapMarkersHistoryFragment historyFragment; + private Snackbar snackbar; + private LockableViewPager viewPager; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -98,7 +109,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm } }); - final LockableViewPager viewPager = mainView.findViewById(R.id.map_markers_view_pager); + viewPager = mainView.findViewById(R.id.map_markers_view_pager); viewPager.setSwipeLocked(true); final MapMarkersViewPagerAdapter adapter = new MapMarkersViewPagerAdapter(getChildFragmentManager()); viewPager.setAdapter(adapter); @@ -178,8 +189,22 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void moveAllToHistoryOnClick() { - mapActivity.getMyApplication().getMapMarkersHelper().moveAllActiveMarkersToHistory(); + final MapMarkersHelper helper = mapActivity.getMyApplication().getMapMarkersHelper(); + final List markers = new ArrayList<>(helper.getMapMarkers()); + helper.moveAllActiveMarkersToHistory(); activeFragment.updateAdapter(); + snackbar = Snackbar.make(viewPager, R.string.all_markers_moved_to_history, Snackbar.LENGTH_LONG) + .setAction(R.string.shared_string_undo, new View.OnClickListener() { + @Override + public void onClick(View view) { + helper.restoreMarkersFromHistory(markers); + activeFragment.updateAdapter(); + } + }); + View snackBarView = snackbar.getView(); + TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action); + tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark)); + snackbar.show(); } }; } From 618f6f59e6bbf69ecd9415fb7305407192cb7c2b Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 14 Sep 2017 18:37:10 +0300 Subject: [PATCH 122/128] Fix reorder color --- .../plus/mapmarkers/adapters/MapMarkersActiveAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index b98f2d345e..6128ee4c83 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -94,7 +94,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Thu, 14 Sep 2017 19:00:02 +0300 Subject: [PATCH 123/128] Disable highlight items when show direction disabled --- .../plus/mapmarkers/MapMarkersActiveFragment.java | 6 ++++++ .../plus/mapmarkers/MapMarkersDialogFragment.java | 4 +++- .../ShowDirectionBottomSheetDialogFragment.java | 8 ++++++-- .../adapters/MapMarkersActiveAdapter.java | 13 ++++++++++--- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 199c76a01b..ca0af55967 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -123,6 +123,12 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL return null; } + void setShowDirectionEnabled(boolean showDirectionEnabled) { + if (adapter != null) { + adapter.setShowDirectionEnabled(showDirectionEnabled); + } + } + void updateAdapter() { if (adapter != null) { adapter.notifyDataSetChanged(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 14852d01ba..dc4c5c25f7 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -215,8 +215,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm final MapActivity mapActivity = getMapActivity(); @Override - public void onMapMarkersModeChanged() { + public void onMapMarkersModeChanged(boolean showDirectionEnabled) { mapActivity.getMapLayers().getMapWidgetRegistry().updateMapMarkersMode(mapActivity); + activeFragment.setShowDirectionEnabled(showDirectionEnabled); + activeFragment.updateAdapter(); } }; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index 4c2d249e3c..43148b2a13 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -206,30 +206,34 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra public void onClick(View view) { OsmandSettings.MapMarkersMode previousMode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); highlightSelectedItem(previousMode, false); + boolean showDirectionEnabled = false; switch (view.getId()) { case R.id.top_bar_image: case R.id.top_bar_row: getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.TOOLBAR); highlightSelectedItem(OsmandSettings.MapMarkersMode.TOOLBAR, true); + showDirectionEnabled = true; break; case R.id.widget_image: case R.id.widget_row: getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.WIDGETS); highlightSelectedItem(OsmandSettings.MapMarkersMode.WIDGETS, true); + showDirectionEnabled = true; break; case R.id.none_row: getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.NONE); highlightSelectedItem(OsmandSettings.MapMarkersMode.NONE, true); + showDirectionEnabled = false; break; } if (listener != null) { - listener.onMapMarkersModeChanged(); + listener.onMapMarkersModeChanged(showDirectionEnabled); } dismiss(); } }; interface ShowDirectionFragmentListener { - void onMapMarkersModeChanged(); + void onMapMarkersModeChanged(boolean showDirectionEnabled); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 6128ee4c83..b16a7470a9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -14,6 +14,7 @@ import android.widget.TextView; import net.osmand.data.LatLon; import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashLocationFragment; @@ -31,6 +32,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter markers; private MapMarkersActiveAdapterListener listener; private Snackbar snackbar; + private boolean showDirectionEnabled; private LatLon location; private Float heading; @@ -42,6 +44,11 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter 1) { + if (showDirectionEnabled && position < 2 && getItemCount() > 1) { notifyItemChanged(1); } else if (position == getItemCount()) { notifyItemChanged(position - 1); @@ -167,7 +174,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter 2) { + if (showDirectionEnabled && position < 2 && getItemCount() > 2) { notifyItemChanged(2); } else if (position == getItemCount() - 1) { notifyItemChanged(position - 1); From bc32376ad119f2f5af7bd8caf685f6ed2f80eb1f Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 15 Sep 2017 10:08:45 +0300 Subject: [PATCH 124/128] Make arrow icon smaller --- OsmAnd/res/layout/map_marker_item_new.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 824de91705..5ccdc4ea92 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -30,8 +30,8 @@ Date: Fri, 15 Sep 2017 10:17:25 +0300 Subject: [PATCH 125/128] Fix space between icons --- OsmAnd/res/layout/map_marker_item_new.xml | 9 ++++++++- .../mapmarkers/adapters/MapMarkerItemViewHolder.java | 2 ++ .../mapmarkers/adapters/MapMarkersHistoryAdapter.java | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 5ccdc4ea92..0f4ddb6a42 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -28,13 +28,20 @@ android:tint="?attr/secondary_icon_color" tools:src="@drawable/ic_action_reorder"/> + + Date: Fri, 15 Sep 2017 10:27:44 +0300 Subject: [PATCH 126/128] Remove visibility methods from view holder --- .../mapmarkers/MapMarkersHistoryFragment.java | 4 ++-- .../adapters/MapMarkerItemViewHolder.java | 23 +------------------ .../adapters/MapMarkersActiveAdapter.java | 12 +++++----- .../adapters/MapMarkersHistoryAdapter.java | 13 ++++++----- 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index eb0e41d54b..e40938ebd5 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -99,7 +99,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) { if (!iconHidden && isCurrentlyActive) { - ((MapMarkerItemViewHolder) viewHolder).setOptionsButtonVisibility(View.GONE); + ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE); iconHidden = true; } View itemView = viewHolder.itemView; @@ -135,7 +135,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel @Override public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { if (viewHolder instanceof MapMarkerItemViewHolder) { - ((MapMarkerItemViewHolder) viewHolder).setOptionsButtonVisibility(View.VISIBLE); + ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE); iconHidden = false; } super.clearView(recyclerView, viewHolder); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java index 788b6174c8..8b41e6d81c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java @@ -21,7 +21,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { final TextView point; final View rightPointSpace; final TextView description; - final ImageButton optionsBtn; + public final ImageButton optionsBtn; final View divider; final View bottomShadow; @@ -42,25 +42,4 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { divider = view.findViewById(R.id.divider); bottomShadow = view.findViewById(R.id.bottom_shadow); } - - public void setOptionsButtonVisibility(int visibility) { - optionsBtn.setVisibility(visibility); - } - - public void setIconDirectionVisibility(int visibility) { - iconDirection.setVisibility(visibility); - } - - public void setBottomShadowVisibility(int visibility) { - bottomShadow.setVisibility(visibility); - } - - public void setPointSpaceVisibility(int visibility) { - leftPointSpace.setVisibility(visibility); - rightPointSpace.setVisibility(visibility); - } - - public void setDividerVisibility(int visibility) { - divider.setVisibility(visibility); - } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index b16a7470a9..d531c4d1f7 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -93,7 +93,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Fri, 15 Sep 2017 10:33:16 +0300 Subject: [PATCH 127/128] Change list icon --- OsmAnd/res/menu/map_markers_bottom_navigation.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/res/menu/map_markers_bottom_navigation.xml b/OsmAnd/res/menu/map_markers_bottom_navigation.xml index 4764258e39..694432c5ef 100644 --- a/OsmAnd/res/menu/map_markers_bottom_navigation.xml +++ b/OsmAnd/res/menu/map_markers_bottom_navigation.xml @@ -2,7 +2,7 @@ Date: Fri, 15 Sep 2017 10:53:16 +0300 Subject: [PATCH 128/128] Add null check; clear onUpgrade --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 3 +++ OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 82720e9ef2..501f009d7e 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -302,6 +302,9 @@ public class MapMarkersHelper { if (group.getType() == MarkersSyncGroup.FAVORITES_TYPE) { FavouritesDbHelper.FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.name); + if (favGroup == null) { + return; + } if (!favGroup.visible) { removeActiveMarkersFromSyncGroup(group.id); return; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 939e1732c3..ba49cfd77d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -117,9 +117,7 @@ public class MapMarkersDbHelper { } private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) { - db.execSQL("DROP TABLE IF EXISTS " + MARKERS_TABLE_NAME); - db.execSQL("DROP TABLE IF EXISTS " + GROUPS_TABLE_NAME); - onCreate(db); + } private void saveExistingMarkersToDb() {