Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KnollFrank committed Dec 18, 2024
1 parent 673c901 commit e929d75
Showing 1 changed file with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.osmand.plus.plugins.accessibility;

import static net.osmand.plus.plugins.PluginInfoFragment.PLUGIN_INFO;
import static net.osmand.plus.settings.fragments.search.PreferenceDialogs.showDialogForPreference;

import android.content.Context;
import android.content.Intent;
Expand All @@ -14,6 +15,7 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
Expand All @@ -29,17 +31,15 @@
import net.osmand.plus.settings.bottomsheets.ResetProfilePrefsBottomSheet;
import net.osmand.plus.settings.bottomsheets.ResetProfilePrefsBottomSheet.ResetAppModePrefsListener;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.settings.fragments.SearchablePreferenceDialogFragmentHolder;
import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog;
import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialogProvider;
import net.osmand.plus.settings.fragments.search.ShowableSearchablePreferenceDialog;
import net.osmand.plus.settings.fragments.search.ShowableSearchablePreferenceDialogProvider;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;

import java.util.Optional;

import de.KnollFrank.lib.settingssearch.provider.PreferenceDialogAndSearchableInfoByPreferenceDialogProvider;

public class AccessibilitySettingsFragment extends BaseSettingsFragment implements CopyAppModePrefsListener, ResetAppModePrefsListener, SearchablePreferenceDialogProvider {
public class AccessibilitySettingsFragment extends BaseSettingsFragment implements CopyAppModePrefsListener, ResetAppModePrefsListener, ShowableSearchablePreferenceDialogProvider {

private static final String ACCESSIBILITY_OPTIONS = "accessibility_options";
private static final String COPY_PLUGIN_SETTINGS = "copy_plugin_settings";
Expand Down Expand Up @@ -257,13 +257,8 @@ public void onPreferenceChanged(@NonNull String prefId) {
}

@Override
public boolean onPreferenceClick(Preference preference) {
final Optional<SearchablePreferenceDialog> searchablePreferenceDialog =
this
.createSearchablePreferenceDialog(preference, this)
.map(SearchablePreferenceDialogFragmentHolder::searchablePreferenceDialogFragment);
if (searchablePreferenceDialog.isPresent()) {
searchablePreferenceDialog.get().show(getFragmentManager(), app);
public boolean onPreferenceClick(final Preference preference) {
if (showDialogForPreference(preference, this)) {
return true;
}
if (COPY_PLUGIN_SETTINGS.equals(preference.getKey())) {
Expand All @@ -276,24 +271,19 @@ public boolean onPreferenceClick(Preference preference) {
}

@Override
public Optional<PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<?>> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) {
return this
.createSearchablePreferenceDialog(preference, null)
.map(SearchablePreferenceDialogFragmentHolder::searchablePreferenceDialogFragment)
.map(searchablePreferenceDialog ->
new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>(
searchablePreferenceDialog,
_preferenceDialog -> searchablePreferenceDialog.getSearchableInfo()));
}

private Optional<SearchablePreferenceDialogFragmentHolder<?>> createSearchablePreferenceDialog(final Preference preference,
final AccessibilitySettingsFragment target) {
public Optional<ShowableSearchablePreferenceDialog<?>> getShowableSearchablePreferenceDialog(final Preference preference, final Fragment target) {
if (RESET_TO_DEFAULT.equals(preference.getKey())) {
return Optional.of(
SearchablePreferenceDialogFragmentHolder.of(
new ShowableSearchablePreferenceDialog<>(
ResetProfilePrefsBottomSheet.createInstance(
getSelectedAppMode(),
target)));
target)) {

@Override
protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
searchablePreferenceDialog.show(getFragmentManager(), app);
}
});
}
return Optional.empty();
}
Expand Down

0 comments on commit e929d75

Please sign in to comment.