package Ġcom . s ba . notes . database Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroidx . lifecycle . Android ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠNote Save ViewModel ( application : ĠApplication ) Ġ: ĠAndroid ViewModel ( application ) Ġ{ ĊĠĠĠ Ġprivate Ġval Ġrepository : ĠNotes Repository ĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnotes Dao Ġ= ĠNotes Room Database . get Database ( application , viewModel Scope ). notes Dao () ĊĠĠĠĠĠĠĠ Ġrepository Ġ= ĠNotes Repository ( notes Dao ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġfun Ġinsert Note ( note : ĠNotes ) Ġ= ĠviewModel Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . insert Note ( note ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġfun Ġupdate Note ( note : ĠNotes ) Ġ= ĠviewModel Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . update Note ( note ) ĊĠĠĠ Ġ} Ċ }