Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Update UserInterfaceSettingsFragment.java
Browse files Browse the repository at this point in the history
It fixes the issue Remove this use of "setTargetFragment"; it is deprecated.
#137
  • Loading branch information
carlosdanielgt authored Oct 14, 2023
1 parent 30bd907 commit ea0af5a
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, String> options = TrackFileFormat.toPreferenceIdLabelMap(getResources(), IntentDashboardUtils.SHOW_ON_MAP_TRACK_FILE_FORMATS);
options.put(IntentDashboardUtils.PREFERENCE_ID_DASHBOARD, getString(R.string.show_on_dashboard));
Expand Down

0 comments on commit ea0af5a

Please sign in to comment.