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

Commit bd0136a2 authored by Adam Cohen's avatar Adam Cohen
Browse files

AdapterViewAnimator now properly handles notifyDataSetChanged

Change-Id: Icc22671b76d49c4229f118f77a5c269253a07b84
parent 467e8e13
Loading
Loading
Loading
Loading
+34 −10
Original line number Diff line number Diff line
@@ -339,6 +339,25 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
        return new ViewGroup.LayoutParams(0, 0);
    }

    private void refreshChildren() {
        for (int i = mCurrentWindowStart; i <= mCurrentWindowEnd; i++) {
            int index = modulo(i, mNumActiveViews);

            // get the fresh child from the adapter
            View updatedChild = mAdapter.getView(i, null, this);

            if (mActiveViews[index] != null) {
                FrameLayout fl = (FrameLayout) mActiveViews[index];
                // flush out the old child
                fl.removeAllViewsInLayout();
                // add the new child to the frame, if it exists
                if (updatedChild != null) {
                    fl.addView(updatedChild);
                }
            }
        }
    }

    void showOnly(int childIndex, boolean animate, boolean onLayout) {
        if (mAdapter == null) return;

@@ -414,17 +433,20 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
                    // We've cleared a spot for the new view. Get it from the adapter, add it
                    // and apply any transform / animation
                    View newView = mAdapter.getView(i, null, this);
                    if (newView != null) {

                    // We wrap the new view in a FrameLayout so as to respect the contract
                    // with the adapter, that is, that we don't modify this view directly
                    FrameLayout fl = new FrameLayout(mContext);

                    // If the view from the adapter is null, we still keep an empty frame in place
                    if (newView != null) {
                       fl.addView(newView);
                    }
                    mActiveViews[index] = fl;
                    addChild(fl);
                    applyTransformForChildAtIndex(fl, newRelativeIndex);
                    animateViewForTransition(-1, newRelativeIndex, fl);
                }
                }
                mActiveViews[index].bringToFront();
            }

@@ -523,11 +545,13 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>

            // if the data changes, mWhichChild might be out of the bounds of the adapter
            // in this case, we reset mWhichChild to the beginning
            if (mWhichChild >= mAdapter.getCount())
            if (mWhichChild >= mAdapter.getCount()) {
                mWhichChild = 0;

                showOnly(mWhichChild, true, true);
            }
            refreshChildren();
        }

        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {