Last active
November 15, 2019 17:40
-
-
Save gastsail/c4bb95bd3a9d0521db1848de087f6784 to your computer and use it in GitHub Desktop.
MainActivity
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
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