How to make pagination work for firestore in realtime on Android?
I went through Doug Coding's solution to pagination for Firestore using Android architecture patterns present at https://github.com/CodingDoug/firebase-jetpack. My concern is that how do I make this work in realtime using Android architecture components.
I attempted a solution which is described as follows but there are some issues with it. I tried to make pagination work in realtime by creating a FirestoreBoundaryCallback
:-
class FirestoreBoundaryCallback<T>(
private val baseQuery: Query,
private val factory: FirestoreQueryDataSource.Factory,
private val lifecycleOwner: LifecycleOwner): PagedList.BoundaryCallback<QueryItemOrException<T>>() {
private val allLiveData = mutableListOf<FirebaseQueryLiveData>()
private val mutableLoadingState = MutableLiveData<LoadingState>()
val loadingState: LiveData<LoadingState>
get() = mutableLoadingState
override fun onZeroItemsLoaded() {
allLiveData.clear()
mutableLoadingState.value = LoadingState.LOADING_INITIAL
val query = baseQuery.limit(50)
val liveData = FirebaseQueryLiveData(query)
liveData.observe(lifecycleOwner, Observer {
mergeAllDocs()
if (mutableLoadingState.value != LoadingState.LOADED) {
mutableLoadingState.value = LoadingState.LOADED
}
})
allLiveData.add(liveData)
}
override fun onItemAtEndLoaded(itemAtEnd: QueryItemOrException<T>) {
if (allLiveData.isNotEmpty() && allLiveData.last().value?.data?.documents?.isNotEmpty() == true) {
val lastDocument = allLiveData.last().value?.data?.documents?.last()
if (lastDocument != null) {
val query = baseQuery.startAfter(lastDocument).limit(50)
val liveData = FirebaseQueryLiveData(query)
mutableLoadingState.value = LoadingState.LOADING_MORE
liveData.observe(lifecycleOwner, Observer {
mergeAllDocs()
if (mutableLoadingState.value != LoadingState.LOADED) {
mutableLoadingState.value = LoadingState.LOADED
}
})
allLiveData.add(liveData)
}
}
}
fun mergeAllDocs() {
val items = mutableListOf<DocumentSnapshot>()
allLiveData.forEach{
val docs = it.value?.data?.documents
if (docs != null) {
items.addAll(docs)
}
}
factory.setItems(items)
}
override fun onItemAtFrontLoaded(itemAtFront: QueryItemOrException<T>) {
}
}
And then I modified the FirestoreQueryDataSource in the following way:-
class FirestoreQueryDataSource private constructor(
private val documentSnapshots: List<DocumentSnapshot>
) : PageKeyedDataSource<PageKey, DocumentSnapshot>() {
companion object {
private const val TAG = "FirestoreQueryDataSrc"
}
class Factory(private val query: Query, private val source: Source) : DataSource.Factory<PageKey, DocumentSnapshot>() {
val sourceLiveData = MutableLiveData<FirestoreQueryDataSource>()
var documentSnapshots: List<DocumentSnapshot> = mutableListOf()
fun setItems(items: List<DocumentSnapshot>) {
sourceLiveData.value?.invalidate()
documentSnapshots = items
sourceLiveData.postValue(FirestoreQueryDataSource(documentSnapshots))
}
override fun create(): DataSource<PageKey, DocumentSnapshot> {
val dataSource = FirestoreQueryDataSource(documentSnapshots)
sourceLiveData.postValue(dataSource)
return dataSource
}
}
override fun loadInitial(
params: LoadInitialParams<PageKey>,
callback: LoadInitialCallback<PageKey, DocumentSnapshot>) {
val firstPageDocSnapshots = documentSnapshots.take(params.requestedLoadSize)
val nextPageKey = getNextPageKey(firstPageDocSnapshots)
callback.onResult(firstPageDocSnapshots, null, nextPageKey)
}
override fun loadAfter(
params: LoadParams<PageKey>,
callback: LoadCallback<PageKey, DocumentSnapshot>) {
val startAfterIndex = documentSnapshots.indexOf(params.key.startAfterDoc)
var endIndex = startAfterIndex + params.requestedLoadSize
if (endIndex > documentSnapshots.size) {
endIndex = documentSnapshots.size - 1;
}
val afterInitialPageDocs = documentSnapshots.subList(startAfterIndex, endIndex)
val nextPageKey = getNextPageKey(afterInitialPageDocs)
callback.onResult(afterInitialPageDocs, nextPageKey)
}
override fun loadBefore(
params: LoadParams<PageKey>,
callback: LoadCallback<PageKey, DocumentSnapshot>) {
// The paging here only understands how to append new items to the
// results, not prepend items from earlier pages.
callback.onResult(emptyList(), null)
}
private fun getNextPageKey(documents: List<DocumentSnapshot>): PageKey? {
return if (documents.isNotEmpty()) {
PageKey(documents.last())
} else {
null
}
}
}
data class PageKey(val startAfterDoc: DocumentSnapshot)
In my ViewModel, this is what I return:-
val sourceFactory = FirestoreQueryDataSource.Factory(query, Source.DEFAULT)
val deserializedDataSourceFactory = sourceFactory.map { snapshot ->
try {
val item = QueryItem(Deserializer.deserialize(snapshot, Record::class.java), snapshot.id)
item.item.id = snapshot.id
QueryItemOrException(item, null)
} catch (e: Exception) {
Log.e(TAG, "Error while deserializing order", e)
QueryItemOrException<PosOrder>(null, e)
}
}
val boundaryCallback = FirestoreBoundaryCallback<Record>(query, sourceFactory, lifecycleOwner)
val livePagedList = LivePagedListBuilder(deserializedDataSourceFactory, 30)
.setFetchExecutor(executors.cpuExecutorService)
.setBoundaryCallback(boundaryCallback)
.build()
return Listing(
pagedList = livePagedList,
loadingState = boundaryCallback.loadingState,
refresh = {
sourceFactory.sourceLiveData.value?.invalidate()
}
)
The performance is not good and also I am concerned that when a new record is inserted, the first page will lose its last record (since the limit is fixed for the first query) and second page will continue to start AFTER the last record of the older first page. What would be the correct way of paginating firestore data on Android with realtime updates?
android firebase google-cloud-firestore android-architecture-components
add a comment |
I went through Doug Coding's solution to pagination for Firestore using Android architecture patterns present at https://github.com/CodingDoug/firebase-jetpack. My concern is that how do I make this work in realtime using Android architecture components.
I attempted a solution which is described as follows but there are some issues with it. I tried to make pagination work in realtime by creating a FirestoreBoundaryCallback
:-
class FirestoreBoundaryCallback<T>(
private val baseQuery: Query,
private val factory: FirestoreQueryDataSource.Factory,
private val lifecycleOwner: LifecycleOwner): PagedList.BoundaryCallback<QueryItemOrException<T>>() {
private val allLiveData = mutableListOf<FirebaseQueryLiveData>()
private val mutableLoadingState = MutableLiveData<LoadingState>()
val loadingState: LiveData<LoadingState>
get() = mutableLoadingState
override fun onZeroItemsLoaded() {
allLiveData.clear()
mutableLoadingState.value = LoadingState.LOADING_INITIAL
val query = baseQuery.limit(50)
val liveData = FirebaseQueryLiveData(query)
liveData.observe(lifecycleOwner, Observer {
mergeAllDocs()
if (mutableLoadingState.value != LoadingState.LOADED) {
mutableLoadingState.value = LoadingState.LOADED
}
})
allLiveData.add(liveData)
}
override fun onItemAtEndLoaded(itemAtEnd: QueryItemOrException<T>) {
if (allLiveData.isNotEmpty() && allLiveData.last().value?.data?.documents?.isNotEmpty() == true) {
val lastDocument = allLiveData.last().value?.data?.documents?.last()
if (lastDocument != null) {
val query = baseQuery.startAfter(lastDocument).limit(50)
val liveData = FirebaseQueryLiveData(query)
mutableLoadingState.value = LoadingState.LOADING_MORE
liveData.observe(lifecycleOwner, Observer {
mergeAllDocs()
if (mutableLoadingState.value != LoadingState.LOADED) {
mutableLoadingState.value = LoadingState.LOADED
}
})
allLiveData.add(liveData)
}
}
}
fun mergeAllDocs() {
val items = mutableListOf<DocumentSnapshot>()
allLiveData.forEach{
val docs = it.value?.data?.documents
if (docs != null) {
items.addAll(docs)
}
}
factory.setItems(items)
}
override fun onItemAtFrontLoaded(itemAtFront: QueryItemOrException<T>) {
}
}
And then I modified the FirestoreQueryDataSource in the following way:-
class FirestoreQueryDataSource private constructor(
private val documentSnapshots: List<DocumentSnapshot>
) : PageKeyedDataSource<PageKey, DocumentSnapshot>() {
companion object {
private const val TAG = "FirestoreQueryDataSrc"
}
class Factory(private val query: Query, private val source: Source) : DataSource.Factory<PageKey, DocumentSnapshot>() {
val sourceLiveData = MutableLiveData<FirestoreQueryDataSource>()
var documentSnapshots: List<DocumentSnapshot> = mutableListOf()
fun setItems(items: List<DocumentSnapshot>) {
sourceLiveData.value?.invalidate()
documentSnapshots = items
sourceLiveData.postValue(FirestoreQueryDataSource(documentSnapshots))
}
override fun create(): DataSource<PageKey, DocumentSnapshot> {
val dataSource = FirestoreQueryDataSource(documentSnapshots)
sourceLiveData.postValue(dataSource)
return dataSource
}
}
override fun loadInitial(
params: LoadInitialParams<PageKey>,
callback: LoadInitialCallback<PageKey, DocumentSnapshot>) {
val firstPageDocSnapshots = documentSnapshots.take(params.requestedLoadSize)
val nextPageKey = getNextPageKey(firstPageDocSnapshots)
callback.onResult(firstPageDocSnapshots, null, nextPageKey)
}
override fun loadAfter(
params: LoadParams<PageKey>,
callback: LoadCallback<PageKey, DocumentSnapshot>) {
val startAfterIndex = documentSnapshots.indexOf(params.key.startAfterDoc)
var endIndex = startAfterIndex + params.requestedLoadSize
if (endIndex > documentSnapshots.size) {
endIndex = documentSnapshots.size - 1;
}
val afterInitialPageDocs = documentSnapshots.subList(startAfterIndex, endIndex)
val nextPageKey = getNextPageKey(afterInitialPageDocs)
callback.onResult(afterInitialPageDocs, nextPageKey)
}
override fun loadBefore(
params: LoadParams<PageKey>,
callback: LoadCallback<PageKey, DocumentSnapshot>) {
// The paging here only understands how to append new items to the
// results, not prepend items from earlier pages.
callback.onResult(emptyList(), null)
}
private fun getNextPageKey(documents: List<DocumentSnapshot>): PageKey? {
return if (documents.isNotEmpty()) {
PageKey(documents.last())
} else {
null
}
}
}
data class PageKey(val startAfterDoc: DocumentSnapshot)
In my ViewModel, this is what I return:-
val sourceFactory = FirestoreQueryDataSource.Factory(query, Source.DEFAULT)
val deserializedDataSourceFactory = sourceFactory.map { snapshot ->
try {
val item = QueryItem(Deserializer.deserialize(snapshot, Record::class.java), snapshot.id)
item.item.id = snapshot.id
QueryItemOrException(item, null)
} catch (e: Exception) {
Log.e(TAG, "Error while deserializing order", e)
QueryItemOrException<PosOrder>(null, e)
}
}
val boundaryCallback = FirestoreBoundaryCallback<Record>(query, sourceFactory, lifecycleOwner)
val livePagedList = LivePagedListBuilder(deserializedDataSourceFactory, 30)
.setFetchExecutor(executors.cpuExecutorService)
.setBoundaryCallback(boundaryCallback)
.build()
return Listing(
pagedList = livePagedList,
loadingState = boundaryCallback.loadingState,
refresh = {
sourceFactory.sourceLiveData.value?.invalidate()
}
)
The performance is not good and also I am concerned that when a new record is inserted, the first page will lose its last record (since the limit is fixed for the first query) and second page will continue to start AFTER the last record of the older first page. What would be the correct way of paginating firestore data on Android with realtime updates?
android firebase google-cloud-firestore android-architecture-components
1
If you want a solution for a realtime pagination, please see my answer from this post.
– Alex Mamo
Nov 26 '18 at 6:53
add a comment |
I went through Doug Coding's solution to pagination for Firestore using Android architecture patterns present at https://github.com/CodingDoug/firebase-jetpack. My concern is that how do I make this work in realtime using Android architecture components.
I attempted a solution which is described as follows but there are some issues with it. I tried to make pagination work in realtime by creating a FirestoreBoundaryCallback
:-
class FirestoreBoundaryCallback<T>(
private val baseQuery: Query,
private val factory: FirestoreQueryDataSource.Factory,
private val lifecycleOwner: LifecycleOwner): PagedList.BoundaryCallback<QueryItemOrException<T>>() {
private val allLiveData = mutableListOf<FirebaseQueryLiveData>()
private val mutableLoadingState = MutableLiveData<LoadingState>()
val loadingState: LiveData<LoadingState>
get() = mutableLoadingState
override fun onZeroItemsLoaded() {
allLiveData.clear()
mutableLoadingState.value = LoadingState.LOADING_INITIAL
val query = baseQuery.limit(50)
val liveData = FirebaseQueryLiveData(query)
liveData.observe(lifecycleOwner, Observer {
mergeAllDocs()
if (mutableLoadingState.value != LoadingState.LOADED) {
mutableLoadingState.value = LoadingState.LOADED
}
})
allLiveData.add(liveData)
}
override fun onItemAtEndLoaded(itemAtEnd: QueryItemOrException<T>) {
if (allLiveData.isNotEmpty() && allLiveData.last().value?.data?.documents?.isNotEmpty() == true) {
val lastDocument = allLiveData.last().value?.data?.documents?.last()
if (lastDocument != null) {
val query = baseQuery.startAfter(lastDocument).limit(50)
val liveData = FirebaseQueryLiveData(query)
mutableLoadingState.value = LoadingState.LOADING_MORE
liveData.observe(lifecycleOwner, Observer {
mergeAllDocs()
if (mutableLoadingState.value != LoadingState.LOADED) {
mutableLoadingState.value = LoadingState.LOADED
}
})
allLiveData.add(liveData)
}
}
}
fun mergeAllDocs() {
val items = mutableListOf<DocumentSnapshot>()
allLiveData.forEach{
val docs = it.value?.data?.documents
if (docs != null) {
items.addAll(docs)
}
}
factory.setItems(items)
}
override fun onItemAtFrontLoaded(itemAtFront: QueryItemOrException<T>) {
}
}
And then I modified the FirestoreQueryDataSource in the following way:-
class FirestoreQueryDataSource private constructor(
private val documentSnapshots: List<DocumentSnapshot>
) : PageKeyedDataSource<PageKey, DocumentSnapshot>() {
companion object {
private const val TAG = "FirestoreQueryDataSrc"
}
class Factory(private val query: Query, private val source: Source) : DataSource.Factory<PageKey, DocumentSnapshot>() {
val sourceLiveData = MutableLiveData<FirestoreQueryDataSource>()
var documentSnapshots: List<DocumentSnapshot> = mutableListOf()
fun setItems(items: List<DocumentSnapshot>) {
sourceLiveData.value?.invalidate()
documentSnapshots = items
sourceLiveData.postValue(FirestoreQueryDataSource(documentSnapshots))
}
override fun create(): DataSource<PageKey, DocumentSnapshot> {
val dataSource = FirestoreQueryDataSource(documentSnapshots)
sourceLiveData.postValue(dataSource)
return dataSource
}
}
override fun loadInitial(
params: LoadInitialParams<PageKey>,
callback: LoadInitialCallback<PageKey, DocumentSnapshot>) {
val firstPageDocSnapshots = documentSnapshots.take(params.requestedLoadSize)
val nextPageKey = getNextPageKey(firstPageDocSnapshots)
callback.onResult(firstPageDocSnapshots, null, nextPageKey)
}
override fun loadAfter(
params: LoadParams<PageKey>,
callback: LoadCallback<PageKey, DocumentSnapshot>) {
val startAfterIndex = documentSnapshots.indexOf(params.key.startAfterDoc)
var endIndex = startAfterIndex + params.requestedLoadSize
if (endIndex > documentSnapshots.size) {
endIndex = documentSnapshots.size - 1;
}
val afterInitialPageDocs = documentSnapshots.subList(startAfterIndex, endIndex)
val nextPageKey = getNextPageKey(afterInitialPageDocs)
callback.onResult(afterInitialPageDocs, nextPageKey)
}
override fun loadBefore(
params: LoadParams<PageKey>,
callback: LoadCallback<PageKey, DocumentSnapshot>) {
// The paging here only understands how to append new items to the
// results, not prepend items from earlier pages.
callback.onResult(emptyList(), null)
}
private fun getNextPageKey(documents: List<DocumentSnapshot>): PageKey? {
return if (documents.isNotEmpty()) {
PageKey(documents.last())
} else {
null
}
}
}
data class PageKey(val startAfterDoc: DocumentSnapshot)
In my ViewModel, this is what I return:-
val sourceFactory = FirestoreQueryDataSource.Factory(query, Source.DEFAULT)
val deserializedDataSourceFactory = sourceFactory.map { snapshot ->
try {
val item = QueryItem(Deserializer.deserialize(snapshot, Record::class.java), snapshot.id)
item.item.id = snapshot.id
QueryItemOrException(item, null)
} catch (e: Exception) {
Log.e(TAG, "Error while deserializing order", e)
QueryItemOrException<PosOrder>(null, e)
}
}
val boundaryCallback = FirestoreBoundaryCallback<Record>(query, sourceFactory, lifecycleOwner)
val livePagedList = LivePagedListBuilder(deserializedDataSourceFactory, 30)
.setFetchExecutor(executors.cpuExecutorService)
.setBoundaryCallback(boundaryCallback)
.build()
return Listing(
pagedList = livePagedList,
loadingState = boundaryCallback.loadingState,
refresh = {
sourceFactory.sourceLiveData.value?.invalidate()
}
)
The performance is not good and also I am concerned that when a new record is inserted, the first page will lose its last record (since the limit is fixed for the first query) and second page will continue to start AFTER the last record of the older first page. What would be the correct way of paginating firestore data on Android with realtime updates?
android firebase google-cloud-firestore android-architecture-components
I went through Doug Coding's solution to pagination for Firestore using Android architecture patterns present at https://github.com/CodingDoug/firebase-jetpack. My concern is that how do I make this work in realtime using Android architecture components.
I attempted a solution which is described as follows but there are some issues with it. I tried to make pagination work in realtime by creating a FirestoreBoundaryCallback
:-
class FirestoreBoundaryCallback<T>(
private val baseQuery: Query,
private val factory: FirestoreQueryDataSource.Factory,
private val lifecycleOwner: LifecycleOwner): PagedList.BoundaryCallback<QueryItemOrException<T>>() {
private val allLiveData = mutableListOf<FirebaseQueryLiveData>()
private val mutableLoadingState = MutableLiveData<LoadingState>()
val loadingState: LiveData<LoadingState>
get() = mutableLoadingState
override fun onZeroItemsLoaded() {
allLiveData.clear()
mutableLoadingState.value = LoadingState.LOADING_INITIAL
val query = baseQuery.limit(50)
val liveData = FirebaseQueryLiveData(query)
liveData.observe(lifecycleOwner, Observer {
mergeAllDocs()
if (mutableLoadingState.value != LoadingState.LOADED) {
mutableLoadingState.value = LoadingState.LOADED
}
})
allLiveData.add(liveData)
}
override fun onItemAtEndLoaded(itemAtEnd: QueryItemOrException<T>) {
if (allLiveData.isNotEmpty() && allLiveData.last().value?.data?.documents?.isNotEmpty() == true) {
val lastDocument = allLiveData.last().value?.data?.documents?.last()
if (lastDocument != null) {
val query = baseQuery.startAfter(lastDocument).limit(50)
val liveData = FirebaseQueryLiveData(query)
mutableLoadingState.value = LoadingState.LOADING_MORE
liveData.observe(lifecycleOwner, Observer {
mergeAllDocs()
if (mutableLoadingState.value != LoadingState.LOADED) {
mutableLoadingState.value = LoadingState.LOADED
}
})
allLiveData.add(liveData)
}
}
}
fun mergeAllDocs() {
val items = mutableListOf<DocumentSnapshot>()
allLiveData.forEach{
val docs = it.value?.data?.documents
if (docs != null) {
items.addAll(docs)
}
}
factory.setItems(items)
}
override fun onItemAtFrontLoaded(itemAtFront: QueryItemOrException<T>) {
}
}
And then I modified the FirestoreQueryDataSource in the following way:-
class FirestoreQueryDataSource private constructor(
private val documentSnapshots: List<DocumentSnapshot>
) : PageKeyedDataSource<PageKey, DocumentSnapshot>() {
companion object {
private const val TAG = "FirestoreQueryDataSrc"
}
class Factory(private val query: Query, private val source: Source) : DataSource.Factory<PageKey, DocumentSnapshot>() {
val sourceLiveData = MutableLiveData<FirestoreQueryDataSource>()
var documentSnapshots: List<DocumentSnapshot> = mutableListOf()
fun setItems(items: List<DocumentSnapshot>) {
sourceLiveData.value?.invalidate()
documentSnapshots = items
sourceLiveData.postValue(FirestoreQueryDataSource(documentSnapshots))
}
override fun create(): DataSource<PageKey, DocumentSnapshot> {
val dataSource = FirestoreQueryDataSource(documentSnapshots)
sourceLiveData.postValue(dataSource)
return dataSource
}
}
override fun loadInitial(
params: LoadInitialParams<PageKey>,
callback: LoadInitialCallback<PageKey, DocumentSnapshot>) {
val firstPageDocSnapshots = documentSnapshots.take(params.requestedLoadSize)
val nextPageKey = getNextPageKey(firstPageDocSnapshots)
callback.onResult(firstPageDocSnapshots, null, nextPageKey)
}
override fun loadAfter(
params: LoadParams<PageKey>,
callback: LoadCallback<PageKey, DocumentSnapshot>) {
val startAfterIndex = documentSnapshots.indexOf(params.key.startAfterDoc)
var endIndex = startAfterIndex + params.requestedLoadSize
if (endIndex > documentSnapshots.size) {
endIndex = documentSnapshots.size - 1;
}
val afterInitialPageDocs = documentSnapshots.subList(startAfterIndex, endIndex)
val nextPageKey = getNextPageKey(afterInitialPageDocs)
callback.onResult(afterInitialPageDocs, nextPageKey)
}
override fun loadBefore(
params: LoadParams<PageKey>,
callback: LoadCallback<PageKey, DocumentSnapshot>) {
// The paging here only understands how to append new items to the
// results, not prepend items from earlier pages.
callback.onResult(emptyList(), null)
}
private fun getNextPageKey(documents: List<DocumentSnapshot>): PageKey? {
return if (documents.isNotEmpty()) {
PageKey(documents.last())
} else {
null
}
}
}
data class PageKey(val startAfterDoc: DocumentSnapshot)
In my ViewModel, this is what I return:-
val sourceFactory = FirestoreQueryDataSource.Factory(query, Source.DEFAULT)
val deserializedDataSourceFactory = sourceFactory.map { snapshot ->
try {
val item = QueryItem(Deserializer.deserialize(snapshot, Record::class.java), snapshot.id)
item.item.id = snapshot.id
QueryItemOrException(item, null)
} catch (e: Exception) {
Log.e(TAG, "Error while deserializing order", e)
QueryItemOrException<PosOrder>(null, e)
}
}
val boundaryCallback = FirestoreBoundaryCallback<Record>(query, sourceFactory, lifecycleOwner)
val livePagedList = LivePagedListBuilder(deserializedDataSourceFactory, 30)
.setFetchExecutor(executors.cpuExecutorService)
.setBoundaryCallback(boundaryCallback)
.build()
return Listing(
pagedList = livePagedList,
loadingState = boundaryCallback.loadingState,
refresh = {
sourceFactory.sourceLiveData.value?.invalidate()
}
)
The performance is not good and also I am concerned that when a new record is inserted, the first page will lose its last record (since the limit is fixed for the first query) and second page will continue to start AFTER the last record of the older first page. What would be the correct way of paginating firestore data on Android with realtime updates?
android firebase google-cloud-firestore android-architecture-components
android firebase google-cloud-firestore android-architecture-components
asked Nov 26 '18 at 6:40
Nikhil AgarwalNikhil Agarwal
143110
143110
1
If you want a solution for a realtime pagination, please see my answer from this post.
– Alex Mamo
Nov 26 '18 at 6:53
add a comment |
1
If you want a solution for a realtime pagination, please see my answer from this post.
– Alex Mamo
Nov 26 '18 at 6:53
1
1
If you want a solution for a realtime pagination, please see my answer from this post.
– Alex Mamo
Nov 26 '18 at 6:53
If you want a solution for a realtime pagination, please see my answer from this post.
– Alex Mamo
Nov 26 '18 at 6:53
add a comment |
1 Answer
1
active
oldest
votes
The limitation of the the Paging architecture component is that you can't also get realtime updates at the same time. You have to choose if you want realtime updates or paging. (Or come up with your own solution entirely that doesn't using Paging or LiveData). This is because of the way the Paging component works. It only deals with sets of static data retrieved by paging the one-time queries to the actual data.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475903%2fhow-to-make-pagination-work-for-firestore-in-realtime-on-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The limitation of the the Paging architecture component is that you can't also get realtime updates at the same time. You have to choose if you want realtime updates or paging. (Or come up with your own solution entirely that doesn't using Paging or LiveData). This is because of the way the Paging component works. It only deals with sets of static data retrieved by paging the one-time queries to the actual data.
add a comment |
The limitation of the the Paging architecture component is that you can't also get realtime updates at the same time. You have to choose if you want realtime updates or paging. (Or come up with your own solution entirely that doesn't using Paging or LiveData). This is because of the way the Paging component works. It only deals with sets of static data retrieved by paging the one-time queries to the actual data.
add a comment |
The limitation of the the Paging architecture component is that you can't also get realtime updates at the same time. You have to choose if you want realtime updates or paging. (Or come up with your own solution entirely that doesn't using Paging or LiveData). This is because of the way the Paging component works. It only deals with sets of static data retrieved by paging the one-time queries to the actual data.
The limitation of the the Paging architecture component is that you can't also get realtime updates at the same time. You have to choose if you want realtime updates or paging. (Or come up with your own solution entirely that doesn't using Paging or LiveData). This is because of the way the Paging component works. It only deals with sets of static data retrieved by paging the one-time queries to the actual data.
answered Nov 26 '18 at 8:01
Doug StevensonDoug Stevenson
82.1k997115
82.1k997115
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475903%2fhow-to-make-pagination-work-for-firestore-in-realtime-on-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If you want a solution for a realtime pagination, please see my answer from this post.
– Alex Mamo
Nov 26 '18 at 6:53