void deferBoundaryCallbacks ( final boolean deferEmpty , final boolean deferBegin , final boolean deferEnd ) { if ( mBoundaryCallback == null ) { throw new IllegalStateException ( "Can't defer BoundaryCallback, no instance" ) ; } /* * If lowest/highest haven't been initialized, set them to storage size, * since placeholders must already be computed by this point. * * This is just a minor optimization so that BoundaryCallback callbacks are sent immediately * if the initial load size is smaller than the prefetch window (see * TiledPagedListTest#boundaryCallback_immediate()) */ if ( mLowestIndexAccessed == Integer . MAX_VALUE ) { mLowestIndexAccessed = mStorage . size ( ) ; } if ( mHighestIndexAccessed == Integer . MIN_VALUE ) { mHighestIndexAccessed = 0 ; } if ( deferEmpty || deferBegin || deferEnd ) { // Post to the main thread, since we may be on creation thread currently mMainThreadExecutor . execute ( new Runnable ( ) { @ Override public void run ( ) { // on is dispatched immediately, since items won't be accessed //noinspection ConstantConditions if ( deferEmpty ) { mBoundaryCallback . onZeroItemsLoaded ( ) ; } // for other callbacks, mark deferred, and only dispatch if loadAround // has been called near to the position if ( deferBegin ) { mBoundaryCallbackBeginDeferred = true ; } if ( deferEnd ) { mBoundaryCallbackEndDeferred = true ; } tryDispatchBoundaryCallbacks ( false ) ; } } ) ; } }
Safe to access main thread only state - no other thread has reference during construction