Skip to content

Instantly share code, notes, and snippets.

@mcatta
Created March 22, 2020 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcatta/875bed948fb83b3852e110c451a2fd9c to your computer and use it in GitHub Desktop.
Save mcatta/875bed948fb83b3852e110c451a2fd9c to your computer and use it in GitHub Desktop.
The esample with RX
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