Jelajahi Sumber

增加网格模式封面大小自定义

HapeLee 5 bulan lalu
induk
melakukan
c6cf239d49

+ 7 - 0
app/src/main/java/io/legado/app/ui/config/bookshelfConfig/BookshelfConfig.kt

@@ -301,6 +301,13 @@ object BookshelfConfig {
     var bookshelfListCoverWidth by _bookshelfListCoverWidth
     val bookshelfListCoverWidthState: State<Int> get() = _bookshelfListCoverWidth.state
 
+    /**
+     * 书架网格模式下封面宽度
+     */
+    private val _bookshelfGridCoverWidth = prefStateDelegate(PreferKey.bookshelfGridCoverWidth, 120)
+    var bookshelfGridCoverWidth by _bookshelfGridCoverWidth
+    val bookshelfGridCoverWidthState: State<Int> get() = _bookshelfGridCoverWidth.state
+
     /**
      * 书架搜索按钮是否直接跳转搜索页
      */

+ 9 - 3
app/src/main/java/io/legado/app/ui/main/bookshelf/BookItem.kt

@@ -99,6 +99,7 @@ fun BookshelfItem(
     if (isGrid) {
         Box(
             modifier = modifier
+                .fillMaxWidth()
                 .clip(RoundedCornerShape(4.dp))
                 .then(
                     if (isSelected) {
@@ -112,7 +113,12 @@ fun BookshelfItem(
                     onLongClick = onLongClick
                 )
         ) {
-            Column(horizontalAlignment = Alignment.CenterHorizontally) {
+            Column(
+                horizontalAlignment = Alignment.CenterHorizontally,
+                modifier = Modifier
+                    .align(Alignment.Center)
+                    .width(coverWidth.dp)
+            ) {
 
                 Box(
                     modifier = Modifier
@@ -434,7 +440,7 @@ fun BookGroupItemGrid(
         titleCenter = titleCenter,
         titleMaxLines = titleMaxLines,
         coverShadow = coverShadow,
-        coverWidth = 84,
+        coverWidth = BookshelfConfig.bookshelfGridCoverWidth,
         onClick = onClick,
         onLongClick = onLongClick
     )
@@ -757,7 +763,7 @@ fun BookItem(
         titleCenter = titleCenter,
         titleMaxLines = titleMaxLines,
         coverShadow = coverShadow,
-        coverWidth = if (layoutMode == 0) BookshelfConfig.bookshelfListCoverWidth else 84,
+        coverWidth = if (layoutMode == 0) BookshelfConfig.bookshelfListCoverWidth else BookshelfConfig.bookshelfGridCoverWidth,
         onClick = onClick,
         onLongClick = onLongClick
     )

+ 16 - 8
app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfConfigSheet.kt

@@ -257,6 +257,14 @@ fun BookshelfConfigSheet(
                         color = LegadoTheme.colorScheme.surface,
                         onCheckedChange = { BookshelfConfig.bookshelfTitleCenter = it }
                     )
+
+                    CompactSliderSettingItem(
+                        title = "网格封面宽度",
+                        value = BookshelfConfig.bookshelfGridCoverWidth.toFloat(),
+                        valueRange = 40f..150f,
+                        steps = 110,
+                        onValueChange = { BookshelfConfig.bookshelfGridCoverWidth = it.toInt() }
+                    )
                 }
             }
 
@@ -315,14 +323,6 @@ fun BookshelfConfigSheet(
                         }
                     )
 
-                    CompactSliderSettingItem(
-                        title = "列表封面宽度",
-                        value = BookshelfConfig.bookshelfListCoverWidth.toFloat(),
-                        valueRange = 40f..120f,
-                        steps = 80,
-                        onValueChange = { BookshelfConfig.bookshelfListCoverWidth = it.toInt() }
-                    )
-
                     CompactSwitchSettingItem(
                         title = "精简详情",
                         checked = BookshelfConfig.bookshelfLayoutCompact,
@@ -332,6 +332,14 @@ fun BookshelfConfigSheet(
 
                     val listColCount =
                         if (isLandscape) BookshelfConfig.bookshelfLayoutListLandscape else BookshelfConfig.bookshelfLayoutListPortrait
+                    CompactSliderSettingItem(
+                        title = "列表封面宽度",
+                        value = BookshelfConfig.bookshelfListCoverWidth.toFloat(),
+                        valueRange = 40f..120f,
+                        steps = 80,
+                        onValueChange = { BookshelfConfig.bookshelfListCoverWidth = it.toInt() }
+                    )
+
                     CompactSliderSettingItem(
                         title = stringResource(R.string.number_rows_columns),
                         value = listColCount.toFloat(),

+ 9 - 0
app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfScreen.kt

@@ -232,6 +232,15 @@ fun BookshelfScreen(
     val latestGroups by rememberUpdatedState(uiState.groups)
     val latestSelectedGroupId by rememberUpdatedState(uiState.selectedGroupId)
 
+    LaunchedEffect(uiState.selectedGroupIndex, uiState.groups.size) {
+        if (uiState.groups.isNotEmpty()
+            && uiState.selectedGroupIndex in uiState.groups.indices
+            && pagerState.currentPage != uiState.selectedGroupIndex
+        ) {
+            pagerState.scrollToPage(uiState.selectedGroupIndex)
+        }
+    }
+
     LaunchedEffect(pagerState) {
         snapshotFlow { pagerState.settledPage }
             .distinctUntilChanged()