mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
split a partly downloaded list's menu into one row
The mixed state offered two stacked rows; the spec wants one row divided between Download and Delete. Everything else is a single full-width row.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.subtracks.ui.components
|
package com.subtracks.ui.components
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
@@ -31,6 +32,7 @@ import androidx.compose.material3.LocalContentColor
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.VerticalDivider
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@@ -351,23 +353,55 @@ private fun BulkDownloadItem(
|
|||||||
dismiss: (() -> Unit) -> Unit,
|
dismiss: (() -> Unit) -> Unit,
|
||||||
) {
|
) {
|
||||||
val bulk = actions.bulkDownload ?: return
|
val bulk = actions.bulkDownload ?: return
|
||||||
for (action in (target.listDownload() ?: ListDownloadStatus()).actions()) {
|
val offered = (target.listDownload() ?: ListDownloadStatus()).actions()
|
||||||
when (action) {
|
if (offered.size > 1) {
|
||||||
BulkDownloadAction.Delete -> {
|
SplitDownloadItem(offered, target, bulk, dismiss)
|
||||||
MenuItem(Icons.Rounded.Delete, "Delete downloads") { dismiss { bulk(target, action) } }
|
return
|
||||||
}
|
}
|
||||||
|
offered.singleOrNull()?.let { action ->
|
||||||
|
MenuItem(bulkIcon(action), bulkLabel(action)) { dismiss { bulk(target, action) } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BulkDownloadAction.Cancel -> {
|
@Composable
|
||||||
MenuItem(Icons.Rounded.Cancel, "Cancel downloads") { dismiss { bulk(target, action) } }
|
private fun SplitDownloadItem(
|
||||||
|
offered: List<BulkDownloadAction>,
|
||||||
|
target: MenuTarget,
|
||||||
|
bulk: (MenuTarget, BulkDownloadAction) -> Unit,
|
||||||
|
dismiss: (() -> Unit) -> Unit,
|
||||||
|
) {
|
||||||
|
Row(Modifier.fillMaxWidth().height(56.dp)) {
|
||||||
|
offered.forEachIndexed { index, action ->
|
||||||
|
if (index > 0) {
|
||||||
|
VerticalDivider(color = MaterialTheme.colorScheme.outlineVariant)
|
||||||
}
|
}
|
||||||
|
Row(
|
||||||
BulkDownloadAction.Download -> {
|
modifier = Modifier.weight(1f).clickable { dismiss { bulk(target, action) } },
|
||||||
MenuItem(Icons.Rounded.Download, "Download") { dismiss { bulk(target, action) } }
|
horizontalArrangement = Arrangement.Center,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Icon(bulkIcon(action), contentDescription = null)
|
||||||
|
Spacer(Modifier.width(8.dp))
|
||||||
|
Text(bulkLabel(action))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun bulkIcon(action: BulkDownloadAction): ImageVector =
|
||||||
|
when (action) {
|
||||||
|
BulkDownloadAction.Download -> Icons.Rounded.Download
|
||||||
|
BulkDownloadAction.Cancel -> Icons.Rounded.Cancel
|
||||||
|
BulkDownloadAction.Delete -> Icons.Rounded.Delete
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bulkLabel(action: BulkDownloadAction): String =
|
||||||
|
when (action) {
|
||||||
|
BulkDownloadAction.Download -> "Download"
|
||||||
|
BulkDownloadAction.Cancel -> "Cancel downloads"
|
||||||
|
BulkDownloadAction.Delete -> "Delete downloads"
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun StarItem(
|
private fun StarItem(
|
||||||
current: Long?,
|
current: Long?,
|
||||||
|
|||||||
Reference in New Issue
Block a user