Skip to content

Commit

Permalink
multiqueue: Play artist songs instead of endpoint/radio
Browse files Browse the repository at this point in the history
* Siiiigh. One day this bug will be gone for good
  • Loading branch information
mikooomich committed Nov 1, 2024
1 parent 24269a5 commit a6051da
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -163,10 +162,10 @@ fun ArtistItemsScreen(
state = lazyListState,
contentPadding = LocalPlayerAwareWindowInsets.current.asPaddingValues()
) {
items(
itemsIndexed(
items = itemsPage?.items?.filterIsInstance<SongItem>().orEmpty(),
key = { it.id }
) { song ->
key = { _, item -> item.hashCode() }
) { index, song ->
val onCheckedChange: (Boolean) -> Unit = {
if (it) {
selection.add(song.id)
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand All @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
}
Expand Down

0 comments on commit a6051da

Please sign in to comment.