refactor(ui): move set-cover button to image preview screen
- Remove onSetCoverClick from ImageGallery component - Add onSetCover callback to ImagePreviewScreen - Display set-cover and save buttons in preview bottom row
This commit is contained in:
@@ -8,13 +8,10 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
@@ -23,9 +20,7 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ErrorOutline
|
||||
import androidx.compose.material.icons.filled.HourglassEmpty
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
@@ -52,8 +47,7 @@ fun ImageGallery(
|
||||
images: List<GalleryImage>,
|
||||
modifier: Modifier = Modifier,
|
||||
onImageClick: ((Int) -> Unit)? = null,
|
||||
onSaveClick: ((Int) -> Unit)? = null,
|
||||
onSetCoverClick: ((Int) -> Unit)? = null
|
||||
onSaveClick: ((Int) -> Unit)? = null
|
||||
) {
|
||||
Box(modifier = modifier.fillMaxSize()) {
|
||||
if (images.isEmpty()) {
|
||||
@@ -70,8 +64,7 @@ fun ImageGallery(
|
||||
onClick = {
|
||||
onImageClick?.invoke(index)
|
||||
},
|
||||
onSave = onSaveClick?.let { { it(index) } },
|
||||
onSetCover = onSetCoverClick?.let { { it(index) } }
|
||||
onSave = onSaveClick?.let { { it(index) } }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -83,8 +76,7 @@ fun ImageGallery(
|
||||
private fun GalleryImageItem(
|
||||
image: GalleryImage,
|
||||
onClick: () -> Unit,
|
||||
onSave: (() -> Unit)?,
|
||||
onSetCover: (() -> Unit)?
|
||||
onSave: (() -> Unit)?
|
||||
) {
|
||||
val shape = RoundedCornerShape(12.dp)
|
||||
val aspectRatio = image.bitmap?.let { it.width.toFloat() / it.height.toFloat() } ?: 1f
|
||||
@@ -141,26 +133,7 @@ private fun GalleryImageItem(
|
||||
}
|
||||
}
|
||||
|
||||
// Action buttons
|
||||
if (image.bitmap != null && onSetCover != null) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.End
|
||||
) {
|
||||
FilledTonalButton(
|
||||
onClick = onSetCover,
|
||||
contentPadding = PaddingValues(horizontal = ComfySpacing.md, vertical = ComfySpacing.sm)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.PhotoLibrary,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(ComfySpacing.xs))
|
||||
Text("设为封面")
|
||||
}
|
||||
}
|
||||
}
|
||||
// Action buttons (reserved)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+39
-16
@@ -7,14 +7,14 @@ import androidx.compose.foundation.gestures.detectTransformGestures
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import androidx.compose.material.icons.filled.Save
|
||||
import androidx.compose.material3.FilledTonalIconButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.IconButtonDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -40,7 +40,8 @@ import org.jetbrains.compose.resources.decodeToImageBitmap
|
||||
data class ImagePreviewScreen(
|
||||
val filename: String,
|
||||
val bytes: ByteArray,
|
||||
val onSave: (() -> Unit)? = null
|
||||
val onSave: (() -> Unit)? = null,
|
||||
val onSetCover: (() -> Unit)? = null
|
||||
) : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
@@ -99,22 +100,44 @@ data class ImagePreviewScreen(
|
||||
)
|
||||
}
|
||||
|
||||
if (onSave != null) {
|
||||
FilledTonalIconButton(
|
||||
onClick = onSave,
|
||||
if (onSave != null || onSetCover != null) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomEnd)
|
||||
.padding(ComfySpacing.lg)
|
||||
.size(48.dp),
|
||||
colors = IconButtonDefaults.filledTonalIconButtonColors(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
.padding(ComfySpacing.lg),
|
||||
horizontalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(ComfySpacing.sm),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Save,
|
||||
contentDescription = "保存"
|
||||
)
|
||||
if (onSetCover != null) {
|
||||
FilledTonalIconButton(
|
||||
onClick = onSetCover,
|
||||
modifier = Modifier.size(48.dp),
|
||||
colors = IconButtonDefaults.filledTonalIconButtonColors(
|
||||
containerColor = MaterialTheme.colorScheme.secondaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onSecondaryContainer
|
||||
)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.PhotoLibrary,
|
||||
contentDescription = "设为封面"
|
||||
)
|
||||
}
|
||||
}
|
||||
if (onSave != null) {
|
||||
FilledTonalIconButton(
|
||||
onClick = onSave,
|
||||
modifier = Modifier.size(48.dp),
|
||||
colors = IconButtonDefaults.filledTonalIconButtonColors(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Save,
|
||||
contentDescription = "保存"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user