This commit is contained in:
Alexander Sytnyk 2017-05-25 19:24:47 +03:00
parent 0b4dd0ef03
commit 143b058ea2

View file

@ -1,6 +1,8 @@
package net.osmand.plus.myplaces; package net.osmand.plus.myplaces;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -1230,49 +1232,41 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} }
} }
private List<GpxDisplayGroup> getGpxFile(GpxInfo gpxInfo) {
if (gpxInfo.gpx == null) {
return new ArrayList<>();
}
List<GpxDisplayGroup> displayGroups = selectedGpxHelper.collectDisplayGroups(gpxInfo.gpx);
if (gpxInfo.file != null) {
SelectedGpxFile sf = selectedGpxHelper.getSelectedFileByPath(gpxInfo.gpx.path);
if (sf != null && gpxInfo.file != null && sf.getDisplayGroups() != null) {
displayGroups = sf.getDisplayGroups();
}
}
return displayGroups;
}
private class OpenGpxDetailsTask extends AsyncTask<Void, Void, GPXFile> { private class OpenGpxDetailsTask extends AsyncTask<Void, Void, GPXFile> {
GpxInfo gpxInfo; GpxInfo gpxInfo;
Dialog progressDialog;
OpenGpxDetailsTask(GpxInfo gpxInfo) { OpenGpxDetailsTask(GpxInfo gpxInfo) {
this.gpxInfo = gpxInfo; this.gpxInfo = gpxInfo;
} }
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(getActivity());
progressDialog.setCancelable(false);
progressDialog.setTitle(R.string.loading_data);
progressDialog.show();
}
@Override @Override
protected GPXFile doInBackground(Void... voids) { protected GPXFile doInBackground(Void... voids) {
GPXFile result = null; GPXFile result;
if (gpxInfo.gpx == null) { if (gpxInfo.gpx == null) {
if (gpxInfo.file == null) { if (gpxInfo.file == null) {
result = getMyApplication().getSavingTrackHelper().getCurrentGpx(); result = getMyApplication().getSavingTrackHelper().getCurrentGpx();
} else {
SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxInfo.file.getAbsolutePath());
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
result = selectedGpxFile.getGpxFile();
} else { } else {
result = GPXUtilities.loadGPXFile(getActivity(), gpxInfo.file); result = GPXUtilities.loadGPXFile(getActivity(), gpxInfo.file);
} }
} } else {
return gpxInfo.gpx;
} }
return result; return result;
} }
@Override @Override
protected void onPostExecute(GPXFile gpxFile) { protected void onPostExecute(GPXFile gpxFile) {
List<GpxDisplayGroup> gpxDisplayGroupList = getGpxFile(gpxInfo); List<GpxDisplayGroup> gpxDisplayGroupList = selectedGpxHelper.collectDisplayGroups(gpxFile);
List<GpxDisplayItem> items = null; List<GpxDisplayItem> items = null;
for (GpxDisplayGroup group : gpxDisplayGroupList) { for (GpxDisplayGroup group : gpxDisplayGroupList) {
if (group.getType() == GpxSelectionHelper.GpxDisplayItemType.TRACK_SEGMENT) { if (group.getType() == GpxSelectionHelper.GpxDisplayItemType.TRACK_SEGMENT) {
@ -1280,9 +1274,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
break; break;
} }
} }
if (items != null) { if (items != null && items.size() > 0) {
GpxDisplayItem gpxItem = items.get(0); GpxDisplayItem gpxItem = items.get(0);
if (gpxItem.analysis != null) { if (gpxItem != null && gpxItem.analysis != null) {
ArrayList<GPXDataSetType> list = new ArrayList<>(); ArrayList<GPXDataSetType> list = new ArrayList<>();
if (gpxItem.analysis.hasElevationData) { if (gpxItem.analysis.hasElevationData) {
list.add(GPXDataSetType.ALTITUDE); list.add(GPXDataSetType.ALTITUDE);
@ -1306,6 +1300,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} }
} }
progressDialog.cancel();
} }
} }