From a6051da84223d685c26f3046caeac6f27b307978 Mon Sep 17 00:00:00 2001 From: mikooomich Date: Fri, 1 Nov 2024 17:18:17 -0400 Subject: [PATCH] multiqueue: Play artist songs instead of endpoint/radio * Siiiigh. One day this bug will be gone for good --- .../ui/screens/artist/ArtistItemsScreen.kt | 37 ++++++++++++------- .../ui/screens/artist/ArtistScreen.kt | 8 ++-- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/dd3boh/outertune/ui/screens/artist/ArtistItemsScreen.kt b/app/src/main/java/com/dd3boh/outertune/ui/screens/artist/ArtistItemsScreen.kt index 753e81d44..bd13e3309 100644 --- a/app/src/main/java/com/dd3boh/outertune/ui/screens/artist/ArtistItemsScreen.kt +++ b/app/src/main/java/com/dd3boh/outertune/ui/screens/artist/ArtistItemsScreen.kt @@ -12,8 +12,8 @@ import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid -import androidx.compose.foundation.lazy.grid.items -import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.grid.itemsIndexed +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.rounded.ArrowBack @@ -54,7 +54,7 @@ import com.dd3boh.outertune.constants.GridThumbnailHeight import com.dd3boh.outertune.extensions.toMediaItem import com.dd3boh.outertune.extensions.togglePlayPause import com.dd3boh.outertune.models.toMediaMetadata -import com.dd3boh.outertune.playback.queues.YouTubeQueue +import com.dd3boh.outertune.playback.queues.ListQueue import com.dd3boh.outertune.ui.component.IconButton import com.dd3boh.outertune.ui.component.LocalMenuState import com.dd3boh.outertune.ui.component.SelectHeader @@ -73,7 +73,6 @@ import com.zionhuang.innertube.models.AlbumItem import com.zionhuang.innertube.models.ArtistItem import com.zionhuang.innertube.models.PlaylistItem import com.zionhuang.innertube.models.SongItem -import com.zionhuang.innertube.models.WatchEndpoint @OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class) @Composable @@ -163,10 +162,10 @@ fun ArtistItemsScreen( state = lazyListState, contentPadding = LocalPlayerAwareWindowInsets.current.asPaddingValues() ) { - items( + itemsIndexed( items = itemsPage?.items?.filterIsInstance().orEmpty(), - key = { it.id } - ) { song -> + key = { _, item -> item.hashCode() } + ) { index, song -> val onCheckedChange: (Boolean) -> Unit = { if (it) { selection.add(song.id) @@ -213,8 +212,13 @@ fun ArtistItemsScreen( } else if (song.id == mediaMetadata?.id) { playerConnection.player.togglePlayPause() } else { - playerConnection.playQueue(YouTubeQueue(song.endpoint ?: WatchEndpoint( - videoId = song.id), song.toMediaMetadata())) + playerConnection.playQueue( + ListQueue( + title = "Artist songs: ${song.artists.firstOrNull()?.name}", + items = itemsPage?.items.orEmpty().map { (it as SongItem).toMediaMetadata() }, + startIndex = index + ) + ) } }, onLongClick = { @@ -250,10 +254,11 @@ fun ArtistItemsScreen( columns = GridCells.Adaptive(minSize = GridThumbnailHeight + 24.dp), contentPadding = LocalPlayerAwareWindowInsets.current.asPaddingValues() ) { - items( + itemsIndexed( items = itemsPage?.items.orEmpty(), - key = { it.id } - ) { item -> + key = { _, item -> item.hashCode() } + ) { index, item -> + itemsPage?.items?.map {it.id} YouTubeGridItem( item = item, isActive = when (item) { @@ -268,7 +273,13 @@ fun ArtistItemsScreen( .combinedClickable( onClick = { when (item) { - is SongItem -> playerConnection.playQueue(YouTubeQueue(item.endpoint ?: WatchEndpoint(videoId = item.id), item.toMediaMetadata())) + is SongItem -> playerConnection.playQueue( + ListQueue( + title = "Artist songs: ${item.artists.firstOrNull()?.name}", + items = itemsPage?.items.orEmpty().map { (it as SongItem).toMediaMetadata() }, + startIndex = index + ) + ) is AlbumItem -> navController.navigate("album/${item.id}") is ArtistItem -> navController.navigate("artist/${item.id}") is PlaylistItem -> navController.navigate("online_playlist/${item.id}") diff --git a/app/src/main/java/com/dd3boh/outertune/ui/screens/artist/ArtistScreen.kt b/app/src/main/java/com/dd3boh/outertune/ui/screens/artist/ArtistScreen.kt index ac5205332..0269d8569 100644 --- a/app/src/main/java/com/dd3boh/outertune/ui/screens/artist/ArtistScreen.kt +++ b/app/src/main/java/com/dd3boh/outertune/ui/screens/artist/ArtistScreen.kt @@ -339,11 +339,11 @@ fun ArtistScreen( if (song.id == mediaMetadata?.id) { playerConnection.player.togglePlayPause() } else { - val endpoint = song.endpoint ?: WatchEndpoint(videoId = song.id) playerConnection.playQueue( - YouTubeQueue( - endpoint, - song.toMediaMetadata() + ListQueue( + title = "Artist songs (preview): ${artistPage.artist.title}", + items = section.items.map { (it as SongItem).toMediaMetadata() }, + startIndex = section.items.indexOf(song) ) ) }