Skip to content

Instantly share code, notes, and snippets.

View Elforama's full-sized avatar
😃

Jonathan Muller Elforama

😃
View GitHub Profile
@Elforama
Elforama / VMInjectionFactory.kt
Last active January 1, 2022 14:58
Android view model factory implementation allowing easy view model constructor injection.
/**
* Usage example:
*
* @Inject
* lateinit var mFactory: VMInjectionFactory<MyViewModel>
*/
class VMInjectionFactory <out Type: ViewModel> @Inject constructor(val vm: Lazy<Type>): ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(p0: Class<T>): T {