I want to update Recyclerview in realtime when a document is added or removed from firestore. I am using this logic in Kotlin:
for (doc in docs!!.documentChanges) {
val classElement: FireClassModel=doc.document.toObject(FireClassModel::class.java)
if (doc.type == DocumentChange.Type.ADDED) {
adapterList.add(classElement)
} else if(doc.type == DocumentChange.Type.REMOVED){
adapterList.remove(classElement)
}
adapter.notifyDataSetChanged()
}
Its working fine when document is added but it does not work when data is removed. It has no error but it doesn't update in real-time. It only updates when I restart the Application.
Updated
FireClassModel:
class FireClassModel {
var classID: String = ""
var className: String = ""
}
I tried this classesList.contains(classElement)
and it returns false. It means I am unable to compare objects in my ArrayList.