Adjust style of thumbnails to show they can be tapped

This commit is contained in:
Pierre-Yves Nicolas
2026-01-31 14:36:52 +01:00
parent 37d4ded7f8
commit ec14abd696
3 changed files with 44 additions and 30 deletions

View File

@@ -16,12 +16,14 @@ package org.fairscan.app.ui.components
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.border import androidx.compose.foundation.border
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
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.BoxScope
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
@@ -33,6 +35,8 @@ import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@@ -60,6 +64,7 @@ data class CommonPageListState(
val onPageClick: (Int) -> Unit, val onPageClick: (Int) -> Unit,
val onPageReorder: (String, Int) -> Unit, val onPageReorder: (String, Int) -> Unit,
val listState: LazyListState, val listState: LazyListState,
val showPageNumbers: Boolean,
val currentPageIndex: Int? = null, val currentPageIndex: Int? = null,
val onLastItemPosition: ((Offset) -> Unit)? = null, val onLastItemPosition: ((Offset) -> Unit)? = null,
) )
@@ -129,7 +134,7 @@ private fun PageThumbnail(
val bitmap = image.asImageBitmap() val bitmap = image.asImageBitmap()
val isSelected = index == state.currentPageIndex val isSelected = index == state.currentPageIndex
val borderColor = val borderColor =
if (isSelected) MaterialTheme.colorScheme.secondary else Color.Transparent if (isSelected) MaterialTheme.colorScheme.primary else Color.LightGray
val maxImageSize = PAGE_LIST_ELEMENT_SIZE_DP.dp val maxImageSize = PAGE_LIST_ELEMENT_SIZE_DP.dp
var imageModifier = var imageModifier =
if (bitmap.height > bitmap.width) if (bitmap.height > bitmap.width)
@@ -141,15 +146,26 @@ private fun PageThumbnail(
imageModifier = imageModifier.addPositionCallback(state.onLastItemPosition, density, 1.0f) imageModifier = imageModifier.addPositionCallback(state.onLastItemPosition, density, 1.0f)
} }
Box(modifier = modifier.height(PAGE_LIST_ELEMENT_SIZE_DP.dp)) { Box(modifier = modifier.height(PAGE_LIST_ELEMENT_SIZE_DP.dp)) {
Card(
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
shape = RoundedCornerShape(6.dp),
border = BorderStroke(1.dp, borderColor),
modifier = Modifier.padding(4.dp).align(Alignment.Center)
) {
Image( Image(
bitmap = bitmap, bitmap = bitmap,
contentDescription = null, contentDescription = "${index + 1}",
modifier = imageModifier modifier = imageModifier.clickable { state.onPageClick(index) }
.align(Alignment.Center)
.padding(4.dp)
.border(2.dp, borderColor)
.clickable { state.onPageClick(index) }
) )
}
if (state.showPageNumbers) {
PageNumberBadge(index)
}
}
}
@Composable
private fun BoxScope.PageNumberBadge(index: Int) {
Box( Box(
modifier = Modifier modifier = Modifier
.padding(8.dp) .padding(8.dp)
@@ -165,7 +181,6 @@ private fun PageThumbnail(
) )
} }
} }
}
fun Modifier.addPositionCallback(callback: ((Offset) -> Unit)?, density: Density, xFactor: Float): Modifier { fun Modifier.addPositionCallback(callback: ((Offset) -> Unit)?, density: Density, xFactor: Float): Modifier {
if (callback == null) { if (callback == null) {

View File

@@ -14,6 +14,7 @@
*/ */
package org.fairscan.app.ui.screens package org.fairscan.app.ui.screens
import android.content.res.Configuration
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
@@ -103,6 +104,7 @@ fun DocumentScreen(
onPageReorder = onPageReorder, onPageReorder = onPageReorder,
currentPageIndex = currentPageIndex.intValue, currentPageIndex = currentPageIndex.intValue,
listState = listState, listState = listState,
showPageNumbers = true,
), ),
onBack = navigation.back, onBack = navigation.back,
bottomBar = { bottomBar = {
@@ -235,11 +237,13 @@ private fun BottomBar(
@Composable @Composable
@Preview @Preview
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
@Preview(name = "Landscape", showBackground = true, widthDp = 640, heightDp = 320)
fun DocumentScreenPreview() { fun DocumentScreenPreview() {
FairScanTheme { FairScanTheme {
DocumentScreen( DocumentScreen(
fakeDocument( fakeDocument(
listOf(1, 2).map { "gallica.bnf.fr-bpt6k5530456s-$it.jpg" }.toImmutableList(), listOf(1, 2).map { "gallica.bnf.fr-bpt6k5530456s-$it" }.toImmutableList(),
LocalContext.current LocalContext.current
), ),
initialPage = 1, initialPage = 1,
@@ -251,10 +255,3 @@ fun DocumentScreenPreview() {
) )
} }
} }
@Preview(showBackground = true, widthDp = 640, heightDp = 320)
@Composable
fun DocumentScreenPreviewInLandscapeMode() {
DocumentScreenPreview()
}

View File

@@ -177,6 +177,7 @@ fun CameraScreen(
onPageClick = { index -> viewModel.navigateTo(Screen.Main.Document(index)) }, onPageClick = { index -> viewModel.navigateTo(Screen.Main.Document(index)) },
onPageReorder = { id, index -> viewModel.movePage(id, index) }, onPageReorder = { id, index -> viewModel.movePage(id, index) },
listState = listState, listState = listState,
showPageNumbers = false,
onLastItemPosition = { offset -> thumbnailCoords.value = offset }, onLastItemPosition = { offset -> thumbnailCoords.value = offset },
), ),
cameraUiState = CameraUiState( cameraUiState = CameraUiState(
@@ -556,6 +557,7 @@ private fun ScreenPreview(captureState: CaptureState, rotationDegrees: Float = 0
onPageClick = {}, onPageClick = {},
onPageReorder = { _, _ -> }, onPageReorder = { _, _ -> },
listState = LazyListState(), listState = LazyListState(),
showPageNumbers = false,
), ),
cameraUiState = CameraUiState(pageCount = 4, LiveAnalysisState(), captureState, cameraUiState = CameraUiState(pageCount = 4, LiveAnalysisState(), captureState,
false, rotationDegrees > 0, false, false), false, rotationDegrees > 0, false, false),