Skip to content

Instantly share code, notes, and snippets.

@Nimrodda
Last active February 26, 2020 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nimrodda/2583cb6d88bc8b70785a548080b87efa to your computer and use it in GitHub Desktop.
Save Nimrodda/2583cb6d88bc8b70785a548080b87efa to your computer and use it in GitHub Desktop.
class DetailViewModel( // Remove @Inject annotation from here
private val handle: SavedStateHandle
private val githubApi: GithubApi,
) : ViewModel() {
fun loadData() {
val id = handle["id"] ?: "default"
viewModelScope.launch {
val response = githubApi.getCommit(id)
// Handle response
}
}
}
class DetailViewModelFactory @Inject constructor(
private val githubApi: GithubApi
) : ViewModelAssistedFactory<DetailViewModel> {
fun create(handle: SavedStateHandle) {
return DetailViewModel(handle, githubApi)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment