Browse Source

Fix sub-screens in settings not opening the edit dialog

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

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

@ -0,0 +1,13 @@ @@ -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);
}
}

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

@ -8,19 +8,20 @@ import androidx.appcompat.app.AppCompatCallback; @@ -8,19 +8,20 @@ import androidx.appcompat.app.AppCompatCallback;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceManagerBinder;
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;
public void addPreferencesFromResource(@XmlRes int preferencesResId) {
fragment = new RootPreferencesFragment(preferencesResId);
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commitNow();
}
public void addPreferencesFromResource(@XmlRes int preferencesResId) {
fragment = new RootPreferencesFragment(preferencesResId);
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commitNow();
}
public PreferenceManager getPreferenceManager() {
return fragment.getPreferenceManager();
public PreferenceManager getPreferenceManager() {
return fragment.getPreferenceManager();
}
public PreferenceScreen getPreferenceScreen() {
@ -66,6 +67,10 @@ import androidx.preference.PreferenceScreen; @@ -66,6 +67,10 @@ import androidx.preference.PreferenceScreen;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
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);
prefs = null;
}

Loading…
Cancel
Save