Support simple state restoration cases
This CL allows paging to restore its state when:
a) flow is cached and application is not killed (e.g. flow is cached
in a view model and activity is recreated in process)
b) paging source is counted, placeholders are enabled and the layout is
not staggered.
This CL changes PagingDataAdapter's state restoration strategy to
PREVENT and then watches for the first insert event to allow it.
When first insert event arrives (even when it is empty), we allow state
restoration (to acocunt for new list being empty for real).
If user calls, setRestorationStrategy, this logic is no-op.
Both if these work without any aide from `initialKey`. In case of option
`B`, not having initial key means we'll load all pages from beginning
till the current position, which is why placeholders are necessary
(otherwise, recyclerview won't find the position it wants and abort
restoration or go to closest position).
Bug: 141189835
Test: StateRestorationTest
Change-Id: Ibd8a54cbb12b3f5e00010ea22c90646bcf385e70
diff --git a/paging/runtime/build.gradle b/paging/runtime/build.gradle
index 9a80921..4c3019b 100644
--- a/paging/runtime/build.gradle
+++ b/paging/runtime/build.gradle
@@ -26,6 +26,12 @@
id("kotlin-android")
}
+android {
+ defaultConfig {
+ multiDexEnabled true
+ }
+}
+
dependencies {
api(project(":paging:paging-common"))
// Ensure that the -ktx dependency graph mirrors the Java dependency graph
@@ -46,9 +52,11 @@
androidTestImplementation(ANDROIDX_TEST_EXT_JUNIT)
androidTestImplementation(ANDROIDX_TEST_RUNNER)
androidTestImplementation("androidx.arch.core:core-testing:2.1.0")
+ androidTestImplementation(TRUTH)
androidTestImplementation(KOTLIN_TEST)
androidTestImplementation(KOTLIN_COROUTINES_TEST)
androidTestImplementation(JUNIT)
+ androidTestImplementation(MULTIDEX)
}
androidx {