diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 1500dde7fa..0da3176e26 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -56,8 +56,12 @@ public class GpxSelectionHelper { private Map selectedGpxFilesBackUp = new java.util.HashMap<>(); private SavingTrackHelper savingTrackHelper; private final static Log LOG = PlatformUtil.getLog(GpxSelectionHelper.class); - SelectGpxTask selectGpxTask; + private SelectGpxTask selectGpxTask; + private SelectGpxTaskListener gpxTaskListener; + public void setGpxTaskListener(SelectGpxTaskListener gpxTaskListener) { + this.gpxTaskListener = gpxTaskListener; + } public GpxSelectionHelper(OsmandApplication osmandApplication, SavingTrackHelper trackHelper) { this.app = osmandApplication; @@ -625,7 +629,7 @@ public class GpxSelectionHelper { return sf; } - public void addRemoveSelected(boolean show, SelectedGpxFile sf) { + private void addRemoveSelected(boolean show, SelectedGpxFile sf) { List newSelectedGPXFiles = new ArrayList<>(selectedGPXFiles); if (show) { if (!newSelectedGPXFiles.contains(sf)) { @@ -963,12 +967,12 @@ public class GpxSelectionHelper { } } - public void runSelection(Map selectedItems, SelectGpxTaskListener gpxTaskListener) { + public void runSelection(Map selectedItems) { if (selectGpxTask != null && (selectGpxTask.getStatus() == AsyncTask.Status.RUNNING || selectGpxTask.getStatus() == AsyncTask.Status.PENDING)) { selectGpxTask.cancel(false); } - selectGpxTask = new SelectGpxTask(selectedItems, gpxTaskListener); + selectGpxTask = new SelectGpxTask(selectedItems); selectGpxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -984,12 +988,10 @@ public class GpxSelectionHelper { public class SelectGpxTask extends AsyncTask { - final Set originalSelectedItems = new HashSet<>(); - private SelectGpxTaskListener gpxTaskListener; - Map selectedItems; + private Set originalSelectedItems = new HashSet<>(); + private Map selectedItems; - SelectGpxTask(Map selectedItems, SelectGpxTaskListener gpxTaskListener) { - this.gpxTaskListener = gpxTaskListener; + SelectGpxTask(Map selectedItems) { this.selectedItems = selectedItems; } @@ -1010,13 +1012,17 @@ public class GpxSelectionHelper { @Override protected void onProgressUpdate(Void... values) { - gpxTaskListener.gpxSelectionInProgress(); + if (gpxTaskListener != null) { + gpxTaskListener.gpxSelectionInProgress(); + } } @Override protected void onPreExecute() { collectSelectedItems(); - gpxTaskListener.gpxSelectionStarted(); + if (gpxTaskListener != null) { + gpxTaskListener.gpxSelectionStarted(); + } } private void collectSelectedItems() { @@ -1048,7 +1054,9 @@ public class GpxSelectionHelper { @Override protected void onPostExecute(String result) { - gpxTaskListener.gpxSelectionFinished(); + if (gpxTaskListener != null) { + gpxTaskListener.gpxSelectionFinished(); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 7468f24e9c..f64e63d314 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -205,7 +205,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement @Override public void onResume() { super.onResume(); - + selectedGpxHelper.setGpxTaskListener(gpxTaskListener); if (!importing) { if (asyncLoader == null || asyncLoader.getResult() == null) { asyncLoader = new LoadGpxTask(); @@ -225,6 +225,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement @Override public void onPause() { super.onPause(); + selectedGpxHelper.setGpxTaskListener(null); updateEnable = false; if (operationTask != null) { operationTask.cancel(true); @@ -656,7 +657,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement String path = gpxInfo.currentlyRecordingTrack ? CURRENT_TRACK : gpxInfo.file.getAbsolutePath(); selectedItemsFileNames.put(path, selectedItems.contains(gpxInfo)); } - selectedGpxHelper.runSelection(selectedItemsFileNames, gpxTaskListener); + selectedGpxHelper.runSelection(selectedItemsFileNames); } public void openSelectionMode(final int actionResId, int darkIcon, int lightIcon,