Skip to content

Instantly share code, notes, and snippets.

@cdmunoz
Created March 8, 2018 02:20
Show Gist options
  • Save cdmunoz/f1195bfdfc21b67c0198a9bedcd4c33c to your computer and use it in GitHub Desktop.
Save cdmunoz/f1195bfdfc21b67c0198a9bedcd4c33c to your computer and use it in GitHub Desktop.
class CryptocurrenciesActivity : AppCompatActivity() {
@Inject
lateinit var cryptocurrenciesViewModelFactory: CryptocurrenciesViewModelFactory
lateinit var cryptocurrenciesViewModel: CryptocurrenciesViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(layout.activity_main)
AndroidInjection.inject(this)
cryptocurrenciesViewModel = ViewModelProviders.of(this, cryptocurrenciesViewModelFactory).get(
CryptocurrenciesViewModel::class.java)
cryptocurrenciesViewModel.loadCryptocurrencies()
cryptocurrenciesViewModel.cryptocurrenciesResult().observe(this,
Observer<List<Cryptocurrency>> {
hello_world_textview.text = "Hello ${it?.size} cryptocurrencies"
})
cryptocurrenciesViewModel.cryptocurrenciesError().observe(this, Observer<String>{
hello_world_textview.text = "Hello error $it"
})
}
override fun onDestroy() {
cryptocurrenciesViewModel.disposeElements()
super.onDestroy()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment