HapeLee 5 месяцев назад
Родитель
Сommit
8633dd775f
1 измененных файлов с 57 добавлено и 14 удалено
  1. 57 14
      app/src/main/java/io/legado/app/help/config/ThemeImportExport.kt

+ 57 - 14
app/src/main/java/io/legado/app/help/config/ThemeImportExport.kt

@@ -238,9 +238,7 @@ object ThemeImportExport {
             "navIconExplore" to ThemeConfig.navIconExplore,
             "navIconExplore" to ThemeConfig.navIconExplore,
             "navIconRss" to ThemeConfig.navIconRss,
             "navIconRss" to ThemeConfig.navIconRss,
             "navIconMy" to ThemeConfig.navIconMy,
             "navIconMy" to ThemeConfig.navIconMy,
-            "appFontPath" to ThemeConfig.appFontPath,
-            "coverDefaultImage" to CoverConfig.defaultCover,
-            "coverDefaultImageDark" to CoverConfig.defaultCoverDark
+            "appFontPath" to ThemeConfig.appFontPath
         )
         )
 
 
         assetPaths.forEach { (key, path) ->
         assetPaths.forEach { (key, path) ->
@@ -259,9 +257,37 @@ object ThemeImportExport {
                 }
                 }
             }
             }
         }
         }
+
+        // 处理封面图集(可能包含多个逗号分隔的路径)
+        exportCoverAssets(assets, "coverDefaultImage", CoverConfig.defaultCover)
+        exportCoverAssets(assets, "coverDefaultImageDark", CoverConfig.defaultCoverDark)
+
         return assets
         return assets
     }
     }
 
 
+    /**
+     * 导出封面图集资源(支持多个逗号分隔的路径)
+     */
+    private fun exportCoverAssets(assets: MutableMap<String, String>, keyPrefix: String, paths: String?) {
+        if (paths.isNullOrBlank()) return
+        val pathList = paths.split(",").filter { it.isNotBlank() }
+        pathList.forEachIndexed { index, path ->
+            try {
+                val file = if (path.startsWith("content://")) {
+                    null
+                } else {
+                    File(path)
+                }
+                if (file?.exists() == true) {
+                    val key = if (pathList.size == 1) keyPrefix else "${keyPrefix}_$index"
+                    assets[key] = EncoderUtils.base64Encode(file.readBytes())
+                }
+            } catch (e: Exception) {
+                e.printStackTrace()
+            }
+        }
+    }
+
     /**
     /**
      * 将导出数据应用到当前配置
      * 将导出数据应用到当前配置
      */
      */
@@ -373,6 +399,8 @@ object ThemeImportExport {
     }
     }
 
 
     private fun applyAssets(assets: Map<String, String>) {
     private fun applyAssets(assets: Map<String, String>) {
+        val coverPaths = mutableMapOf<String, MutableList<String>>()
+
         assets.forEach { (key, base64) ->
         assets.forEach { (key, base64) ->
             try {
             try {
                 val bytes = EncoderUtils.base64DecodeToByteArray(base64)
                 val bytes = EncoderUtils.base64DecodeToByteArray(base64)
@@ -409,23 +437,38 @@ object ThemeImportExport {
                 destFile?.let { file ->
                 destFile?.let { file ->
                     FileOutputStream(file).use { it.write(bytes) }
                     FileOutputStream(file).use { it.write(bytes) }
                     val path = file.absolutePath
                     val path = file.absolutePath
-                    when (key) {
-                        "bgImageLight" -> ThemeConfig.bgImageLight = path
-                        "bgImageDark" -> ThemeConfig.bgImageDark = path
-                        "navIconHome" -> ThemeConfig.navIconHome = path
-                        "navIconBookshelf" -> ThemeConfig.navIconBookshelf = path
-                        "navIconExplore" -> ThemeConfig.navIconExplore = path
-                        "navIconRss" -> ThemeConfig.navIconRss = path
-                        "navIconMy" -> ThemeConfig.navIconMy = path
-                        "appFontPath" -> ThemeConfig.appFontPath = path
-                        "coverDefaultImage" -> CoverConfig.defaultCover = path
-                        "coverDefaultImageDark" -> CoverConfig.defaultCoverDark = path
+                    when {
+                        key == "bgImageLight" -> ThemeConfig.bgImageLight = path
+                        key == "bgImageDark" -> ThemeConfig.bgImageDark = path
+                        key == "navIconHome" -> ThemeConfig.navIconHome = path
+                        key == "navIconBookshelf" -> ThemeConfig.navIconBookshelf = path
+                        key == "navIconExplore" -> ThemeConfig.navIconExplore = path
+                        key == "navIconRss" -> ThemeConfig.navIconRss = path
+                        key == "navIconMy" -> ThemeConfig.navIconMy = path
+                        key == "appFontPath" -> ThemeConfig.appFontPath = path
+                        key.startsWith("coverDefaultImage") -> {
+                            // 判断是日间还是夜间封面
+                            val baseKey = if (key.removePrefix("coverDefaultImage").startsWith("Dark")) {
+                                "coverDefaultImageDark"
+                            } else {
+                                "coverDefaultImage"
+                            }
+                            coverPaths.getOrPut(baseKey) { mutableListOf() }.add(path)
+                        }
                     }
                     }
                 }
                 }
             } catch (e: Exception) {
             } catch (e: Exception) {
                 e.printStackTrace()
                 e.printStackTrace()
             }
             }
         }
         }
+
+        // 将收集到的封面路径合并为逗号分隔的字符串
+        coverPaths["coverDefaultImage"]?.let { paths ->
+            CoverConfig.defaultCover = paths.joinToString(",")
+        }
+        coverPaths["coverDefaultImageDark"]?.let { paths ->
+            CoverConfig.defaultCoverDark = paths.joinToString(",")
+        }
     }
     }
 
 
     /**
     /**