From 54337f5cf4b466028a77fcc2de1dad0070d2752f Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 11 Nov 2020 14:30:57 +0200 Subject: [PATCH 1/2] Change markers export time format --- .../main/java/net/osmand/GPXUtilities.java | 2 +- .../plus/mapmarkers/MapMarkersHelper.java | 32 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index c2b961646e..1d1b1da020 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -55,7 +55,7 @@ public class GPXUtilities { private static final String GAP_PROFILE_TYPE = "gap"; private static final String TRKPT_INDEX_EXTENSION = "trkpt_idx"; - private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$ + public final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$ private final static String GPX_TIME_FORMAT_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$ private final static NumberFormat latLonFormat = new DecimalFormat("0.00#####", new DecimalFormatSymbols( diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java index b0a13d8e44..1240de75dc 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java @@ -35,17 +35,23 @@ import org.apache.commons.logging.Log; import java.io.File; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.TimeZone; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import static net.osmand.GPXUtilities.GPX_TIME_FORMAT; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; public class MapMarkersHelper { @@ -1024,6 +1030,9 @@ public class MapMarkersHelper { } public GPXFile generateGpx(List markers, boolean completeBackup) { + SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US); + format.setTimeZone(TimeZone.getTimeZone("UTC")); + GPXFile gpxFile = new GPXFile(Version.getFullVersion(ctx)); for (MapMarker marker : markers) { WptPt wpt = new WptPt(); @@ -1033,10 +1042,10 @@ public class MapMarkersHelper { wpt.setColor(ContextCompat.getColor(ctx, MapMarker.getColorId(marker.colorIndex))); if (completeBackup) { if (marker.creationDate != 0) { - wpt.getExtensionsToWrite().put(CREATION_DATE, String.valueOf(marker.creationDate)); + wpt.getExtensionsToWrite().put(CREATION_DATE, format.format(new Date(marker.creationDate))); } if (marker.visitedDate != 0) { - wpt.getExtensionsToWrite().put(VISITED_DATE, String.valueOf(marker.visitedDate)); + wpt.getExtensionsToWrite().put(VISITED_DATE, format.format(new Date(marker.visitedDate))); } } gpxFile.addPoint(wpt); @@ -1045,6 +1054,9 @@ public class MapMarkersHelper { } public List readMarkersFromGpx(GPXFile gpxFile, boolean history) { + SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US); + format.setTimeZone(TimeZone.getTimeZone("UTC")); + List mapMarkers = new ArrayList<>(); for (WptPt point : gpxFile.getPoints()) { LatLon latLon = new LatLon(point.lat, point.lon); @@ -1055,8 +1067,8 @@ public class MapMarkersHelper { String visitedDateStr = point.getExtensionsToRead().get(VISITED_DATE); String creationDateStr = point.getExtensionsToRead().get(CREATION_DATE); - marker.visitedDate = Algorithms.parseLongSilently(visitedDateStr, 0); - marker.creationDate = Algorithms.parseLongSilently(creationDateStr, 0); + marker.visitedDate = parseTime(visitedDateStr, format); + marker.creationDate = parseTime(creationDateStr, format); marker.nextKey = history ? MapMarkersDbHelper.HISTORY_NEXT_VALUE : MapMarkersDbHelper.TAIL_NEXT_VALUE; mapMarkers.add(marker); @@ -1064,6 +1076,18 @@ public class MapMarkersHelper { return mapMarkers; } + private static long parseTime(String text, SimpleDateFormat format) { + long time = 0; + if (text != null) { + try { + time = format.parse(text).getTime(); + } catch (ParseException e) { + LOG.error(e); + } + } + return time; + } + // --------------------------------------------------------------------------------------------- // accessors to active markers: From 6fb592bde1449f59df3c0cdbd06d5f2861eb068f Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 12 Nov 2020 14:21:56 +0200 Subject: [PATCH 2/2] Remove export of GPX and favorite markers --- .../osmand/plus/mapmarkers/MapMarkersHelper.java | 14 ++++++++++++++ .../backend/backup/HistoryMarkersSettingsItem.java | 2 +- .../backend/backup/MarkersSettingsItem.java | 2 +- .../settings/backend/backup/SettingsHelper.java | 4 ++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java index 1240de75dc..9839ccffda 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java @@ -1011,6 +1011,20 @@ public class MapMarkersHelper { }); } + public List getMapMarkersFromDefaultGroups(boolean history) { + List mapMarkers = new ArrayList<>(); + for (MapMarkersGroup group : mapMarkersGroups) { + if (group.getType() == MapMarkersGroup.ANY_TYPE) { + for (MapMarker marker : group.getMarkers()) { + if (history && marker.history || !history && !marker.history) { + mapMarkers.add(marker); + } + } + } + } + return mapMarkers; + } + public String saveMarkersToFile(String fileName) { GPXFile gpxFile = generateGpx(); String dirName = IndexConstants.GPX_INDEX_DIR + IndexConstants.MAP_MARKERS_INDEX_DIR; diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java index a07aeb07ea..cc152f7ad3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java @@ -46,7 +46,7 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem(markersHelper.getMapMarkersHistory()); + existingItems = new ArrayList<>(markersHelper.getMapMarkersFromDefaultGroups(true)); } @NonNull diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/MarkersSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/MarkersSettingsItem.java index 3fea648619..ed0a072c2e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/MarkersSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/MarkersSettingsItem.java @@ -46,7 +46,7 @@ public class MarkersSettingsItem extends CollectionSettingsItem { protected void init() { super.init(); markersHelper = app.getMapMarkersHelper(); - existingItems = new ArrayList<>(markersHelper.getMapMarkers()); + existingItems = new ArrayList<>(markersHelper.getMapMarkersFromDefaultGroups(false)); } @NonNull diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 35f85b8ee8..c974e72686 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -597,7 +597,7 @@ public class SettingsHelper { if (!files.isEmpty()) { dataList.put(ExportSettingsType.VOICE, files); } - List mapMarkers = app.getMapMarkersHelper().getMapMarkers(); + List mapMarkers = app.getMapMarkersHelper().getMapMarkersFromDefaultGroups(false); if (!mapMarkers.isEmpty()) { String name = app.getString(R.string.map_markers); String groupId = ExportSettingsType.ACTIVE_MARKERS.name(); @@ -605,7 +605,7 @@ public class SettingsHelper { markersGroup.setMarkers(mapMarkers); dataList.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup)); } - List markersHistory = app.getMapMarkersHelper().getMapMarkersHistory(); + List markersHistory = app.getMapMarkersHelper().getMapMarkersFromDefaultGroups(true); if (!markersHistory.isEmpty()) { String name = app.getString(R.string.shared_string_history); String groupId = ExportSettingsType.HISTORY_MARKERS.name();