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 MainViewModel( | |
private val iRepository: IRepository | |
) : ViewModel() { | |
private val _errorLiveData: MutableLiveData<String> = MutableLiveData() | |
val errorLiveData: LiveData<String> | |
get() = _errorLiveData | |
private val _fetchRandomQuoteLiveData: MutableLiveData<RandomQuoteResponse> = MutableLiveData() | |
val fetchRandomQuoteLiveData: LiveData<RandomQuoteResponse> |
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 mBinding by viewBinding(ActivityMainBinding::inflate) | |
private val mViewModel by viewModel<MainViewModel>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(mBinding.root) | |
mBinding.viewModel = mViewModel | |
mViewModel.fetchRandomQuoteLiveData.observe(this, Observer { // observing response from viewmodel |
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
<layout> | |
<data> | |
<variable | |
name="viewModel" | |
type="com.thebotbox.letsmvvm.presentation.viewmodel.MainViewModel" /> | |
</data> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" |
OlderNewer