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 dda12aa commit 80c7ff9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.os.Debug;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
Expand All @@ -26,6 +25,7 @@
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.preferences.SwitchPreferenceEx;
import net.osmand.plus.simulation.OsmAndLocationSimulation;
import net.osmand.plus.simulation.SimulateLocationFragment;
Expand Down Expand Up @@ -316,17 +316,6 @@ private void setupResetToDefaultButton() {
resetToDefault.setIcon(getActiveIcon(R.drawable.ic_action_reset_to_default_dark));
}

private static abstract class ShowableSearchablePreferenceDialog<T extends Fragment & SearchablePreferenceDialog> {

public final T searchablePreferenceDialog;

public ShowableSearchablePreferenceDialog(final T searchablePreferenceDialog) {
this.searchablePreferenceDialog = searchablePreferenceDialog;
}

public abstract void show();
}

@Override
public boolean onPreferenceClick(Preference preference) {
String prefId = preference.getKey();
Expand Down Expand Up @@ -372,7 +361,7 @@ private Optional<ShowableSearchablePreferenceDialog<?>> createPreferenceDialog(f
false)) {

@Override
public void show() {
public void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
final FragmentActivity activity = getActivity();
if (activity != null) {
searchablePreferenceDialog.show(activity.getSupportFragmentManager(), app);
Expand All @@ -388,9 +377,8 @@ public void show() {
target,
getSelectedAppMode())) {

// FK-TODO: refactor
@Override
public void show() {
public void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
final FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
searchablePreferenceDialog.show(fragmentManager, app);
Expand All @@ -407,7 +395,7 @@ public void show() {
getSelectedAppMode())) {

@Override
public void show() {
public void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
final FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
searchablePreferenceDialog.show(fragmentManager, app);
Expand All @@ -422,11 +410,7 @@ public void show() {
public Optional<PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<?>> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) {
return this
.createPreferenceDialog(preference, null)
.map(showableSearchablePreferenceDialog -> showableSearchablePreferenceDialog.searchablePreferenceDialog)
.map(searchablePreferenceDialog ->
new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>(
searchablePreferenceDialog,
_preferenceDialog -> searchablePreferenceDialog.getSearchableInfo()));
.map(ShowableSearchablePreferenceDialog::asPreferenceDialogAndSearchableInfoByPreferenceDialogProvider);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.osmand.plus.settings.fragments.search;

import androidx.fragment.app.Fragment;

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

public abstract class ShowableSearchablePreferenceDialog<T extends Fragment & SearchablePreferenceDialog> {

public final T searchablePreferenceDialog;

public ShowableSearchablePreferenceDialog(final T searchablePreferenceDialog) {
this.searchablePreferenceDialog = searchablePreferenceDialog;
}

public void show() {
show(searchablePreferenceDialog);
}

public PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<T> asPreferenceDialogAndSearchableInfoByPreferenceDialogProvider() {
return new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>(
searchablePreferenceDialog,
SearchablePreferenceDialog::getSearchableInfo);
}

protected abstract void show(final SearchablePreferenceDialog searchablePreferenceDialog);
}

0 comments on commit 80c7ff9

Please sign in to comment.