lineage-sdk self-removing prefs: move reap from onBindViewHolder to onAttached
*) Eliminates visibility of the pref removal. You could previously see vertical movement of text during initial display of replaced prefs. *) In addition, when reaping, use setVisible(false) instead of removePreference. Otherwise, array out of bounds index exceptions occur in frameworks pref support libraries (as a result of moving from onBindViewHolder to onAttached). Change-Id: I1a0045552572a590f89715f8d94156eddaaec469
This commit is contained in:
committed by
Bruno Martins
parent
3c54d58691
commit
027b615325
@@ -300,7 +300,7 @@ public class ConstraintsHelper {
|
||||
return fallbackAttr;
|
||||
}
|
||||
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
public void onAttached() {
|
||||
checkIntent();
|
||||
|
||||
if (isAvailable() && mReplacesKey != null) {
|
||||
@@ -308,7 +308,9 @@ public class ConstraintsHelper {
|
||||
}
|
||||
|
||||
Graveyard.get(mContext).summonReaper(mPref.getPreferenceManager());
|
||||
}
|
||||
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
if (!isAvailable()) {
|
||||
return;
|
||||
}
|
||||
@@ -325,7 +327,7 @@ public class ConstraintsHelper {
|
||||
* If we want to keep this at the preference level vs the fragment level, we need to
|
||||
* collate all the preferences that need to be removed when attached to the
|
||||
* hierarchy, then purge them all when loading is complete. The Graveyard keeps track
|
||||
* of this, and will reap the dead during the first call to onBindViewHolder.
|
||||
* of this, and will reap the dead when onAttached is called.
|
||||
*/
|
||||
private static class Graveyard {
|
||||
|
||||
@@ -370,20 +372,12 @@ public class ConstraintsHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void removePreference(PreferenceManager mgr, Preference pref) {
|
||||
final PreferenceGroup group = getParent(pref, pref);
|
||||
group.removePreference(pref);
|
||||
if (group.getPreferenceCount() == 0) {
|
||||
getParent(pref, group).removePreference(group);
|
||||
}
|
||||
}
|
||||
|
||||
public void summonReaper(PreferenceManager mgr) {
|
||||
synchronized (mDeathRow) {
|
||||
for (String dead : mDeathRow) {
|
||||
Preference deadPref = mgr.findPreference(dead);
|
||||
if (deadPref != null) {
|
||||
removePreference(mgr, deadPref);
|
||||
deadPref.setVisible(false);
|
||||
}
|
||||
}
|
||||
mDeathRow.clear();
|
||||
|
||||
@@ -43,6 +43,12 @@ public class SelfRemovingDropDownPreference extends DropDownPreference {
|
||||
mConstraints = new ConstraintsHelper(context, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached() {
|
||||
super.onAttached();
|
||||
mConstraints.onAttached();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
@@ -43,6 +43,12 @@ public class SelfRemovingListPreference extends ListPreference {
|
||||
mConstraints = new ConstraintsHelper(context, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached() {
|
||||
super.onAttached();
|
||||
mConstraints.onAttached();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
@@ -48,6 +48,12 @@ public class SelfRemovingPreference extends Preference {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached() {
|
||||
super.onAttached();
|
||||
mConstraints.onAttached();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
@@ -43,6 +43,12 @@ public class SelfRemovingSwitchPreference extends SwitchPreference {
|
||||
mConstraints = new ConstraintsHelper(context, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached() {
|
||||
super.onAttached();
|
||||
mConstraints.onAttached();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
Reference in New Issue
Block a user