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

View file

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