Parcourir la source

feat: 主页模块布局配置支持自定义列数

HapeLee il y a 4 mois
Parent
commit
2eaf4be8ac

+ 1 - 0
app/src/main/java/io/legado/app/ui/main/homepage/HomepageModuleFeed.kt

@@ -284,6 +284,7 @@ fun HomepageModuleFeed(
                                 onOpenKind = actions.onKindUrlClick,
                                 onOpenKind = actions.onKindUrlClick,
                                 onRefreshKinds = actions.onRefreshButtonGroup,
                                 onRefreshKinds = actions.onRefreshButtonGroup,
                                 modifier = Modifier.fillMaxWidth(),
                                 modifier = Modifier.fillMaxWidth(),
+                                columns = moduleUi.config["layout_columns"]?.toIntOrNull() ?: 5,
                                 layoutConfig = moduleUi.layoutConfig
                                 layoutConfig = moduleUi.layoutConfig
                             )
                             )
                         }
                         }

+ 6 - 1
app/src/main/java/io/legado/app/ui/main/homepage/HomepageViewModel.kt

@@ -297,7 +297,12 @@ class HomepageViewModel(
                         val json = GSON.fromJson(configStr, Map::class.java)
                         val json = GSON.fromJson(configStr, Map::class.java)
                         if (json != null) {
                         if (json != null) {
                             val map = mutableMapOf<String, String>()
                             val map = mutableMapOf<String, String>()
-                            json.forEach { (k, v) -> map["layout_$k"] = v.toString() }
+                            json.forEach { (k, v) ->
+                                map["layout_$k"] = when (v) {
+                                    is Double -> if (v % 1.0 == 0.0) v.toLong().toString() else v.toString()
+                                    else -> v.toString()
+                                }
+                            }
                             cache[module.id] = map
                             cache[module.id] = map
                         }
                         }
                     } catch (_: Exception) {
                     } catch (_: Exception) {

+ 3 - 3
app/src/main/java/io/legado/app/ui/main/homepage/modules/ButtonGroupModule.kt

@@ -40,6 +40,7 @@ fun ButtonGroupModule(
     onRefreshKinds: (globalId: String) -> Unit,
     onRefreshKinds: (globalId: String) -> Unit,
     modifier: Modifier = Modifier,
     modifier: Modifier = Modifier,
     icon: String? = null,
     icon: String? = null,
+    columns: Int = 5,
     layoutConfig: String? = null,
     layoutConfig: String? = null,
 ) {
 ) {
     if (kinds.isEmpty()) return
     if (kinds.isEmpty()) return
@@ -65,12 +66,11 @@ fun ButtonGroupModule(
         } ?: (emptyMap<String, String>() to icon)
         } ?: (emptyMap<String, String>() to icon)
     }
     }
 
 
-    // --- 动态布局计算逻辑 ---
-    val maxColumns = 5
+    // Keep rows balanced without exceeding the configured column count.
+    val maxColumns = columns.coerceAtLeast(1)
     val total = kinds.size
     val total = kinds.size
     val numRows = (total + maxColumns - 1) / maxColumns
     val numRows = (total + maxColumns - 1) / maxColumns
     val actualColumns = (total + numRows - 1) / numRows
     val actualColumns = (total + numRows - 1) / numRows
-    // -----------------------
 
 
     Column(
     Column(
         modifier = modifier
         modifier = modifier