From 8b5cedd991723e48be12328386cc5e33e7988aa3 Mon Sep 17 00:00:00 2001 From: Yuriy Panov Date: Fri, 23 Oct 2026 15:34:26 +0600 Subject: [PATCH] Add remove buttons to downloaded content Downloaded albums and playlists get a bin on their row in Downloads and on their own page, which asks before deleting the files. Downloaded track rows show a bin in place of the heart that removes the track at once. The end of the Downloads page has Remove all downloads, the same button Settings uses. Co-Authored-By: Claude Opus 5.5 --- .../musyx/mobile/ui/components/Tracks.kt | 13 ++++ .../musyx/mobile/ui/screens/Downloads.kt | 77 +++++++++++++++---- .../panov/musyx/mobile/ui/screens/Settings.kt | 30 +------- .../src/main/res/values-ru/strings_phone.xml | 1 + mobile/src/main/res/values/strings_phone.xml | 1 + 5 files changed, 80 insertions(+), 42 deletions(-) diff --git a/mobile/src/main/java/it/panov/musyx/mobile/ui/components/Tracks.kt b/mobile/src/main/java/it/panov/musyx/mobile/ui/components/Tracks.kt index 1ced122..5d3ea83 100644 --- a/mobile/src/main/java/it/panov/musyx/mobile/ui/components/Tracks.kt +++ b/mobile/src/main/java/it/panov/musyx/mobile/ui/components/Tracks.kt @@ -22,6 +22,8 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp @@ -59,6 +61,8 @@ fun LazyListScope.trackItems( keyPrefix: String = "t", /** Off in Liked tracks, where every heart would be full; unliking is in the menu. */ hearts: Boolean = true, + /** A bin on downloaded rows that deletes the track's file. */ + removable: Boolean = false, ) { itemsIndexed(tracks, key = { i, t -> "$keyPrefix:$i:${t.id}" }) { i, track -> TrackRow( @@ -71,6 +75,7 @@ fun LazyListScope.trackItems( shift = shifts?.getOrNull(i), onPlay = { state.playTracks(tracks, i) }, onLike = if (hearts) ({ state.likeTrack(track, !state.liked.contains(track.id)) }) else null, + onRemove = if (removable && state.downloads.isWanted(track.id)) ({ state.removeDownload(track) }) else null, onMore = { val at = positions ?: tracks.indices.toList() state.openSheet(Sheet.TrackMenu(track, playlist?.let { PlaylistSlot(it, at[i], at.getOrNull(i - 1), at.getOrNull(i + 1)) })) @@ -94,6 +99,8 @@ fun TrackRow( /** Null hides the heart. */ onLike: (() -> Unit)?, onMore: () -> Unit, + /** Deletes the downloaded file; null hides the bin. */ + onRemove: (() -> Unit)? = null, ) { val c = MusyxTheme.colors val titleColor = when { @@ -137,6 +144,12 @@ fun TrackRow( MusyxIcon(if (liked) R.drawable.ic_heart_fill else R.drawable.ic_heart, tint = if (liked) c.like else c.muted, size = 20.dp) } } + if (onRemove != null) { + val label = stringResource(R.string.action_remove_from_device) + IconButton(onClick = onRemove, modifier = Modifier.semantics { contentDescription = label }) { + MusyxIcon(R.drawable.ic_trash_2, tint = c.muted, size = 20.dp) + } + } IconButton(onClick = onMore) { MusyxIcon(R.drawable.ic_ellipsis, tint = c.muted, size = 20.dp) } } } diff --git a/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Downloads.kt b/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Downloads.kt index b4ff96c..81d628c 100644 --- a/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Downloads.kt +++ b/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Downloads.kt @@ -17,6 +17,7 @@ import androidx.compose.material3.AlertDialog import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.IconButton import androidx.compose.material3.LinearProgressIndicator +import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable @@ -79,8 +80,10 @@ private fun AllDownloads(state: AppState) { val size = Formatter.formatShortFileSize(LocalContext.current, d.bytes) PlayBar(state, tracks, summary = "${tracksWord(tracks.size)} · ${durationWords(tracks.sumOf { it.durationMs })} · $size") } - trackItems(state, tracks, keyPrefix = "dl", hearts = state.client != null) + trackItems(state, tracks, keyPrefix = "dl", hearts = false, removable = true) } + gap("clear-gap") + item(key = "clear") { Box(Modifier.padding(horizontal = space.gutter)) { ClearDownloadsButton(state) } } } } @@ -141,6 +144,7 @@ private fun SetRow(state: AppState, set: OfflineSet) { Text("${setKind(set)} · $count", style = MusyxTheme.type.meta, color = c.muted, maxLines = 1, overflow = TextOverflow.Ellipsis) } SetMark(done, total) + RemoveSetButton(state, set) } } @@ -174,10 +178,10 @@ private fun DownloadedSet(state: AppState, key: String) { } item(key = "play") { PlayBar(state, tracks, summary = "${tracksWord(tracks.size)} · ${durationWords(tracks.sumOf { it.durationMs })}") { - DownloadButton(state, set.key, setTitle(set)) {} + RemoveSetButton(state, set) } } - trackItems(state, all, keyPrefix = "dls", hearts = state.client != null) + trackItems(state, all, keyPrefix = "dls", hearts = false, removable = true) } } @@ -202,21 +206,66 @@ fun DownloadButton(state: AppState, key: String, title: String, download: () -> } } if (confirm) { - AlertDialog( - onDismissRequest = { confirm = false }, - title = { Text(stringResource(R.string.download_remove_title, title)) }, - text = { Text(stringResource(R.string.download_remove_body)) }, - confirmButton = { - TextButton(onClick = { confirm = false; state.removeDownloadSet(key) }) { - Text(stringResource(R.string.action_remove), color = MusyxTheme.colors.like) - } - }, - dismissButton = { TextButton(onClick = { confirm = false }) { Text(stringResource(R.string.action_cancel)) } }, - containerColor = MusyxTheme.colors.panel, + ConfirmRemove( + stringResource(R.string.download_remove_title, title), + stringResource(R.string.download_remove_body), + onDismiss = { confirm = false }, + ) { state.removeDownloadSet(key) } + } +} + +/** A bin that deletes a downloaded set's files after asking. */ +@Composable +private fun RemoveSetButton(state: AppState, set: OfflineSet) { + var confirm by remember { mutableStateOf(false) } + val label = stringResource(R.string.action_remove_from_device) + IconButton(onClick = { confirm = true }, modifier = Modifier.semantics { contentDescription = label }) { + MusyxIcon(R.drawable.ic_trash_2, tint = MusyxTheme.colors.muted, size = 20.dp) + } + if (confirm) { + val title = setTitle(set) + ConfirmRemove( + stringResource(R.string.download_remove_title, title), + stringResource(R.string.download_remove_body), + onDismiss = { confirm = false }, + ) { state.removeDownloadSet(set.key) } + } +} + +/** Deletes every download, after asking. Also in Settings. */ +@Composable +fun ClearDownloadsButton(state: AppState) { + var confirm by remember { mutableStateOf(false) } + OutlinedButton(onClick = { confirm = true }) { + MusyxIcon(R.drawable.ic_trash_2, size = 18.dp) + Text(stringResource(R.string.action_clear_downloads), modifier = Modifier.padding(start = 8.dp)) + } + if (confirm) { + ConfirmRemove( + stringResource(R.string.clear_downloads_title), + stringResource(R.string.clear_downloads_body), + onDismiss = { confirm = false }, + remove = state::clearDownloads, ) } } +@Composable +private fun ConfirmRemove(title: String, body: String, onDismiss: () -> Unit, remove: () -> Unit) { + AlertDialog( + onDismissRequest = onDismiss, + title = { Text(title) }, + text = { Text(body) }, + confirmButton = { + TextButton(onClick = { onDismiss(); remove() }) { + Text(stringResource(R.string.action_remove), color = MusyxTheme.colors.like) + } + }, + dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(R.string.action_cancel)) } }, + containerColor = MusyxTheme.colors.panel, + ) +} + /** A ring filling up while a set downloads, then a tick. */ @Composable private fun SetMark(done: Int, total: Int) { diff --git a/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Settings.kt b/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Settings.kt index 52d6f43..3978935 100644 --- a/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Settings.kt +++ b/mobile/src/main/java/it/panov/musyx/mobile/ui/screens/Settings.kt @@ -14,16 +14,10 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.AlertDialog import androidx.compose.material3.FilterChip import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text -import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext @@ -132,37 +126,17 @@ fun SettingsScreen(state: AppState) { } } -/** What downloads take, and a way to remove them all after asking. */ +/** What downloads take, and a way to remove them all. */ @Composable private fun Downloads(state: AppState) { val d = state.downloads - var confirm by remember { mutableStateOf(false) } val size = Formatter.formatShortFileSize(LocalContext.current, d.bytes) Text( if (d.hasAny) stringResource(R.string.settings_downloads, size) else stringResource(R.string.settings_downloads_none), style = MusyxTheme.type.meta, color = MusyxTheme.colors.muted, ) - if (d.hasAny) { - OutlinedButton(onClick = { confirm = true }) { - MusyxIcon(R.drawable.ic_trash_2, size = 18.dp) - Text(stringResource(R.string.action_clear_downloads), modifier = Modifier.padding(start = 8.dp)) - } - } - if (confirm) { - AlertDialog( - onDismissRequest = { confirm = false }, - title = { Text(stringResource(R.string.clear_downloads_title)) }, - text = { Text(stringResource(R.string.clear_downloads_body)) }, - confirmButton = { - TextButton(onClick = { confirm = false; state.clearDownloads() }) { - Text(stringResource(R.string.action_remove), color = MusyxTheme.colors.like) - } - }, - dismissButton = { TextButton(onClick = { confirm = false }) { Text(stringResource(R.string.action_cancel)) } }, - containerColor = MusyxTheme.colors.panel, - ) - } + if (d.hasAny) ClearDownloadsButton(state) } @Composable diff --git a/mobile/src/main/res/values-ru/strings_phone.xml b/mobile/src/main/res/values-ru/strings_phone.xml index 287ff04..ad3bd2d 100644 --- a/mobile/src/main/res/values-ru/strings_phone.xml +++ b/mobile/src/main/res/values-ru/strings_phone.xml @@ -27,6 +27,7 @@ Скачать Скачано + Удалить с устройства Удалить Скачать Удалить загрузку diff --git a/mobile/src/main/res/values/strings_phone.xml b/mobile/src/main/res/values/strings_phone.xml index f1ee941..674b8fc 100644 --- a/mobile/src/main/res/values/strings_phone.xml +++ b/mobile/src/main/res/values/strings_phone.xml @@ -25,6 +25,7 @@ Download Downloaded + Remove from device Remove Download Remove download