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 80c7ff9 commit b0bae6f
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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 +27,7 @@
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;
import net.osmand.plus.simulation.OsmAndLocationSimulation;
import net.osmand.plus.simulation.SimulateLocationFragment;
Expand All @@ -37,7 +39,7 @@

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

public class DevelopmentSettingsFragment extends BaseSettingsFragment implements ConfirmationDialogListener, SearchablePreferenceDialogProvider {
public class DevelopmentSettingsFragment extends BaseSettingsFragment implements ConfirmationDialogListener, SearchablePreferenceDialogProvider, 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 @@ -318,10 +320,8 @@ private void setupResetToDefaultButton() {

@Override
public boolean onPreferenceClick(Preference preference) {
String prefId = preference.getKey();
final Optional<ShowableSearchablePreferenceDialog<?>> preferenceDialog = createPreferenceDialog(preference, this);
if (preferenceDialog.isPresent()) {
preferenceDialog.get().show();
final String prefId = preference.getKey();
if (showDialogForPreference(preference)) {
return true;
} else if (SIMULATE_INITIAL_STARTUP.equals(prefId)) {
app.getAppInitializer().resetFirstTimeRun();
Expand Down Expand Up @@ -351,8 +351,17 @@ public boolean onPreferenceClick(Preference preference) {
return super.onPreferenceClick(preference);
}

private Optional<ShowableSearchablePreferenceDialog<?>> createPreferenceDialog(final Preference preference,
final DevelopmentSettingsFragment target) {
private boolean showDialogForPreference(final Preference preference) {
final Optional<ShowableSearchablePreferenceDialog<?>> preferenceDialog = getShowableSearchablePreferenceDialog(preference, this);
if (preferenceDialog.isPresent()) {
preferenceDialog.get().show();
return true;
}
return false;
}

@Override
public Optional<ShowableSearchablePreferenceDialog<?>> getShowableSearchablePreferenceDialog(final Preference preference, final Fragment target) {
if (SIMULATE_YOUR_LOCATION.equals(preference.getKey())) {
return Optional.of(
new ShowableSearchablePreferenceDialog<>(
Expand All @@ -361,7 +370,7 @@ private Optional<ShowableSearchablePreferenceDialog<?>> createPreferenceDialog(f
false)) {

@Override
public void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
final FragmentActivity activity = getActivity();
if (activity != null) {
searchablePreferenceDialog.show(activity.getSupportFragmentManager(), app);
Expand All @@ -378,7 +387,7 @@ public void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
getSelectedAppMode())) {

@Override
public void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
final FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
searchablePreferenceDialog.show(fragmentManager, app);
Expand All @@ -395,7 +404,7 @@ public void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
getSelectedAppMode())) {

@Override
public void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
final FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
searchablePreferenceDialog.show(fragmentManager, app);
Expand All @@ -409,7 +418,7 @@ public void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
@Override
public Optional<PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<?>> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) {
return this
.createPreferenceDialog(preference, null)
.getShowableSearchablePreferenceDialog(preference, null)
.map(ShowableSearchablePreferenceDialog::asPreferenceDialogAndSearchableInfoByPreferenceDialogProvider);
}

Expand Down

0 comments on commit b0bae6f

Please sign in to comment.