Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: add button to play all songs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Oct 15, 2023
1 parent bf447f6 commit 3d139c1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ class PlayerViewModel(
controller!!.seekToPrevious()
}

fun shuffleSongs(songs: List<Song>) {
fun playSongs(songs: List<Song>, shuffle: Boolean = false) {
viewModelScope.launch {
val shuffleQueue = songs.shuffled().map { it.asMediaItem }
playAll(shuffleQueue)
val queue = if (shuffle) {
songs.shuffled()
} else {
songs
}
.map { it.asMediaItem }
playAll(queue)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package app.suhasdissa.vibeyou.ui.screens.music
import android.view.SoundEffectConstants
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.Shuffle
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -98,14 +102,28 @@ fun LocalMusicScreen(
0 -> {
val view = LocalView.current
Scaffold(floatingActionButton = {
FloatingActionButton(onClick = {
view.playSoundEffect(SoundEffectConstants.CLICK)
playerViewModel.shuffleSongs(localSongViewModel.songs)
}) {
Icon(
imageVector = Icons.Default.Shuffle,
contentDescription = stringResource(R.string.shuffle)
)
Row {
FloatingActionButton(onClick = {
view.playSoundEffect(SoundEffectConstants.CLICK)
playerViewModel.playSongs(localSongViewModel.songs)
}) {
Icon(
imageVector = Icons.Default.PlayArrow,
contentDescription = stringResource(R.string.play_all)
)
}

Spacer(modifier = Modifier.width(12.dp))

FloatingActionButton(onClick = {
view.playSoundEffect(SoundEffectConstants.CLICK)
playerViewModel.playSongs(localSongViewModel.songs, shuffle = true)
}) {
Icon(
imageVector = Icons.Default.Shuffle,
contentDescription = stringResource(R.string.shuffle)
)
}
}
}) { innerPadding ->
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun AlbumScreen(
MiniPlayerScaffold(fab = {
if (state is AlbumInfoState.Success) {
FloatingActionButton(onClick = {
playerViewModel.shuffleSongs(state.songs)
playerViewModel.playSongs(state.songs, shuffle = true)
}) {
Icon(
imageVector = Icons.Default.Shuffle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun SongsScreen(
Scaffold(floatingActionButton = {
FloatingActionButton(onClick = {
view.playSoundEffect(SoundEffectConstants.CLICK)
playerViewModel.shuffleSongs(songs)
playerViewModel.playSongs(songs)
}) {
Icon(
imageVector = Icons.Default.Shuffle,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@
<string name="change_music_cache_size">Change music cache size</string>
<string name="music_cache_limit">Music cache limit</string>
<string name="unlimited">Unlimited</string>
<string name="play_all">Play all</string>
</resources>

0 comments on commit 3d139c1

Please sign in to comment.