package Ġdev . dvd ci ri . sample app . post details Ċ Ċ import Ġandroid . arch . lifecycle . Mutable LiveData Ċ import Ġandroid . support . annotation . String Res Ċ import Ġdev . dvd ci ri . sample app . R Ċ import Ġdev . dvd ci ri . sample app . domain . model . Comment Ċ import Ġdev . dvd ci ri . sample app . domain . model . Post Details Ċ import Ġdev . dvd ci ri . sample app . domain . use case . Get Comments By Post Id UseCase Ċ import Ġdev . dvd ci ri . sample app . domain . use case . Get Post Details By Post Id UseCase Ċ import Ġdev . dvd ci ri . sample app . framework . Schedule Provider Ċ import Ġdev . dvd ci ri . sample app . framework . view model . Base ViewModel Ċ import Ġdev . dvd ci ri . sample app . framework . view model . view state . Error Ui Model Ċ import Ġdev . dvd ci ri . sample app . post details . mapper . Comment List To Item Ui Model Mapper Ċ import Ġdev . dvd ci ri . sample app . post details . mapper . Post Details To Ui Models Mapper Ċ import Ġdev . dvd ci ri . sample app . ui . Item Ui Model ĊĊ Ċ class ĠPost Details ViewModel Ċ constructor ( ĊĠĠĠ Ġprivate Ġval Ġschedule Provider : ĠSchedule Provider , ĊĠĠĠ Ġprivate Ġval Ġget Post Details By Post Id UseCase : ĠGet Post Details By Post Id UseCase , ĊĠĠĠ Ġprivate Ġval Ġget Comments By Post Id UseCase : ĠGet Comments By Post Id UseCase , ĊĠĠĠ Ġprivate Ġval Ġpost Details To Ui Models Mapper : ĠPost Details To Ui Models Mapper , ĊĠĠĠ Ġprivate Ġval Ġcomment List To Item Ui Model Mapper : ĠComment List To Item Ui Model Mapper Ċ ) Ġ: ĠBase ViewModel () Ġ{ ĊĊĠĠĠ Ġval Ġpost Details ViewState Ġ= ĠMutable LiveData < Post Details ViewState >() ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġpost Details : ĠPost Details ĊĊĠĠĠ Ġfun Ġload Post Details ( details Navigation Params : ĠDetails Navigation Params ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdis posable Ġ= Ġget Post Details By Post Id UseCase . build UseCase ( details Navigation Params . post Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. do On Success Ġ{ Ġpost Details Ġ= Ġit Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġmap To Ui Models ( it , Ġempty List ()) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġcreate Data State ( it ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( schedule Provider . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpost Details ViewState . post Value ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġload Comments ( details Navigation Params . post Id ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ{ Ġpost Details ViewState . post Value ( create Error State ( R . string . post _ details _ generic _ error )) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . add ( dis posable ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġload Comments ( post Id : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdis posable Ġ= Ġget Comments By Post Id UseCase . build UseCase ( post Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġmap To Ui Models ( post Details , Ġit ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġcreate Data State ( it ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( schedule Provider . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe Ġ{ Ġit Ġ-> Ġpost Details ViewState . post Value ( it ) Ġ} ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . add ( dis posable ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġmap To Ui Models ( post Details : ĠPost Details , Ġcomment List : ĠList < Comment >) Ġ= ĊĠĠĠĠĠĠĠ Ġpost Details To Ui Models Mapper . map To Presentation ( post Details ) Ġ+ Ġcomment List To Item Ui Model Mapper . map To Presentation ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcomment List ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠ Ġprivate Ġfun Ġcre te Random ImageUrl (): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġ" https :// pic sum . photos / 4 0 0 / 4 0 0 /? random " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Error State (@ String Res Ġmessage : ĠInt ): ĠPost Details ViewState Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠPost Details ViewState ( Error Ui Model . Message ( message ), Ġ"", ĠlistOf ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Data State ( ui Model List : ĠList < Item Ui Model >): ĠPost Details ViewState Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠPost Details ViewState ( Error Ui Model . None , Ġcre te Random ImageUrl (), Ġui Model List ) ĊĠĠĠ Ġ} Ċ } Ċ