Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

menu: disable instead of hiding menu options, to boost muscle memory #121

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/src/main/java/com/dd3boh/outertune/ui/component/GridMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand All @@ -157,15 +159,17 @@ fun LazyGridScope.DownloadGridMenu(
)
},
title = R.string.downloading,
onClick = onRemoveDownload
onClick = onRemoveDownload,
enabled = enabled
)
}

else -> {
GridMenuItem(
icon = Icons.Rounded.Download,
title = R.string.download,
onClick = onDownload
onClick = onDownload,
enabled = enabled
)
}
}
Expand Down
119 changes: 59 additions & 60 deletions app/src/main/java/com/dd3boh/outertune/ui/menu/SongMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -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())
}
}
}
Expand Down
36 changes: 17 additions & 19 deletions app/src/main/java/com/dd3boh/outertune/ui/menu/YouTubeSongMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading