package Ġcom . example . ko ge bo g . data Base Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroid . util . Log Ċ import Ġandroidx . lifecycle . Android ViewModel Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . Job Ċ import Ġkotlinx . coroutines . flow . Flow Ċ import Ġkotlinx . coroutines . launch ĊĊĊĊ Ċ class ĠFood ViewModel ( application : ĠApplication ): ĠAndroid ViewModel ( application ) Ġ{ ĊĠĠĠ Ġval Ġread All Data : ĠLive Data < List < Food >> ĊĠĠĠ Ġprivate Ġval Ġrepository : ĠFood Repository ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfood Dao Ġ= ĠFood Database . get Database ( application ). food Dao () ĊĠĠĠĠĠĠĠ Ġrepository Ġ= ĠFood Repository ( food Dao ) ĊĠĠĠĠĠĠĠ Ġread All Data Ġ= Ġrepository . read All Data ĊĠĠĠ Ġ} ĊĊĊĊĠĠĠ Ġfun Ġadd Food ( food : ĠFood ){ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrepository . add Food ( food ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĊĊĠĠĠ Ġfun Ġdelete All Food (){ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrepository . delete All Food () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ}} Ċ