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

Commit 99c532d0 authored by George Mount's avatar George Mount
Browse files

Properly track fragments from pop operations.

Bug 33849992

When popping and executing another transaction, the pop
transaction weren't properly tracking the fragments that were
added and removed.

This CL adds tracking the fragments during the pop execution.
It also fixes a small issue in when fragment state was executed
during pop.

Test: I89ed2386220deb21b417cd6674292c12accab18b
Change-Id: Ie693eef38b0136bf8ea76027dbc756b35ee9a366
parent c21dfd9b
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -807,7 +807,7 @@ final class BackStackRecord extends FragmentTransaction implements
                default:
                    throw new IllegalArgumentException("Unknown cmd: " + op.cmd);
            }
            if (!mAllowOptimization && op.cmd != OP_ADD) {
            if (!mAllowOptimization && op.cmd != OP_REMOVE) {
                mManager.moveFragmentToExpectedState(f);
            }
        }
@@ -873,6 +873,29 @@ final class BackStackRecord extends FragmentTransaction implements
        }
    }

    /**
     * Removes fragments that are added or removed during a pop operation.
     *
     * @param added Initialized to the fragments that are in the mManager.mAdded, this
     *              will be modified to contain the fragments that will be in mAdded
     *              after the execution ({@link #executeOps()}.
     */
    void trackAddedFragmentsInPop(ArrayList<Fragment> added) {
        for (int opNum = 0; opNum < mOps.size(); opNum++) {
            final Op op = mOps.get(opNum);
            switch (op.cmd) {
                case OP_ADD:
                case OP_ATTACH:
                    added.remove(op.fragment);
                    break;
                case OP_REMOVE:
                case OP_DETACH:
                    added.add(op.fragment);
                    break;
            }
        }
    }

    boolean isPostponed() {
        for (int opNum = 0; opNum < mOps.size(); opNum++) {
            final Op op = mOps.get(opNum);
+2 −0
Original line number Diff line number Diff line
@@ -2026,6 +2026,8 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
            final boolean isPop = isRecordPop.get(recordNum);
            if (!isPop) {
                record.expandReplaceOps(mTmpAddedFragments);
            } else {
                record.trackAddedFragmentsInPop(mTmpAddedFragments);
            }
            final int bumpAmount = isPop ? -1 : 1;
            record.bumpBackStackNesting(bumpAmount);