From 05ed6b38b3d17674babbff30b3cb5c8d38d727f8 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Wed, 27 Feb 2019 18:18:43 +0200 Subject: [PATCH] Added check for file existence and time of modification --- .../net/osmand/plus/GpxSelectionHelper.java | 21 +++++++++++-------- .../osmand/plus/dialogs/ConfigureMapMenu.java | 8 ++++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 7cdb603760..da0517bf0c 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -35,7 +35,6 @@ import org.json.JSONObject; import java.io.File; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; public class GpxSelectionHelper { @@ -43,7 +42,7 @@ public class GpxSelectionHelper { private static final String CURRENT_TRACK = "currentTrack"; private static final String FILE = "file"; private static final String BACKUP = "backup"; - private static final String BACKUPTIME = "backupTime"; + private static final String BACKUPMODIFIEDTIME = "backupTime"; private static final String COLOR = "color"; private static final String SELECTED_BY_USER = "selected_by_user"; private OsmandApplication app; @@ -62,7 +61,7 @@ public class GpxSelectionHelper { public void clearAllGpxFileToShow() { selectedGpxFilesBackUp.clear(); for(SelectedGpxFile s : selectedGPXFiles) { - selectedGpxFilesBackUp.put(s.gpxFile, System.currentTimeMillis()); + selectedGpxFilesBackUp.put(s.gpxFile, s.modifiedTime); } selectedGPXFiles.clear(); saveCurrentSelections(); @@ -71,17 +70,21 @@ public class GpxSelectionHelper { public void restoreSelectedGpxFiles() { if (!selectedGpxFilesBackUp.isEmpty()) { for(Map.Entry gpx : selectedGpxFilesBackUp.entrySet()) { - File file = new File(gpx.getKey().path); - if (file.exists() && !file.isDirectory() && file.lastModified() < gpx.getValue()) { - selectGpxFile(gpx.getKey(), true, false); + LOG.debug("file path: " + gpx.getKey().path); + if (!Algorithms.isEmpty(gpx.getKey().path)) { + File file = new File(gpx.getKey().path); + if (file.exists() && !file.isDirectory()) { + if (file.lastModified() > gpx.getValue()) { + GPXUtilities.loadGPXFile(file); + } + selectGpxFile(gpx.getKey(), true, false); + } } } saveCurrentSelections(); } - } - public boolean isShowingAnyGpxFiles() { return !selectedGPXFiles.isEmpty(); } @@ -527,7 +530,7 @@ public class GpxSelectionHelper { } obj.put(SELECTED_BY_USER, true); obj.put(BACKUP, true); - obj.put(BACKUPTIME, s.getValue()); + obj.put(BACKUPMODIFIEDTIME, s.getValue()); ar.put(obj); } catch (JSONException e) { e.printStackTrace(); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index cd1f8d6d46..0df53e0546 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -163,9 +163,11 @@ public class ConfigureMapMenu { } Map fls = selectedGpxHelper.getSelectedGpxFilesBackUp(); for(Map.Entry f : fls.entrySet()) { - File file = new File(f.getKey().path); - if(file.exists() && !file.isDirectory()) { - files.add(f.getKey().path); + if(!Algorithms.isEmpty(f.getKey().path)) { + File file = new File(f.getKey().path); + if(file.exists() && !file.isDirectory()) { + files.add(f.getKey().path); + } } } return files;