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

Commit 3042944c authored by Adam Cohen's avatar Adam Cohen
Browse files

Fixing AdapterViewAnimator crash when associated adapter is empty

Change-Id: I3186452eb93f1141b06531507b13d87804e684d4
parent e86b8a18
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -324,7 +324,11 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
    }

    private int modulo(int pos, int size) {
        if (size > 0) {
            return (size + (pos % size)) % size;
        } else {
            return 0;
        }
    }

    /**
@@ -383,6 +387,8 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>

    void showOnly(int childIndex, boolean animate, boolean onLayout) {
        if (mAdapter == null) return;
        final int adapterCount = mAdapter.getCount();
        if (adapterCount == 0) return;

        for (int i = 0; i < mPreviousViews.size(); i++) {
            View viewToRemove = mViewsMap.get(mPreviousViews.get(i)).view;
@@ -399,7 +405,6 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
            removeViewInLayout(viewToRemove);
        }
        mPreviousViews.clear();
        int adapterCount = mAdapter.getCount();
        int newWindowStartUnbounded = childIndex - mActiveOffset;
        int newWindowEndUnbounded = newWindowStartUnbounded + mNumActiveViews - 1;
        int newWindowStart = Math.max(0, newWindowStartUnbounded);
+3 −1
Original line number Diff line number Diff line
@@ -749,8 +749,10 @@ public class StackView extends AdapterViewAnimator {
        if (mAdapter != null && mWhichChild == -1) {
            mWhichChild = mAdapter.getCount() - 1;
        }
        if (mWhichChild >= 0) {
            setDisplayedChild(mWhichChild);
        }
    }

    LayoutParams createOrReuseLayoutParams(View v) {
        final ViewGroup.LayoutParams currentLp = v.getLayoutParams();