Fixed bug with null reference on long click at gpx in settings.

This commit is contained in:
unknown 2014-07-06 08:57:56 +03:00
parent 157b5b0209
commit 237036a7e4
2 changed files with 57 additions and 17 deletions

View file

@ -328,7 +328,7 @@ public class GpxSelectionHelper {
private void selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog) { private void selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog) {
boolean displayed = false; boolean displayed = false;
SelectedGpxFile sf ; SelectedGpxFile sf ;
if(gpx.showCurrentTrack) { if(gpx != null && gpx.showCurrentTrack) {
sf = savingTrackHelper.getCurrentTrack(); sf = savingTrackHelper.getCurrentTrack();
sf.notShowNavigationDialog = notShowNavigationDialog; sf.notShowNavigationDialog = notShowNavigationDialog;
displayed = selectedGPXFiles.contains(sf); displayed = selectedGPXFiles.contains(sf);

View file

@ -398,9 +398,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
renameFile(info); renameFile(info);
} else if (resId == R.string.local_index_unselect_gpx_file || } else if (resId == R.string.local_index_unselect_gpx_file ||
resId == R.string.local_index_select_gpx_file) { resId == R.string.local_index_select_gpx_file) {
getMyApplication().getSelectedGpxHelper().selectGpxFile(info.gpx, resId == R.string.local_index_select_gpx_file, true); if (info.gpx == null) {
listAdapter.notifyDataSetChanged(); loadGpxAsync(info, resId == R.string.local_index_select_gpx_file);
selectedGpxHelper.runUiListeners(); } else {
getMyApplication().getSelectedGpxHelper().selectGpxFile(info.gpx, resId == R.string.local_index_select_gpx_file, true);
listAdapter.notifyDataSetChanged();
selectedGpxHelper.runUiListeners();
}
} else if (resId == R.string.local_index_mi_delete) { } else if (resId == R.string.local_index_mi_delete) {
Builder confirm = new AlertDialog.Builder(getActivity()); Builder confirm = new AlertDialog.Builder(getActivity());
confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@ -437,20 +441,18 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} }
} }
}; };
if(info.gpx != null){ if (info.gpx != null && info.file == null) {
if (info.file == null) { GpxSelectionHelper.SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedCurrentRecordingTrack();
GpxSelectionHelper.SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedCurrentRecordingTrack(); if (selectedGpxFile != null && selectedGpxFile.getGpxFile() == info.gpx) {
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() == info.gpx) { adapter.item(R.string.local_index_unselect_gpx_file).listen(listener).reg();
adapter.item(R.string.local_index_unselect_gpx_file).listen(listener).reg();
} else {
adapter.item(R.string.local_index_select_gpx_file).listen(listener).reg();
}
} else { } else {
if (getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(info.file.getAbsolutePath()) == null) { adapter.item(R.string.local_index_select_gpx_file).listen(listener).reg();
adapter.item(R.string.local_index_select_gpx_file).listen(listener).reg(); }
} else { } else if (info.file != null) {
adapter.item(R.string.local_index_unselect_gpx_file).listen(listener).reg(); if (getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(info.file.getAbsolutePath()) == null) {
} adapter.item(R.string.local_index_select_gpx_file).listen(listener).reg();
} else {
adapter.item(R.string.local_index_unselect_gpx_file).listen(listener).reg();
} }
} }
adapter.item(R.string.show_gpx_route).listen(listener).reg(); adapter.item(R.string.show_gpx_route).listen(listener).reg();
@ -932,6 +934,44 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} }
} }
private void loadGpxAsync(GpxInfo info, boolean isSelected){
final boolean selected = isSelected;
new AsyncTask<GpxInfo, Void, Void>() {
GpxInfo info;
@Override
protected Void doInBackground(GpxInfo... params) {
if (params == null){
return null;
}
info = params[0];
params[0].updateGpxInfo(getMyApplication());
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
}
@Override
protected void onPreExecute() {
getSherlockActivity().setProgressBarIndeterminateVisibility(true);
}
@Override
protected void onPostExecute(Void result) {
getSherlockActivity().setProgressBarIndeterminateVisibility(false);
if (info.gpx != null){
getMyApplication().getSelectedGpxHelper().selectGpxFile(info.gpx, selected, true);
listAdapter.notifyDataSetChanged();
selectedGpxHelper.runUiListeners();
}
}
}.execute(info);
}
private class SearchFilter extends Filter { private class SearchFilter extends Filter {