tolgaprm / Mova-MovieApp

"A movie and TV show information app for teaching MVVM, Paging3, Flow-Coroutines with Clean Architecture. With this app, you can easily find information about your favorite films and TV series. You can view the cast, plot summary, release date, and more. "

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mova-100 Remove callbacks from using Firebase functions.

tolgaprm opened this issue · comments

Example

Remove the code

   override fun addMovieToFavoriteList(
        userUid: String,
        data: Map<String, List<Movie>>,
        onSuccess: () -> Unit,
        onFailure: (uiText: UiText) -> Unit,
    ) {
        firestore.collection(userUid).document(Constants.FIREBASE_FAVORITE_MOVIE_DOCUMENT_NAME)
            .set(data.toConvertToFavoriteMovieMap(), SetOptions.merge())
            .addOnSuccessListener {
                onSuccess()
            }.addOnFailureListener { exception ->
                setExceptionToFirebaseMessage(exception = exception, onFailure = onFailure)
            }
    }
   override suspend fun addMovieToFavoriteList(
        userUid: String,
        movieInFavoriteList: List<Movie>
    ): SimpleResource {
        return safeCallWithForFirebase {
            val data = mapOf(
                FIREBASE_MOVIES_FIELD_NAME to movieInFavoriteList
            )
            val result =
                firestore.collection(userUid)
                    .document(Constants.FIREBASE_FAVORITE_MOVIE_DOCUMENT_NAME)
                    .set(data.toConvertToFavoriteMovieMap(), SetOptions.merge())
            result.await()
            if (result.isSuccessful) {
                Resource.Success(Unit)
            } else {
                Resource.Error(UiText.unknownError())
            }
        }
    }