-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
247 additions
and
34 deletions.
There are no files selected for viewing
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
101 changes: 101 additions & 0 deletions
101
app/src/main/java/com/zionhuang/music/ui/menu/YouTubeSongSelectionMenu.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.zionhuang.music.ui.menu | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.WindowInsets | ||
import androidx.compose.foundation.layout.asPaddingValues | ||
import androidx.compose.foundation.layout.systemBars | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.unit.dp | ||
import com.zionhuang.innertube.models.SongItem | ||
import com.zionhuang.music.LocalDatabase | ||
import com.zionhuang.music.LocalPlayerConnection | ||
import com.zionhuang.music.R | ||
import com.zionhuang.music.extensions.toMediaItem | ||
import com.zionhuang.music.models.toMediaMetadata | ||
import com.zionhuang.music.playback.queues.ListQueue | ||
import com.zionhuang.music.ui.component.GridMenu | ||
import com.zionhuang.music.ui.component.GridMenuItem | ||
|
||
@Composable | ||
fun YouTubeSongSelectionMenu( | ||
selection: List<SongItem>, | ||
onDismiss: () -> Unit, | ||
onExitSelectionMode: () -> Unit, | ||
) { | ||
val database = LocalDatabase.current | ||
val playerConnection = LocalPlayerConnection.current ?: return | ||
|
||
var showChoosePlaylistDialog by rememberSaveable { | ||
mutableStateOf(false) | ||
} | ||
|
||
AddToPlaylistDialog( | ||
isVisible = showChoosePlaylistDialog, | ||
onGetSong = { | ||
val mediaMetadatas = selection.map { | ||
it.toMediaMetadata() | ||
} | ||
database.transaction { | ||
mediaMetadatas.forEach(::insert) | ||
} | ||
selection.map { it.id } | ||
}, | ||
onDismiss = { showChoosePlaylistDialog = false }, | ||
) | ||
|
||
GridMenu( | ||
contentPadding = | ||
PaddingValues( | ||
start = 8.dp, | ||
top = 8.dp, | ||
end = 8.dp, | ||
bottom = 8.dp + WindowInsets.systemBars.asPaddingValues().calculateBottomPadding(), | ||
), | ||
) { | ||
GridMenuItem( | ||
icon = R.drawable.play, | ||
title = R.string.play, | ||
) { | ||
onDismiss() | ||
playerConnection.playQueue( | ||
ListQueue( | ||
items = selection.map { it.toMediaItem() }, | ||
), | ||
) | ||
onExitSelectionMode() | ||
} | ||
|
||
GridMenuItem( | ||
icon = R.drawable.shuffle, | ||
title = R.string.shuffle, | ||
) { | ||
onDismiss() | ||
playerConnection.playQueue( | ||
ListQueue( | ||
items = selection.shuffled().map { it.toMediaItem() }, | ||
), | ||
) | ||
onExitSelectionMode() | ||
} | ||
|
||
GridMenuItem( | ||
icon = R.drawable.queue_music, | ||
title = R.string.add_to_queue, | ||
) { | ||
onDismiss() | ||
playerConnection.addToQueue(selection.map { it.toMediaItem() }) | ||
onExitSelectionMode() | ||
} | ||
|
||
GridMenuItem( | ||
icon = R.drawable.playlist_add, | ||
title = R.string.add_to_playlist, | ||
) { | ||
showChoosePlaylistDialog = true | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.