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

Commit 6de56bb0 authored by George Mount's avatar George Mount
Browse files

Fix mismatch in Transition ID/instances

Bug 14597573

In a Transition, when a View is removed from a Scene
and that View has an ID in common with another View
in the end Scene, it will be matched, even if the
View in the start Scene already had a matching View
by instance. This CL prevents a match by ID when an
instance match is available.

Future: disable matching when two views have the
same ID.

Change-Id: I0e51d1f2d0a2d05d09e8e135f090d0e1b2a67efc
parent 973a1d27
Loading
Loading
Loading
Loading
+13 −47
Original line number Diff line number Diff line
@@ -351,18 +351,8 @@ public abstract class Transition implements Cloneable {
        }
        ArrayMap<View, TransitionValues> endCopy =
                new ArrayMap<View, TransitionValues>(endValues.viewValues);
        SparseArray<TransitionValues> endIdCopy =
                new SparseArray<TransitionValues>(endValues.idValues.size());
        for (int i = 0; i < endValues.idValues.size(); ++i) {
            int id = endValues.idValues.keyAt(i);
            endIdCopy.put(id, endValues.idValues.valueAt(i));
        }
        LongSparseArray<TransitionValues> endItemIdCopy =
                new LongSparseArray<TransitionValues>(endValues.itemIdValues.size());
        for (int i = 0; i < endValues.itemIdValues.size(); ++i) {
            long id = endValues.itemIdValues.keyAt(i);
            endItemIdCopy.put(id, endValues.itemIdValues.valueAt(i));
        }
        SparseArray<TransitionValues> endIdCopy = endValues.idValues.clone();
        LongSparseArray<TransitionValues> endItemIdCopy = endValues.itemIdValues.clone();
        // Walk through the start values, playing everything we find
        // Remove from the end set as we go
        ArrayList<TransitionValues> startValuesList = new ArrayList<TransitionValues>();
@@ -376,21 +366,17 @@ public abstract class Transition implements Cloneable {
            }
            if (!isInListView) {
                int id = view.getId();
                start = startValues.viewValues.get(view) != null ?
                        startValues.viewValues.get(view) : startValues.idValues.get(id);
                if (endValues.viewValues.get(view) != null) {
                start = startValues.viewValues.get(view);
                end = endValues.viewValues.get(view);
                if (end != null) {
                    endCopy.remove(view);
                } else if (id != View.NO_ID) {
                    end = endValues.idValues.get(id);
                    View removeView = null;
                    for (View viewToRemove : endCopy.keySet()) {
                        if (viewToRemove.getId() == id) {
                            removeView = viewToRemove;
                        }
                    }
                    if (removeView != null) {
                        endCopy.remove(removeView);
                    end = endIdCopy.get(id);
                    if (end == null || startValues.viewValues.containsKey(end.view)) {
                        end = null;
                        id = View.NO_ID;
                    } else {
                        endCopy.remove(end.view);
                    }
                }
                endIdCopy.remove(id);
@@ -423,36 +409,16 @@ public abstract class Transition implements Cloneable {
            }
        }
        // Now walk through the remains of the end set
        // We've already matched everything from start to end, everything else doesn't match.
        for (View view : endCopy.keySet()) {
            int id = view.getId();
            if (isValidTarget(view, id)) {
                TransitionValues start = startValues.viewValues.get(view) != null ?
                        startValues.viewValues.get(view) : startValues.idValues.get(id);
                TransitionValues start = null;
                TransitionValues end = endCopy.get(view);
                endIdCopy.remove(id);
                startValuesList.add(start);
                endValuesList.add(end);
            }
        }
        int endIdCopySize = endIdCopy.size();
        for (int i = 0; i < endIdCopySize; ++i) {
            int id = endIdCopy.keyAt(i);
            if (isValidTarget(null, id)) {
                TransitionValues start = startValues.idValues.get(id);
                TransitionValues end = endIdCopy.get(id);
                startValuesList.add(start);
                endValuesList.add(end);
            }
        }
        int endItemIdCopySize = endItemIdCopy.size();
        for (int i = 0; i < endItemIdCopySize; ++i) {
            long id = endItemIdCopy.keyAt(i);
            // TODO: Deal with targetIDs and itemIDs
            TransitionValues start = startValues.itemIdValues.get(id);
            TransitionValues end = endItemIdCopy.get(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
        ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
        long minStartDelay = Long.MAX_VALUE;
        int minAnimator = mAnimators.size();