package Ġcom . em 4 n 0 1 0 1 . my tv shows . view Models Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroidx . lifecycle . Android ViewModel Ċ import Ġandroidx . lifecycle . as LiveData Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . em 4 n 0 1 0 1 . my tv shows . model . Person Ċ import Ġcom . em 4 n 0 1 0 1 . my tv shows . repositories . Pers ons Repository Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠPers ons ViewModel ( application : ĠApplication ) Ġ: ĠAndroid ViewModel ( application ) Ġ{ ĊĠĠĠ Ġprivate Ġval Ġrepository Ġ= ĠPers ons Repository ( application ) ĊĊĠĠĠ Ġfun Ġsave Person ( person : ĠPerson ) Ġ= ĠviewModel Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . insert Person ( person ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Pers ons () Ġ= Ġrepository . get Pers ons (). as LiveData () ĊĊĠĠĠ Ġfun Ġget Person ByName ( name : ĠString ) Ġ= Ġrepository . get Person ByName ( name ). as LiveData () ĊĊĠĠĠ Ġfun Ġdelete Person ByName ( name : ĠString ) Ġ= ĠviewModel Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . delete Person By ( name ) ĊĠĠĠ Ġ} Ċ }