diff --git a/app/src/main/java/com/dd3boh/outertune/ui/component/GridMenu.kt b/app/src/main/java/com/dd3boh/outertune/ui/component/GridMenu.kt index 68b852185..16d7f9955 100644 --- a/app/src/main/java/com/dd3boh/outertune/ui/component/GridMenu.kt +++ b/app/src/main/java/com/dd3boh/outertune/ui/component/GridMenu.kt @@ -138,13 +138,15 @@ fun LazyGridScope.DownloadGridMenu( @Download.State state: Int?, onRemoveDownload: () -> Unit, onDownload: () -> Unit, + enabled: Boolean = true ) { when (state) { Download.STATE_COMPLETED -> { GridMenuItem( icon = Icons.Rounded.OfflinePin, title = R.string.remove_download, - onClick = onRemoveDownload + onClick = onRemoveDownload, + enabled = enabled ) } @@ -157,7 +159,8 @@ fun LazyGridScope.DownloadGridMenu( ) }, title = R.string.downloading, - onClick = onRemoveDownload + onClick = onRemoveDownload, + enabled = enabled ) } @@ -165,7 +168,8 @@ fun LazyGridScope.DownloadGridMenu( GridMenuItem( icon = Icons.Rounded.Download, title = R.string.download, - onClick = onDownload + onClick = onDownload, + enabled = enabled ) } } diff --git a/app/src/main/java/com/dd3boh/outertune/ui/menu/SongMenu.kt b/app/src/main/java/com/dd3boh/outertune/ui/menu/SongMenu.kt index 30b776de2..88bf7c729 100644 --- a/app/src/main/java/com/dd3boh/outertune/ui/menu/SongMenu.kt +++ b/app/src/main/java/com/dd3boh/outertune/ui/menu/SongMenu.kt @@ -51,6 +51,7 @@ import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.media3.exoplayer.offline.DownloadRequest import androidx.media3.exoplayer.offline.DownloadService import androidx.navigation.NavController import coil.compose.AsyncImage @@ -233,14 +234,14 @@ fun SongMenu( bottom = 8.dp + WindowInsets.systemBars.asPaddingValues().calculateBottomPadding() ) ) { - if (!song.song.isLocal) - GridMenuItem( - icon = Icons.Rounded.Radio, - title = R.string.start_radio - ) { - onDismiss() - playerConnection.playQueue(YouTubeQueue(WatchEndpoint(videoId = song.id), song.toMediaMetadata(), playlistId = WatchEndpoint(videoId = song.id).playlistId)) - } + GridMenuItem( + icon = Icons.Rounded.Radio, + title = R.string.start_radio, + enabled = !song.song.isLocal + ) { + onDismiss() + playerConnection.playQueue(YouTubeQueue(WatchEndpoint(videoId = song.id), song.toMediaMetadata(), playlistId = WatchEndpoint(videoId = song.id).playlistId)) + } GridMenuItem( icon = Icons.AutoMirrored.Rounded.PlaylistPlay, title = R.string.play_next @@ -290,26 +291,25 @@ fun SongMenu( } } - if (!song.song.isLocal) - DownloadGridMenu( - state = download?.state, - onDownload = { - downloadUtil.download(song.toMediaMetadata()) - }, - onRemoveDownload = { - DownloadService.sendRemoveDownload( - context, - ExoDownloadService::class.java, - song.id, - false - ) - } - ) - - + DownloadGridMenu( + state = download?.state, + enabled = !song.song.isLocal, + onDownload = { + downloadUtil.download(song.toMediaMetadata()) + }, + onRemoveDownload = { + DownloadService.sendRemoveDownload( + context, + ExoDownloadService::class.java, + song.id, + false + ) + } + ) GridMenuItem( icon = R.drawable.artist, - title = R.string.view_artist + title = R.string.view_artist, + enabled = song.artists.isNotEmpty() ) { if (song.artists.size == 1) { navController.navigate("artist/${song.artists[0].id}") @@ -318,46 +318,45 @@ fun SongMenu( showSelectArtistDialog = true } } - if (song.song.albumId != null && !song.song.isLocal) { - GridMenuItem( - icon = Icons.Rounded.Album, - title = R.string.view_album - ) { - onDismiss() - navController.navigate("album/${song.song.albumId}") + GridMenuItem( + icon = Icons.Rounded.Album, + title = R.string.view_album, + enabled = song.song.albumId != null && !song.song.isLocal + ) { + onDismiss() + navController.navigate("album/${song.song.albumId}") + } + GridMenuItem( + icon = Icons.Rounded.Share, + title = R.string.share, + enabled = !song.song.isLocal + ) { + onDismiss() + val intent = Intent().apply { + action = Intent.ACTION_SEND + type = "text/plain" + putExtra(Intent.EXTRA_TEXT, "https://music.youtube.com/watch?v=${song.id}") } + context.startActivity(Intent.createChooser(intent, null)) } - if (!song.song.isLocal) + if (song.song.inLibrary == null) { GridMenuItem( - icon = Icons.Rounded.Share, - title = R.string.share + icon = Icons.Rounded.LibraryAdd, + title = R.string.add_to_library, + enabled = !song.song.isLocal ) { - onDismiss() - val intent = Intent().apply { - action = Intent.ACTION_SEND - type = "text/plain" - putExtra(Intent.EXTRA_TEXT, "https://music.youtube.com/watch?v=${song.id}") + database.query { + update(song.song.toggleLibrary()) } - context.startActivity(Intent.createChooser(intent, null)) } - if (!song.song.isLocal) { - if (song.song.inLibrary == null) { - GridMenuItem( - icon = Icons.Rounded.LibraryAdd, - title = R.string.add_to_library - ) { - database.query { - update(song.song.toggleLibrary()) - } - } - } else { - GridMenuItem( - icon = Icons.Rounded.LibraryAddCheck, - title = R.string.remove_from_library - ) { - database.query { - update(song.song.toggleLibrary()) - } + } else { + GridMenuItem( + icon = Icons.Rounded.LibraryAddCheck, + title = R.string.remove_from_library, + enabled = !song.song.isLocal + ) { + database.query { + update(song.song.toggleLibrary()) } } } diff --git a/app/src/main/java/com/dd3boh/outertune/ui/menu/YouTubeSongMenu.kt b/app/src/main/java/com/dd3boh/outertune/ui/menu/YouTubeSongMenu.kt index c539ae919..2e3b63cc2 100644 --- a/app/src/main/java/com/dd3boh/outertune/ui/menu/YouTubeSongMenu.kt +++ b/app/src/main/java/com/dd3boh/outertune/ui/menu/YouTubeSongMenu.kt @@ -276,28 +276,26 @@ fun YouTubeSongMenu( ) } ) - if (artists.isNotEmpty()) { - GridMenuItem( - icon = Icons.Rounded.Person, - title = R.string.view_artist - ) { - if (artists.size == 1) { - navController.navigate("artist/${artists[0].id}") - onDismiss() - } else { - showSelectArtistDialog = true - } - } - } - song.album?.let { album -> - GridMenuItem( - icon = Icons.Rounded.Album, - title = R.string.view_album - ) { - navController.navigate("album/${album.id}") + GridMenuItem( + icon = Icons.Rounded.Person, + title = R.string.view_artist, + enabled = song.artists.isNotEmpty() + ) { + if (artists.size == 1) { + navController.navigate("artist/${artists[0].id}") onDismiss() + } else { + showSelectArtistDialog = true } } + GridMenuItem( + icon = Icons.Rounded.Album, + title = R.string.view_album, + enabled = song.album?.id != null + ) { + navController.navigate("album/${song.album?.id}") + onDismiss() + } GridMenuItem( icon = Icons.Rounded.Share, title = R.string.share