Remove unnecessary changes

This commit is contained in:
Vitaliy 2020-09-08 23:55:34 +03:00
parent 5c4c347e4c
commit 1783796e59

View file

@ -43,6 +43,7 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -51,6 +52,8 @@ import java.util.Set;
public class GpxSelectionHelper { public class GpxSelectionHelper {
private final static Log LOG = PlatformUtil.getLog(GpxSelectionHelper.class);
public static final String CURRENT_TRACK = "currentTrack"; public static final String CURRENT_TRACK = "currentTrack";
private static final String FILE = "file"; private static final String FILE = "file";
private static final String BACKUP = "backup"; private static final String BACKUP = "backup";
@ -61,52 +64,21 @@ public class GpxSelectionHelper {
private static final String SHOW_ARROWS = "show_arrows"; private static final String SHOW_ARROWS = "show_arrows";
private static final String GRADIENT_SCALE_TYPE = "gradient_scale_type"; private static final String GRADIENT_SCALE_TYPE = "gradient_scale_type";
private static final String SHOW_START_FINISH = "show_start_finish"; private static final String SHOW_START_FINISH = "show_start_finish";
private static final String TRACK_TO_FOLLOW = "trackToFollow";
private static final String SHOULD_HIDE_TRACK_TO_FOLLOW = "should_hide_track_to_follow";
private OsmandApplication app; private OsmandApplication app;
@NonNull @NonNull
private List<SelectedGpxFile> selectedGPXFiles = new java.util.ArrayList<>(); private List<SelectedGpxFile> selectedGPXFiles = new ArrayList<>();
private Map<GPXFile, Long> selectedGpxFilesBackUp = new java.util.HashMap<>(); private Map<GPXFile, Long> selectedGpxFilesBackUp = new HashMap<>();
private SavingTrackHelper savingTrackHelper; private SavingTrackHelper savingTrackHelper;
private final static Log LOG = PlatformUtil.getLog(GpxSelectionHelper.class);
private SelectGpxTask selectGpxTask; private SelectGpxTask selectGpxTask;
private StateChangedListener<String> followTrackListener;
private SelectedGpxFile trackToFollow; private SelectedGpxFile trackToFollow;
private StateChangedListener<String> followTrackListener;
private boolean shouldHideTrackToFollow; private boolean shouldHideTrackToFollow;
public GpxSelectionHelper(OsmandApplication app, SavingTrackHelper trackHelper) { public GpxSelectionHelper(OsmandApplication app, SavingTrackHelper trackHelper) {
this.app = app; this.app = app;
savingTrackHelper = trackHelper; savingTrackHelper = trackHelper;
followTrackListener = new StateChangedListener<String>() { app.getSettings().FOLLOW_THE_GPX_ROUTE.addListener(getFollowTrackListener());
@Override
public void stateChanged(String gpxRoutePath) {
if (trackToFollow != null) {
if (shouldHideTrackToFollow) {
selectGpxFile(trackToFollow.getGpxFile(), false, false);
shouldHideTrackToFollow = false;
}
trackToFollow = null;
}
if (!Algorithms.isEmpty(gpxRoutePath)) {
trackToFollow = getSelectedFileByPath(gpxRoutePath);
if (trackToFollow == null) {
shouldHideTrackToFollow = true;
File file = new File(gpxRoutePath);
if (file.exists() && !file.isDirectory()) {
new GpxFileLoaderTask(file, new CallbackWithObject<GPXFile>() {
@Override
public boolean processResult(GPXFile result) {
trackToFollow = selectGpxFile(result, true, false);
return true;
}
}).execute();
}
}
}
}
};
app.getSettings().FOLLOW_THE_GPX_ROUTE.addListener(followTrackListener);
} }
public void clearAllGpxFilesToShow(boolean backupSelection) { public void clearAllGpxFilesToShow(boolean backupSelection) {
@ -144,6 +116,40 @@ public class GpxSelectionHelper {
} }
} }
private StateChangedListener<String> getFollowTrackListener() {
if (followTrackListener == null) {
followTrackListener = new StateChangedListener<String>() {
@Override
public void stateChanged(String gpxRoutePath) {
if (trackToFollow != null) {
if (shouldHideTrackToFollow) {
selectGpxFile(trackToFollow.getGpxFile(), false, false);
shouldHideTrackToFollow = false;
}
trackToFollow = null;
}
if (!Algorithms.isEmpty(gpxRoutePath)) {
trackToFollow = getSelectedFileByPath(gpxRoutePath);
if (trackToFollow == null) {
shouldHideTrackToFollow = true;
File file = new File(gpxRoutePath);
if (file.exists() && !file.isDirectory()) {
new GpxFileLoaderTask(file, new CallbackWithObject<GPXFile>() {
@Override
public boolean processResult(GPXFile result) {
trackToFollow = selectGpxFile(result, true, false);
return true;
}
}).execute();
}
}
}
}
};
}
return followTrackListener;
}
private static class GpxFileLoaderTask extends AsyncTask<Void, Void, GPXFile> { private static class GpxFileLoaderTask extends AsyncTask<Void, Void, GPXFile> {
private File fileToLoad; private File fileToLoad;
@ -647,7 +653,6 @@ public class GpxSelectionHelper {
obj.put(scaleType.getColorTypeName(), Algorithms.colorToString(gradientScaleColor)); obj.put(scaleType.getColorTypeName(), Algorithms.colorToString(gradientScaleColor));
} }
} }
obj.put(TRACK_TO_FOLLOW, shouldHideTrackToFollow);
} }
obj.put(SELECTED_BY_USER, s.selectedByUser); obj.put(SELECTED_BY_USER, s.selectedByUser);
} catch (JSONException e) { } catch (JSONException e) {