From a58c0069a73800b5454f1c16e08130615206c510 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 21 Feb 2020 19:03:44 +0200 Subject: [PATCH] Refactoring SelectGpxTaskListener --- .../src/net/osmand/plus/GpxSelectionHelper.java | 17 +++++------------ .../plus/myplaces/AvailableGPXFragment.java | 4 +--- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 0da3176e26..1c2f17ffe2 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -57,11 +57,6 @@ public class GpxSelectionHelper { private SavingTrackHelper savingTrackHelper; private final static Log LOG = PlatformUtil.getLog(GpxSelectionHelper.class); private SelectGpxTask selectGpxTask; - private SelectGpxTaskListener gpxTaskListener; - - public void setGpxTaskListener(SelectGpxTaskListener gpxTaskListener) { - this.gpxTaskListener = gpxTaskListener; - } public GpxSelectionHelper(OsmandApplication osmandApplication, SavingTrackHelper trackHelper) { this.app = osmandApplication; @@ -967,12 +962,12 @@ public class GpxSelectionHelper { } } - public void runSelection(Map selectedItems) { + public void runSelection(Map selectedItems, SelectGpxTaskListener gpxTaskListener) { if (selectGpxTask != null && (selectGpxTask.getStatus() == AsyncTask.Status.RUNNING || selectGpxTask.getStatus() == AsyncTask.Status.PENDING)) { selectGpxTask.cancel(false); } - selectGpxTask = new SelectGpxTask(selectedItems); + selectGpxTask = new SelectGpxTask(selectedItems, gpxTaskListener); selectGpxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -990,9 +985,11 @@ public class GpxSelectionHelper { private Set originalSelectedItems = new HashSet<>(); private Map selectedItems; + private SelectGpxTaskListener gpxTaskListener; - SelectGpxTask(Map selectedItems) { + SelectGpxTask(Map selectedItems, SelectGpxTaskListener gpxTaskListener) { this.selectedItems = selectedItems; + this.gpxTaskListener = gpxTaskListener; } @Override @@ -1012,17 +1009,13 @@ public class GpxSelectionHelper { @Override protected void onProgressUpdate(Void... values) { - if (gpxTaskListener != null) { gpxTaskListener.gpxSelectionInProgress(); - } } @Override protected void onPreExecute() { collectSelectedItems(); - if (gpxTaskListener != null) { gpxTaskListener.gpxSelectionStarted(); - } } private void collectSelectedItems() { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index f64e63d314..94f20115e7 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -205,7 +205,6 @@ 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,7 +224,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement @Override public void onPause() { super.onPause(); - selectedGpxHelper.setGpxTaskListener(null); updateEnable = false; if (operationTask != null) { operationTask.cancel(true); @@ -657,7 +655,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); + selectedGpxHelper.runSelection(selectedItemsFileNames, gpxTaskListener); } public void openSelectionMode(final int actionResId, int darkIcon, int lightIcon,