package Ġcom . tang ji . qa . battery log Ċ Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroidx . lifecycle . as LiveData Ċ import Ġcom . tang ji . qa . battery log . database . Battery Info Ċ import Ġcom . tang ji . qa . battery log . database . Battery Info Repository Ċ Ċ class ĠTest ListView Mode ( private Ġval Ġrepository : ĠB attery Info Repository ) Ġ: ĠViewModel (){ ĊĠĠĠ Ġsuspend Ġfun Ġdelete ( lo : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . delete ( lo ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsuspend Ġfun Ġdelete All () Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . delete All () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġall Test Title : ĠLive Data < List < Long >> Ġ= Ġrepository . getAll Test Title (). as LiveData () Ċ Ċ } Ċ Ċ class ĠTest ListView Mode Factory ( private Ġval Ġrepository : ĠB attery Info Repository ) Ġ: ĠViewModel Provider . Factory Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġ< T Ġ: ĠViewModel > Ġcreate ( model Class : ĠClass < T >): ĠT Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( model Class . isAssignableFrom ( Test ListView Mode :: class . java )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠTest ListView Mode ( repository ) Ġas ĠT ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġthrow ĠIllegalArgumentException (" Unknown ĠViewModel Ġclass ") ĊĠĠĠ Ġ} Ċ }