--- a/geekdroid-firebase/src/main/java/com/geekorum/geekdroid/firebase/firestore/Firestore.kt Tue Jan 16 17:01:14 2024 -0400
+++ b/geekdroid-firebase/src/main/java/com/geekorum/geekdroid/firebase/firestore/Firestore.kt Tue Jan 16 17:05:53 2024 -0400
@@ -21,86 +21,11 @@
*/
package com.geekorum.geekdroid.firebase.firestore
-import androidx.lifecycle.LiveData
import com.google.firebase.firestore.CollectionReference
import com.google.firebase.firestore.DocumentReference
import com.google.firebase.firestore.DocumentSnapshot
-import com.google.firebase.firestore.ListenerRegistration
-import com.google.firebase.firestore.Query
-import com.google.firebase.firestore.QuerySnapshot
-import com.google.firebase.firestore.ktx.toObject
-import com.google.firebase.firestore.ktx.toObjects
+import com.google.firebase.firestore.toObject
import kotlinx.coroutines.tasks.await
-import timber.log.Timber
-
-@Deprecated("Use coroutine flows")
-class FirestoreQueryLiveData<T> constructor(
- private val query: Query,
- private val clazz: Class<T>
-) : LiveData<List<T>>() {
-
- private val TAG = FirestoreQueryLiveData::class.java.simpleName
- private var listenerRegistration: ListenerRegistration? = null
-
-
- override fun onActive() {
- listenerRegistration = query.addSnapshotListener { snapshot, firestoreException ->
- if (firestoreException != null) {
- Timber.e(firestoreException, "Error when listening to firestore")
- }
- value = snapshot?.toObjects(clazz) ?: emptyList()
- }
-
- }
-
- override fun onInactive() {
- super.onInactive()
- listenerRegistration?.remove()
- }
-}
-
-@Deprecated("Use coroutine flows")
-inline fun <reified T> Query.toLiveData() : LiveData<List<T>> =
- FirestoreQueryLiveData(this)
-
-@Deprecated("Use coroutine flows")
-inline fun <reified T> FirestoreQueryLiveData(query: Query): FirestoreQueryLiveData<T> {
- return FirestoreQueryLiveData(query, T::class.java)
-}
-
-@Deprecated("Use coroutine flows")
-class FirestoreDocumentLiveData<T>(
- private val document: DocumentReference,
- private val clazz: Class<T>
-) : LiveData<T>() {
-
- private val TAG = FirestoreDocumentLiveData::class.java.simpleName
- private var listenerRegistration: ListenerRegistration? = null
-
-
- override fun onActive() {
- listenerRegistration = document.addSnapshotListener { snapshot, firestoreException ->
- if (firestoreException != null) {
- Timber.e(firestoreException, "Error when listening to firestore")
- }
- value = snapshot?.toObject(clazz)
- }
- }
-
- override fun onInactive() {
- super.onInactive()
- listenerRegistration?.remove()
- }
-}
-
-@Deprecated("Use coroutine flows")
-inline fun <reified T> DocumentReference.toLiveData(): LiveData<T?> =
- FirestoreDocumentLiveData(this)
-
-@Deprecated("Use coroutine flows")
-inline fun <reified T> FirestoreDocumentLiveData(document: DocumentReference): FirestoreDocumentLiveData<T> {
- return FirestoreDocumentLiveData(document, T::class.java)
-}
/* suspend version of get(), set(), update(), delete() */
suspend fun DocumentReference.aSet(pojo: Any): Void = set(pojo).await()
--- a/geekdroid-firebase/src/main/java/com/geekorum/geekdroid/gms/Tasks.kt Tue Jan 16 17:01:14 2024 -0400
+++ b/geekdroid-firebase/src/main/java/com/geekorum/geekdroid/gms/Tasks.kt Tue Jan 16 17:05:53 2024 -0400
@@ -24,59 +24,6 @@
import com.google.android.gms.tasks.Task
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
-import kotlinx.coroutines.suspendCancellableCoroutine
-import kotlin.coroutines.resume
-import kotlin.coroutines.resumeWithException
-
-/**
- * Await for the result of a [Task]
- */
-@Deprecated("Use kotlinx-coroutines-play-services")
-suspend fun <T> Task<T>.await(): T {
- try {
- if (isComplete) return result as T
- } catch (e: RuntimeException) {
- return suspendCancellableCoroutine {
- it.resumeWithException(e.cause ?: e)
- }
- }
-
- return suspendCancellableCoroutine { cont ->
- addOnCompleteListener { task ->
- if (task.isSuccessful) {
- cont.resume(task.result!!)
- } else {
- cont.resumeWithException(task.exception!!)
- }
- }
- }
-}
-
-/**
- * Await for the nullable result of a [Task]
- * As [Task] is a Java API without proper nullability annotations,
- * use this method if you know the task can returns null
- */
-@Deprecated("Use kotlinx-coroutines-play-services")
-suspend fun <T> Task<T>.awaitNullable(): T? {
- try {
- if (isComplete) return result
- } catch (e: RuntimeException) {
- return suspendCancellableCoroutine {
- it.resumeWithException(e.cause ?: e)
- }
- }
-
- return suspendCancellableCoroutine { cont ->
- addOnCompleteListener { task ->
- if (task.isSuccessful) {
- cont.resume(task.result)
- } else {
- cont.resumeWithException(task.exception!!)
- }
- }
- }
-}
/**