Tying the Android app to the shared code
We'll be using a simple ViewModel
pattern to interact with the shared code and expose the needed data and actions to our UI, based on Android's architecture ViewModel
to leverage some life cycle functionality provided by the framework.
We'll create a simple MainViewModel
class in the androidApp
module. Let's go through the implementation step by step.
First, let's think about what dependencies this ViewModel
has:
class MainViewModel( breedsRepository: BreedsRepository, private val getBreeds: GetBreedsUseCase, private val fetchBreeds: FetchBreedsUseCase, private val onToggleFavouriteState: ToggleFavouriteStateUseCase ) : ViewModel() {
Since we'll be communicating with the shared code, we'll make use of the three use cases for running the specific actions, and we&apos...