diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/CustomizableSingleSelectionBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/CustomizableSingleSelectionBottomSheet.java index 8792ac5a42a..68793a170e9 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/CustomizableSingleSelectionBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/CustomizableSingleSelectionBottomSheet.java @@ -11,6 +11,7 @@ import androidx.annotation.NonNull; import androidx.fragment.app.FragmentManager; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton.Builder; @@ -18,6 +19,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.dialog.data.DisplayItem; +import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog; import net.osmand.plus.utils.UiUtilities; import java.util.List; @@ -28,7 +30,7 @@ * When choosing one of the options, the selected option is passed to the controller * and dialog automatically closed without the need for confirmation by the user. */ -public class CustomizableSingleSelectionBottomSheet extends CustomizableBottomSheet { +public class CustomizableSingleSelectionBottomSheet extends CustomizableBottomSheet implements SearchablePreferenceDialog { public static final String TAG = CustomizableSingleSelectionBottomSheet.class.getSimpleName(); @@ -88,11 +90,6 @@ protected boolean hideButtonsContainer() { return show == null || !show; } - public static boolean showInstance(@NonNull FragmentManager fragmentManager, - @NonNull String processId, boolean usedOnMap) { - return createInstance(processId, usedOnMap).show(fragmentManager); - } - public static @NonNull CustomizableSingleSelectionBottomSheet createInstance(final @NonNull String processId, final boolean usedOnMap) { final CustomizableSingleSelectionBottomSheet fragment = new CustomizableSingleSelectionBottomSheet(); fragment.setProcessId(processId); @@ -100,13 +97,17 @@ public static boolean showInstance(@NonNull FragmentManager fragmentManager, return fragment; } - public boolean show(@NonNull final FragmentManager fragmentManager) { - try { - show(fragmentManager, TAG); - return true; - } catch (final RuntimeException e) { - return false; - } + @Override + public void show(final FragmentManager fragmentManager, final OsmandApplication app) { + show(fragmentManager, TAG); + } + + @Override + public String getSearchableInfo() { + return CustomizableSingleSelectionBottomSheetSearchableInfoProvider.getSearchableInfo( + getTitle(), + getDescription(), + getDisplayItems()); } private String getTitle() { @@ -120,11 +121,4 @@ private String getDescription() { private List getDisplayItems() { return displayData.getDisplayItems(); } - - public String getSearchableInfo() { - return CustomizableSingleSelectionBottomSheetSearchableInfoProvider.getSearchableInfo( - getTitle(), - getDescription(), - getDisplayItems()); - } } diff --git a/OsmAnd/src/net/osmand/plus/settings/controllers/CompassModeWidgetDialogController.java b/OsmAnd/src/net/osmand/plus/settings/controllers/CompassModeWidgetDialogController.java index de9bd9cc512..bec0631d529 100644 --- a/OsmAnd/src/net/osmand/plus/settings/controllers/CompassModeWidgetDialogController.java +++ b/OsmAnd/src/net/osmand/plus/settings/controllers/CompassModeWidgetDialogController.java @@ -18,7 +18,8 @@ public CompassModeWidgetDialogController(OsmandApplication app) { super(app, app.getSettings().getApplicationMode()); } - @NonNull @Override + @NonNull + @Override public String getProcessId() { return PROCESS_ID; } @@ -40,6 +41,8 @@ public static void showDialog(@NonNull MapActivity mapActivity) { dialogManager.register(PROCESS_ID, controller); FragmentManager manager = mapActivity.getSupportFragmentManager(); - CustomizableSingleSelectionBottomSheet.showInstance(manager, PROCESS_ID, true); + CustomizableSingleSelectionBottomSheet + .createInstance(PROCESS_ID, true) + .show(manager, app); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/controllers/MapFocusDialogController.java b/OsmAnd/src/net/osmand/plus/settings/controllers/MapFocusDialogController.java index 8a4d8c6501b..7e543166f69 100644 --- a/OsmAnd/src/net/osmand/plus/settings/controllers/MapFocusDialogController.java +++ b/OsmAnd/src/net/osmand/plus/settings/controllers/MapFocusDialogController.java @@ -15,8 +15,8 @@ import net.osmand.plus.base.dialog.DialogManager; import net.osmand.plus.base.dialog.data.DisplayData; import net.osmand.plus.base.dialog.data.DisplayItem; -import net.osmand.plus.base.dialog.interfaces.controller.IDisplayDataProvider; import net.osmand.plus.base.dialog.interfaces.controller.IDialogItemSelected; +import net.osmand.plus.base.dialog.interfaces.controller.IDisplayDataProvider; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.bottomsheets.CustomizableSingleSelectionBottomSheet; @@ -97,6 +97,8 @@ public static void showDialog(@NonNull MapActivity mapActivity, @NonNull Applica dialogManager.register(PROCESS_ID, controller); FragmentManager manager = mapActivity.getSupportFragmentManager(); - CustomizableSingleSelectionBottomSheet.showInstance(manager, PROCESS_ID, true); + CustomizableSingleSelectionBottomSheet + .createInstance(PROCESS_ID, true) + .show(manager, app); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java index 2823401520a..4f49db46e68 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java @@ -866,7 +866,9 @@ protected void showSingleSelectionDialog(@NonNull String processId, DialogManager dialogManager = app.getDialogManager(); dialogManager.register(processId, controller); FragmentManager fm = activity.getSupportFragmentManager(); - CustomizableSingleSelectionBottomSheet.showInstance(fm, processId, false); + CustomizableSingleSelectionBottomSheet + .createInstance(processId, false) + .show(fm, app); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/profileappearance/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/profileappearance/ProfileAppearanceFragment.java index e8f4facd3ba..2ba0fbb29c6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/profileappearance/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/profileappearance/ProfileAppearanceFragment.java @@ -38,10 +38,11 @@ import net.osmand.plus.card.icon.IconsPaletteCard; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.routepreparationmenu.cards.BaseCard; -import net.osmand.plus.settings.bottomsheets.CustomizableSingleSelectionBottomSheet; import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.plus.settings.fragments.SettingsScreenType; -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.utils.AndroidUtils; import net.osmand.plus.utils.ColorUtilities; import net.osmand.plus.utils.UiUtilities; @@ -54,9 +55,7 @@ import java.util.Optional; -import de.KnollFrank.lib.settingssearch.provider.PreferenceDialogAndSearchableInfoByPreferenceDialogProvider; - -public class ProfileAppearanceFragment extends BaseSettingsFragment implements IProfileAppearanceScreen, SearchablePreferenceDialogProvider { +public class ProfileAppearanceFragment extends BaseSettingsFragment implements IProfileAppearanceScreen, ShowableSearchablePreferenceDialogProvider { private static final Log LOG = PlatformUtil.getLog(ProfileAppearanceFragment.class); @@ -230,48 +229,45 @@ public void afterTextChanged(Editable s) { } @Override - public boolean onPreferenceClick(Preference preference) { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - this - .createPreferenceDialog(preference) - .ifPresent(dialog -> dialog.show(mapActivity.getSupportFragmentManager())); - } - return super.onPreferenceClick(preference); - } - - @Override - public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { - return this - .createPreferenceDialog(preference) - .map(preferenceDialog -> - new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>( - preferenceDialog, - CustomizableSingleSelectionBottomSheet::getSearchableInfo)); - } - - private Optional createPreferenceDialog(final Preference preference) { + public Optional> getShowableSearchablePreferenceDialog(final Preference preference, final Fragment target) { if (settings.VIEW_ANGLE_VISIBILITY.getId().equals(preference.getKey())) { return Optional.of( - screenController - .getProfileOptionController() - .createDialog( - app.getString(R.string.view_angle), - app.getString(R.string.view_angle_description), - settings.VIEW_ANGLE_VISIBILITY)); + new ShowableSearchablePreferenceDialog<>( + screenController + .getProfileOptionController() + .createDialog( + app.getString(R.string.view_angle), + app.getString(R.string.view_angle_description), + settings.VIEW_ANGLE_VISIBILITY)) { + @Override + protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) { + ProfileAppearanceFragment.this.show(searchablePreferenceDialog); + } + }); } if (settings.LOCATION_RADIUS_VISIBILITY.getId().equals(preference.getKey())) { return Optional.of( - screenController - .getProfileOptionController() - .createDialog( - app.getString(R.string.location_radius), - app.getString(R.string.location_radius_description), - settings.LOCATION_RADIUS_VISIBILITY)); + new ShowableSearchablePreferenceDialog<>( + screenController + .getProfileOptionController() + .createDialog( + app.getString(R.string.location_radius), + app.getString(R.string.location_radius_description), + settings.LOCATION_RADIUS_VISIBILITY)) { + + @Override + protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) { + ProfileAppearanceFragment.this.show(searchablePreferenceDialog); + } + }); } return Optional.empty(); } + private void show(final SearchablePreferenceDialog searchablePreferenceDialog) { + searchablePreferenceDialog.show(getMapActivity().getSupportFragmentManager(), app); + } + private void bindCard(@NonNull PreferenceViewHolder holder, @NonNull BaseCard card) { ViewGroup container = (ViewGroup) holder.itemView; container.removeAllViews(); diff --git a/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchParameterizedTest.java b/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchParameterizedTest.java index ad53372312a..17a549aec1e 100644 --- a/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchParameterizedTest.java +++ b/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchParameterizedTest.java @@ -59,6 +59,9 @@ public static Iterable data() { {"SendAnalyticsBottomSheetDialogFragment: description", R.string.make_osmand_better_descr}, + {"ProfileAppearanceFragment: view_angle_description", R.string.view_angle_description}, + {"ProfileAppearanceFragment: location_radius_description", R.string.location_radius_description}, + // FK-TODO: enable development plugin for these two test cases // {"LocationInterpolationBottomSheet: title", R.string.location_interpolation_percent}, // {"LocationInterpolationBottomSheet: description", R.string.location_interpolation_percent_desc}