package Ġir . ah fz . rent car . ui . home Ċ Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġir . ah fz . rent car . io . model . Authenticated Response Ċ import Ġir . ah fz . rent car . io . model . Car Response Ċ import Ġir . ah fz . rent car . io . model . Make Response Ċ import Ġir . ah fz . rent car . repository . Authentication Repository Ċ import Ġir . ah fz . rent car . repository . Car Repository Ċ import Ġir . ah fz . rent car . repository . Public Access Repository Ċ import Ġkotlinx . coroutines . Coroutine ExceptionHandler Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠHome ViewModel ( ĊĠĠĠ Ġprivate Ġval Ġpublic Access Repository : ĠPublic Access Repository , ĊĠĠĠ Ġprivate Ġval Ġauthentication Repository : ĠAuthentication Repository , ĊĠĠĠ Ġprivate Ġval Ġcar Repository : ĠCar Repository Ċ ) Ġ: ĠViewModel () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġexception Handler Ġ= ĠCor outine ExceptionHandler Ġ{ Ġ_, Ġthrowable Ġ-> ĊĠĠĠĠĠĠĠ Ġerror LiveData . post Value ( throwable . message ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġerror LiveData Ġ= ĠMutable LiveData < String ?> () ĊĠĠĠ Ġval Ġuser Auth LiveData Ġ= ĠMutable LiveData < Authenticated Response ?> () ĊĠĠĠ Ġval Ġcar List LiveData Ġ= Ġcar Repository . getAll C ars Live () ĊĠĠĠ Ġval Ġmake List LiveData Ġ= ĠMutable LiveData < List < Make Response . Make >>() ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġget Br ands () ĊĠĠĠĠĠĠĠ ĠgetC ars () ĊĠĠĠĠĠĠĠ Ġis Authenticated () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġis Authenticated () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch ( Dispatch ers . IO Ġ+ Ġexception Handler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġis Auth Response Ġ= Ġauthentication Repository . is Authenticated () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġuser Auth LiveData . post Value ( is Auth Response ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Br ands () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch ( Dispatch ers . IO Ġ+ Ġexception Handler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġmake Response Ġ= Ġpublic Access Repository . getM akes () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmake List LiveData . post Value ( make Response . body ()?. m akes ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠgetC ars () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch ( Dispatch ers . IO Ġ+ Ġexception Handler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcar Response Ġ= Ġpublic Access Repository . getC ars () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcar Repository . add Car Ignore Conflict ( car Response . body ()?. cars Ġ?: Ġreturn @ launch ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġlogout () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch ( Dispatch ers . IO Ġ+ Ġexception Handler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġauthentication Repository . logout () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġuser Auth LiveData . post Value ( null ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }