[go: nahoru, domu]

Implement PagedSource with suspend load

Part of a series of changes needed to convert Paging for
ListenerableFutures to Kotlin coroutines.

Introduces the new PagedSource API that makes use of a KeyProvider to
delegate between different types of DataSources without requiring
developers to choose the correct subclass.

Additionally, adds an optional CoroutineScope parameter which defaults
to GlobalScope to PagedList builders that will be used to launch
PagedSource loads.

Test: ./greadlew paging:paging-common:check
Change-Id: I1847a43ac4aa693209fae620c63677398cbc94e0
diff --git a/paging/common/api/current.txt b/paging/common/api/current.txt
index 000c1e9..115c938 100644
--- a/paging/common/api/current.txt
+++ b/paging/common/api/current.txt
@@ -161,6 +161,7 @@
     method @Deprecated @WorkerThread public androidx.paging.PagedList<Value> build();
     method public com.google.common.util.concurrent.ListenableFuture<androidx.paging.PagedList<Value>> buildAsync();
     method public androidx.paging.PagedList.Builder<Key,Value> setBoundaryCallback(androidx.paging.PagedList.BoundaryCallback<Value>? boundaryCallback);
+    method public androidx.paging.PagedList.Builder<Key,Value> setCoroutineScope(kotlinx.coroutines.CoroutineScope coroutineScope);
     method public androidx.paging.PagedList.Builder<Key,Value> setFetchExecutor(java.util.concurrent.Executor fetchExecutor);
     method public androidx.paging.PagedList.Builder<Key,Value> setInitialKey(Key? initialKey);
     method public androidx.paging.PagedList.Builder<Key,Value> setNotifyExecutor(java.util.concurrent.Executor notifyExecutor);
@@ -222,7 +223,7 @@
     method public abstract androidx.paging.PagedSource.KeyProvider<Key,Value> getKeyProvider();
     method public abstract void invalidate();
     method public abstract boolean isRetryableError(Throwable error);
-    method public abstract com.google.common.util.concurrent.ListenableFuture<androidx.paging.PagedSource.LoadResult<Key,Value>> load(androidx.paging.PagedSource.LoadParams<Key> params);
+    method public abstract suspend Object load(androidx.paging.PagedSource.LoadParams<Key> params, kotlin.coroutines.Continuation<? super androidx.paging.PagedSource.LoadResult<Key,Value>> p);
     property public abstract boolean invalid;
     property public abstract androidx.paging.PagedSource.KeyProvider<Key,Value> keyProvider;
     field public static final int COUNT_UNDEFINED = -1; // 0xffffffff