HLCaptain / jay-android

Driver behaviour analytics app.
https://hlcaptain.github.io/jay-android/
GNU General Public License v3.0
1 stars 1 forks source link

Use `Firestore` model objects #56

Closed HLCaptain closed 1 year ago

HLCaptain commented 1 year ago

Create model classes for Firestore documents to eliminate getting resources from raw string references. This enables us to be more flexible when handling data transactions.

Current code:

val pathSnapshotListener = firestore
    .collection(PathsCollectionPath)
    .whereEqualTo("ownerUUID", authInteractor.userUUID)
    .addSnapshotListener { pathSnapshot, pathError ->
        if (pathError != null) {
            Timber.e(pathError, "Error while deleting user data: ${pathError.message}")
        } else if (!arePathsDeleted.value) {
            Timber.d("Delete ${pathSnapshot!!.documents.size} path data for user ${authInteractor.userUUID?.take(4)}")
            pathSnapshot.documents.forEach {
                it.reference.delete()
            }
            arePathsDeleted.value = true
        }
    }

New code should try to eliminate using raw strings, like "ownerUUID" and PathsCollectionPath.