package Ġcom . ped rog ome z . cars store . presentation Ċ Ċ import Ġandroidx . lifecycle .* Ċ import Ġcom . ped rog ome z . cars store . dom ian . db . Category Ċ import Ġcom . ped rog ome z . cars store . dom ian . view . Car Model Ċ import Ġcom . ped rog ome z . cars store . repository . Repository Contract Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠC ars ViewModel ( ĊĠĠĠ Ġprivate Ġval Ġcontract : ĠRepository Contract Ċ ) Ġ: ĠViewModel () Ġ{ ĊĊĠĠĠ Ġval Ġcars List Ġ: ĠLive Data < List < Car Model >> Ġ= Ġcontract . getC ars () ĊĊĠĠĠ Ġval Ġcategories List Ġ: ĠLive Data < List < Category >> Ġ= Ġcontract . getC ategories () ĊĊĠĠĠ Ġprivate Ġvar Ġcar Detail To View Ġ: ĠMutable LiveData < Car Model > Ġ= ĠMutable LiveData () ĊĊĠĠĠ Ġprivate Ġvar Ġcar Detail To Edit Ġ: ĠMutable LiveData < Car Model ?> Ġ= ĠMutable LiveData () ĊĊĠĠĠ Ġfun Ġadd Car ( car From View : ĠCar Model ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontract . add Car ( car From View ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġadd Category ( category : ĠCategory ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontract . add Category ( category ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġupdate Car ( car From View : ĠCar Model ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontract . update Car ( car From View ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġset Car To View ( car From View : ĠCar Model ){ ĊĠĠĠĠĠĠĠ Ġcar Detail To View . post Value ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcar From View ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Car To View () Ġ= Ġcar Detail To View ĊĊĠĠĠ Ġfun Ġset Car To Edit ( car From View : ĠCar Model ? ){ ĊĠĠĠĠĠĠĠ Ġcar Detail To Edit . post Value ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcar From View ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Car To Edit () Ġ= Ġcar Detail To Edit ĊĊĠĠĠ Ġfun Ġsave Car ( car From View : ĠCar Model ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif ( car Detail To Edit . value != null ){ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcontract . update Car ( car From View ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} else { ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcontract . add Car ( car From View ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} Ċ Ċ }