diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/FuelTankCapacityBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/FuelTankCapacityBottomSheet.java index 7d0e6b96718..5d369cf5f62 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/FuelTankCapacityBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/FuelTankCapacityBottomSheet.java @@ -9,6 +9,7 @@ import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import androidx.preference.Preference; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; @@ -19,6 +20,7 @@ import net.osmand.plus.settings.enums.VolumeUnit; import net.osmand.plus.settings.fragments.ApplyQueryType; import net.osmand.plus.settings.fragments.OnConfirmPreferenceChange; +import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog; import net.osmand.plus.utils.OsmAndFormatter; import net.osmand.plus.widgets.chips.ChipItem; import net.osmand.plus.widgets.dialogbutton.DialogButtonType; @@ -33,7 +35,7 @@ import java.util.List; import java.util.Locale; -public class FuelTankCapacityBottomSheet extends BaseTextFieldBottomSheet { +public class FuelTankCapacityBottomSheet extends BaseTextFieldBottomSheet implements SearchablePreferenceDialog { private static final Log LOG = PlatformUtil.getLog(VehicleParametersBottomSheet.class); public static final String TAG = FuelTankCapacityBottomSheet.class.getSimpleName(); @@ -77,7 +79,7 @@ public void afterTextChanged(Editable s) { @NonNull public List collectChipItems(@NonNull OsmandApplication app, - @NonNull VolumeUnit volumeUnit) { + @NonNull VolumeUnit volumeUnit) { List chips = new ArrayList<>(); String none = app.getString(R.string.shared_string_none); ChipItem chip = new ChipItem(none); @@ -129,21 +131,42 @@ protected String formatInputValue(float input) { return formatter.format(input); } - public static void showInstance(@NonNull FragmentManager fm, String key, Fragment target, - boolean usedOnMap, @Nullable ApplicationMode appMode) { + @NonNull + public static FuelTankCapacityBottomSheet createInstance(final Preference preference, + final Fragment target, + final boolean usedOnMap, + final @Nullable ApplicationMode appMode, + final boolean configureSettingsSearch) { + final Bundle args = new Bundle(); + args.putString(PREFERENCE_ID, preference.getKey()); + final FuelTankCapacityBottomSheet fragment = new FuelTankCapacityBottomSheet(); + fragment.setArguments(args); + fragment.setUsedOnMap(usedOnMap); + fragment.setAppMode(appMode); + fragment.setTargetFragment(target, 0); + if (target == null) { + fragment.setPreference(preference); + } + fragment.setConfigureSettingsSearch(configureSettingsSearch); + return fragment; + } + + @Override + public void show(final FragmentManager fragmentManager, final OsmandApplication app) { try { - if (!fm.isStateSaved()) { - Bundle args = new Bundle(); - args.putString(PREFERENCE_ID, key); - FuelTankCapacityBottomSheet fragment = new FuelTankCapacityBottomSheet(); - fragment.setArguments(args); - fragment.setUsedOnMap(usedOnMap); - fragment.setAppMode(appMode); - fragment.setTargetFragment(target, 0); - fragment.show(fm, TAG); + if (!fragmentManager.isStateSaved()) { + show(fragmentManager, TAG); } - } catch (RuntimeException e) { + } catch (final RuntimeException e) { LOG.error("showInstance", e); } } + + @Override + public String getSearchableInfo() { + return String.join( + ", ", + title.getText(), + tvDescription.getText()); + } } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java index dd2d1f7da0b..a92fa4aabee 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java @@ -38,7 +38,6 @@ import java.text.DecimalFormatSymbols; import java.util.List; import java.util.Locale; -import java.util.Optional; public class VehicleParametersBottomSheet extends BaseTextFieldBottomSheet implements SearchablePreferenceDialog { private static final Log LOG = PlatformUtil.getLog(VehicleParametersBottomSheet.class); @@ -135,21 +134,22 @@ protected String formatInputValue(float input) { return formatter.format(input); } - public static @NonNull VehicleParametersBottomSheet createInstance(final String key, - final Fragment target, - final boolean usedOnMap, - final @Nullable ApplicationMode appMode, - final boolean configureSettingsSearch, - final Optional preference) { + @NonNull + public static VehicleParametersBottomSheet createInstance(final Preference preference, + final Fragment target, + final boolean usedOnMap, + final @Nullable ApplicationMode appMode, + final boolean configureSettingsSearch) { final Bundle args = new Bundle(); - args.putString(PREFERENCE_ID, key); - + args.putString(PREFERENCE_ID, preference.getKey()); final VehicleParametersBottomSheet fragment = new VehicleParametersBottomSheet(); fragment.setArguments(args); fragment.setUsedOnMap(usedOnMap); fragment.setAppMode(appMode); fragment.setTargetFragment(target, 0); - preference.ifPresent(fragment::setPreference); + if (target == null) { + fragment.setPreference(preference); + } fragment.setConfigureSettingsSearch(configureSettingsSearch); return fragment; } @@ -160,7 +160,7 @@ public void show(final FragmentManager fragmentManager, final OsmandApplication if (!fragmentManager.isStateSaved()) { show(fragmentManager, TAG); } - } catch (RuntimeException e) { + } catch (final RuntimeException e) { LOG.error("showInstance", e); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java index 5284cdf9514..d4b9e4ac8cd 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java @@ -490,13 +490,12 @@ private Optional createPreferenceDialog(final Prefer final Optional preferenceParam) { if (settings.PRECISE_DISTANCE_NUMBERS.getId().equals(preference.getKey())) { return Optional.of( - DistanceDuringNavigationBottomSheet - .createInstance( - preference.getKey(), - target, - getSelectedAppMode(), - false, - preferenceParam)); + DistanceDuringNavigationBottomSheet.createInstance( + preference.getKey(), + target, + getSelectedAppMode(), + false, + preferenceParam)); } return Optional.empty(); } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java index 8c523962ef8..a13901c9c54 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java @@ -263,11 +263,13 @@ public boolean onPreferenceClick(Preference preference) { } return true; } else if (settings.FUEL_TANK_CAPACITY.getId().equals(key)) { - FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - FuelTankCapacityBottomSheet.showInstance(fragmentManager, preference.getKey(), - this, false, getSelectedAppMode()); - } + final Optional preferenceDialog = + createPreferenceDialog( + preference, + this, + false); + show(preferenceDialog.get()); + return true; } return super.onPreferenceClick(preference); } @@ -278,8 +280,7 @@ public void onDisplayPreferenceDialog(Preference preference) { createPreferenceDialog( preference, this, - false, - Optional.empty()); + false); if (preferenceDialog.isPresent()) { show(preferenceDialog.get()); } else { @@ -297,33 +298,39 @@ private void show(final SearchablePreferenceDialog dialog) { private Optional createPreferenceDialog( final Preference preference, final VehicleParametersFragment target, - final boolean configureSettingsSearch, - final Optional preferenceParam) { + final boolean configureSettingsSearch) { if (preference instanceof SizePreference) { return Optional.of( VehicleParametersBottomSheet .createInstance( - preference.getKey(), + preference, target, false, getSelectedAppMode(), - configureSettingsSearch, - preferenceParam)); + configureSettingsSearch)); } if (MOTOR_TYPE_PREF_ID.equals(preference.getKey())) { final ListPreferenceEx pref = (ListPreferenceEx) preference; return Optional.of( - SimpleSingleSelectionBottomSheet - .createInstance( - target, - preference.getKey(), - pref.getTitle().toString(), - pref.getDescription(), - getSelectedAppMode(), - false, - pref.getEntries(), - pref.getEntryValues(), - pref.getValueIndex())); + SimpleSingleSelectionBottomSheet.createInstance( + target, + preference.getKey(), + pref.getTitle().toString(), + pref.getDescription(), + getSelectedAppMode(), + false, + pref.getEntries(), + pref.getEntryValues(), + pref.getValueIndex())); + } + if (settings.FUEL_TANK_CAPACITY.getId().equals(preference.getKey())) { + return Optional.of( + FuelTankCapacityBottomSheet.createInstance( + preference, + target, + false, + getSelectedAppMode(), + configureSettingsSearch)); } return Optional.empty(); } @@ -337,7 +344,7 @@ public Optional> _preferenceDialog -> new VehicleSpeedHelper(app, getSelectedAppMode()).getSearchableInfo())); } return this - .createPreferenceDialog(preference, null, true, Optional.of(preference)) + .createPreferenceDialog(preference, null, true) .map(preferenceDialog -> new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>( (Fragment) preferenceDialog, diff --git a/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchTest.java b/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchTest.java index f0795bc5123..7b617fd77c2 100644 --- a/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchTest.java +++ b/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchTest.java @@ -89,6 +89,11 @@ public void test_search_within_AnnouncementTimeBottomSheet_description() { testSearchAndFind(R.string.announcement_time_descr); } + @Test + public void test_search_within_FuelTankCapacityBottomSheet_description() { + testSearchAndFind(R.string.fuel_tank_capacity_description); + } + private void testSearchAndFind(final int id) { testSearchAndFind(app.getResources().getString(id)); }