Fix "Configure Profile" button in Plan Route
This commit is contained in:
parent
639537280b
commit
da6273d126
6 changed files with 166 additions and 63 deletions
|
@ -9,6 +9,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:elevation="2dp">
|
android:elevation="2dp">
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/profile"
|
android:id="@+id/profile"
|
||||||
android:layout_width="@dimen/map_route_buttons_height_land"
|
android:layout_width="@dimen/map_route_buttons_height_land"
|
||||||
|
@ -31,5 +32,7 @@
|
||||||
app:srcCompat="@drawable/ic_action_settings"
|
app:srcCompat="@drawable/ic_action_settings"
|
||||||
android:background="@color/color_transparent"
|
android:background="@color/color_transparent"
|
||||||
android:contentDescription="@string/configure_profile" />
|
android:contentDescription="@string/configure_profile" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -385,6 +385,22 @@ public class MeasurementEditingContext {
|
||||||
return allSegments.size() > 0 ? allSegments : null;
|
return allSegments.size() > 0 ? allSegments : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void recalculateRouteSegmentsForAppMode() {
|
||||||
|
clearRouteSegmentsByAppMode();
|
||||||
|
updateSegmentsForSnap();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearRouteSegmentsByAppMode() {
|
||||||
|
for (Pair<WptPt, WptPt> key : getOrderedRoadSegmentDataKeys()) {
|
||||||
|
if(key.first.getProfileType().equals(appMode.getStringKey())) {
|
||||||
|
RoadSegmentData data = roadSegmentData.get(key);
|
||||||
|
if (data != null) {
|
||||||
|
roadSegmentData.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void splitSegments(int position) {
|
void splitSegments(int position) {
|
||||||
List<WptPt> points = new ArrayList<>();
|
List<WptPt> points = new ArrayList<>();
|
||||||
points.addAll(before.points);
|
points.addAll(before.points);
|
||||||
|
|
|
@ -71,6 +71,7 @@ import net.osmand.plus.measurementtool.command.RemovePointCommand;
|
||||||
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
|
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
|
||||||
import net.osmand.plus.measurementtool.command.ReversePointsCommand;
|
import net.osmand.plus.measurementtool.command.ReversePointsCommand;
|
||||||
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
|
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
|
||||||
|
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DialogMode;
|
||||||
import net.osmand.plus.measurementtool.command.SplitPointsCommand;
|
import net.osmand.plus.measurementtool.command.SplitPointsCommand;
|
||||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
|
@ -107,7 +108,8 @@ import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCo
|
||||||
|
|
||||||
public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener,
|
public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener,
|
||||||
OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener,
|
OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener,
|
||||||
SaveAsNewTrackFragmentListener, MapControlsLayer.MapControlsThemeInfoProvider {
|
SaveAsNewTrackFragmentListener, MapControlsLayer.MapControlsThemeInfoProvider,
|
||||||
|
RouteOptionsBottomSheet.OnAppModeConfiguredCallback{
|
||||||
|
|
||||||
public static final String TAG = MeasurementToolFragment.class.getSimpleName();
|
public static final String TAG = MeasurementToolFragment.class.getSimpleName();
|
||||||
public static final String TAPS_DISABLED_KEY = "taps_disabled_key";
|
public static final String TAPS_DISABLED_KEY = "taps_disabled_key";
|
||||||
|
@ -131,6 +133,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
private ImageView redoBtn;
|
private ImageView redoBtn;
|
||||||
private ImageView mainIcon;
|
private ImageView mainIcon;
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
private OnBackPressedCallback onBackPressedCallback;
|
||||||
|
|
||||||
private InfoType currentInfoType;
|
private InfoType currentInfoType;
|
||||||
|
|
||||||
|
@ -218,11 +221,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
onBackPressedCallback = new OnBackPressedCallback(true) {
|
||||||
public void handleOnBackPressed() {
|
public void handleOnBackPressed() {
|
||||||
quit(true);
|
quit(true);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -531,7 +535,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
configBtn.setOnClickListener(new OnClickListener() {
|
configBtn.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
RouteOptionsBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
|
RouteOptionsBottomSheet.showInstance(
|
||||||
|
mapActivity, MeasurementToolFragment.this, DialogMode.PLAN_ROUTE,
|
||||||
editingCtx.getAppMode().getStringKey());
|
editingCtx.getAppMode().getStringKey());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -551,6 +556,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OnBackPressedCallback getOnBackPressedCallback() {
|
||||||
|
return onBackPressedCallback;
|
||||||
|
}
|
||||||
|
|
||||||
private OnRadioItemClickListener getInfoTypeBtnListener(@NonNull final InfoType type) {
|
private OnRadioItemClickListener getInfoTypeBtnListener(@NonNull final InfoType type) {
|
||||||
return new OnRadioItemClickListener() {
|
return new OnRadioItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -687,6 +696,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
super.onResume();
|
super.onResume();
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
|
onBackPressedCallback.setEnabled(true);
|
||||||
detailsMenu.setMapActivity(mapActivity);
|
detailsMenu.setMapActivity(mapActivity);
|
||||||
mapActivity.getMapLayers().getMapControlsLayer().addThemeInfoProviderTag(TAG);
|
mapActivity.getMapLayers().getMapControlsLayer().addThemeInfoProviderTag(TAG);
|
||||||
mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden();
|
mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden();
|
||||||
|
@ -1091,6 +1101,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
||||||
updateDistancePointsText();
|
updateDistancePointsText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAppModeConfigured() {
|
||||||
|
editingCtx.recalculateRouteSegmentsForAppMode();
|
||||||
|
updateDistancePointsText();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChangeRouteTypeBefore() {
|
public void onChangeRouteTypeBefore() {
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
|
|
|
@ -1535,7 +1535,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
||||||
private void clickRouteParams() {
|
private void clickRouteParams() {
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
RouteOptionsBottomSheet.showInstance(mapActivity.getSupportFragmentManager());
|
RouteOptionsBottomSheet.showInstance(mapActivity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ import net.osmand.plus.settings.backend.CommonPreference;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
import net.osmand.plus.settings.bottomsheets.ElevationDateBottomSheet;
|
import net.osmand.plus.settings.bottomsheets.ElevationDateBottomSheet;
|
||||||
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
||||||
|
import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType;
|
||||||
import net.osmand.router.GeneralRouter;
|
import net.osmand.router.GeneralRouter;
|
||||||
import net.osmand.router.GeneralRouter.RoutingParameter;
|
import net.osmand.router.GeneralRouter.RoutingParameter;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
@ -67,8 +68,6 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static net.osmand.plus.measurementtool.RouteBetweenPointsBottomSheetDialogFragment.RouteBetweenPointsDialogMode.ALL;
|
|
||||||
import static net.osmand.plus.measurementtool.RouteBetweenPointsBottomSheetDialogFragment.RouteBetweenPointsDialogType.WHOLE_ROUTE_CALCULATION;
|
|
||||||
import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE;
|
import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE;
|
||||||
import static net.osmand.plus.settings.fragments.RouteParametersFragment.RELIEF_SMOOTHNESS_FACTOR;
|
import static net.osmand.plus.settings.fragments.RouteParametersFragment.RELIEF_SMOOTHNESS_FACTOR;
|
||||||
import static net.osmand.plus.settings.fragments.RouteParametersFragment.getRoutingParameterTitle;
|
import static net.osmand.plus.settings.fragments.RouteParametersFragment.getRoutingParameterTitle;
|
||||||
|
@ -80,7 +79,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
public static final String TAG = RouteOptionsBottomSheet.class.getSimpleName();
|
public static final String TAG = RouteOptionsBottomSheet.class.getSimpleName();
|
||||||
private static final Log LOG = PlatformUtil.getLog(RouteOptionsBottomSheet.class);
|
private static final Log LOG = PlatformUtil.getLog(RouteOptionsBottomSheet.class);
|
||||||
public static final String APP_MODE_KEY = "APP_MODE_KEY";
|
public static final String APP_MODE_KEY = "APP_MODE_KEY";
|
||||||
public static final String PLANE_ROUTE = "PLANE_ROUTE";
|
public static final String DIALOG_MODE_KEY = "DIALOG_MODE_KEY";
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private OsmandSettings settings;
|
private OsmandSettings settings;
|
||||||
|
@ -95,8 +94,38 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
private CommonPreference<Boolean> useHeightPref;
|
private CommonPreference<Boolean> useHeightPref;
|
||||||
private StateChangedListener<Boolean> voiceMuteChangeListener;
|
private StateChangedListener<Boolean> voiceMuteChangeListener;
|
||||||
private StateChangedListener<Boolean> useHeightChangeListener;
|
private StateChangedListener<Boolean> useHeightChangeListener;
|
||||||
private boolean planRouteMode;
|
|
||||||
private List<RoutingParameter> reliefParameters = new ArrayList<>();
|
private List<RoutingParameter> reliefParameters = new ArrayList<>();
|
||||||
|
private DialogMode dialogMode;
|
||||||
|
|
||||||
|
public enum DialogMode {
|
||||||
|
DIRECTIONS(),
|
||||||
|
PLAN_ROUTE(MuteSoundRoutingParameter.class,
|
||||||
|
RouteSimulationItem.class,
|
||||||
|
GpxLocalRoutingParameter.class);
|
||||||
|
|
||||||
|
private final Class<? extends LocalRoutingParameter>[] excludeParameters;
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
DialogMode(Class<? extends LocalRoutingParameter> ... excludeParameters) {
|
||||||
|
this.excludeParameters = excludeParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAvailableParameter(LocalRoutingParameter parameter) {
|
||||||
|
for (Class<? extends LocalRoutingParameter> c : excludeParameters) {
|
||||||
|
if (Algorithms.objectEquals(parameter.getClass(), c)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DialogMode getModeByName(String modeName) {
|
||||||
|
if (modeName != null) {
|
||||||
|
return valueOf(modeName);
|
||||||
|
}
|
||||||
|
return DIRECTIONS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -106,8 +135,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
String appMode = args.getString(APP_MODE_KEY, null);
|
String appMode = args.getString(APP_MODE_KEY, null);
|
||||||
if (appMode != null) {
|
if (appMode != null) {
|
||||||
applicationMode = ApplicationMode.valueOfStringKey(appMode, null);
|
applicationMode = ApplicationMode.valueOfStringKey(appMode, null);
|
||||||
planRouteMode = true;
|
|
||||||
}
|
}
|
||||||
|
String dialogModeName = args.getString(DIALOG_MODE_KEY, null);
|
||||||
|
dialogMode = DialogMode.getModeByName(dialogModeName);
|
||||||
}
|
}
|
||||||
app = requiredMyApplication();
|
app = requiredMyApplication();
|
||||||
settings = app.getSettings();
|
settings = app.getSettings();
|
||||||
|
@ -117,6 +147,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
if (applicationMode == null) {
|
if (applicationMode == null) {
|
||||||
applicationMode = routingHelper.getAppMode();
|
applicationMode = routingHelper.getAppMode();
|
||||||
}
|
}
|
||||||
|
if (dialogMode == null) {
|
||||||
|
dialogMode = DialogMode.DIRECTIONS;
|
||||||
|
}
|
||||||
selectedModeColorId = applicationMode.getIconColorInfo().getColor(nightMode);
|
selectedModeColorId = applicationMode.getIconColorInfo().getColor(nightMode);
|
||||||
voiceMuteChangeListener = new StateChangedListener<Boolean>() {
|
voiceMuteChangeListener = new StateChangedListener<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,28 +172,27 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
items.add(new TitleItem(app.getString(R.string.shared_string_settings), nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
items.add(new TitleItem(app.getString(R.string.shared_string_settings), nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||||
|
|
||||||
List<LocalRoutingParameter> list = getRoutingParameters(applicationMode);
|
List<LocalRoutingParameter> list = getRoutingParameters(applicationMode);
|
||||||
|
|
||||||
for (final LocalRoutingParameter optionsItem : list) {
|
for (final LocalRoutingParameter optionsItem : list) {
|
||||||
if (optionsItem instanceof DividerItem) {
|
if (!dialogMode.isAvailableParameter(optionsItem)) {
|
||||||
items.add(new DividerStartItem(app));
|
continue;
|
||||||
} else if (optionsItem instanceof MuteSoundRoutingParameter) {
|
|
||||||
if (!planRouteMode) {
|
|
||||||
items.add(createMuteSoundItem(optionsItem));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (optionsItem instanceof DividerItem) {
|
||||||
|
if (isDividerRequired()) {
|
||||||
|
items.add(new DividerStartItem(app));
|
||||||
|
}
|
||||||
|
} else if (optionsItem instanceof MuteSoundRoutingParameter) {
|
||||||
|
items.add(createMuteSoundItem(optionsItem));
|
||||||
} else if (optionsItem instanceof ShowAlongTheRouteItem) {
|
} else if (optionsItem instanceof ShowAlongTheRouteItem) {
|
||||||
items.add(createShowAlongTheRouteItem(optionsItem));
|
items.add(createShowAlongTheRouteItem(optionsItem));
|
||||||
} else if (optionsItem instanceof RouteSimulationItem) {
|
} else if (optionsItem instanceof RouteSimulationItem) {
|
||||||
if (!planRouteMode) {
|
|
||||||
items.add(createRouteSimulationItem(optionsItem));
|
items.add(createRouteSimulationItem(optionsItem));
|
||||||
}
|
|
||||||
} else if (optionsItem instanceof AvoidPTTypesRoutingParameter) {
|
} else if (optionsItem instanceof AvoidPTTypesRoutingParameter) {
|
||||||
items.add(createAvoidPTTypesItem(optionsItem));
|
items.add(createAvoidPTTypesItem(optionsItem));
|
||||||
} else if (optionsItem instanceof AvoidRoadsRoutingParameter) {
|
} else if (optionsItem instanceof AvoidRoadsRoutingParameter) {
|
||||||
items.add(createAvoidRoadsItem(optionsItem));
|
items.add(createAvoidRoadsItem(optionsItem));
|
||||||
} else if (optionsItem instanceof GpxLocalRoutingParameter) {
|
} else if (optionsItem instanceof GpxLocalRoutingParameter) {
|
||||||
if (!planRouteMode) {
|
|
||||||
items.add(createGpxRoutingItem(optionsItem));
|
items.add(createGpxRoutingItem(optionsItem));
|
||||||
}
|
|
||||||
} else if (optionsItem instanceof TimeConditionalRoutingItem) {
|
} else if (optionsItem instanceof TimeConditionalRoutingItem) {
|
||||||
items.add(createTimeConditionalRoutingItem(optionsItem));
|
items.add(createTimeConditionalRoutingItem(optionsItem));
|
||||||
} else if (optionsItem instanceof OtherSettingsRoutingParameter) {
|
} else if (optionsItem instanceof OtherSettingsRoutingParameter) {
|
||||||
|
@ -173,6 +205,11 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDividerRequired() {
|
||||||
|
// do not show two dividers at once
|
||||||
|
return items.size() > 1 && !(items.get(items.size() - 1) instanceof DividerStartItem);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -282,8 +319,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
voicePromptsBtn.setOnClickListener(new View.OnClickListener() {
|
voicePromptsBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
BaseSettingsFragment.showInstance(
|
BaseSettingsFragment.showInstance(mapActivity, SettingsScreenType.VOICE_ANNOUNCES);
|
||||||
mapActivity, BaseSettingsFragment.SettingsScreenType.VOICE_ANNOUNCES);
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -508,10 +544,16 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
dismiss();
|
dismiss();
|
||||||
|
|
||||||
|
Fragment fragment = getTargetFragment();
|
||||||
|
if (fragment instanceof MeasurementToolFragment) {
|
||||||
|
((MeasurementToolFragment) fragment).getOnBackPressedCallback().setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putBoolean(PLANE_ROUTE, planRouteMode);
|
args.putString(DIALOG_MODE_KEY, dialogMode.name());
|
||||||
BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.NAVIGATION,
|
BaseSettingsFragment.showInstance(mapActivity,
|
||||||
applicationMode, args);
|
SettingsScreenType.NAVIGATION, applicationMode, args);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.create();
|
.create();
|
||||||
|
@ -614,16 +656,13 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||||
super.onDismiss(dialog);
|
super.onDismiss(dialog);
|
||||||
updatePlanRoute();
|
notifyAppModeConfigurationChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePlanRoute() {
|
private void notifyAppModeConfigurationChanged() {
|
||||||
MapActivity mapActivity = getMapActivity();
|
Fragment fragment = getTargetFragment();
|
||||||
if (mapActivity != null) {
|
if (fragment instanceof OnAppModeConfiguredCallback) {
|
||||||
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(MeasurementToolFragment.TAG);
|
((OnAppModeConfiguredCallback) fragment).onAppModeConfigured();
|
||||||
if (fragment != null) {
|
|
||||||
((MeasurementToolFragment) fragment).onChangeApplicationMode(applicationMode, WHOLE_ROUTE_CALCULATION, ALL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,17 +697,23 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
return (MapActivity) getActivity();
|
return (MapActivity) getActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstance(FragmentManager fragmentManager) {
|
public static void showInstance(MapActivity mapActivity) {
|
||||||
showInstance(fragmentManager, null);
|
showInstance(mapActivity, null, DialogMode.DIRECTIONS, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstance(FragmentManager fm, String appModeKey) {
|
public static void showInstance(MapActivity mapActivity,
|
||||||
|
Fragment targetFragment,
|
||||||
|
DialogMode dialogMode,
|
||||||
|
String appModeKey) {
|
||||||
try {
|
try {
|
||||||
|
FragmentManager fm = mapActivity.getSupportFragmentManager();
|
||||||
if (!fm.isStateSaved()) {
|
if (!fm.isStateSaved()) {
|
||||||
RouteOptionsBottomSheet fragment = new RouteOptionsBottomSheet();
|
RouteOptionsBottomSheet fragment = new RouteOptionsBottomSheet();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(APP_MODE_KEY, appModeKey);
|
args.putString(APP_MODE_KEY, appModeKey);
|
||||||
|
args.putString(DIALOG_MODE_KEY, dialogMode.name());
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
|
fragment.setTargetFragment(targetFragment, 0);
|
||||||
fragment.show(fm, TAG);
|
fragment.show(fm, TAG);
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
@ -694,6 +739,10 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface OnAppModeConfiguredCallback {
|
||||||
|
void onAppModeConfigured();
|
||||||
|
}
|
||||||
|
|
||||||
public enum AppModeOptions {
|
public enum AppModeOptions {
|
||||||
|
|
||||||
CAR(MuteSoundRoutingParameter.KEY,
|
CAR(MuteSoundRoutingParameter.KEY,
|
||||||
|
|
|
@ -4,10 +4,14 @@ import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.activity.OnBackPressedCallback;
|
import androidx.activity.OnBackPressedCallback;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.SwitchPreferenceCompat;
|
import androidx.preference.SwitchPreferenceCompat;
|
||||||
|
|
||||||
|
import net.osmand.plus.measurementtool.MeasurementToolFragment;
|
||||||
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
|
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
|
||||||
|
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DialogMode;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
|
@ -35,7 +39,7 @@ import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS
|
||||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
|
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
|
||||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
|
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
|
||||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
|
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
|
||||||
import static net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.PLANE_ROUTE;
|
import static net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DIALOG_MODE_KEY;
|
||||||
|
|
||||||
public class NavigationFragment extends BaseSettingsFragment {
|
public class NavigationFragment extends BaseSettingsFragment {
|
||||||
|
|
||||||
|
@ -51,16 +55,31 @@ public class NavigationFragment extends BaseSettingsFragment {
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
routingProfileDataObjects = getRoutingProfiles(app);
|
routingProfileDataObjects = getRoutingProfiles(app);
|
||||||
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
setupOnBackPressedCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupOnBackPressedCallback() {
|
||||||
|
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
|
||||||
public void handleOnBackPressed() {
|
public void handleOnBackPressed() {
|
||||||
|
MapActivity mapActivity = getMapActivity();
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
if (args != null && args.getBoolean(PLANE_ROUTE, false)) {
|
if (mapActivity != null && args != null) {
|
||||||
RouteOptionsBottomSheet.showInstance(getMapActivity().getSupportFragmentManager(),
|
String dialogModeName = args.getString(DIALOG_MODE_KEY, null);
|
||||||
|
if (DialogMode.getModeByName(dialogModeName) == DialogMode.PLAN_ROUTE) {
|
||||||
|
FragmentManager fm = mapActivity.getSupportFragmentManager();
|
||||||
|
Fragment fragment = fm.findFragmentByTag(MeasurementToolFragment.TAG);
|
||||||
|
if (fragment != null) {
|
||||||
|
RouteOptionsBottomSheet.showInstance(
|
||||||
|
mapActivity, fragment, DialogMode.PLAN_ROUTE,
|
||||||
getSelectedAppMode().getStringKey());
|
getSelectedAppMode().getStringKey());
|
||||||
|
((MeasurementToolFragment) fragment).getOnBackPressedCallback().setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue