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 <noreply@anthropic.com>
This commit is contained in:
1 parent
75a02c61e5
commit
8b5cedd991
5 files changed
+75
-37
No files matched your search
@@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,19 +206,64 @@ fun DownloadButton(state: AppState, key: String, title: String, download: () ->
|
||||
}
|
||||
}
|
||||
if (confirm) {
|
||||
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 = { confirm = false },
|
||||
title = { Text(stringResource(R.string.download_remove_title, title)) },
|
||||
text = { Text(stringResource(R.string.download_remove_body)) },
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title) },
|
||||
text = { Text(body) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { confirm = false; state.removeDownloadSet(key) }) {
|
||||
TextButton(onClick = { onDismiss(); remove() }) {
|
||||
Text(stringResource(R.string.action_remove), color = MusyxTheme.colors.like)
|
||||
}
|
||||
},
|
||||
dismissButton = { TextButton(onClick = { confirm = false }) { Text(stringResource(R.string.action_cancel)) } },
|
||||
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. */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
</plurals>
|
||||
<string name="action_download">Скачать</string>
|
||||
<string name="action_downloaded">Скачано</string>
|
||||
<string name="action_remove_from_device">Удалить с устройства</string>
|
||||
<string name="action_remove">Удалить</string>
|
||||
<string name="menu_download">Скачать</string>
|
||||
<string name="menu_remove_download">Удалить загрузку</string>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
</plurals>
|
||||
<string name="action_download">Download</string>
|
||||
<string name="action_downloaded">Downloaded</string>
|
||||
<string name="action_remove_from_device">Remove from device</string>
|
||||
<string name="action_remove">Remove</string>
|
||||
<string name="menu_download">Download</string>
|
||||
<string name="menu_remove_download">Remove download</string>
|
||||
|
||||
Reference in new issue
Block a user