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 adeff6a commit 4aae3fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.osmand.plus.settings.bottomsheets.ConfirmationBottomSheet.ConfirmationDialogListener;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
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.SwitchPreferenceEx;
Expand All @@ -37,9 +36,7 @@
import java.text.SimpleDateFormat;
import java.util.Optional;

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

public class DevelopmentSettingsFragment extends BaseSettingsFragment implements ConfirmationDialogListener, SearchablePreferenceDialogProvider, ShowableSearchablePreferenceDialogProvider {
public class DevelopmentSettingsFragment extends BaseSettingsFragment implements ConfirmationDialogListener, ShowableSearchablePreferenceDialogProvider {

private static final String SIMULATE_INITIAL_STARTUP = "simulate_initial_startup";
private static final String SIMULATE_YOUR_LOCATION = "simulate_your_location";
Expand Down Expand Up @@ -415,13 +412,6 @@ protected void show(final SearchablePreferenceDialog searchablePreferenceDialog)
return Optional.empty();
}

@Override
public Optional<PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<?>> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) {
return this
.getShowableSearchablePreferenceDialog(preference, null)
.map(ShowableSearchablePreferenceDialog::asPreferenceDialogAndSearchableInfoByPreferenceDialogProvider);
}

@Override
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
if (prefId.equals(settings.LOCATION_INTERPOLATION_PERCENT.getId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ public Optional<PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<?>>
final Preference preference,
final PreferenceFragmentCompat hostOfPreference) {
// FK-TODO: handle more preference dialogs, which shall be searchable
return hostOfPreference instanceof final SearchablePreferenceDialogProvider searchablePreferenceDialogProvider ?
searchablePreferenceDialogProvider.getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(preference) :
Optional.empty();
if (hostOfPreference instanceof final SearchablePreferenceDialogProvider searchablePreferenceDialogProvider) {
return searchablePreferenceDialogProvider.getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(preference);
}
if (hostOfPreference instanceof final ShowableSearchablePreferenceDialogProvider showableSearchablePreferenceDialogProvider) {
return showableSearchablePreferenceDialogProvider
.getShowableSearchablePreferenceDialog(preference, null)
.map(ShowableSearchablePreferenceDialog::asPreferenceDialogAndSearchableInfoByPreferenceDialogProvider);
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.osmand.plus.settings.fragments.search;

import androidx.fragment.app.Fragment;
import androidx.preference.Preference;

import java.util.Optional;

@FunctionalInterface
public interface ShowableSearchablePreferenceDialogProvider {

// Fk-TODO: make Fragment parameter an Optional<Fragment>
Optional<ShowableSearchablePreferenceDialog<?>> getShowableSearchablePreferenceDialog(Preference preference, Fragment target);
}

0 comments on commit 4aae3fb

Please sign in to comment.