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

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

            if (type != PageResult.INIT && type != PageResult.TILE) {
                throw new IllegalArgumentException("unexpected resultType" + type);
            }

            if (mStorage.getPageCount() == 0) {
                mStorage.initAndSplit(
                        pageResult.leadingNulls, pageResult.page, pageResult.trailingNulls,
                        pageResult.positionOffset, mConfig.pageSize, TiledPagedList.this);
            } else {
                mStorage.insertPage(pageResult.positionOffset, pageResult.page,
                        TiledPagedList.this);
            }

            if (mBoundaryCallback != null) {
                boolean deferEmpty = mStorage.size() == 0;
                boolean deferBegin = !deferEmpty
                        && pageResult.leadingNulls == 0
                        && pageResult.positionOffset == 0;
                int size = size();
                boolean deferEnd = !deferEmpty
                        && ((type == PageResult.INIT && pageResult.trailingNulls == 0)
                                || (type == PageResult.TILE
                                        && (pageResult.positionOffset + mConfig.pageSize >= size)));
                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 type,
                @NonNull PageResult<T> pageResult) {
            if (pageResult.isInvalid()) {
                detach();
                return;
            }
            if (isDetached()) {
                return;
            }
            if (type != PageResult.INIT && type != PageResult.TILE) {
                throw new IllegalArgumentException("unexpected resultType" + type);
            }
            if (mStorage.getPageCount() == 0) {
                mStorage.initAndSplit(
                        pageResult.leadingNulls, pageResult.page, pageResult.trailingNulls,
                        pageResult.positionOffset, mConfig.pageSize, TiledPagedList.this);
            } else {
                mStorage.insertPage(pageResult.positionOffset, pageResult.page,
                        TiledPagedList.this);
            }
            if (mBoundaryCallback != null) {
                boolean deferEmpty = mStorage.size() == 0;
                boolean deferBegin = !deferEmpty
                        && pageResult.leadingNulls == 0
                        && pageResult.positionOffset == 0;
                int size = size();
                boolean deferEnd = !deferEmpty
                        && ((type == PageResult.INIT && pageResult.trailingNulls == 0)
                                || (type == PageResult.TILE
                                        && (pageResult.positionOffset + mConfig.pageSize >= size)));
                deferBoundaryCallbacks(deferEmpty, deferBegin, deferEnd);
            }
        }
@ AnyThread @ Override public void onPageResult ( @ PageResult . ResultType int type , @ NonNull PageResult < T > pageResult ) { if ( pageResult . isInvalid ( ) ) { detach ( ) ; return ; } if ( isDetached ( ) ) { return ; } if ( type != PageResult . INIT && type != PageResult . TILE ) { throw new IllegalArgumentException ( "unexpected resultType" + type ) ; } if ( mStorage . getPageCount ( ) == 0 ) { mStorage . initAndSplit ( pageResult . leadingNulls , pageResult . page , pageResult . trailingNulls , pageResult . positionOffset , mConfig . pageSize , TiledPagedList . this ) ; } else { mStorage . insertPage ( pageResult . positionOffset , pageResult . page , TiledPagedList . this ) ; } if ( mBoundaryCallback != null ) { boolean deferEmpty = mStorage . size ( ) == 0 ; boolean deferBegin = ! deferEmpty && pageResult . leadingNulls == 0 && pageResult . positionOffset == 0 ; int size = size ( ) ; boolean deferEnd = ! deferEmpty && ( ( type == PageResult . INIT && pageResult . trailingNulls == 0 ) || ( type == PageResult . TILE && ( pageResult . positionOffset + mConfig . pageSize >= size ) ) ) ; 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