paging/common/src/main/java/androidx/paging/ContiguousPagedList.java
@AnyThread
        @Override
        public void onPageResult(@PageResult.ResultType int resultType,
                @NonNull PageResult<V> pageResult) {
            if (pageResult.isInvalid()) {
                detach();
                return;
            }

            if (isDetached()) {
                // No op, have detached
                return;
            }

            List<V> page = pageResult.page;
            if (resultType == PageResult.INIT) {
                mStorage.init(pageResult.leadingNulls, page, pageResult.trailingNulls,
                        pageResult.positionOffset, ContiguousPagedList.this);
                if (mLastLoad == LAST_LOAD_UNSPECIFIED) {
                    // Because the ContiguousPagedList wasn't initialized with a last load position,
                    // initialize it to the middle of the initial load
                    mLastLoad =
                            pageResult.leadingNulls + pageResult.positionOffset + page.size() / 2;
                }
            } else if (resultType == PageResult.APPEND) {
                mStorage.appendPage(page, ContiguousPagedList.this);
            } else if (resultType == PageResult.PREPEND) {
                mStorage.prependPage(page, ContiguousPagedList.this);
            } else {
                throw new IllegalArgumentException("unexpected resultType " + resultType);
            }


            if (mBoundaryCallback != null) {
                boolean deferEmpty = mStorage.size() == 0;
                boolean deferBegin = !deferEmpty
                        && resultType == PageResult.PREPEND
                        && pageResult.page.size() == 0;
                boolean deferEnd = !deferEmpty
                        && resultType == PageResult.APPEND
                        && pageResult.page.size() == 0;
                deferBoundaryCallbacks(deferEmpty, deferBegin, deferEnd);
            }
        }
// Safe to access main thread only state - no other thread has reference during construction
Safe to access main thread only state - no other thread has reference during construction
Safe to access main thread only state - no other thread has reference during construction
@AnyThread
        @Override
        public void onPageResult(@PageResult.ResultType int resultType,
                @NonNull PageResult<V> pageResult) {
            if (pageResult.isInvalid()) {
                detach();
                return;
            }
            if (isDetached()) {
                return;
            }
            List<V> page = pageResult.page;
            if (resultType == PageResult.INIT) {
                mStorage.init(pageResult.leadingNulls, page, pageResult.trailingNulls,
                        pageResult.positionOffset, ContiguousPagedList.this);
                if (mLastLoad == LAST_LOAD_UNSPECIFIED) {
                    mLastLoad =
                            pageResult.leadingNulls + pageResult.positionOffset + page.size() / 2;
                }
            } else if (resultType == PageResult.APPEND) {
                mStorage.appendPage(page, ContiguousPagedList.this);
            } else if (resultType == PageResult.PREPEND) {
                mStorage.prependPage(page, ContiguousPagedList.this);
            } else {
                throw new IllegalArgumentException("unexpected resultType " + resultType);
            }
            if (mBoundaryCallback != null) {
                boolean deferEmpty = mStorage.size() == 0;
                boolean deferBegin = !deferEmpty
                        && resultType == PageResult.PREPEND
                        && pageResult.page.size() == 0;
                boolean deferEnd = !deferEmpty
                        && resultType == PageResult.APPEND
                        && pageResult.page.size() == 0;
                deferBoundaryCallbacks(deferEmpty, deferBegin, deferEnd);
            }
        }
@ AnyThread @ Override public void onPageResult ( @ PageResult . ResultType int resultType , @ NonNull PageResult < V > pageResult ) { if ( pageResult . isInvalid ( ) ) { detach ( ) ; return ; } if ( isDetached ( ) ) { return ; } List < V > page = pageResult . page ; if ( resultType == PageResult . INIT ) { mStorage . init ( pageResult . leadingNulls , page , pageResult . trailingNulls , pageResult . positionOffset , ContiguousPagedList . this ) ; if ( mLastLoad == LAST_LOAD_UNSPECIFIED ) { mLastLoad = pageResult . leadingNulls + pageResult . positionOffset + page . size ( ) / 2 ; } } else if ( resultType == PageResult . APPEND ) { mStorage . appendPage ( page , ContiguousPagedList . this ) ; } else if ( resultType == PageResult . PREPEND ) { mStorage . prependPage ( page , ContiguousPagedList . this ) ; } else { throw new IllegalArgumentException ( "unexpected resultType " + resultType ) ; } if ( mBoundaryCallback != null ) { boolean deferEmpty = mStorage . size ( ) == 0 ; boolean deferBegin = ! deferEmpty && resultType == PageResult . PREPEND && pageResult . page . size ( ) == 0 ; boolean deferEnd = ! deferEmpty && resultType == PageResult . APPEND && pageResult . page . size ( ) == 0 ; deferBoundaryCallbacks ( deferEmpty , deferBegin , deferEnd ) ; } }
Safe to access main thread only state - no other thread has reference during construction
Safe to access main thread only state - no other thread has reference during construction
// No op, have detached // Because the ContiguousPagedList wasn't initialized with a last load position, // initialize it to the middle of the initial load