Merge "Add PagedList#getConfig" into oc-mr1-support-27.0-dev
diff --git a/paging/common/src/main/java/android/arch/paging/ContiguousPagedList.java b/paging/common/src/main/java/android/arch/paging/ContiguousPagedList.java
index 7835dbe..2a5cd42 100644
--- a/paging/common/src/main/java/android/arch/paging/ContiguousPagedList.java
+++ b/paging/common/src/main/java/android/arch/paging/ContiguousPagedList.java
@@ -85,8 +85,8 @@
         // blocking init just triggers the initial load on the construction thread -
         // Could still be posted with callback, if desired.
         mDataSource.loadInitial(key,
-                mConfig.mInitialLoadSizeHint,
-                mConfig.mEnablePlaceholders,
+                mConfig.initialLoadSizeHint,
+                mConfig.enablePlaceholders,
                 mReceiver);
     }
 
@@ -143,8 +143,8 @@
     @MainThread
     @Override
     protected void loadAroundInternal(int index) {
-        int prependItems = mConfig.mPrefetchDistance - (index - mStorage.getLeadingNullCount());
-        int appendItems = index + mConfig.mPrefetchDistance
+        int prependItems = mConfig.prefetchDistance - (index - mStorage.getLeadingNullCount());
+        int appendItems = index + mConfig.prefetchDistance
                 - (mStorage.getLeadingNullCount() + mStorage.getStorageCount());
 
         mPrependItemsRequested = Math.max(prependItems, mPrependItemsRequested);
@@ -175,7 +175,7 @@
                 if (isDetached()) {
                     return;
                 }
-                mDataSource.loadBefore(position, item, mConfig.mPageSize, mReceiver);
+                mDataSource.loadBefore(position, item, mConfig.pageSize, mReceiver);
             }
         });
     }
@@ -198,7 +198,7 @@
                 if (isDetached()) {
                     return;
                 }
-                mDataSource.loadAfter(position, item, mConfig.mPageSize, mReceiver);
+                mDataSource.loadAfter(position, item, mConfig.pageSize, mReceiver);
             }
         });
     }
diff --git a/paging/common/src/main/java/android/arch/paging/PagedList.java b/paging/common/src/main/java/android/arch/paging/PagedList.java
index 1f07bfa..51f524a 100644
--- a/paging/common/src/main/java/android/arch/paging/PagedList.java
+++ b/paging/common/src/main/java/android/arch/paging/PagedList.java
@@ -93,10 +93,12 @@
  * @param <T> The type of the entries in the list.
  */
 public abstract class PagedList<T> extends AbstractList<T> {
+    @NonNull
     final Executor mMainThreadExecutor;
+    @NonNull
     final Executor mBackgroundThreadExecutor;
+    @NonNull
     final Config mConfig;
-
     @NonNull
     final PagedStorage<?, T> mStorage;
 
@@ -139,7 +141,7 @@
             @NonNull Executor backgroundThreadExecutor,
             @NonNull Config config,
             @Nullable K key) {
-        if (dataSource.isContiguous() || !config.mEnablePlaceholders) {
+        if (dataSource.isContiguous() || !config.enablePlaceholders) {
             if (!dataSource.isContiguous()) {
                 //noinspection unchecked
                 dataSource = (DataSource<K, T>) ((TiledDataSource<T>) dataSource).getAsContiguous();
@@ -361,6 +363,16 @@
     abstract boolean isContiguous();
 
     /**
+     * Return the Config used to construct this PagedList.
+     *
+     * @return the Config of this PagedList
+     */
+    @NonNull
+    public Config getConfig() {
+        return mConfig;
+    }
+
+    /**
      * Return the key for the position passed most recently to {@link #loadAround(int)}.
      * <p>
      * When a PagedList is invalidated, you can pass the key returned by this function to initialize
@@ -480,6 +492,7 @@
         if (count != 0) {
             for (int i = mCallbacks.size() - 1; i >= 0; i--) {
                 Callback callback = mCallbacks.get(i).get();
+
                 if (callback != null) {
                     callback.onChanged(position, count);
                 }
@@ -538,17 +551,41 @@
      * {@link Builder#setPageSize(int)}, which defines number of items loaded at a time}.
      */
     public static class Config {
-        final int mPageSize;
-        final int mPrefetchDistance;
-        final boolean mEnablePlaceholders;
-        final int mInitialLoadSizeHint;
+        /**
+         * Size of each page loaded by the PagedList.
+         */
+        public final int pageSize;
+
+        /**
+         * Prefetch distance which defines how far ahead to load.
+         * <p>
+         * If this value is set to 50, the paged list will attempt to load 50 items in advance of
+         * data that's already been accessed.
+         *
+         * @see PagedList#loadAround(int)
+         */
+        @SuppressWarnings("WeakerAccess")
+        public final int prefetchDistance;
+
+        /**
+         * Defines whether the PagedList may display null placeholders, if the DataSource provides
+         * them.
+         */
+        @SuppressWarnings("WeakerAccess")
+        public final boolean enablePlaceholders;
+
+        /**
+         * Size hint for initial load of PagedList, often larger than a regular page.
+         */
+        @SuppressWarnings("WeakerAccess")
+        public final int initialLoadSizeHint;
 
         private Config(int pageSize, int prefetchDistance,
                 boolean enablePlaceholders, int initialLoadSizeHint) {
-            mPageSize = pageSize;
-            mPrefetchDistance = prefetchDistance;
-            mEnablePlaceholders = enablePlaceholders;
-            mInitialLoadSizeHint = initialLoadSizeHint;
+            this.pageSize = pageSize;
+            this.prefetchDistance = prefetchDistance;
+            this.enablePlaceholders = enablePlaceholders;
+            this.initialLoadSizeHint = initialLoadSizeHint;
         }
 
         /**
diff --git a/paging/common/src/main/java/android/arch/paging/TiledPagedList.java b/paging/common/src/main/java/android/arch/paging/TiledPagedList.java
index c45d029..934a0dd 100644
--- a/paging/common/src/main/java/android/arch/paging/TiledPagedList.java
+++ b/paging/common/src/main/java/android/arch/paging/TiledPagedList.java
@@ -80,11 +80,11 @@
                 mainThreadExecutor, backgroundThreadExecutor, config);
         mDataSource = dataSource;
 
-        final int pageSize = mConfig.mPageSize;
+        final int pageSize = mConfig.pageSize;
 
         final int itemCount = mDataSource.countItems();
         final int firstLoadSize = Math.min(itemCount,
-                (Math.max(mConfig.mInitialLoadSizeHint / pageSize, 2)) * pageSize);
+                (Math.max(mConfig.initialLoadSizeHint / pageSize, 2)) * pageSize);
         final int firstLoadPosition = computeFirstLoadPosition(
                 position, firstLoadSize, pageSize, itemCount);
 
@@ -126,7 +126,7 @@
 
         // loop through each page and signal the callback for any pages that are present now,
         // but not in the snapshot.
-        final int pageSize = mConfig.mPageSize;
+        final int pageSize = mConfig.pageSize;
         final int leadingNullPages = mStorage.getLeadingNullCount() / pageSize;
         final int pageCount = mStorage.getPageCount();
         for (int i = 0; i < pageCount; i++) {
@@ -148,7 +148,7 @@
 
     @Override
     protected void loadAroundInternal(int index) {
-        mStorage.allocatePlaceholders(index, mConfig.mPrefetchDistance, mConfig.mPageSize, this);
+        mStorage.allocatePlaceholders(index, mConfig.prefetchDistance, mConfig.pageSize, this);
     }
 
     @Override
@@ -175,7 +175,7 @@
                 if (isDetached()) {
                     return;
                 }
-                final int pageSize = mConfig.mPageSize;
+                final int pageSize = mConfig.pageSize;
                 mDataSource.loadRange(pageIndex * pageSize, pageSize, mReceiver);
             }
         });