package Ġorg . z java . android . quartz . view model Ċ Ċ import Ġandroidx . lifecycle .* Ċ import Ġkotlinx . coroutines . launch Ċ import Ġorg . z java . android . quartz . data . model . Device Ċ import Ġorg . z java . android . quartz . data . repository . Device Repository Ċ Ċ class ĠDevice List ViewModel ( private Ġval Ġdevice Repository : ĠDevice Repository ) Ġ: ĠViewModel () Ġ{ ĊĊĠĠĠ Ġval Ġall Devices : ĠLive Data < List < Device >> Ġ= Ġdevice Repository . all Devices . as LiveData () ĊĊĠĠĠ Ġfun Ġinsert ( device : ĠDevice ) Ġ= ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠ Ġdevice Repository . insert ( device ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ class ĠDevice List ViewModel Factory ( private Ġval Ġdevice Repository : ĠDevice Repository ) Ġ: ĠViewModel Provider . Factory Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġ< T Ġ: ĠViewModel > Ġcreate ( model Class : ĠClass < T >): ĠT Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( model Class . isAssignableFrom ( Device List ViewModel :: class . java )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠDevice List ViewModel ( device Repository ) Ġas ĠT ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġthrow ĠIllegalArgumentException (" Unknown ĠViewModel Ġclass ") ĊĠĠĠ Ġ} Ċ }