Last active
October 21, 2018 11:59
-
-
Save Abhityagi16/d7c70d305d63c6278ec27e2714d28b44 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
package clean.architecture.example.utils | |
import android.arch.lifecycle.ViewModel | |
import android.arch.lifecycle.ViewModelProvider | |
import clean.architecture.example.postlist.PostListViewModel | |
class ViewModelFactory : ViewModelProvider.Factory { | |
override fun <T : ViewModel> create(modelClass: Class<T>): T { | |
if (modelClass == PostListViewModel::class.java) { | |
return PostListViewModel( | |
Injection.provideUseCaseHandler() | |
, Injection.provideGetPosts(), Injection.provideSavePost()) as T | |
} | |
throw IllegalArgumentException("unknown model class $modelClass") | |
} | |
companion object { | |
private var INSTANCE: ViewModelFactory? = null | |
fun getInstance(): ViewModelFactory { | |
if (INSTANCE == null) { | |
INSTANCE = ViewModelFactory() | |
} | |
return INSTANCE!! | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment