daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package id.ihwan.aac.network
  2.  
  3. import id.ihwan.aac.model.MovieResponse
  4. import io.reactivex.android.schedulers.AndroidSchedulers
  5. import io.reactivex.disposables.CompositeDisposable
  6. import io.reactivex.schedulers.Schedulers
  7.  
  8. class MainRepository {
  9.     private val apiService = ApiFactory.create()
  10.     private val compositeDisposable = CompositeDisposable()
  11.  
  12.     fun requestMovie(onResult: (MovieResponse) -> Unit, onError: (Throwable) -> Unit){
  13.         apiService.getMovie()
  14.             .subscribeOn(Schedulers.io())
  15.             .observeOn(AndroidSchedulers.mainThread())
  16.             .subscribe(object: ApiObserver<MovieResponse>(compositeDisposable){
  17.                 override fun onApiSuccess(data: MovieResponse) {
  18.                     onResult(data)
  19.                 }
  20.  
  21.                 override fun onApiError(er: Throwable) {
  22.                     onError(er)
  23.                 }
  24.             })
  25.     }
  26.  
  27.     fun onDestroy(){
  28.         compositeDisposable.clear()
  29.     }
  30. }
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