package Ġcom . android . v eng ates hm . android room database sample . viewModel Ċ Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroidx . lifecycle . as LiveData Ċ import Ġcom . android . v eng ates hm . android room database sample . repository . App Repository Ċ Ċ class ĠMain ViewModel ( private Ġval Ġrepository : ĠApp Repository ) Ġ: ĠViewModel () Ġ{ ĊĊĠĠĠ Ġval Ġemployees Ġ= Ġrepository . all Employees . as LiveData () ĊĠĠĠ Ġval Ġemployees FullName Ġ= Ġrepository . employees FullName . as LiveData () ĊĠĠĠ Ġval Ġunique Depart ments From Employees Ġ= Ġrepository . unique Depart ments From Employees . as LiveData () ĊĠĠĠ Ġval Ġemployees FullName Sorted By FirstName Ġ= ĊĠĠĠĠĠĠĠ Ġrepository . employees FullName Sorted By FirstName . as LiveData () ĊĠĠĠ Ġval Ġemployees Salary With PF Ġ= Ġrepository . employees Salary With PF . as LiveData () ĊĠĠĠ Ġval Ġemployee Details Ordered By Salary Ġ= Ġrepository . employee Details Ordered By Salary . as LiveData () ĊĠĠĠ Ġval Ġtotal Salary Paid To All Employees Ġ= Ġrepository . total Salary Paid To All Employees . as LiveData () ĊĠĠĠ Ġval Ġmax And Min Salary Ġ= Ġrepository . max And Min Salary . as LiveData () ĊĠĠĠ Ġval Ġavg Salary And Total Employees Count Ġ= Ġrepository . avg Salary And Total Employees Count . as LiveData () ĊĠĠĠ Ġval Ġemployees FirstName In UpperCase Ġ= Ġrepository . employees FirstName In UpperCase . as LiveData () ĊĠĠĠ Ġval Ġemployees App ended Name Ġ= Ġrepository . employees App ended Name . as LiveData () ĊĠĠĠ Ġfun Ġget Employees By Count ( count : ĠInt ) Ġ= Ġrepository . get Employees By Count ( count ). as LiveData () ĊĠĠĠ Ġval Ġemployees With Monthly Salary Ġ= Ġrepository . employees With Monthly Salary . as LiveData () Ċ } Ċ Ċ class ĠMain ViewModel Factory ( private Ġval Ġrepository : ĠApp Repository ) Ġ: ĠViewModel Provider . Factory Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġ< T Ġ: ĠViewModel > Ġcreate ( model Class : ĠClass < T >): ĠT Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( model Class . isAssignableFrom ( Main ViewModel :: class . java )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠMain ViewModel ( repository ) Ġas ĠT ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġthrow ĠIllegalArgumentException (" Unknown ĠViewModel Ġclass ") ĊĠĠĠ Ġ} Ċ }