From 92fc3d23cede04650f00fb02d264df9946cf696a Mon Sep 17 00:00:00 2001 From: mikooomich Date: Thu, 9 Jan 2025 19:37:35 -0500 Subject: [PATCH] HomeScreen: Support local songs properly --- .../dd3boh/outertune/ui/component/Items.kt | 24 ++++++++++---- .../dd3boh/outertune/ui/screens/HomeScreen.kt | 32 +++++++++++++++---- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/dd3boh/outertune/ui/component/Items.kt b/app/src/main/java/com/dd3boh/outertune/ui/component/Items.kt index e84e384c3..4fc6a21a1 100644 --- a/app/src/main/java/com/dd3boh/outertune/ui/component/Items.kt +++ b/app/src/main/java/com/dd3boh/outertune/ui/component/Items.kt @@ -641,13 +641,23 @@ fun SongGridItem( contentAlignment = Alignment.Center, modifier = Modifier.size(GridThumbnailHeight) ) { - AsyncImage( - model = song.song.thumbnailUrl, - contentDescription = null, - modifier = Modifier - .fillMaxSize() - .clip(RoundedCornerShape(ThumbnailCornerRadius)) - ) + if (song.song.isLocal) { + AsyncLocalImage( + image = { getLocalThumbnail(song.song.localPath, true) }, + contentDescription = null, + modifier = Modifier + .fillMaxSize() + .clip(RoundedCornerShape(ThumbnailCornerRadius)) + ) + } else { + AsyncImage( + model = song.song.thumbnailUrl, + contentDescription = null, + modifier = Modifier + .fillMaxSize() + .clip(RoundedCornerShape(ThumbnailCornerRadius)) + ) + } PlayingIndicatorBox( isActive = isActive, playWhenReady = isPlaying, diff --git a/app/src/main/java/com/dd3boh/outertune/ui/screens/HomeScreen.kt b/app/src/main/java/com/dd3boh/outertune/ui/screens/HomeScreen.kt index 6fc76dec8..fbb0f8865 100644 --- a/app/src/main/java/com/dd3boh/outertune/ui/screens/HomeScreen.kt +++ b/app/src/main/java/com/dd3boh/outertune/ui/screens/HomeScreen.kt @@ -166,7 +166,7 @@ fun HomeScreen( } } - val localGridItem: @Composable (LocalItem) -> Unit = { + val localGridItem: @Composable (LocalItem, String) -> Unit = { it, source -> when (it) { is Song -> SongGridItem( song = it, @@ -177,9 +177,19 @@ fun HomeScreen( if (it.id == mediaMetadata?.id) { playerConnection.player.togglePlayPause() } else { - playerConnection.playQueue( - YouTubeQueue.radio(it.toMediaMetadata()), - ) + val song = it.toMediaMetadata() + if (song.isLocal) { + playerConnection.playQueue( + ListQueue( + title = source, + items = listOf(song) + ) + ) + } else { + playerConnection.playQueue( + YouTubeQueue.radio(song), + ) + } } }, onLongClick = { @@ -496,6 +506,7 @@ fun HomeScreen( } item { + val queueTitle = stringResource(R.string.forgotten_favorites) // take min in case list size is less than 4 val rows = min(4, forgottenFavorites.size) LazyHorizontalGrid( @@ -519,7 +530,16 @@ fun HomeScreen( SongListItem( song = song!!, onPlay = { - playerConnection.playQueue(YouTubeQueue.radio(song!!.toMediaMetadata())) + if (song!!.song.isLocal) { + playerConnection.playQueue( + ListQueue( + title = queueTitle, + items = listOf(song!!.toMediaMetadata()) + ) + ) + } else { + playerConnection.playQueue(YouTubeQueue.radio(song!!.toMediaMetadata())) + } }, onSelectedChange = {}, inSelectMode = null, @@ -555,7 +575,7 @@ fun HomeScreen( .animateItem() ) { items(keepListening) { - localGridItem(it) + localGridItem(it, stringResource(R.string.keep_listening)) } } }