Demo: Music Player
This week, we'll be practicing more MVVM abstractions and UIEvents.
Last updated
Was this helpful?
This week, we'll be practicing more MVVM abstractions and UIEvents.
Last updated
Was this helpful?
This app starts at the MiniPlayerScreen. When we click on the MiniPlayerCard, we are taken to LoadingScreen. There's a slight delay as our next screen "loads" before the app navigates there.
Download the starter code:
Remember that LaunchedEffects define a function that will be called when a certain value changes (the 'certain value' that we want LaunchedEffect to keep an eye on here is navigateEvent).
In LoadingScreen.kt, you'll see that there's already a LaunchedEffect. You'll need to make the first LaunchedEffect before that, which actually does the navigation.
The first LaunchedEffect will listen for a navigation event and perform the navigation.
The second LaunchedEffect starts the process (detailed in the function call) that will eventually produce the navigation event.
Once you've correctly implemented the LaunchedEffect, clicking on the MiniPlayerCard should take you to the LoadingScreen and then the PlayerCardScreen after a short delay.
Currently, the PlayerCard component is managing its own states (its values change base on mutable states). We want it to have the same functionality as the MiniPlayerCard and practice keeping components dumb, so we want to let the ViewModel handle all of the logic.
Take a look at the PlayerScreen.kt. This is where the PlayerCard is called. Notice that right now, the PlayerCard takes no arguments.
To make it dynamic, we'll start by updating the arguments that PlayerCard needs to take: title, artist, isPlaying, progress, onPlayPauseClicked
Try to figure out the types on your own! title and artist are just Strings.
Fix the error that occurs in the IconButton before moving on
Hint: use one of our newly defined arguments.
Update the PlayerCard call in PlayerScreen(). You'll need to get the data from the ViewModel. Here's an example of how to do that.
Hint: use MiniPlayerCard as a reference!
Once this is all set up, you should be able to run the emulator and see the PlayerCard changing progressing through and changing songs!