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

Commit 830a0024 authored by Jorge Ruesga's avatar Jorge Ruesga
Browse files

listview: ensure active views are filled prior than scrap views



The internal Recycler#fillActiveViews should be called prior to add any view
to the scrapViews queue, so it can be use safely without detaching views
because out of sync.

Change-Id: Ie119ad871a89e0a3fa1e07e955fcd5ca7b171f46
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent 3c0c8f14
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -6500,6 +6500,12 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        private SparseArray<View> mTransientStateViews;
        private LongSparseArray<View> mTransientStateViewsById;

        private boolean mIsActiveViewsInitialized;

        boolean isActiveViewsInitialized() {
            return mIsActiveViewsInitialized;
        }

        public void setViewTypeCount(int viewTypeCount) {
            if (viewTypeCount < 1) {
                throw new IllegalArgumentException("Can't have a viewTypeCount < 1");
@@ -6571,6 +6577,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            }

            clearTransientStateViews();

            // We want to a refresh of mActiveViews
            mIsActiveViewsInitialized = false;
        }

        /**
@@ -6581,6 +6590,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
         *        mActiveViews
         */
        void fillActiveViews(int childCount, int firstActivePosition) {
            // The recyclebin is initialized when we have some active views.
            if (childCount > 0) {
                mIsActiveViewsInitialized = true;
            }

            if (mActiveViews.length < childCount) {
                mActiveViews = new View[childCount];
            }
+1 −1
Original line number Diff line number Diff line
@@ -1207,7 +1207,7 @@ public class GridView extends AbsListView {
            final int firstPosition = mFirstPosition;
            final RecycleBin recycleBin = mRecycler;

            if (dataChanged) {
            if (mRecycler.isActiveViewsInitialized() && dataChanged) {
                for (int i = 0; i < childCount; i++) {
                    recycleBin.addScrapView(getChildAt(i), firstPosition+i);
                }
+1 −1
Original line number Diff line number Diff line
@@ -1584,7 +1584,7 @@ public class ListView extends AbsListView {
            // These views will be reused if possible
            final int firstPosition = mFirstPosition;
            final RecycleBin recycleBin = mRecycler;
            if (dataChanged) {
            if (mRecycler.isActiveViewsInitialized() && dataChanged) {
                for (int i = 0; i < childCount; i++) {
                    recycleBin.addScrapView(getChildAt(i), firstPosition+i);
                }