Fix "Configure Profile" button in Plan Route

This commit is contained in:
nazar-kutz 2020-12-14 18:32:09 +02:00
parent 639537280b
commit da6273d126
6 changed files with 166 additions and 63 deletions

View file

@ -9,27 +9,30 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="2dp">
<ImageButton
android:id="@+id/profile"
android:layout_width="@dimen/map_route_buttons_height_land"
android:layout_height="@dimen/map_route_buttons_height_land"
app:srcCompat="@drawable/ic_action_car_dark"
android:background="@color/color_transparent"
android:contentDescription="@string/app_modes_choose"/>
<View
android:id="@+id/divider"
android:layout_width="1dp"
android:layout_height="24dp"
android:background="?attr/divider_color"
android:layout_gravity="center_vertical"/>
<ImageButton
android:id="@+id/profile"
android:layout_width="@dimen/map_route_buttons_height_land"
android:layout_height="@dimen/map_route_buttons_height_land"
app:srcCompat="@drawable/ic_action_car_dark"
android:background="@color/color_transparent"
android:contentDescription="@string/app_modes_choose"/>
<View
android:id="@+id/divider"
android:layout_width="1dp"
android:layout_height="24dp"
android:background="?attr/divider_color"
android:layout_gravity="center_vertical"/>
<ImageButton
android:id="@+id/profile_config"
android:layout_width="@dimen/map_route_buttons_height_land"
android:layout_height="@dimen/map_route_buttons_height_land"
app:srcCompat="@drawable/ic_action_settings"
android:background="@color/color_transparent"
android:contentDescription="@string/configure_profile" />
<ImageButton
android:id="@+id/profile_config"
android:layout_width="@dimen/map_route_buttons_height_land"
android:layout_height="@dimen/map_route_buttons_height_land"
app:srcCompat="@drawable/ic_action_settings"
android:background="@color/color_transparent"
android:contentDescription="@string/configure_profile" />
</LinearLayout>
</LinearLayout>

View file

@ -385,6 +385,22 @@ public class MeasurementEditingContext {
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) {
List<WptPt> points = new ArrayList<>();
points.addAll(before.points);

View file

@ -71,6 +71,7 @@ import net.osmand.plus.measurementtool.command.RemovePointCommand;
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
import net.osmand.plus.measurementtool.command.ReversePointsCommand;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DialogMode;
import net.osmand.plus.measurementtool.command.SplitPointsCommand;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
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,
OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener,
SaveAsNewTrackFragmentListener, MapControlsLayer.MapControlsThemeInfoProvider {
SaveAsNewTrackFragmentListener, MapControlsLayer.MapControlsThemeInfoProvider,
RouteOptionsBottomSheet.OnAppModeConfiguredCallback{
public static final String TAG = MeasurementToolFragment.class.getSimpleName();
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 mainIcon;
private String fileName;
private OnBackPressedCallback onBackPressedCallback;
private InfoType currentInfoType;
@ -218,11 +221,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
onBackPressedCallback = new OnBackPressedCallback(true) {
public void handleOnBackPressed() {
quit(true);
}
});
};
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
}
@Nullable
@ -531,7 +535,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
configBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RouteOptionsBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
RouteOptionsBottomSheet.showInstance(
mapActivity, MeasurementToolFragment.this, DialogMode.PLAN_ROUTE,
editingCtx.getAppMode().getStringKey());
}
});
@ -551,6 +556,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return view;
}
public OnBackPressedCallback getOnBackPressedCallback() {
return onBackPressedCallback;
}
private OnRadioItemClickListener getInfoTypeBtnListener(@NonNull final InfoType type) {
return new OnRadioItemClickListener() {
@Override
@ -687,6 +696,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
super.onResume();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
onBackPressedCallback.setEnabled(true);
detailsMenu.setMapActivity(mapActivity);
mapActivity.getMapLayers().getMapControlsLayer().addThemeInfoProviderTag(TAG);
mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden();
@ -1091,6 +1101,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
updateDistancePointsText();
}
@Override
public void onAppModeConfigured() {
editingCtx.recalculateRouteSegmentsForAppMode();
updateDistancePointsText();
}
@Override
public void onChangeRouteTypeBefore() {
MapActivity mapActivity = getMapActivity();

View file

@ -1535,7 +1535,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
private void clickRouteParams() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
RouteOptionsBottomSheet.showInstance(mapActivity.getSupportFragmentManager());
RouteOptionsBottomSheet.showInstance(mapActivity);
}
}

View file

@ -55,6 +55,7 @@ import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.bottomsheets.ElevationDateBottomSheet;
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.RoutingParameter;
import net.osmand.util.Algorithms;
@ -67,8 +68,6 @@ import java.util.Arrays;
import java.util.List;
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.settings.fragments.RouteParametersFragment.RELIEF_SMOOTHNESS_FACTOR;
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();
private static final Log LOG = PlatformUtil.getLog(RouteOptionsBottomSheet.class);
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 OsmandSettings settings;
@ -95,8 +94,38 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
private CommonPreference<Boolean> useHeightPref;
private StateChangedListener<Boolean> voiceMuteChangeListener;
private StateChangedListener<Boolean> useHeightChangeListener;
private boolean planRouteMode;
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
public void onCreate(Bundle savedInstanceState) {
@ -106,8 +135,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
String appMode = args.getString(APP_MODE_KEY, null);
if (appMode != null) {
applicationMode = ApplicationMode.valueOfStringKey(appMode, null);
planRouteMode = true;
}
String dialogModeName = args.getString(DIALOG_MODE_KEY, null);
dialogMode = DialogMode.getModeByName(dialogModeName);
}
app = requiredMyApplication();
settings = app.getSettings();
@ -117,6 +147,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
if (applicationMode == null) {
applicationMode = routingHelper.getAppMode();
}
if (dialogMode == null) {
dialogMode = DialogMode.DIRECTIONS;
}
selectedModeColorId = applicationMode.getIconColorInfo().getColor(nightMode);
voiceMuteChangeListener = new StateChangedListener<Boolean>() {
@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));
List<LocalRoutingParameter> list = getRoutingParameters(applicationMode);
for (final LocalRoutingParameter optionsItem : list) {
if (!dialogMode.isAvailableParameter(optionsItem)) {
continue;
}
if (optionsItem instanceof DividerItem) {
items.add(new DividerStartItem(app));
} else if (optionsItem instanceof MuteSoundRoutingParameter) {
if (!planRouteMode) {
items.add(createMuteSoundItem(optionsItem));
if (isDividerRequired()) {
items.add(new DividerStartItem(app));
}
} else if (optionsItem instanceof MuteSoundRoutingParameter) {
items.add(createMuteSoundItem(optionsItem));
} else if (optionsItem instanceof ShowAlongTheRouteItem) {
items.add(createShowAlongTheRouteItem(optionsItem));
} else if (optionsItem instanceof RouteSimulationItem) {
if (!planRouteMode) {
items.add(createRouteSimulationItem(optionsItem));
}
items.add(createRouteSimulationItem(optionsItem));
} else if (optionsItem instanceof AvoidPTTypesRoutingParameter) {
items.add(createAvoidPTTypesItem(optionsItem));
} else if (optionsItem instanceof AvoidRoadsRoutingParameter) {
items.add(createAvoidRoadsItem(optionsItem));
} else if (optionsItem instanceof GpxLocalRoutingParameter) {
if (!planRouteMode) {
items.add(createGpxRoutingItem(optionsItem));
}
items.add(createGpxRoutingItem(optionsItem));
} else if (optionsItem instanceof TimeConditionalRoutingItem) {
items.add(createTimeConditionalRoutingItem(optionsItem));
} 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
public void onResume() {
super.onResume();
@ -282,8 +319,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
voicePromptsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BaseSettingsFragment.showInstance(
mapActivity, BaseSettingsFragment.SettingsScreenType.VOICE_ANNOUNCES);
BaseSettingsFragment.showInstance(mapActivity, SettingsScreenType.VOICE_ANNOUNCES);
dismiss();
}
});
@ -508,10 +544,16 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
@Override
public void onClick(View view) {
dismiss();
Fragment fragment = getTargetFragment();
if (fragment instanceof MeasurementToolFragment) {
((MeasurementToolFragment) fragment).getOnBackPressedCallback().setEnabled(false);
}
Bundle args = new Bundle();
args.putBoolean(PLANE_ROUTE, planRouteMode);
BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.NAVIGATION,
applicationMode, args);
args.putString(DIALOG_MODE_KEY, dialogMode.name());
BaseSettingsFragment.showInstance(mapActivity,
SettingsScreenType.NAVIGATION, applicationMode, args);
}
})
.create();
@ -614,16 +656,13 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
@Override
public void onDismiss(@NonNull DialogInterface dialog) {
super.onDismiss(dialog);
updatePlanRoute();
notifyAppModeConfigurationChanged();
}
private void updatePlanRoute() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(MeasurementToolFragment.TAG);
if (fragment != null) {
((MeasurementToolFragment) fragment).onChangeApplicationMode(applicationMode, WHOLE_ROUTE_CALCULATION, ALL);
}
private void notifyAppModeConfigurationChanged() {
Fragment fragment = getTargetFragment();
if (fragment instanceof OnAppModeConfiguredCallback) {
((OnAppModeConfiguredCallback) fragment).onAppModeConfigured();
}
}
@ -658,17 +697,23 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
return (MapActivity) getActivity();
}
public static void showInstance(FragmentManager fragmentManager) {
showInstance(fragmentManager, null);
public static void showInstance(MapActivity mapActivity) {
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 {
FragmentManager fm = mapActivity.getSupportFragmentManager();
if (!fm.isStateSaved()) {
RouteOptionsBottomSheet fragment = new RouteOptionsBottomSheet();
Bundle args = new Bundle();
args.putString(APP_MODE_KEY, appModeKey);
args.putString(DIALOG_MODE_KEY, dialogMode.name());
fragment.setArguments(args);
fragment.setTargetFragment(targetFragment, 0);
fragment.show(fm, TAG);
}
} catch (RuntimeException e) {
@ -694,6 +739,10 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
}
}
public interface OnAppModeConfiguredCallback {
void onAppModeConfigured();
}
public enum AppModeOptions {
CAR(MuteSoundRoutingParameter.KEY,

View file

@ -4,10 +4,14 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import androidx.activity.OnBackPressedCallback;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
import androidx.preference.SwitchPreferenceCompat;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DialogMode;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication;
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.SELECTED_KEY;
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 {
@ -51,16 +55,31 @@ public class NavigationFragment extends BaseSettingsFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
routingProfileDataObjects = getRoutingProfiles(app);
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
setupOnBackPressedCallback();
}
private void setupOnBackPressedCallback() {
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
public void handleOnBackPressed() {
MapActivity mapActivity = getMapActivity();
Bundle args = getArguments();
if (args != null && args.getBoolean(PLANE_ROUTE, false)) {
RouteOptionsBottomSheet.showInstance(getMapActivity().getSupportFragmentManager(),
getSelectedAppMode().getStringKey());
if (mapActivity != null && args != null) {
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());
((MeasurementToolFragment) fragment).getOnBackPressedCallback().setEnabled(true);
}
}
}
dismiss();
}
});
};
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, callback);
}
@Override