From db8efbfc148f3bf93277b5e7f4b9f94e2255f3c4 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Thu, 19 Dec 2024 08:56:48 +0100 Subject: [PATCH] refactoring RouteParametersFragment --- .../fragments/RouteParametersFragment.java | 96 ++++++++++--------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java index c4ca038b6bd..d3fa2f7c90e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java @@ -66,7 +66,9 @@ import net.osmand.plus.settings.enums.RoutingType; import net.osmand.plus.settings.fragments.search.PreferenceFragmentHandler; import net.osmand.plus.settings.fragments.search.PreferenceFragmentHandlerProvider; -import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialogProvider; +import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog; +import net.osmand.plus.settings.fragments.search.ShowableSearchablePreferenceDialog; +import net.osmand.plus.settings.fragments.search.ShowableSearchablePreferenceDialogProvider; import net.osmand.plus.settings.preferences.ListParameters; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference; @@ -91,9 +93,7 @@ import java.util.Optional; import java.util.Set; -import de.KnollFrank.lib.settingssearch.provider.PreferenceDialogAndSearchableInfoByPreferenceDialogProvider; - -public class RouteParametersFragment extends BaseSettingsFragment implements PreferenceFragmentHandlerProvider, SearchablePreferenceDialogProvider { +public class RouteParametersFragment extends BaseSettingsFragment implements PreferenceFragmentHandlerProvider, ShowableSearchablePreferenceDialogProvider { public static final String TAG = RouteParametersFragment.class.getSimpleName(); @@ -577,17 +577,9 @@ public boolean onPreferenceClick(Preference preference) { HazmatCategoryBottomSheet.showInstance(manager, this, HAZMAT_TRANSPORTING_ENABLED, appMode, false, hazmatParameters.localizedNames, hazmatParameters.values, selectedValueIndex); } } else if (GOODS_RESTRICTIONS_PREFERENCE.equals(prefId)) { - final FragmentManager manager = getFragmentManager(); - if (manager != null) { - GoodsRestrictionsBottomSheet - .createInstance( - this, - preference, - appMode, - false, - getGoodsRestrictionPreference().getModeValue(appMode)) - .show(manager, app); - } + this + .getPreferenceDialogForGoodsRestrictionsPreference(preference, this) + .show(); } else if (ALLOW_VIA_FERRATA_PREFERENCE.equals(prefId)) { FragmentManager manager = getFragmentManager(); if (manager != null) { @@ -635,39 +627,53 @@ public boolean showPreferenceFragment(final PreferenceFragmentCompat preferenceF } @Override - public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { - return this - .getSearchablePreferenceDialog(preference) - .map(SearchablePreferenceDialogFragmentHolder::searchablePreferenceDialogFragment) - .map(preferenceDialog -> - new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>( - preferenceDialog, - _preferenceDialog -> preferenceDialog.getSearchableInfo())); - } - - private Optional> getSearchablePreferenceDialog(final Preference preference) { + public Optional> getShowableSearchablePreferenceDialog( + final Preference preference, + final Fragment target) { if (settings.ROUTE_RECALCULATION_DISTANCE.getId().equals(preference.getKey())) { - return Optional.of( - SearchablePreferenceDialogFragmentHolder.of( - RecalculateRouteInDeviationBottomSheet.createInstance( - preference, - null, - false, - getSelectedAppMode()))); + return Optional.of(getPreferenceDialogForRouteRecalculationDistancePreference(preference, target)); } if (GOODS_RESTRICTIONS_PREFERENCE.equals(preference.getKey())) { - return Optional.of( - SearchablePreferenceDialogFragmentHolder.of( - GoodsRestrictionsBottomSheet.createInstance( - null, - preference, - getSelectedAppMode(), - false, - getGoodsRestrictionPreference().getModeValue(getSelectedAppMode())))); + return Optional.of(getPreferenceDialogForGoodsRestrictionsPreference(preference, target)); } return Optional.empty(); } + private ShowableSearchablePreferenceDialog getPreferenceDialogForRouteRecalculationDistancePreference( + final Preference preference, + final Fragment target) { + return new ShowableSearchablePreferenceDialog<>( + RecalculateRouteInDeviationBottomSheet.createInstance( + preference, + target, + false, + getSelectedAppMode())) { + + @Override + protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) { + searchablePreferenceDialog.show(getFragmentManager(), app); + } + }; + } + + private ShowableSearchablePreferenceDialog getPreferenceDialogForGoodsRestrictionsPreference( + final Preference preference, + final Fragment target) { + return new ShowableSearchablePreferenceDialog<>( + GoodsRestrictionsBottomSheet.createInstance( + target, + preference, + getSelectedAppMode(), + false, + getGoodsRestrictionPreference().getModeValue(getSelectedAppMode()))) { + + @Override + protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) { + searchablePreferenceDialog.show(getFragmentManager(), app); + } + }; + } + @Override public void onDisplayPreferenceDialog(Preference preference) { String prefId = preference.getKey(); @@ -675,11 +681,9 @@ public void onDisplayPreferenceDialog(Preference preference) { FragmentManager manager = getFragmentManager(); if (settings.ROUTE_RECALCULATION_DISTANCE.getId().equals(prefId)) { - if (manager != null) { - RecalculateRouteInDeviationBottomSheet - .createInstance(preference, this, false, getSelectedAppMode()) - .show(manager, RecalculateRouteInDeviationBottomSheet.TAG); - } + this + .getPreferenceDialogForRouteRecalculationDistancePreference(preference, this) + .show(); } else if (!reliefFactorParameters.isEmpty() && prefId.equals(ROUTING_PREFERENCE_PREFIX + USE_HEIGHT_OBSTACLES)) { if (manager != null) { ElevationDateBottomSheet.showInstance(manager, appMode, this, false);