Skip to content

Instantly share code, notes, and snippets.

@ivanalvarado
Last active June 11, 2019 00:16
Show Gist options
  • Save ivanalvarado/c0ac263c0dd593f6cc722c8438825534 to your computer and use it in GitHub Desktop.
Save ivanalvarado/c0ac263c0dd593f6cc722c8438825534 to your computer and use it in GitHub Desktop.
Activity that passes Intent arguments to ViewModel via AssistedInject.Factory create method.
const val ARGUMENT_USER_ID = "ARGUMENT_USER_ID"
class UserDetailActivity : AppCompatActivity() {
// Pass Intent Argument to ViewModel
private val userDetailViewModel by lazy {
injector.userDetailViewModelFactory.create(
userId = intent.getIntExtra(ARGUMENT_USER_ID, 0)
)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_user_detail)
setUpUi()
fetchUserDetail()
}
private fun setUpUi() {
// Wire up UI widgets
}
private fun fetchUserDetail() {
userDetailViewModel.getUserDetail().observe(this, Observer { userDetail ->
// Display User Detail
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment