Fix gpx files
This commit is contained in:
parent
4bc4696c7e
commit
f82b7b3938
2 changed files with 40 additions and 10 deletions
|
@ -31,18 +31,20 @@ import org.json.JSONObject;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class GpxSelectionHelper {
|
||||
|
||||
private static final String CURRENT_TRACK = "currentTrack";
|
||||
private static final String FILE = "file";
|
||||
private static final String BACKUP = "backup";
|
||||
private static final String COLOR = "color";
|
||||
private static final String SELECTED_BY_USER = "selected_by_user";
|
||||
private OsmandApplication app;
|
||||
@NonNull
|
||||
private List<SelectedGpxFile> selectedGPXFiles = new java.util.ArrayList<>();
|
||||
private List<SelectedGpxFile> selectedGpxFilesBackUp = new java.util.ArrayList<>();
|
||||
private List<GPXFile> selectedGpxFilesBackUp = new java.util.ArrayList<>();
|
||||
private SavingTrackHelper savingTrackHelper;
|
||||
|
||||
public GpxSelectionHelper(OsmandApplication osmandApplication, SavingTrackHelper trackHelper) {
|
||||
|
@ -52,23 +54,23 @@ public class GpxSelectionHelper {
|
|||
|
||||
public void clearAllGpxFileToShow() {
|
||||
selectedGpxFilesBackUp.clear();
|
||||
selectedGpxFilesBackUp.addAll(selectedGPXFiles);
|
||||
for(SelectedGpxFile s : selectedGPXFiles) {
|
||||
selectedGpxFilesBackUp.add(s.gpxFile);
|
||||
}
|
||||
selectedGPXFiles.clear();
|
||||
saveCurrentSelections();
|
||||
}
|
||||
|
||||
public void restoreSelectedGpxFiles() {
|
||||
if (!selectedGpxFilesBackUp.isEmpty()) {
|
||||
selectedGPXFiles.clear();
|
||||
selectedGPXFiles.addAll(selectedGpxFilesBackUp);
|
||||
for(GPXFile gpx : selectedGpxFilesBackUp) {
|
||||
selectGpxFile(gpx, true, false);
|
||||
}
|
||||
saveCurrentSelections();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isSelectedGpxFilesBackUp() {
|
||||
return !selectedGpxFilesBackUp.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isShowingAnyGpxFiles() {
|
||||
return !selectedGPXFiles.isEmpty();
|
||||
|
@ -79,6 +81,10 @@ public class GpxSelectionHelper {
|
|||
return selectedGPXFiles;
|
||||
}
|
||||
|
||||
public List<GPXFile> getSelectedGpxFilesBackUp() {
|
||||
return selectedGpxFilesBackUp;
|
||||
}
|
||||
|
||||
public String getGpxDescription() {
|
||||
if (selectedGPXFiles.size() == 1) {
|
||||
GPXFile currentGPX = app.getSavingTrackHelper().getCurrentGpx();
|
||||
|
@ -455,6 +461,8 @@ public class GpxSelectionHelper {
|
|||
}
|
||||
if (gpx.error != null) {
|
||||
save = true;
|
||||
} else if(obj.has(BACKUP)) {
|
||||
selectedGpxFilesBackUp.add(gpx);
|
||||
} else {
|
||||
selectGpxFile(gpx, true, false, true, selectedByUser, false);
|
||||
}
|
||||
|
@ -496,6 +504,23 @@ public class GpxSelectionHelper {
|
|||
ar.put(obj);
|
||||
}
|
||||
}
|
||||
for (GPXFile s : selectedGpxFilesBackUp) {
|
||||
if (s != null) {
|
||||
try {
|
||||
JSONObject obj = new JSONObject();
|
||||
if(Algorithms.isEmpty(s.path)) {
|
||||
obj.put(CURRENT_TRACK, true);
|
||||
} else {
|
||||
obj.put(FILE, s.path);
|
||||
}
|
||||
obj.put(SELECTED_BY_USER, true);
|
||||
obj.put(BACKUP, true);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ar.put(obj);
|
||||
}
|
||||
}
|
||||
app.getSettings().SELECTED_GPX.set(ar.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.widget.Spinner;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.core.android.MapRendererContext;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
|
@ -153,12 +154,16 @@ public class ConfigureMapMenu {
|
|||
|
||||
private List<String> getAlreadySelectedGpx() {
|
||||
GpxSelectionHelper selectedGpxHelper = ma.getMyApplication().getSelectedGpxHelper();
|
||||
selectedGpxHelper.restoreSelectedGpxFiles();
|
||||
List<GpxSelectionHelper.SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles();
|
||||
|
||||
List<String> files = new ArrayList<>();
|
||||
for (GpxSelectionHelper.SelectedGpxFile file : selectedGpxFiles) {
|
||||
files.add(file.getGpxFile().path);
|
||||
}
|
||||
List<GPXUtilities.GPXFile> fls = selectedGpxHelper.getSelectedGpxFilesBackUp();
|
||||
for(GPXUtilities.GPXFile f : fls) {
|
||||
files.add(f.path);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
|
@ -236,8 +241,8 @@ public class ConfigureMapMenu {
|
|||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
OsmandApplication app = ma.getMyApplication();
|
||||
boolean selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles() || app.getSelectedGpxHelper().isSelectedGpxFilesBackUp();
|
||||
item.setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles());
|
||||
boolean selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
|
||||
item.setSelected(selected);
|
||||
item.setDescription(app.getSelectedGpxHelper().getGpxDescription());
|
||||
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
|
Loading…
Reference in a new issue