Fix saving gpx at plan route

This commit is contained in:
max-klaus 2020-08-26 15:13:51 +03:00
parent da4c08c05d
commit ffde5da67a
3 changed files with 21 additions and 13 deletions

View file

@ -596,10 +596,10 @@ public class MeasurementEditingContext {
@Override @Override
public void updateProgress(int progress) { public void updateProgress(int progress) {
int pairs = calculatedPairs + pointsToCalculateSize; int pairs = pointsToCalculateSize;
if (pairs != 0) { if (pairs != 0) {
int pairProgress = 100 / pairs; float pairProgress = 100f / pairs;
progress = calculatedPairs * pairProgress + progress / pairs; progress = (int)(calculatedPairs * pairProgress + (float) progress / pairs);
} }
progressListener.updateProgress(progress); progressListener.updateProgress(progress);
} }
@ -633,6 +633,7 @@ public class MeasurementEditingContext {
pts.add(pt); pts.add(pt);
} }
calculatedPairs++; calculatedPairs++;
params.calculationProgressCallback.updateProgress(0);
List<RouteSegmentResult> originalRoute = route.getOriginalRoute(); List<RouteSegmentResult> originalRoute = route.getOriginalRoute();
if (Algorithms.isEmpty(originalRoute)) { if (Algorithms.isEmpty(originalRoute)) {
originalRoute = Collections.singletonList(routePlannerFrontEnd.generateStraightLineSegment( originalRoute = Collections.singletonList(routePlannerFrontEnd.generateStraightLineSegment(

View file

@ -472,13 +472,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
displaySegmentPoints(); displaySegmentPoints();
} }
} }
/*
if (saved == null) {
saved = gpxData != null
&& (gpxData.getActionType() == ActionType.ADD_ROUTE_POINTS
|| gpxData.getActionType() == ActionType.EDIT_SEGMENT);
}
*/
} }
} }
@ -1443,6 +1436,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private ProgressDialog progressDialog; private ProgressDialog progressDialog;
private File toSave; private File toSave;
private GPXFile savedGpxFile;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
@ -1494,6 +1488,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
} }
Exception res = GPXUtilities.writeGpxFile(toSave, gpx); Exception res = GPXUtilities.writeGpxFile(toSave, gpx);
gpx.path = toSave.getAbsolutePath(); gpx.path = toSave.getAbsolutePath();
savedGpxFile = gpx;
if (showOnMap) { if (showOnMap) {
app.getSelectedGpxHelper().selectGpxFile(gpx, true, false); app.getSelectedGpxHelper().selectGpxFile(gpx, true, false);
} }
@ -1564,6 +1559,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
} }
} }
Exception res = GPXUtilities.writeGpxFile(toSave, gpx); Exception res = GPXUtilities.writeGpxFile(toSave, gpx);
savedGpxFile = gpx;
if (showOnMap) { if (showOnMap) {
SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, true, false); SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, true, false);
if (sf != null) { if (sf != null) {
@ -1592,6 +1588,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
mapActivity.refreshMap(); mapActivity.refreshMap();
if (warning == null) { if (warning == null) {
editingCtx.setChangesSaved(); editingCtx.setChangesSaved();
if (editingCtx.isNewData() && savedGpxFile != null) {
QuadRect rect = savedGpxFile.getRect();
TrkSegment segment = savedGpxFile.getNonEmptyTrkSegment();
GpxData gpxData = new GpxData(savedGpxFile, rect, ActionType.EDIT_SEGMENT, segment);
editingCtx.setGpxData(gpxData);
updateToolbar();
}
if (isInEditMode()) { if (isInEditMode()) {
dismiss(mapActivity); dismiss(mapActivity);
} else { } else {
@ -1605,7 +1608,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
public void onClick(View view) { public void onClick(View view) {
MapActivity mapActivity = mapActivityRef.get(); MapActivity mapActivity = mapActivityRef.get();
if (AndroidUtils.isActivityNotDestroyed(mapActivity)) { if (AndroidUtils.isActivityNotDestroyed(mapActivity)) {
FileUtils.renameFile(mapActivity, toSave, null); FileUtils.renameFile(mapActivity, toSave, new FileUtils.RenameCallback() {
@Override
public void renamedTo(File file) {
}
});
} }
} }
}); });

View file

@ -1263,13 +1263,12 @@ public class RoutingHelper {
public void run() { public void run() {
RouteCalculationProgress calculationProgress = params.calculationProgress; RouteCalculationProgress calculationProgress = params.calculationProgress;
if (isRouteBeingCalculated()) { if (isRouteBeingCalculated()) {
float pr = calculationProgress.getLinearProgress();
progressRoute.updateProgress((int) pr);
Thread t = currentRunningJob; Thread t = currentRunningJob;
if(t instanceof RouteRecalculationThread && ((RouteRecalculationThread) t).params != params) { if(t instanceof RouteRecalculationThread && ((RouteRecalculationThread) t).params != params) {
// different calculation started // different calculation started
return; return;
} else { } else {
progressRoute.updateProgress((int) calculationProgress.getLinearProgress());
if (calculationProgress.requestPrivateAccessRouting) { if (calculationProgress.requestPrivateAccessRouting) {
progressRoute.requestPrivateAccessRouting(); progressRoute.requestPrivateAccessRouting();
} }