SHARE
TWEET

Untitled

a guest Sep 20th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sealed class DataHolder<out T> {
  2.     data class Success<out T>(val value: T) : DataHolder<T>()
  3.     data class Error(val cause: Throwable) : DataHolder<Nothing>()
  4. }
  5.  
  6. disposables += Usecase5sec().getSingle()
  7.     .observeOn(AndroidSchedulers.mainThread())
  8.     .subscribe (
  9.         {s -> liveData.value = DataHolder.Success(s)},
  10.         {e -> liveData.value = DataHolder.Error(e)}
  11.     )  
  12.  
  13.  
  14. val viewModel = ViewModelProviders.of(this).get(VmDashboard::class.java)
  15. viewModel.liveData.observe(this, object: Observer<DataHolder<String>> {
  16.     override fun onChanged(dataHolder:DataHolder<String>?) {
  17.         when(dataHolder){
  18.             is DataHolder.Success -> vh?.setData(dataHolder.value)
  19.             is DataHolder.Error -> vh?.setError(dataHolder.cause)
  20.         }
  21.     }
  22. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top