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

Commit aadf4fb6 authored by Adam Powell's avatar Adam Powell
Browse files

More fun with AbsListView smooth scrolling

If any data set change is pending when a smooth scroll is requested,
post it for later - not just if the list is currently empty.

Fix a bug in relative smooth scrolling where the last view was being
determined incorrectly.

Bug 6434713

Change-Id: Ic249eefc594151a414a6a8758074a9a60888e2b4
parent 1705b2a5
Loading
Loading
Loading
Loading
+39 −19
Original line number Diff line number Diff line
@@ -4009,17 +4009,19 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        void start(final int position) {
            stop();

            final int childCount = getChildCount();
            if (childCount == 0) {
                // Can't scroll without children.
            if (mDataChanged) {
                    // But we might have something in a minute.
                // Wait until we're back in a stable state to try this.
                post(new Runnable() {
                    @Override public void run() {
                        start(position);
                    }
                });
                return;
            }

            final int childCount = getChildCount();
            if (childCount == 0) {
                // Can't scroll without children.
                return;
            }

@@ -4058,17 +4060,19 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                return;
            }

            final int childCount = getChildCount();
            if (childCount == 0) {
                // Can't scroll without children.
            if (mDataChanged) {
                    // But we might have something in a minute.
                // Wait until we're back in a stable state to try this.
                post(new Runnable() {
                    @Override public void run() {
                        start(position, boundPosition);
                    }
                });
                return;
            }

            final int childCount = getChildCount();
            if (childCount == 0) {
                // Can't scroll without children.
                return;
            }

@@ -4129,9 +4133,26 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            startWithOffset(position, offset, SCROLL_DURATION);
        }

        void startWithOffset(int position, int offset, int duration) {
        void startWithOffset(final int position, int offset, final int duration) {
            stop();

            if (mDataChanged) {
                // Wait until we're back in a stable state to try this.
                final int postOffset = offset;
                post(new Runnable() {
                    @Override public void run() {
                        startWithOffset(position, postOffset, duration);
                    }
                });
                return;
            }

            final int childCount = getChildCount();
            if (childCount == 0) {
                // Can't scroll without children.
                return;
            }

            offset += getPaddingTop();

            mTargetPos = position;
@@ -4141,7 +4162,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            mMode = MOVE_OFFSET;

            final int firstPos = mFirstPosition;
            final int childCount = getChildCount();
            final int lastPos = firstPos + childCount - 1;

            int viewTravelCount;
@@ -4514,7 +4534,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

        if (distance == 0 || mItemCount == 0 || childCount == 0 ||
                (firstPos == 0 && getChildAt(0).getTop() == topLimit && distance < 0) ||
                (lastPos == mItemCount - 1 &&
                (lastPos == mItemCount &&
                        getChildAt(childCount - 1).getBottom() == bottomLimit && distance > 0)) {
            mFlingRunnable.endFling();
            if (mPositionScroller != null) {