I hereby claim:
- I am JoseAlcerreca on github.
- I am josealcerreca (https://keybase.io/josealcerreca) on keybase.
- I have a public key whose fingerprint is 40FD D5C0 725B 3A94 2CD6 5D50 D779 D64E 5C2C B75E
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| private void subscribeToModel() { | |
| // Observe product data | |
| viewModel.getObservableProduct().observe(this, new Observer<Product>() { | |
| @Override | |
| public void onChanged(@Nullable Product product) { | |
| mTitle.setText(product.title); | |
| } | |
| }); | |
| } |
| public class MyLiveData extends LiveData<MyData> { | |
| public MyLiveData(Context context) { | |
| // Initialize service | |
| } | |
| @Override | |
| protected void onActive() { | |
| // Start listening | |
| } |
| myViewModel.navigateToDetails.observe(this, Observer { | |
| if (it) startActivity(DetailsActivity...) | |
| }) |
| fun userClicksOnButton() { | |
| _navigateToDetails.value = true | |
| _navigateToDetails.value = false // Don't do this | |
| } |
| // Don't use this for events | |
| class ListViewModel : ViewModel { | |
| private val _navigateToDetails = MutableLiveData<Boolean>() | |
| val navigateToDetails : LiveData<Boolean> | |
| get() = _navigateToDetails | |
| fun userClicksOnButton() { | |
| _navigateToDetails.value = true |
| listViewModel.navigateToDetails.observe(this, Observer { | |
| if (it) { | |
| myViewModel.navigateToDetailsHandled() | |
| startActivity(DetailsActivity...) | |
| } | |
| }) |
| class ListViewModel : ViewModel { | |
| private val _navigateToDetails = MutableLiveData<Boolean>() | |
| val navigateToDetails : LiveData<Boolean> | |
| get() = _navigateToDetails | |
| fun userClicksOnButton() { | |
| _navigateToDetails.value = true | |
| } |
| class ListViewModel : ViewModel { | |
| private val _navigateToDetails = SingleLiveEvent<Any>() | |
| val navigateToDetails : LiveData<Any> | |
| get() = _navigateToDetails | |
| fun userClicksOnButton() { | |
| _navigateToDetails.call() |
| myViewModel.navigateToDetails.observe(this, Observer { | |
| startActivity(DetailsActivity...) | |
| }) |