Revert "lineage-sdk self-removing prefs: move reap from onBindViewHolder to onAttached"

This reverts commit 027b615325.

While it served its original purpose, this was causing bad side-effects
when using our constraints (verified at least with requiresConfig and
requiresAction). Moving the reap to onAttached was rendering self-removing
prefs useless because if the view isn't loaded yet, the preference
(which also doesn't yet exists) can't really be hidden.

Change-Id: Ic61fe4b9979412d89c55ea1543c494e69bf6eab7
This commit is contained in:
Bruno Martins
2017-12-03 22:03:02 +00:00
parent 8c4872f801
commit 9f648b7046
5 changed files with 11 additions and 29 deletions

View File

@@ -300,7 +300,7 @@ public class ConstraintsHelper {
return fallbackAttr;
}
public void onAttached() {
public void onBindViewHolder(PreferenceViewHolder holder) {
checkIntent();
if (isAvailable() && mReplacesKey != null) {
@@ -308,9 +308,7 @@ public class ConstraintsHelper {
}
Graveyard.get(mContext).summonReaper(mPref.getPreferenceManager());
}
public void onBindViewHolder(PreferenceViewHolder holder) {
if (!isAvailable()) {
return;
}
@@ -327,7 +325,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 when onAttached is called.
* of this, and will reap the dead during the first call to onBindViewHolder.
*/
private static class Graveyard {
@@ -372,12 +370,20 @@ 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) {
deadPref.setVisible(false);
removePreference(mgr, deadPref);
}
}
mDeathRow.clear();

View File

@@ -43,12 +43,6 @@ 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);

View File

@@ -43,12 +43,6 @@ 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);

View File

@@ -48,12 +48,6 @@ 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);

View File

@@ -43,12 +43,6 @@ 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);