class SleepTrackerViewModelFactory( private val dataSource: SleepDatabaseDao, private val application: Application) : ViewModelProvider.Factory { @Suppress("unchecked_cast") override fun <T : ViewModel?> create(modelClass: Class<T>): T { if (modelClass.isAssignableFrom(SleepTrackerViewModel::class.java)) { return SleepTrackerViewModel(dataSource, application) as T } throw IllegalArgumentException("Unknown ViewModel class") } }