Created
September 22, 2020 16:38
-
-
Save NinoDLC/228dad11dcf58d30d05aad44569bcad5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.app.Application | |
| import androidx.lifecycle.ViewModel | |
| import androidx.lifecycle.ViewModelProvider | |
| import caux.martin.go4lunch.MainApplication | |
| import caux.martin.go4lunch.repositories.UserRepository | |
| import caux.martin.go4lunch.repositories.places.PlacesRepository | |
| import caux.martin.go4lunch.viewModel.LocationViewModel | |
| import caux.martin.go4lunch.viewModel.WorkmatesViewModel | |
| class ViewModelFactory private constructor( | |
| private val permissionChecker: PermissionChecker, | |
| private val application: Application | |
| ) : ViewModelProvider.NewInstanceFactory() { | |
| @Suppress("UNCHECKED_CAST") | |
| override fun <T : ViewModel> create(modelClass: Class<T>): T { | |
| return when (modelClass) { | |
| LocationViewModel::class.java -> LocationViewModel(permissionChecker, application) | |
| WorkmatesViewModel::class.java -> WorkmatesViewModel(UserRepository,PlacesRepository) | |
| else -> throw IllegalArgumentException("Unknown ViewModel class") | |
| } as T | |
| } | |
| companion object { | |
| val INSTANCE = ViewModelFactory( | |
| PermissionChecker(MainApplication.instance), | |
| MainApplication.instance | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment