Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f648b70 authored by Bruno Martins's avatar Bruno Martins
Browse files

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

This reverts commit 027b6153.

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
parent 8c4872f8
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -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();
+0 −6
Original line number Diff line number Diff line
@@ -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);
+0 −6
Original line number Diff line number Diff line
@@ -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);
+0 −6
Original line number Diff line number Diff line
@@ -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);
+0 −6
Original line number Diff line number Diff line
@@ -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);