This commit is contained in:
alex 2017-05-26 10:37:43 +03:00
parent 3d3551717e
commit 05a7aa1ca4

View file

@ -94,6 +94,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static net.osmand.plus.R.id.items;
public class AvailableGPXFragment extends OsmandExpandableListFragment { public class AvailableGPXFragment extends OsmandExpandableListFragment {
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]"); public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
@ -1232,11 +1234,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} }
} }
private class OpenGpxDetailsTask extends AsyncTask<Void, Void, Void> { private class OpenGpxDetailsTask extends AsyncTask<Void, Void, GpxDisplayItem> {
GpxInfo gpxInfo; GpxInfo gpxInfo;
ProgressDialog progressDialog; ProgressDialog progressDialog;
List<GpxDisplayGroup> gpxDisplayGroupList;
OpenGpxDetailsTask(GpxInfo gpxInfo) { OpenGpxDetailsTask(GpxInfo gpxInfo) {
this.gpxInfo = gpxInfo; this.gpxInfo = gpxInfo;
@ -1244,69 +1245,71 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
progressDialog = new ProgressDialog(getActivity()); if (gpxInfo.file != null) {
progressDialog.setTitle(""); progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage(getActivity().getResources().getString(R.string.loading_data)); progressDialog.setTitle("");
progressDialog.setCancelable(false); progressDialog.setMessage(getActivity().getResources().getString(R.string.loading_data));
progressDialog.setCancelable(false);
progressDialog.show();
}
} }
@Override @Override
protected Void doInBackground(Void... voids) { protected GpxDisplayItem doInBackground(Void... voids) {
GPXFile result; GPXFile gpxFile;
List<GpxDisplayGroup> gpxDisplayGroupList;
if (gpxInfo.gpx == null) { if (gpxInfo.gpx == null) {
if (gpxInfo.file == null) { if (gpxInfo.file == null) {
result = getMyApplication().getSavingTrackHelper().getCurrentGpx(); gpxFile = getMyApplication().getSavingTrackHelper().getCurrentGpx();
} else { } else {
publishProgress(); gpxFile = GPXUtilities.loadGPXFile(getActivity(), gpxInfo.file);
result = GPXUtilities.loadGPXFile(getActivity(), gpxInfo.file);
} }
gpxDisplayGroupList = selectedGpxHelper.collectDisplayGroups(result); gpxDisplayGroupList = selectedGpxHelper.collectDisplayGroups(gpxFile);
} else { } else {
gpxDisplayGroupList = selectedGpxHelper.collectDisplayGroups(gpxInfo.gpx); gpxDisplayGroupList = selectedGpxHelper.collectDisplayGroups(gpxInfo.gpx);
} }
List<GpxDisplayItem> items = null;
if (gpxDisplayGroupList != null) {
for (GpxDisplayGroup group : gpxDisplayGroupList) {
if (group.getType() == GpxSelectionHelper.GpxDisplayItemType.TRACK_SEGMENT) {
items = group.getModifiableList();
break;
}
}
}
if (items != null && items.size() > 0) {
return items.get(0);
}
return null; return null;
} }
@Override @Override
protected void onProgressUpdate(Void... values) { protected void onPostExecute(GpxDisplayItem gpxItem) {
progressDialog.show(); if (gpxItem != null && gpxItem.analysis != null) {
} ArrayList<GPXDataSetType> list = new ArrayList<>();
if (gpxItem.analysis.hasElevationData) {
@Override list.add(GPXDataSetType.ALTITUDE);
protected void onPostExecute(Void aVoid) {
List<GpxDisplayItem> items = null;
for (GpxDisplayGroup group : gpxDisplayGroupList) {
if (group.getType() == GpxSelectionHelper.GpxDisplayItemType.TRACK_SEGMENT) {
items = group.getModifiableList();
break;
} }
} if (gpxItem.analysis.hasSpeedData) {
if (items != null && items.size() > 0) { list.add(GPXDataSetType.SPEED);
GpxDisplayItem gpxItem = items.get(0); } else {
if (gpxItem != null && gpxItem.analysis != null) { list.add(GPXDataSetType.SLOPE);
ArrayList<GPXDataSetType> list = new ArrayList<>();
if (gpxItem.analysis.hasElevationData) {
list.add(GPXDataSetType.ALTITUDE);
}
if (gpxItem.analysis.hasSpeedData) {
list.add(GPXDataSetType.SPEED);
} else {
list.add(GPXDataSetType.SLOPE);
}
gpxItem.chartTypes = list.toArray(new GPXDataSetType[list.size()]);
if (gpxItem.group.getGpx() != null) {
gpxItem.wasHidden = app.getSelectedGpxHelper().getSelectedFileByPath(gpxInfo.file.getAbsolutePath()) == null;
app.getSelectedGpxHelper().setGpxFileToDisplay(gpxItem.group.getGpx());
}
final OsmandSettings settings = app.getSettings();
settings.setMapLocationToShow(gpxItem.locationStart.lat, gpxItem.locationStart.lon,
settings.getLastKnownMapZoom(),
new PointDescription(PointDescription.POINT_TYPE_WPT, gpxItem.name),
false,
gpxItem);
progressDialog.dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity());
} }
gpxItem.chartTypes = list.toArray(new GPXDataSetType[list.size()]);
if (gpxItem.group.getGpx() != null) {
gpxItem.wasHidden = app.getSelectedGpxHelper().getSelectedFileByPath(gpxInfo.file.getAbsolutePath()) == null;
app.getSelectedGpxHelper().setGpxFileToDisplay(gpxItem.group.getGpx());
}
final OsmandSettings settings = app.getSettings();
settings.setMapLocationToShow(gpxItem.locationStart.lat, gpxItem.locationStart.lon,
settings.getLastKnownMapZoom(),
new PointDescription(PointDescription.POINT_TYPE_WPT, gpxItem.name),
false,
gpxItem);
progressDialog.dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity());
} else {
progressDialog.dismiss();
} }
} }
} }