Fix #7763 selected gpx file status

This commit is contained in:
Dima-1 2020-02-18 17:18:45 +02:00
parent 1f1739fcc3
commit 41df9fff9e
2 changed files with 89 additions and 19 deletions

View file

@ -440,10 +440,20 @@ public class GpxSelectionHelper {
}
}
private SelectedGpxFile getSelectedFileByLoadedFileName(String path) {
List<SelectedGpxFile> newList = new ArrayList<>(selectedGPXFiles);
for (SelectedGpxFile s : newList) {
if (path.endsWith("/" + s.getLoadedName())) {
return s;
}
}
return null;
}
public SelectedGpxFile getSelectedFileByPath(String path) {
List<SelectedGpxFile> newList = new ArrayList<>(selectedGPXFiles);
for (SelectedGpxFile s : newList) {
if (s.getGpxFile().path.equals(path)) {
if (s.getGpxFile() != null && s.getGpxFile().path.equals(path)) {
return s;
}
}
@ -452,7 +462,10 @@ public class GpxSelectionHelper {
public SelectedGpxFile getSelectedFileByName(String path) {
for (SelectedGpxFile s : selectedGPXFiles) {
if (s.getGpxFile().path.endsWith("/" + path)) {
if (path.equals(s.getLoadedName())) {
return s;
}
if (s.getLoadedName().isEmpty() && s.getGpxFile().path.endsWith("/" + path)) {
return s;
}
}
@ -591,10 +604,18 @@ public class GpxSelectionHelper {
}
} else {
assert gpx != null;
sf = getSelectedFileByPath(gpx.path);
sf = getSelectedFileByLoadedFileName(gpx.path);
if (sf == null) {
sf = getSelectedFileByPath(gpx.path);
}
displayed = sf != null;
if (show && sf == null) {
sf = new SelectedGpxFile();
if (show) {
if (sf == null) {
sf = new SelectedGpxFile();
List<SelectedGpxFile> newSelectedGPXFiles = new ArrayList<>(selectedGPXFiles);
newSelectedGPXFiles.add(sf);
selectedGPXFiles = newSelectedGPXFiles;
}
if (dataItem != null) {
if (dataItem.getColor() != 0) {
gpx.setColor(dataItem.getColor());
@ -602,18 +623,23 @@ public class GpxSelectionHelper {
sf.setJoinSegments(dataItem.isJoinSegments());
}
sf.setGpxFile(gpx, app);
sf.setLoadedName("");
sf.notShowNavigationDialog = notShowNavigationDialog;
sf.selectedByUser = selectedByUser;
}
}
if (displayed != show) {
List<SelectedGpxFile> newSelectedGPXFiles = new ArrayList<>(selectedGPXFiles);
if (show) {
newSelectedGPXFiles.add(sf);
} else {
newSelectedGPXFiles.remove(sf);
if (sf != null && sf.getLoadedName().isEmpty()) {
if (displayed != show) {
List<SelectedGpxFile> newSelectedGPXFiles = new ArrayList<>(selectedGPXFiles);
if (show) {
if (!newSelectedGPXFiles.contains(sf)) {
newSelectedGPXFiles.add(sf);
}
} else {
newSelectedGPXFiles.remove(sf);
}
selectedGPXFiles = newSelectedGPXFiles;
}
selectedGPXFiles = newSelectedGPXFiles;
}
if (syncGroup) {
syncGpxWithMarkers(gpx);
@ -624,6 +650,18 @@ public class GpxSelectionHelper {
return sf;
}
public void addRemoveSelected(boolean show, SelectedGpxFile sf) {
List<SelectedGpxFile> newSelectedGPXFiles = new ArrayList<>(selectedGPXFiles);
if (show) {
if (!newSelectedGPXFiles.contains(sf)) {
newSelectedGPXFiles.add(sf);
}
} else {
newSelectedGPXFiles.remove(sf);
}
selectedGPXFiles = newSelectedGPXFiles;
}
public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog) {
return selectGpxFile(gpx, show, notShowNavigationDialog, true, true, true);
}
@ -689,6 +727,15 @@ public class GpxSelectionHelper {
private boolean joinSegments;
private boolean showCurrentTrack;
private boolean splitProcessed = false;
private String loadedName = "";
public String getLoadedName() {
return loadedName;
}
public void setLoadedName(String loadedName) {
this.loadedName = loadedName;
}
public void setGpxFile(GPXFile gpxFile, OsmandApplication app) {
this.gpxFile = gpxFile;

View file

@ -204,7 +204,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
super.onPause();
updateEnable = false;
if (operationTask != null) {
operationTask.cancel(true);
if (!(operationTask instanceof SelectGpxTask)) {
operationTask.cancel(true);
}
}
if (actionMode != null) {
actionMode.finish();
@ -615,6 +617,17 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
private void runSelection(boolean showOnMap) {
operationTask = new SelectGpxTask(showOnMap);
originalSelectedItems.addAll(selectedItems);
for (GpxInfo gpxInfo : originalSelectedItems) {
if (!gpxInfo.currentlyRecordingTrack) {
final boolean visible = selectedItems.contains(gpxInfo);
SelectedGpxFile sf = selectedGpxHelper.getSelectedFileByName(gpxInfo.fileName);
if (sf == null) {
sf = new SelectedGpxFile();
}
sf.setLoadedName(gpxInfo.fileName);
selectedGpxHelper.addRemoveSelected(visible, sf);
}
}
operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, originalSelectedItems.toArray(new GpxInfo[originalSelectedItems.size()]));
}
@ -678,7 +691,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getString(R.string.local_index_action_do, actionButton.toLowerCase(),
selectedItems.size()));
String.valueOf(selectedItems.size())));
builder.setPositiveButton(actionButton, listener);
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.show();
@ -1547,12 +1560,16 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
@Override
protected void onPreExecute() {
getActivity().setProgressBarIndeterminateVisibility(true);
if(getActivity()!=null){
((FavoritesActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(true);
}
}
@Override
protected void onPostExecute(String result) {
getActivity().setProgressBarIndeterminateVisibility(false);
if(getActivity()!=null) {
((FavoritesActivity)getActivity()).setSupportProgressBarIndeterminateVisibility(false);
}
Toast.makeText(getActivity(), result, Toast.LENGTH_LONG).show();
}
}
@ -1593,12 +1610,16 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
@Override
protected void onPreExecute() {
getActivity().setProgressBarIndeterminateVisibility(true);
if (getActivity() != null) {
((FavoritesActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(true);
}
}
@Override
protected void onPostExecute(String result) {
getActivity().setProgressBarIndeterminateVisibility(false);
if (getActivity() != null) {
((FavoritesActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(false);
}
allGpxAdapter.refreshSelected();
allGpxAdapter.notifyDataSetChanged();
if (showOnMap && toShow != null) {
@ -1863,7 +1884,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
SelectedGpxFile sgpx = getSelectedGpxFile(gpxInfo, app);
GPXTrackAnalysis analysis = null;
if (sgpx != null) {
analysis = sgpx.getTrackAnalysis(app);
if (sgpx.getLoadedName().isEmpty()) {
analysis = sgpx.getTrackAnalysis(app);
}
} else if (gpxInfo.currentlyRecordingTrack) {
analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis(app);
} else if (gpxInfo.file != null) {