Created
March 22, 2020 16:08
-
-
Save mcatta/875bed948fb83b3852e110c451a2fd9c to your computer and use it in GitHub Desktop.
The esample with RX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mcatta.mockksample.ui | |
import com.mcatta.mockksample.data.DataRepository | |
import com.mcatta.mockksample.domain.DataModel | |
import io.reactivex.Single | |
import io.reactivex.SingleObserver | |
import io.reactivex.disposables.Disposable | |
import io.reactivex.schedulers.Schedulers | |
import java.util.* | |
class MainPresenter( | |
private val view: MainContract.View, | |
private val dataRepository: DataRepository | |
) : MainContract.Presenter { | |
override fun fetchDataViaRX() { | |
dataRepository.fetchDataWithRX() | |
.flatMap { result -> | |
val output = | |
result.map { UiDataModel(UUID.randomUUID().toString(), it.id, it.value) } | |
Single.just(output) | |
} | |
.subscribe(object : SingleObserver<List<UiDataModel>> { | |
override fun onSuccess(t: List<UiDataModel>) { | |
view.onResult(t) | |
} | |
override fun onSubscribe(d: Disposable) {} | |
override fun onError(e: Throwable) { | |
view.onError(e) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment