Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sealed class DataHolder<out T> {
- data class Success<out T>(val value: T) : DataHolder<T>()
- data class Error(val cause: Throwable) : DataHolder<Nothing>()
- }
- disposables += Usecase5sec().getSingle()
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe (
- {s -> liveData.value = DataHolder.Success(s)},
- {e -> liveData.value = DataHolder.Error(e)}
- )
- val viewModel = ViewModelProviders.of(this).get(VmDashboard::class.java)
- viewModel.liveData.observe(this, object: Observer<DataHolder<String>> {
- override fun onChanged(dataHolder:DataHolder<String>?) {
- when(dataHolder){
- is DataHolder.Success -> vh?.setData(dataHolder.value)
- is DataHolder.Error -> vh?.setError(dataHolder.cause)
- }
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement