Last active
June 11, 2019 00:16
-
-
Save ivanalvarado/c0ac263c0dd593f6cc722c8438825534 to your computer and use it in GitHub Desktop.
Activity that passes Intent arguments to ViewModel via AssistedInject.Factory create method.
This file contains 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
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