package Ġcom . an alytic ah ouse . test . presentation . screens . favorite Ċ Ċ import Ġandroidx . compose . runtime . Mutable State Ċ import Ġandroidx . compose . runtime . State Ċ import Ġandroidx . compose . runtime . mutable State Of Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . an alytic ah ouse . test . data . local . model . Player Entity Ċ import Ġcom . an alytic ah ouse . test . data . local . repository . Player Repository Ċ import Ġcom . an alytic ah ouse . test . domain . model . team . Team Ċ import Ġdagger . h ilt . android . lifecycle . H ilt ViewModel Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . launch Ċ import Ġjava . lang . Exception Ċ import Ġjavax . inject . Inject Ċ Ċ @ H ilt ViewModel Ċ class ĠF avorite Players ViewModel Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġplayer Repository : ĠPlayer Repository Ċ ) Ġ: ĠViewModel () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġ_ favorite Player List : ĠMutable State < List < Player Entity >> Ġ= Ġmutable State Of ( emptyList ()) ĊĊĠĠĠ Ġval Ġfavorite Player List : ĠState < List < Player Entity >> ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġ_ favorite Player List ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ_ favorite Player List . value Ġ= ĠgetAll Favorite Players () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġe . printStackTrace () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun ĠgetAll Favorite Players (): ĠList < Player Entity > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġplayer Repository . getAll Favorite Players () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Selected Player ( player Id : ĠInt ): ĠPlayer Entity Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġplayer Repository . getSelected Favorite Player ( player Id Ġ= Ġplayer Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġadd Favorite Player ( player : ĠPlayer Entity ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġplayer Repository . add Player ( player Ġ= Ġplayer ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġdelete Favorite Player ( player : ĠPlayer Entity ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġplayer Repository . delete Player ( player Ġ= Ġplayer ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġdelete All Favorite Player () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġplayer Repository . delete All Favorite Player () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ Ċ }