mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-17 15:32:01 +00:00
Refactor library action handling in NuvioPosterActionSheet
Refactored NuvioPosterActionSheet to use LibraryActionRow for library actions, supporting long-press functionality to open a list picker.
This commit is contained in:
parent
9b29823d0e
commit
fe953fda39
1 changed files with 54 additions and 10 deletions
|
|
@ -3,7 +3,9 @@ package com.nuvio.app.core.ui
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
|
@ -30,6 +32,7 @@ import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
|
import androidx.compose.ui.semantics.Role
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
@ -53,8 +56,9 @@ fun NuvioPosterActionSheet(
|
||||||
isWatched: Boolean,
|
isWatched: Boolean,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onToggleLibrary: () -> Unit,
|
onToggleLibrary: () -> Unit,
|
||||||
onOpenListPicker: (() -> Unit)? = null,
|
|
||||||
onToggleWatched: () -> Unit,
|
onToggleWatched: () -> Unit,
|
||||||
|
// Long-press on the library row opens the list/collection picker (Trakt lists etc.)
|
||||||
|
onToggleLibraryLongClick: (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
if (item == null) return
|
if (item == null) return
|
||||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||||
|
|
@ -78,13 +82,8 @@ fun NuvioPosterActionSheet(
|
||||||
) {
|
) {
|
||||||
PosterSheetHeader(item = item)
|
PosterSheetHeader(item = item)
|
||||||
NuvioBottomSheetDivider()
|
NuvioBottomSheetDivider()
|
||||||
NuvioBottomSheetActionRow(
|
LibraryActionRow(
|
||||||
icon = if (isSaved) Icons.Default.Bookmark else Icons.Default.BookmarkBorder,
|
isSaved = isSaved,
|
||||||
title = if (isSaved) {
|
|
||||||
stringResource(Res.string.hero_remove_from_library)
|
|
||||||
} else {
|
|
||||||
stringResource(Res.string.hero_add_to_library)
|
|
||||||
},
|
|
||||||
onClick = {
|
onClick = {
|
||||||
onToggleLibrary()
|
onToggleLibrary()
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
|
|
@ -94,9 +93,9 @@ fun NuvioPosterActionSheet(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongClick = if (onOpenListPicker != null) {
|
onLongClick = if (onToggleLibraryLongClick != null) {
|
||||||
{
|
{
|
||||||
onOpenListPicker()
|
onToggleLibraryLongClick()
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
dismissNuvioBottomSheet(
|
dismissNuvioBottomSheet(
|
||||||
sheetState = sheetState,
|
sheetState = sheetState,
|
||||||
|
|
@ -128,6 +127,51 @@ fun NuvioPosterActionSheet(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Library row that supports both tap (direct save/remove) and long-press (open list picker).
|
||||||
|
* Mirrors the layout of [NuvioBottomSheetActionRow] but uses [combinedClickable] to capture
|
||||||
|
* long-press without adding that capability to the generic row composable.
|
||||||
|
*/
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@Composable
|
||||||
|
private fun LibraryActionRow(
|
||||||
|
isSaved: Boolean,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
onLongClick: (() -> Unit)?,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.combinedClickable(
|
||||||
|
onClick = onClick,
|
||||||
|
onLongClick = onLongClick,
|
||||||
|
role = Role.Button,
|
||||||
|
)
|
||||||
|
.padding(horizontal = 16.dp, vertical = 16.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(14.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = if (isSaved) Icons.Default.Bookmark else Icons.Default.BookmarkBorder,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(22.dp),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = if (isSaved) {
|
||||||
|
stringResource(Res.string.hero_remove_from_library)
|
||||||
|
} else {
|
||||||
|
stringResource(Res.string.hero_add_to_library)
|
||||||
|
},
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun NuvioWatchedBadge(
|
fun NuvioWatchedBadge(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue