chintan369 / Geo-FireStore-Query

This project is created to give support to search geo-location based items using firestore's native query which also supports pagination and all the kind of condition which firestore query does.
21 stars 2 forks source link

Convert addedOrModifiedList to Java Object #15

Closed Tonnie-Dev closed 1 year ago

Tonnie-Dev commented 4 years ago

@chintan369 Thanks lots for this library. I managed to get addedOrModifiedDataList, which fell within distance and given query. However, I am not able to read the object and use it.

This is what I am getting on the log.

[DocumentSnapshot{key=UserPujLocation/Punjabi, metadata=SnapshotMetadata{hasPendingWrites=false, isFromCache=true}, doc=Document{key=UserPujLocation/Punjabi, data=com.google.firebase.firestore.model.ObjectValue@90f60cb1, version=SnapshotVersion(seconds=1599923161, nanos=519260000), documentState=COMMITTED_MUTATIONS}}]

How do I make use of this object?

chintan369 commented 4 years ago

@Fanadezz , I'm happy you found this library useful for you.

If you're using kotlin, then it's very easy to convert this list into your model type class.

val itemList: MutableList<T> = mutableListOf()
//T is type of class or java object in which you want to convert data

geoQuery.get()
    .addOnCompleteListener { firebaseFirestoreException, addedOrModifiedDataList, removedList  ->
        ...
        addedOrModifiedDataList.forEach { item ->
                    val objectT = item.toObject(T::class.java)
                    val idOfObjectInFirestore - item.id
                    //you can add this objectT in itemList or can use as your requirement
                }
                ...
    }