These are chat archives for ReactiveX/RxJava

3rd
Apr 2018
defaultbr
@defaultbr
Apr 03 2018 14:43

someone can say if this make sense:

      checkCode(code)
                            .flatMap {
                                response ->
                                if(response.isSuccessful) {
                                    saveSetupToDatabase(response.body()!!)

                                    fetchCompaniesSetup(response.body()!!.imeirecord.oid)

                                            .flatMap { response ->
                                                if(response.isSuccessful) {
                                                    saveCompaniesToDatabase(response.body()!!)
                                                }
                                                    Observable.just(response)

                                            }
                                } else {
                                    Observable.just(response)
                                }
                            }

                            .subscribeOn(scheduler.io())
                            .observeOn(scheduler.ui())
                            .subscribe(
                                    { response ->
                                        if (response.isSuccessful) {
                                            println("sucess no 1")
                                            view?.hideLoading()
                                            view?.dataSaved()
                                        } else {
                                            println("handle retrofit errorbody2")
                                            view?.hideLoading()
                                            handleErrorBody(response)
                                        }
                                    },
                                    {   it ->
                                        println("handle exception")
                                        view?.hideLoading()
                                        handleException(it)
                                    }

                            )

for some reason i think its wrong, i dont know why, is there a better way?