This commit is contained in:
Alex Sytnyk 2018-09-18 15:29:26 +03:00
parent 3d7c83254a
commit c9a1ebccc8
4 changed files with 39 additions and 21 deletions

View file

@ -36,6 +36,7 @@ public class GpxSelectionHelper {
private static final String CURRENT_TRACK = "currentTrack";
private static final String FILE = "file";
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<>();
@ -410,7 +411,7 @@ public class GpxSelectionHelper {
public void setGpxFileToDisplay(GPXFile... gpxs) {
// special case for gpx current route
for (GPXFile gpx : gpxs) {
selectGpxFileImpl(gpx, true, false, true);
selectGpxFileImpl(gpx, true, false, true, true);
}
saveCurrentSelections();
}
@ -423,6 +424,7 @@ public class GpxSelectionHelper {
boolean save = false;
for (int i = 0; i < ar.length(); i++) {
JSONObject obj = ar.getJSONObject(i);
boolean selectedByUser = obj.optBoolean(SELECTED_BY_USER, true);
if (obj.has(FILE)) {
File fl = new File(obj.getString(FILE));
if (p != null) {
@ -436,10 +438,12 @@ public class GpxSelectionHelper {
if (gpx.warning != null) {
save = true;
} else {
selectGpxFile(gpx, true, false);
selectGpxFile(gpx, true, false, true, selectedByUser);
}
} else if (obj.has(CURRENT_TRACK)) {
selectedGPXFiles.add(savingTrackHelper.getCurrentTrack());
SelectedGpxFile file = savingTrackHelper.getCurrentTrack();
file.selectedByUser = selectedByUser;
selectedGPXFiles.add(file);
}
}
processSplit();
@ -467,6 +471,7 @@ public class GpxSelectionHelper {
obj.put(COLOR, Algorithms.colorToString(s.gpxFile.getColor(0)));
}
}
obj.put(SELECTED_BY_USER, s.selectedByUser);
} catch (JSONException e) {
e.printStackTrace();
}
@ -476,13 +481,16 @@ public class GpxSelectionHelper {
app.getSettings().SELECTED_GPX.set(ar.toString());
}
private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup) {
private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser) {
boolean displayed;
SelectedGpxFile sf;
if (gpx != null && gpx.showCurrentTrack) {
sf = savingTrackHelper.getCurrentTrack();
sf.notShowNavigationDialog = notShowNavigationDialog;
displayed = selectedGPXFiles.contains(sf);
if (!displayed && show) {
sf.selectedByUser = selectedByUser;
}
} else {
assert gpx != null;
sf = getSelectedFileByPath(gpx.path);
@ -491,6 +499,7 @@ public class GpxSelectionHelper {
sf = new SelectedGpxFile();
sf.setGpxFile(gpx);
sf.notShowNavigationDialog = notShowNavigationDialog;
sf.selectedByUser = selectedByUser;
}
}
if (displayed != show) {
@ -507,11 +516,11 @@ public class GpxSelectionHelper {
}
public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog) {
return selectGpxFile(gpx, show, notShowNavigationDialog, true);
return selectGpxFile(gpx, show, notShowNavigationDialog, true, true);
}
public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup) {
SelectedGpxFile sf = selectGpxFileImpl(gpx, show, notShowNavigationDialog, syncGroup);
public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser) {
SelectedGpxFile sf = selectGpxFileImpl(gpx, show, notShowNavigationDialog, syncGroup, selectedByUser);
saveCurrentSelections();
return sf;
}
@ -549,6 +558,7 @@ public class GpxSelectionHelper {
public static class SelectedGpxFile {
public boolean notShowNavigationDialog = false;
public boolean selectedByUser = true;
private boolean showCurrentTrack;
private GPXFile gpxFile;

View file

@ -16,8 +16,6 @@ import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.mapmarkers.adapters.GroupsAdapter;
@ -68,15 +66,21 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
fragment.setArguments(args);
fragment.setUsedOnMap(false);
fragment.show(getParentFragment().getChildFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
dismiss();
} else if(dataItem.getFile() != null) {
getMyApplication().getMapMarkersHelper().addOrEnableGpxGroup(dataItem.getFile());
dismiss();
} else {
OsmandApplication app = getMyApplication();
if (app != null) {
GpxSelectionHelper selectionHelper = app.getSelectedGpxHelper();
File gpx = dataItem.getFile();
if (selectionHelper.getSelectedFileByPath(gpx.getAbsolutePath()) == null) {
GPXFile res = GPXUtilities.loadGPXFile(app, gpx);
selectionHelper.selectGpxFile(res, true, false, false, false);
}
app.getMapMarkersHelper().addOrEnableGpxGroup(gpx);
}
}
dismiss();
}
@SuppressLint("StaticFieldLeak")
public class ProcessGpxTask extends AsyncTask<Void, GpxDataItem, Void> {

View file

@ -136,7 +136,7 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpxFile.path);
if (selectedGpxFile == null) {
gpxSelectionHelper.selectGpxFile(gpxFile, true, false);
gpxSelectionHelper.selectGpxFile(gpxFile, true, false, false, false);
}
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
if (group == null) {

View file

@ -2,6 +2,7 @@ package net.osmand.plus.mapmarkers.adapters;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
@ -464,13 +465,13 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
if (disabled) {
if (selectedGpxFile != null) {
gpxFile[0] = selectedGpxFile.getGpxFile();
switchGpxVisibility(gpxFile[0], false);
switchGpxVisibility(gpxFile[0], selectedGpxFile, false);
}
} else {
if (selectedGpxFile == null) {
// TODO IO load in another thread ?
gpxFile[0] = GPXUtilities.loadGPXFile(app, new File(gpxPath));
switchGpxVisibility(gpxFile[0], true);
switchGpxVisibility(gpxFile[0], null, true);
}
}
}
@ -487,7 +488,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
@Override
public void onClick(View view) {
if (group.getType() == MapMarkersGroup.GPX_TYPE && gpxFile[0] != null) {
switchGpxVisibility(gpxFile[0], true);
switchGpxVisibility(gpxFile[0], null, true);
}
mapMarkersHelper.enableGroup(group);
}
@ -557,9 +558,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
}
}
private void switchGpxVisibility(@NonNull GPXFile gpxFile, boolean visible) {
private void switchGpxVisibility(@NonNull GPXFile gpxFile, @Nullable SelectedGpxFile selectedGpxFile, boolean visible) {
GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
gpxHelper.selectGpxFile(gpxFile, visible, false, false);
if (!visible && selectedGpxFile != null && selectedGpxFile.selectedByUser) {
return;
}
gpxHelper.selectGpxFile(gpxFile, visible, false, false, false);
}
public void hideSnackbar() {