Browse Source

Fix sub-screens in settings not opening the edit dialog

pull/565/head
Eric Kok 4 years ago
parent
commit
6cb5dfd355
  1. 13
      app/src/main/java/androidx/preference/PreferenceManagerBinder.java
  2. 7
      app/src/main/java/org/transdroid/core/gui/settings/PreferenceCompatActivity.java

13
app/src/main/java/androidx/preference/PreferenceManagerBinder.java

@ -0,0 +1,13 @@
package androidx.preference;
/**
* A helper to attach a new {@link PreferenceManager} to a {@link Preference}. This class is in the {@code androidx.preference} package to hack
* around the protected visibility of {@link Preference#onAttachedToHierarchy(PreferenceManager)}.
*/
public class PreferenceManagerBinder {
private PreferenceManagerBinder() {}
public static void bind(Preference pref, PreferenceManager manager) {
pref.onAttachedToHierarchy(manager);
}
}

7
app/src/main/java/org/transdroid/core/gui/settings/PreferenceCompatActivity.java

@ -8,9 +8,10 @@ import androidx.appcompat.app.AppCompatCallback;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceManagerBinder;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
public class PreferenceCompatActivity extends AppCompatActivity implements AppCompatCallback, PreferenceFragmentCompat.OnPreferenceStartScreenCallback { public class PreferenceCompatActivity extends AppCompatActivity implements AppCompatCallback, PreferenceFragmentCompat.OnPreferenceStartScreenCallback {
private PreferenceFragmentCompat fragment; private PreferenceFragmentCompat fragment;
@ -66,6 +67,10 @@ import androidx.preference.PreferenceScreen;
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
if (prefs != null) { if (prefs != null) {
// Update the already loaded preferences with this fragment's manager to handle dialog clicks, etc.
for (int i = 0; i < prefs.getPreferenceCount(); i++) {
PreferenceManagerBinder.bind(prefs.getPreference(i), getPreferenceManager());
}
setPreferenceScreen(prefs); setPreferenceScreen(prefs);
prefs = null; prefs = null;
} }

Loading…
Cancel
Save