package Ġsh ah in . lu as forecast . tr am Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġsh ah in . lu as forecast . network . Tr am Ċ import Ġjava . lang . IllegalArgumentException Ċ Ċ /** Ċ Ġ* ĠSimple ĠViewModel Ġfactory Ġthat Ġprovides Ġthe ĠTr am Ġand Ġcontext Ġto Ġthe ĠViewModel . Ċ Ġ*/ Ċ Ċ class ĠTr am ViewModel Factory ( private Ġval Ġtr am : ĠTr am , Ġprivate Ġval Ġapplication : ĠApplication ) Ġ: ĠViewModel Provider . Factory Ġ{ ĊĠĠĠ Ġ@ Suppress (" unchecked _ cast ") ĊĠĠĠ Ġoverride Ġfun Ġ< T Ġ: ĠViewModel ?> Ġcreate ( model Class : ĠClass < T >): ĠT Ġ{ ĊĠĠĠĠĠĠĠ Ġif ( model Class . isAssignableFrom ( Tr am ViewModel :: class . java )){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠTr am ViewModel ( tr am , application ) Ġas ĠT ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġthrow ĠIllegalArgumentException (" Unknown ĠViewModel Ġclass ") ĊĠĠĠ Ġ} Ċ }