package Ġcom . init ish bh att . mar vel super her os . characters . presentation . viewModel Ċ Ċ import Ġandroid . arch . lifecycle . Mutable LiveData Ċ import Ġandroid . arch . lifecycle . ViewModel Ċ import Ġandroid . databinding . Observable Field Ċ import Ġcom . init ish bh att . mar vel super her os . characters . model . Mar vel Super Hero es Ċ import Ġcom . init ish bh att . mar vel super her os . inter actor . Mar vel Interactor Ċ import Ġcom . init ish bh att . mar vel super her os . util . Scheduler Provider Ċ import Ġio . reactivex . dis pos ables . Composite Disposable Ċ import Ġio . reactivex . dis pos ables . Disposable Ċ import Ġio . reactivex . rx kotlin . subscribe By Ċ import Ġtim ber . log . Tim ber Ċ Ċ /** Ċ Ġ* Ġ@ author Ġn it ish bh att Ċ Ġ*/ Ċ class ĠMain ViewModel ( private Ġval Ġinter actor : ĠMar vel Interactor , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġscheduler Provider : ĠScheduler Provider ) Ġ: ĠViewModel () Ġ{ ĊĠĠĠ Ġprivate Ġval Ġcomposite Disposable Ġby Ġlazy Ġ{ ĠComposite Disposable () Ġ} ĊĠĠĠ Ġval Ġher os Data Ġ= ĠMutable LiveData < List < Mar vel Super Hero es >>() ĊĠĠĠ Ġval ĠisLoading Ġ= ĠObservable Field < Boolean >() ĊĊĠĠĠ Ġfun Ġshow All Super H eros () Ġ{ ĊĠĠĠĠĠĠĠ ĠisLoading . set ( true ) ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . add ( super H eros List ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsuper H eros List (): ĠDis posable Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġinter actor . getAll Super Hero es () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( scheduler Provider . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( scheduler Provider . ui ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe By ( on Success Ġ= Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġon H eros List Received ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ}, ĠonError Ġ= Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġon H eros List Received Error ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon H eros List Received Error ( it : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠ ĠisLoading . set ( false ) ĊĠĠĠĠĠĠĠ Ġher os Data . post Value ( null ) ĊĠĠĠĠĠĠĠ ĠTim ber . e ( it ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon H eros List Received ( it : ĠList < Mar vel Super Hero es >) Ġ{ ĊĠĠĠĠĠĠĠ ĠisLoading . set ( false ) ĊĠĠĠĠĠĠĠ Ġher os Data . post Value ( it ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Cle ared () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Cle ared () ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . clear () ĊĠĠĠ Ġ} Ċ Ċ }