package Ġio . github . g ust av ob arb os ab . movies . detail . presentation Ċ Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġio . github . g ust av ob arb os ab . commons . extension . launch Main Ċ import Ġio . github . g ust av ob arb os ab . commons . ui . base . Base ViewModel Ċ import Ġio . g ust av ob arb os ab . suspend result . Coroutine Result Handler Ċ import Ġio . github . g ust av ob arb os ab . movies . detail . model . Details Button Type Ċ import Ġio . github . g ust av ob arb os ab . movies . detail . model . Detail Model Ċ import Ġio . github . g ust av ob arb os ab . movies . detail . model . Detail Presentation Mapper Ċ import Ġio . github . g ust av ob arb os ab . movies . detail . presentation . Detail Movie State . View Action Ċ import Ġio . github . g ust av ob arb os ab . movies . favorites . domain . model . Movie State Ċ import Ġio . github . g ust av ob arb os ab . movies . favorites . domain . use case . Favorite Movie UseCase Ċ import Ġio . github . g ust av ob arb os ab . movies . navigation . arguments . detail . Movie Detail Argument Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠMovie Detail ViewModel Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġfavorite UseCase : ĠF avorite Movie UseCase Ċ ) Ġ: ĠBase ViewModel < Detail Movie State >(), ĠCor outine Result Handler Ġ{ ĊĊĠĠĠ Ġoverride Ġval Ġstate : ĠDetail Movie State Ġ= ĠDetail Movie State () ĊĠĠĠ Ġprivate Ġval Ġmapper Ġ= ĠDetail Presentation Mapper () ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmovie Selected : ĠDetail Model ĊĊĠĠĠ Ġfun Ġinit ( movie : ĠMovie Detail Argument ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( is Screen Already Created ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĊĠĠĠĠĠĠĠ Ġmovie Selected Ġ= Ġmapper . map ( movie ) ĊĠĠĠĠĠĠĠ Ġstate . movie . value Ġ= Ġmovie Selected ĊĠĠĠĠĠĠĠ Ġhandle Favorite State () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġis Screen Already Created () Ġ= Ġthis :: movie Selected . isInitialized ĊĊĠĠĠ Ġprivate Ġfun Ġhandle Favorite State () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Main Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstate . actions . value Ġ= ĠView Action . Show Loading ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandle Result ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfavorite UseCase . is Movie Favorite ( movie Selected . id ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis @ Movie Detail ViewModel :: search Favorite Movie Success , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis @ Movie Detail ViewModel :: search F avorites Failure ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstate . actions . value Ġ= ĠView Action . Hide Loading ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsearch Favorite Movie Success ( movie State : ĠMovie State ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġstate . favorite Button State . value Ġ= Ġwhen Ġ( movie State ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠMovie State . Movie Lik ed Ġ-> ĠDetails Button Type . Filled ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> ĠDetails Button Type . Outline ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsearch F avorites Failure () Ġ{ ĊĠĠĠĠĠĠĠ Ġstate . actions . value Ġ= ĠView Action . Start Screen Failure ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġfavorite Movie () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Main Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstate . actions . value Ġ= ĠView Action . Show Loading ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġdetail Domain Ġ= Ġmapper . map ( movie Selected ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhandle Result ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfavorite UseCase . update Favorite Movie ( detail Domain ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis @ Movie Detail ViewModel :: favorite Movie Success , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis @ Movie Detail ViewModel :: favorite Movie Failure ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstate . actions . value Ġ= ĠView Action . Hide Loading ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġfavorite Movie Success ( movie State : ĠMovie State ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen Ġ( movie State ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠMovie State . Movie Lik ed Ġ-> Ġupdate Button State ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠDetails Button Type . Filled , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠView Action . Movie Lik ed ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġupdate Button State ( Details Button Type . Outline , ĠView Action . Movie Un lik ed ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġupdate Button State ( newState : ĠDetails Button Type , Ġview Action : ĠView Action ) Ġ{ ĊĠĠĠĠĠĠĠ Ġstate . favorite Button State . value Ġ= ĠnewState ĊĠĠĠĠĠĠĠ Ġstate . actions . value Ġ= Ġview Action ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġfavorite Movie Failure () Ġ{ ĊĠĠĠĠĠĠĠ Ġstate . actions . value Ġ= ĠView Action . Favorite Movie Failure ĊĠĠĠ Ġ} Ċ }