[优化] 修复列数封面等问题

This commit is contained in:
HapeLee
2026-03-30 13:00:34 +08:00
parent f31138338b
commit 2b2b39335a
10 changed files with 54 additions and 6 deletions
@@ -231,6 +231,8 @@ object PreferKey {
const val sharedElementEnterTransitionEnable = "sharedElementEnterTransitionEnable"
const val bookshelfLayoutGridLandscape = "bookshelfLayoutGridLandscape"
const val bookshelfLayoutGridPortrait = "bookshelfLayoutGridPortrait"
const val bookshelfLayoutListLandscape = "bookshelfLayoutListLandscape"
const val bookshelfLayoutListPortrait = "bookshelfLayoutListPortrait"
const val bookshelfTitleSmallFont = "bookshelfTitleSmallFont"
const val bookshelfTitleCenter = "bookshelfTitleCenter"
const val bookshelfTitleMaxLines = "bookshelfTitleMaxLines"
@@ -88,6 +88,16 @@ object BookshelfConfig {
*/
var bookshelfLayoutGridLandscape by prefDelegate(PreferKey.bookshelfLayoutGridLandscape, 7)
/**
* 竖屏书架列表列数
*/
var bookshelfLayoutListPortrait by prefDelegate(PreferKey.bookshelfLayoutListPortrait, 1)
/**
* 横屏书架列表列数
*/
var bookshelfLayoutListLandscape by prefDelegate(PreferKey.bookshelfLayoutListLandscape, 1)
/**
* 网格模式布局样式: 0:标准, 1:紧凑, 2:仅封面
*/
@@ -6,6 +6,8 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Checkbox
import androidx.compose.material3.ExperimentalMaterial3Api
@@ -57,6 +59,7 @@ fun CoverRuleConfigSheet(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.verticalScroll(rememberScrollState())
) {
Text(
text = stringResource(R.string.cover_rule),
@@ -127,6 +127,20 @@ fun BookshelfConfigSheet(
onValueChange = { BookshelfConfig.bookshelfGridLayout = it.toInt() }
)
val gridCount =
if (isLandscape) BookshelfConfig.bookshelfLayoutGridLandscape else BookshelfConfig.bookshelfLayoutGridPortrait
CompactSliderSettingItem(
title = stringResource(R.string.number_rows_columns),
value = gridCount.toFloat(),
valueRange = 1f..15f,
steps = 14,
onValueChange = {
if (isLandscape) BookshelfConfig.bookshelfLayoutGridLandscape =
it.toInt()
else BookshelfConfig.bookshelfLayoutGridPortrait = it.toInt()
}
)
CompactSwitchSettingItem(
title = "标题小字体",
checked = BookshelfConfig.bookshelfTitleSmallFont,
@@ -165,6 +179,20 @@ fun BookshelfConfigSheet(
color = MaterialTheme.colorScheme.surface,
onCheckedChange = { BookshelfConfig.bookshelfShowDivider = it }
)
val listColCount =
if (isLandscape) BookshelfConfig.bookshelfLayoutListLandscape else BookshelfConfig.bookshelfLayoutListPortrait
CompactSliderSettingItem(
title = stringResource(R.string.number_rows_columns),
value = listColCount.toFloat(),
valueRange = 1f..5f,
steps = 4,
onValueChange = {
if (isLandscape) BookshelfConfig.bookshelfLayoutListLandscape =
it.toInt()
else BookshelfConfig.bookshelfLayoutListPortrait = it.toInt()
}
)
}
}
@@ -226,6 +226,8 @@ fun BookshelfScreen(
if (isLandscape) BookshelfConfig.bookshelfLayoutModeLandscape else BookshelfConfig.bookshelfLayoutModePortrait
val bookshelfLayoutGrid =
if (isLandscape) BookshelfConfig.bookshelfLayoutGridLandscape else BookshelfConfig.bookshelfLayoutGridPortrait
val bookshelfLayoutList =
if (isLandscape) BookshelfConfig.bookshelfLayoutListLandscape else BookshelfConfig.bookshelfLayoutListPortrait
ListScaffold(
title = title,
@@ -481,6 +483,7 @@ fun BookshelfScreen(
uiState = uiState,
bookshelfLayoutMode = bookshelfLayoutMode,
bookshelfLayoutGrid = bookshelfLayoutGrid,
bookshelfLayoutList = bookshelfLayoutList,
onBookClick = onBookClick,
onBookLongClick = onBookLongClick
)
@@ -584,11 +587,13 @@ fun BookshelfPage(
uiState: BookshelfUiState,
bookshelfLayoutMode: Int,
bookshelfLayoutGrid: Int,
bookshelfLayoutList: Int,
onBookClick: (BookShelfItem) -> Unit,
onBookLongClick: (BookShelfItem) -> Unit
) {
val columns = if (bookshelfLayoutMode == 0) bookshelfLayoutList else bookshelfLayoutGrid
FastScrollLazyVerticalGrid(
columns = GridCells.Fixed(bookshelfLayoutGrid.coerceAtLeast(1)),
columns = GridCells.Fixed(columns.coerceAtLeast(1)),
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(
top = paddingValues.calculateTopPadding(),
@@ -74,8 +74,10 @@ fun BookCover(
val hasCustomDefault = !randomPath.isNullOrBlank()
var isOnlineCoverLoaded by remember(path) { mutableStateOf(false) }
var isFinalPathLoaded by remember(path) { mutableStateOf(false) }
LaunchedEffect(finalPath) {
isOnlineCoverLoaded = false
isFinalPathLoaded = false
}
BoxWithConstraints(
@@ -98,7 +100,7 @@ fun BookCover(
(minOf(maxWidth, maxHeight).toPx() / 3f).toDp()
}
if (hasCustomDefault) {
if (hasCustomDefault && !isFinalPathLoaded) {
AsyncImage(
model = ImageRequest.Builder(context)
.data(randomPath)
@@ -125,6 +127,7 @@ fun BookCover(
modifier = Modifier.fillMaxSize(),
onSuccess = {
isOnlineCoverLoaded = true
isFinalPathLoaded = true
onLoadFinish?.invoke()
},
onError = {