Skip to content

Commit

Permalink
HomeScreen: Support local songs properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mikooomich committed Jan 10, 2025
1 parent 9932817 commit 92fc3d2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
24 changes: 17 additions & 7 deletions app/src/main/java/com/dd3boh/outertune/ui/component/Items.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 26 additions & 6 deletions app/src/main/java/com/dd3boh/outertune/ui/screens/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -555,7 +575,7 @@ fun HomeScreen(
.animateItem()
) {
items(keepListening) {
localGridItem(it)
localGridItem(it, stringResource(R.string.keep_listening))
}
}
}
Expand Down

0 comments on commit 92fc3d2

Please sign in to comment.