0phelia
11/15/2019 - 11:23 AM

ViewModel with parameters

class ViewModelFactory(private val mApplication: App,
                       private val irepo: IRepo) : ViewModelProvider.Factory {

    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        return when (modelClass) {
            GVM::class.java -> GVM(irepo) as T
            VVM::class.java -> VVM(mApplication, irepo) as T
            AVM::class.java -> AVM(irepo) as T
            else -> throw IllegalArgumentException("Use standard ViewModelProvider to retrieve this ViewModel")
        }
    }

}