diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ItineraryDataHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ItineraryDataHelper.java index 408d0cda97..43dd8bf6b9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ItineraryDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ItineraryDataHelper.java @@ -30,11 +30,13 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Set; import java.util.TimeZone; import static net.osmand.GPXUtilities.writeNotNullText; import static net.osmand.plus.FavouritesDbHelper.backup; +import static net.osmand.util.MapUtils.createShortLinkString; public class ItineraryDataHelper { @@ -48,8 +50,8 @@ public class ItineraryDataHelper { private static final String FILE_TO_BACKUP = "itinerary_bak.gpx"; private static final String ITINERARY_ID = "itinerary_id"; private static final String ITINERARY_GROUP = "itinerary_group"; - private static final String GPX_ORIGIN = "gpx_origin"; - private static final String FAVOURITES_ORIGIN = "favourites_origin"; + private static final String GPX_KEY = "gpx"; + private static final String FAVOURITES_KEY = "favourites_group"; private static final SimpleDateFormat GPX_TIME_FORMAT = new SimpleDateFormat(GPXUtilities.GPX_TIME_FORMAT, Locale.US); @@ -105,6 +107,7 @@ public class ItineraryDataHelper { writeNotNullText(serializer, "osmand:name", group.name); writeNotNullText(serializer, "osmand:type", group.type); writeNotNullText(serializer, "osmand:path", group.path); + writeNotNullText(serializer, "osmand:alias", group.alias); writeNotNullText(serializer, "osmand:categories", group.categories); serializer.endTag(null, "osmand:" + ITINERARY_GROUP); @@ -162,18 +165,17 @@ public class ItineraryDataHelper { for (MapMarker marker : group.getMarkers()) { WptPt wptPt = toWpt(marker); - String markerId = marker.id; - String name = marker.getName(app); - int index = markerId.indexOf(name); - if (index != -1) { - markerId = markerId.substring(index + name.length()); - } - wptPt.getExtensionsToWrite().put(ITINERARY_ID, groupInfo.type + ":" + markerId); - - if (group.getType() == ItineraryType.TRACK) { - wptPt.getExtensionsToWrite().put(GPX_ORIGIN, groupInfo.path); + Map extensions = wptPt.getExtensionsToWrite(); + if (group.getType() != ItineraryType.FAVOURITES) { + String itineraryId = createShortLinkString(wptPt.lat, wptPt.lon, 15); + extensions.put(ITINERARY_ID, groupInfo.alias + ":" + itineraryId); } else { - wptPt.getExtensionsToWrite().put(FAVOURITES_ORIGIN, groupInfo.name); + extensions.put(ITINERARY_ID, groupInfo.alias + ":" + marker.getName(app)); + } + if (group.getType() == ItineraryType.TRACK) { + extensions.put(GPX_KEY, groupInfo.path); + } else if (group.getType() == ItineraryType.FAVOURITES && !Algorithms.isEmpty(groupInfo.name)) { + extensions.put(FAVOURITES_KEY, groupInfo.name); } gpxFile.addPoint(wptPt); } @@ -234,12 +236,13 @@ public class ItineraryDataHelper { public String name; public String type; public String path; + public String alias; public String categories; public static ItineraryGroupInfo createGroupInfo(OsmandApplication app, MapMarkersGroup group) { ItineraryGroupInfo groupInfo = new ItineraryGroupInfo(); + groupInfo.name = group.getName(); groupInfo.type = group.getType().getTypeName(); - groupInfo.name = !Algorithms.isEmpty(group.getName()) ? group.getName() : null; Set wptCategories = group.getWptCategories(); if (!Algorithms.isEmpty(wptCategories)) { @@ -253,6 +256,9 @@ public class ItineraryDataHelper { path = path.substring(gpxDir.length() + 1); } groupInfo.path = path; + groupInfo.alias = groupInfo.type + ":" + path.replace(IndexConstants.GPX_FILE_EXT, ""); + } else { + groupInfo.alias = groupInfo.type + (groupInfo.name == null ? "" : ":" + groupInfo.name); } return groupInfo; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index d9d6280801..814366cb6e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -18,8 +18,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static net.osmand.util.MapUtils.createShortLinkString; - public class MapMarkersDbHelper { private static final int DB_VERSION = 13; @@ -304,7 +302,7 @@ public class MapMarkersDbHelper { private void insertLast(SQLiteConnection db, MapMarker marker) { long currentTime = System.currentTimeMillis(); if (marker.id == null) { - marker.id = marker.getName(context) + createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15); + marker.id = MapMarkersHelper.getMarkerId(context, marker); } marker.creationDate = currentTime; String descr = PointDescription.serializeToString(marker.getOriginalPointDescription()); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java index 2c00511f04..9f4e88d6fa 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java @@ -43,6 +43,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; +import static net.osmand.util.MapUtils.createShortLinkString; public class MapMarkersHelper { @@ -186,6 +187,7 @@ public class MapMarkersHelper { runSynchronization(gr); } } + saveGroups(); } public void lookupAddressAll() { @@ -640,7 +642,7 @@ public class MapMarkersHelper { Iterator iterator = groupMarkers.iterator(); while (iterator.hasNext()) { MapMarker marker = iterator.next(); - if (marker.id.equals(group.getId() + name + MapUtils.createShortLinkString(latLon.getLatitude(), latLon.getLongitude(), 15))) { + if (marker.id.equals(getMarkerId(app, marker))) { exists = true; marker.favouritePoint = favouritePoint; marker.wptPt = wptPt; @@ -907,7 +909,7 @@ public class MapMarkersHelper { MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); if (group != null) { - marker.id = group.getId() + marker.getName(app) + MapUtils.createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15); + marker.id = getMarkerId(app, marker); if (markersDbHelper.getMarker(marker.id) != null) { continue; } @@ -929,6 +931,11 @@ public class MapMarkersHelper { } } + public static String getMarkerId(OsmandApplication app, MapMarker marker) { + String groupId = marker.groupKey == null ? "" : marker.groupKey; + return groupId + marker.getName(app) + createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15); + } + public void updateMapMarker(MapMarker marker, boolean refresh) { if (marker != null) { markersDbHelper.updateMarker(marker);