From d62ba1b075afc474cc69b27021fd017b0d1ddd3f Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Fri, 1 Mar 2019 12:00:26 +0200 Subject: [PATCH] Fix reload of changed files --- .../net/osmand/plus/GpxSelectionHelper.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 6773a5a902..a7a64b5d34 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -78,10 +78,14 @@ public class GpxSelectionHelper { if (file.exists() && !file.isDirectory()) { if (file.lastModified() > gpxEntry.getValue()) { try { - GPXFile reloadedFile = new LoadGpxFileInBackground(file).execute().get(); - if (reloadedFile != null) { - selectGpxFile(reloadedFile, true, false); - } + new LoadGpxFileInBackground(file, new LoadingListener() { + @Override + public void onLoadingComplete(GPXFile file) { + if (file != null) { + selectGpxFile(file, true, false); + } + } + }).execute(); } catch (Exception e) { LOG.error(e.getMessage(), e); } @@ -95,18 +99,29 @@ public class GpxSelectionHelper { } } - static class LoadGpxFileInBackground extends AsyncTask { + static class LoadGpxFileInBackground extends AsyncTask { File fileToLoad; + LoadingListener listener; - LoadGpxFileInBackground(File fileToLoad) { + LoadGpxFileInBackground(File fileToLoad, LoadingListener listener) { this.fileToLoad = fileToLoad; + this.listener = listener; } @Override protected GPXFile doInBackground(Void... voids) { return GPXUtilities.loadGPXFile(fileToLoad); } + + @Override + protected void onPostExecute(GPXFile gpxFile) { + listener.onLoadingComplete(gpxFile); + } + } + + interface LoadingListener { + void onLoadingComplete(GPXFile file); } public boolean isShowingAnyGpxFiles() {