Merge pull request #9859 from osmandapp/plan_route_fixes

Plan route fixes
This commit is contained in:
vshcherb 2020-09-21 18:25:48 +02:00 committed by GitHub
commit 1cc690ecf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 36 deletions

View file

@ -138,6 +138,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private boolean pointsListOpened;
private boolean planRouteMode = false;
private boolean directionMode = false;
private boolean followTrackMode = false;
private boolean approximationApplied = false;
private boolean portrait;
private boolean nightMode;
@ -174,6 +175,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
this.directionMode = directionMode;
}
private void setFollowTrackMode(boolean followTrackMode) {
this.followTrackMode = followTrackMode;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -441,8 +446,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
toolBarController.setOnSaveViewClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (followTrackMode) {
startTrackNavigation();
} else {
saveChanges(FinalSaveAction.SHOW_SNACK_BAR_AND_CLOSE, false);
}
}
});
updateToolbar();
@ -486,7 +495,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
public boolean isInEditMode() {
return !planRouteMode && !editingCtx.isNewData() && !directionMode;
return !planRouteMode && !editingCtx.isNewData() && !directionMode && !followTrackMode;
}
public void setFileName(String fileName) {
@ -628,7 +637,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
toolBarController.setTitle(getString(R.string.route_between_points));
mapActivity.refreshMap();
if (editingCtx.isNewData() || editingCtx.hasRoutePoints() || editingCtx.hasRoute() || editingCtx.getPointsCount() < 2) {
if (editingCtx.isNewData() || editingCtx.hasRoutePoints() || editingCtx.hasRoute() || editingCtx.getPointsCount() <= 2) {
RouteBetweenPointsBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
this, RouteBetweenPointsDialogType.WHOLE_ROUTE_CALCULATION,
editingCtx.getLastCalculationMode() == CalculationMode.NEXT_SEGMENT
@ -749,7 +758,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private void runNavigation(final GPXFile gpx, final ApplicationMode appMode) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (mapActivity.getMyApplication().getRoutingHelper().isFollowingMode()) {
OsmandApplication app = mapActivity.getMyApplication();
if (app.getRoutingHelper().isFollowingMode()) {
if (followTrackMode) {
mapActivity.getMapActions().setGPXRouteParams(gpx);
app.getTargetPointsHelper().updateRouteAndRefresh(true);
app.getRoutingHelper().recalculateRouteDueToSettingsChange();
} else {
mapActivity.getMapActions().stopNavigationActionConfirm(new Runnable() {
@Override
public void run() {
@ -759,6 +774,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
}
});
}
} else {
mapActivity.getMapActions().stopNavigationWithoutConfirm();
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpx, appMode, null, null, true, true, MenuState.HEADER_ONLY);
@ -1675,7 +1691,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
break;
case SHOW_IS_SAVED_FRAGMENT:
SavedTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
toSave.getName());
toSave.getAbsolutePath());
dismiss(mapActivity);
break;
case SHOW_TOAST:
@ -1843,8 +1859,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
cancelAddPointBeforeOrAfterMode();
return;
}
if (followTrackMode) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMapLayers().getMapControlsLayer().showRouteInfoControlDialog();
dismiss(mapActivity);
}
} else {
showQuitDialog(hidePointsListFirst);
}
}
private void showQuitDialog(boolean hidePointsListFirst) {
final MapActivity mapActivity = getMapActivity();
@ -1909,11 +1933,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx,
boolean planRoute, boolean directionMode) {
boolean followTrackMode) {
MeasurementToolFragment fragment = new MeasurementToolFragment();
fragment.setEditingCtx(editingCtx);
fragment.setPlanRouteMode(planRoute);
fragment.setDirectionMode(directionMode);
fragment.setFollowTrackMode(followTrackMode);
return showFragment(fragment, fragmentManager);
}
@ -2010,8 +2033,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
exitApproximationMode();
doAddOrMovePointCommonStuff();
updateSnapToRoadControls();
if (directionMode) {
if (directionMode || followTrackMode) {
directionMode = false;
startTrackNavigation();
}
}
private void startTrackNavigation() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (editingCtx.hasRoute()) {
@ -2029,7 +2057,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
}
}
}
@Override
public void onCancelGpxApproximation() {

View file

@ -1,21 +1,26 @@
package net.osmand.plus.measurementtool;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemButton;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.util.Algorithms;
public class SavedTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -34,7 +39,7 @@ public class SavedTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFr
View mainView = View.inflate(UiUtilities.getThemedContext(getMyApplication(), nightMode),
R.layout.measure_track_is_saved, null);
TextView fileNameView = mainView.findViewById(R.id.file_name);
fileNameView.setText(fileName);
fileNameView.setText(Algorithms.getFileWithoutDirs(fileName));
items.add(new SimpleBottomSheetItem.Builder()
.setCustomView(mainView)
.create());
@ -51,10 +56,13 @@ public class SavedTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFr
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Activity activity = getActivity();
if (activity instanceof MapActivity) {
MeasurementToolFragment.showInstance(((MapActivity) activity).getSupportFragmentManager(),
fileName);
FragmentActivity activity = getActivity();
if (activity != null && !Algorithms.isEmpty(fileName)) {
OsmandApplication app = ((OsmandApplication) activity.getApplication());
Intent newIntent = new Intent(activity, app.getAppCustomization().getTrackActivity());
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, fileName);
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(newIntent);
}
dismiss();
}

View file

@ -542,7 +542,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
if (useAppMode) {
editingContext.setAppMode(app.getRoutingHelper().getAppMode());
}
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext, true, true);
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext, true);
}
}