Refactoring SelectGpxTaskListener

This commit is contained in:
Dima-1 2020-02-21 19:03:44 +02:00
parent 8e872492c7
commit a58c0069a7
2 changed files with 6 additions and 15 deletions

View file

@ -57,11 +57,6 @@ public class GpxSelectionHelper {
private SavingTrackHelper savingTrackHelper; private SavingTrackHelper savingTrackHelper;
private final static Log LOG = PlatformUtil.getLog(GpxSelectionHelper.class); private final static Log LOG = PlatformUtil.getLog(GpxSelectionHelper.class);
private SelectGpxTask selectGpxTask; private SelectGpxTask selectGpxTask;
private SelectGpxTaskListener gpxTaskListener;
public void setGpxTaskListener(SelectGpxTaskListener gpxTaskListener) {
this.gpxTaskListener = gpxTaskListener;
}
public GpxSelectionHelper(OsmandApplication osmandApplication, SavingTrackHelper trackHelper) { public GpxSelectionHelper(OsmandApplication osmandApplication, SavingTrackHelper trackHelper) {
this.app = osmandApplication; this.app = osmandApplication;
@ -967,12 +962,12 @@ public class GpxSelectionHelper {
} }
} }
public void runSelection(Map<String, Boolean> selectedItems) { public void runSelection(Map<String, Boolean> selectedItems, SelectGpxTaskListener gpxTaskListener) {
if (selectGpxTask != null && (selectGpxTask.getStatus() == AsyncTask.Status.RUNNING if (selectGpxTask != null && (selectGpxTask.getStatus() == AsyncTask.Status.RUNNING
|| selectGpxTask.getStatus() == AsyncTask.Status.PENDING)) { || selectGpxTask.getStatus() == AsyncTask.Status.PENDING)) {
selectGpxTask.cancel(false); selectGpxTask.cancel(false);
} }
selectGpxTask = new SelectGpxTask(selectedItems); selectGpxTask = new SelectGpxTask(selectedItems, gpxTaskListener);
selectGpxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); selectGpxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
@ -990,9 +985,11 @@ public class GpxSelectionHelper {
private Set<GPXFile> originalSelectedItems = new HashSet<>(); private Set<GPXFile> originalSelectedItems = new HashSet<>();
private Map<String, Boolean> selectedItems; private Map<String, Boolean> selectedItems;
private SelectGpxTaskListener gpxTaskListener;
SelectGpxTask(Map<String, Boolean> selectedItems) { SelectGpxTask(Map<String, Boolean> selectedItems, SelectGpxTaskListener gpxTaskListener) {
this.selectedItems = selectedItems; this.selectedItems = selectedItems;
this.gpxTaskListener = gpxTaskListener;
} }
@Override @Override
@ -1012,18 +1009,14 @@ public class GpxSelectionHelper {
@Override @Override
protected void onProgressUpdate(Void... values) { protected void onProgressUpdate(Void... values) {
if (gpxTaskListener != null) {
gpxTaskListener.gpxSelectionInProgress(); gpxTaskListener.gpxSelectionInProgress();
} }
}
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
collectSelectedItems(); collectSelectedItems();
if (gpxTaskListener != null) {
gpxTaskListener.gpxSelectionStarted(); gpxTaskListener.gpxSelectionStarted();
} }
}
private void collectSelectedItems() { private void collectSelectedItems() {
for (String filePath : selectedItems.keySet()) { for (String filePath : selectedItems.keySet()) {

View file

@ -205,7 +205,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
selectedGpxHelper.setGpxTaskListener(gpxTaskListener);
if (!importing) { if (!importing) {
if (asyncLoader == null || asyncLoader.getResult() == null) { if (asyncLoader == null || asyncLoader.getResult() == null) {
asyncLoader = new LoadGpxTask(); asyncLoader = new LoadGpxTask();
@ -225,7 +224,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
selectedGpxHelper.setGpxTaskListener(null);
updateEnable = false; updateEnable = false;
if (operationTask != null) { if (operationTask != null) {
operationTask.cancel(true); operationTask.cancel(true);
@ -657,7 +655,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
String path = gpxInfo.currentlyRecordingTrack ? CURRENT_TRACK : gpxInfo.file.getAbsolutePath(); String path = gpxInfo.currentlyRecordingTrack ? CURRENT_TRACK : gpxInfo.file.getAbsolutePath();
selectedItemsFileNames.put(path, selectedItems.contains(gpxInfo)); selectedItemsFileNames.put(path, selectedItems.contains(gpxInfo));
} }
selectedGpxHelper.runSelection(selectedItemsFileNames); selectedGpxHelper.runSelection(selectedItemsFileNames, gpxTaskListener);
} }
public void openSelectionMode(final int actionResId, int darkIcon, int lightIcon, public void openSelectionMode(final int actionResId, int darkIcon, int lightIcon,