FireCat - Firestore real time + pagination recycler view adapter.
Firestore is great solution for no sql data bases,
When you build chat app you need you db to support pagination for efficient old messages loading and also real time update for new messages.
Unfortunately FirebaseUI-Android provide only Real time or pagination recycler view adapter.
For uses cases like chat app we need adapter that support both real time and pagination but is no any official implemantion yet :(
FireCat for the rescue! with 'FirestoreRealTimePaginationAdapter'
Usage FirestoreRealTimePaginationAdapter
class FirestoreRealTimePaginationAdapter(
paginationQuery: Query,
realTimeQuery: Query,
lifecycleOwner: LifecycleOwner?,
val parser: (DocumentSnapshot) -> T?,
val prefetchDistance: Int,
val pageSize: Int
)
Chat implemantation with FirestoreRealTimePaginationAdapter
class ChatAdapter(
lifecycleOwner: LifecycleOwner?
) : FirestoreRealTimePaginationAdapter<Message, ChatAdapter.ViewHolder>(
paginationQuery = messagesQuery,
realTimeQuery = newMessagesQuery,
prefetchDistance = 3,
pageSize = 10,
parser = { documentSnapshot ->
documentSnapshot.toObject(Message::class.java)
},
lifecycleOwner = lifecycleOwner
)