From ea0af5a6faf345b69087d9a0e0edf8535345d2b0 Mon Sep 17 00:00:00 2001 From: carlosdanielgt <44984606+carlosdanielgt@users.noreply.github.com> Date: Fri, 13 Oct 2023 21:31:31 -0400 Subject: [PATCH] Update UserInterfaceSettingsFragment.java It fixes the issue Remove this use of "setTargetFragment"; it is deprecated. https://github.com/rilling/OpenTracksConcordia/issues/137 --- .../UserInterfaceSettingsFragment.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/settings/UserInterfaceSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/UserInterfaceSettingsFragment.java index 38139691e..14bf9c4a1 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/UserInterfaceSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/UserInterfaceSettingsFragment.java @@ -4,12 +4,15 @@ import android.content.SharedPreferences; import android.os.Bundle; +import androidx.annotation.NonNull; import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.FragmentResultListener; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; import java.util.Map; +import java.util.UUID; import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.io.file.TrackFileFormat; @@ -28,7 +31,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.settings_user_interface); Preference customLayoutPreference = findPreference(getString(R.string.stats_custom_layout_key)); - customLayoutPreference.setOnPreferenceClickListener(preference -> { + customLayoutPreference.setOnPreferenceClickListener((preference) -> { Intent intent = new Intent(getContext(), SettingsCustomLayoutListActivity.class); startActivity(intent); return true; @@ -57,21 +60,28 @@ public void onPause() { @Override public void onDisplayPreferenceDialog(Preference preference) { - DialogFragment dialogFragment = null; - if (preference instanceof ResetDialogPreference) { - dialogFragment = ResetDialogPreference.ResetPreferenceDialog.newInstance(preference.getKey()); - } + String requestKey = UUID.randomUUID().toString(); + + getParentFragmentManager().setFragmentResultListener(requestKey, this, new FragmentResultListener() { + public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) { + // Handle the result here, if needed + } + }); + + DialogFragment dialogFragment = ResetDialogPreference.ResetPreferenceDialog.newInstance(preference.getKey()); + Bundle args = new Bundle(); + args.putString("requestKey", requestKey); + dialogFragment.setArguments(args); - if (dialogFragment != null) { - dialogFragment.setTargetFragment(this, 0); dialogFragment.show(getParentFragmentManager(), getClass().getSimpleName()); - return; + } else { + super.onDisplayPreferenceDialog(preference); } - - super.onDisplayPreferenceDialog(preference); } + + private void setShowOnMapFormatOptions() { Map options = TrackFileFormat.toPreferenceIdLabelMap(getResources(), IntentDashboardUtils.SHOW_ON_MAP_TRACK_FILE_FORMATS); options.put(IntentDashboardUtils.PREFERENCE_ID_DASHBOARD, getString(R.string.show_on_dashboard));