Skip to content

Instantly share code, notes, and snippets.

@gastsail
Last active November 15, 2019 17:40
Show Gist options
  • Save gastsail/c4bb95bd3a9d0521db1848de087f6784 to your computer and use it in GitHub Desktop.
Save gastsail/c4bb95bd3a9d0521db1848de087f6784 to your computer and use it in GitHub Desktop.
MainActivity
class MainActivity : AppCompatActivity() {
private val viewModel by lazy { ViewModelProviders.of(this,MainViewModelFactory(UserUseCase())).get(MainViewModel::class.java) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
observeForUserDetails("Gaston")
}
fun observeForUserDetails(userId: String) {
viewModel.retrieveUserData(userId).observe(this, Observer {
when (it.status) {
Status.SUCCESS -> txtView.text = it.data
Status.ERROR -> txtView.text = "Error trying to retrieve the data: ${it.data}"
else -> txtView.text = "Hello world :)"
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment