Status Update
Comments
du...@google.com <du...@google.com> #2
With paging2 and the PagedListAdapter, I was simply checking if the list was empty before sending it to the adapter so I wasn't handle it with the adapter (which is probably wrong).
I tried to migrate to paging3 but I couldn't because I don't know how to check if the list is empty, as the PagingData that we send to the new adapter doesn't expose the list or an isEmpty method.
yb...@google.com <yb...@google.com> #3
Thanks for this, this is something we are definitely interested in! As a workaround, you can check adapter.itemCount
.
yb...@google.com <yb...@google.com> #4
We have a sample snippet showing how to use adapter.itemCount
in this way, but forgot to link it in KDocs (whoops):
Will fix.
yb...@google.com <yb...@google.com> #5
To be clear, adapter.itemCount
will only work if placeholdersEnabled
is false
.
We held off on this change because we wanted to take some time to properly explore what it would look like to provide a public API to view the PagingState or the internal PageEvent stream, but it's clear there's immediate need for this.
In the meantime, here's an idea for a CL which adds a Boolean
to dataRefreshFlow
, which we could merge for alpha02:
yb...@google.com <yb...@google.com> #6
Branch: androidx-master-dev
commit 0deeb4e05177350b8c2b444e6db418b9fc7aa66b
Author: Chris Craik <ccraik@google.com>
Date: Tue Jun 16 08:26:09 2020
Actually link addLoadStateListenerSample in kdocs
Bug: 159054196
Test: Ctrl-Q in Studio
Change-Id: Ieabb25de3625a22f8107f1192af54e986a50d1d3
M paging/runtime/src/main/java/androidx/paging/PagingDataAdapter.kt
yb...@google.com <yb...@google.com> #7
Branch: androidx-master-dev
commit 38a9eb05e73e822f70348aa22264b36e6790dba8
Author: Dustin Lam <dustinlam@google.com>
Date: Tue Jun 16 09:24:15 2020
Add isEmpty param to dataRefreshFlow / listener
RelNote: "The adapter APIs, dataRefreshFlow and dataRefreshListener
now pass a Boolean to signal whether a PagingData is empty"
Fixes: 159054196
Test: ./gradlew paging:paging-runtime:cC
Change-Id: I6e37e844cf9f947aeefaaa99d22b2672e04f207d
M paging/common/src/main/kotlin/androidx/paging/PagingDataDiffer.kt
M paging/common/src/test/kotlin/androidx/paging/PagingDataDifferTest.kt
M paging/runtime/api/3.0.0-alpha02.txt
M paging/runtime/api/current.txt
M paging/runtime/api/public_plus_experimental_3.0.0-alpha02.txt
M paging/runtime/api/public_plus_experimental_current.txt
M paging/runtime/api/restricted_3.0.0-alpha02.txt
M paging/runtime/api/restricted_current.txt
M paging/runtime/src/main/java/androidx/paging/AsyncPagingDataDiffer.kt
M paging/runtime/src/main/java/androidx/paging/PagingDataAdapter.kt
yb...@google.com <yb...@google.com> #8
btw, until we fix this, you can work around it by adding a flowOn(some background dispatcher)
your pagingData collector which will work around this issue by always calling the factory on a background thread.
ap...@google.com <ap...@google.com> #9
Branch: androidx-master-dev
commit cfd1258a8911348898cd07d1b02b00d14917159d
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Dec 01 17:01:50 2020
Ensure legacy data source is always created on the fetcher
This CL fixes a bug where we could possibly create the legacy data
source on the main thread (more specifically, the thread where flow
collection happens).
We already tried to prevent it by making it lazy, assuming the first
call will be a loadInitial call but it is not the case for invalidations
where we end up calling dataSource.isInvalid which might create it
(lazy) and then call isInvalid. This issue became more appearant because
Room's limit offset data source implementations might run a database
query to check for invalidation, possibly causing ANR.
In this CL, I changed the paging source factory to be a suspend function
in Fetcher (it is internal class). Public API (Pager) still expects a
regular function. To workaround it, now asPagingSource returns a known
internal class (SuspendingPagingSourceFactory) which extends Function0
but also has another suspend function to create the paging source.
Pager, when initializing PageFetcher, checks the instance of the
function to unwrap it before creating the fetcher.
This WONT work if someone wraps that function but besides that, for the
common case, this should fix the issue until we can move everyone off of
Paging2 APIs, including Room.
I've also slightly changed the legacy paging source implementation not
to rely on overriding invalidate to be able to remove that method from
public API.
Bug: 173029013
Bug: 137971356
Test: LegacyPagingSourceTest
RelNote: "PagingSource.invalidate is no longer an open function. If you
need to get notified when invalidation happens, consider calling the
registerInvalidatedCallback method instead of overriding invalidate."
Change-Id: I628d9893a4ac55409aa24e49de1e2d2c35beda4f
M paging/common/api/current.txt
M paging/common/api/public_plus_experimental_current.txt
M paging/common/api/restricted_current.txt
M paging/common/src/main/kotlin/androidx/paging/DataSource.kt
M paging/common/src/main/kotlin/androidx/paging/LegacyPagingSource.kt
M paging/common/src/main/kotlin/androidx/paging/PageFetcher.kt
M paging/common/src/main/kotlin/androidx/paging/PagedList.kt
M paging/common/src/main/kotlin/androidx/paging/Pager.kt
M paging/common/src/main/kotlin/androidx/paging/PagingSource.kt
A paging/common/src/main/kotlin/androidx/paging/SuspendingPagingSourceFactory.kt
M paging/common/src/test/kotlin/androidx/paging/LegacyPagingSourceTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageFetcherSnapshotTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageFetcherTest.kt
M paging/common/src/test/kotlin/androidx/paging/PageKeyedDataSourceTest.kt
M paging/common/src/test/kotlin/androidx/paging/PagedListTest.kt
M paging/runtime/src/androidTest/java/androidx/paging/AsyncPagedListDifferTest.kt
M testutils/testutils-common/src/main/java/androidx/testutils/TestExecutor.kt
yb...@google.com <yb...@google.com>
sa...@gmail.com <sa...@gmail.com> #10
For the ones like me, an android dev working on a real project using the Paging 3, the suggested workaround flowOn(some background dispatcher)
was the only solution that fixed my need of creating a source in a suspendable fashion.
Why not allowing the pagingSourceFactory
to be suspendable? I didn't find a prettier solution than doing:
// viewModel
pagingSourceFactory = { runBlocking { createPagingSource() } }
// fragment
viewLifecycleOwner.lifecycleScope.launchWhenStarted {
successState.results
.flowOn(Dispatchers.IO)
.collect(searchResultsAdapter::submitData)
}
Which is not readable nor straightforward. At least, opening your internal SuspendingPagingSourceFactory<Key, Value>
would help, letting me extend my source factory to be cleaner and readable.
Description
Component used: paging3 Version used: androidx.paging:paging-runtime-ktx:3.0.0-alpha09 Devices/Android versions reproduced on: Pixel 4 xl
sometimes ANR happens, see BLOCKED threads