package Ġcom . el ih im as . mov ied atabase . view models Ċ Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . el ih im as . mov ied atabase . apis . API Factory Ċ import Ġcom . el ih im as . mov ied atabase . apis . Movies Database Service Ċ import Ġcom . el ih im as . mov ied atabase . model . Movie Ċ import Ġcom . el ih im as . mov ied atabase . view models . states . Movie Details State Ċ import Ġio . reactivex . android . schedul ers . Android Schedulers Ċ import Ġio . reactivex . dis pos ables . Composite Disposable Ċ import Ġio . reactivex . dis pos ables . Disposable Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠMovie Details ViewModel ( private Ġval Ġmovies Database Service : ĠMov ies Database Service ) Ġ: ĊĠĠĠ ĠViewModel () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġcurrent State Ġ= ĠMutable LiveData < Movie Details State >() ĊĊĠĠĠ Ġprivate Ġval Ġcomposite Disposable Ġ= ĠComposite Disposable () ĊĊĠĠĠ Ġfun Ġcurrent State (): ĠLive Data < Movie Details State > Ġ= Ġcurrent State ĊĊĠĠĠ Ġfun Ġload Movie ( movie Id : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcurrent State . post Value ( Movie Details State . Loading State ) ĊĠĠĠĠĠĠĠ Ġadd Disposable ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmovies Database Service . get Movie Details ( movie Id ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe (:: on Load Movie Success , Ġ:: on Load Movie Error ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġadd Disposable ( dis posable : ĠDis posable ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . add ( dis posable ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠonLoad Movie Success ( movie : ĠMovie ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcurrent State . value Ġ= ĠMovie Details State . Movie Loaded State ( movie ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠonLoad Movie Error ( cause : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcurrent State . value Ġ= ĠMovie Details State . Load Error State ( cause ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Cle ared () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Cle ared () ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . dispose () ĊĠĠĠ Ġ} Ċ }