From 19788b6a3255995b8708d774a5358eb7f61eaade Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 5 Sep 2020 22:30:54 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=85=E8=AF=BB=E9=85=8D=E7=BD=AE=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/ReadBookConfig.kt | 10 +++++++++- .../ui/book/read/config/BgTextConfigDialog.kt | 16 +++++++++++----- .../io/legado/app/ui/filechooser/FilePicker.kt | 1 - 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 55a2078cb..948c56c6d 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -25,7 +25,15 @@ object ReadBookConfig { val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes()) GSON.fromJsonArray(json)!! } - val durConfig get() = getConfig(styleSelect) + var durConfig + get() = getConfig(styleSelect) + set(value) { + configList[styleSelect] = value + if (shareLayout) { + configList[5] = value + } + upBg() + } var bg: Drawable? = null var bgMeanColor: Int = 0 diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index a08f1b96c..982a4b19d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -235,7 +235,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { ?.writeBytes(requireContext(), File(configZipPath).readBytes()) } } else { - val exportPath = FileUtils.getPath(File(uri.toString()), configFileName) + val exportPath = FileUtils.getPath(File(uri.path!!), configFileName) FileUtils.deleteFile(exportPath) FileUtils.createFileIfNotExist(exportPath) .writeBytes(File(configZipPath).readBytes()) @@ -274,8 +274,15 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { } if (config.bgType() == 2) { val bgName = FileUtils.getName(config.bgStr()) - + val file = FileUtils.createFileIfNotExist( + requireContext().externalFilesDir, + "bg", + bgName + ) + FileUtils.getFile(configDir, bgName).compareTo(file) } + ReadBookConfig.durConfig = config + postEvent(EventBus.UP_CONFIG, true) }.onSuccess { toast("导入成功") }.onError { @@ -316,9 +323,8 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { if (uri.toString().isContentPath()) { val doc = DocumentFile.fromSingleUri(requireContext(), uri) doc?.name?.let { - var file = requireContext().getExternalFilesDir(null) - ?: requireContext().filesDir - file = FileUtils.createFileIfNotExist(file, "bg", it) + val file = + FileUtils.createFileIfNotExist(requireContext().externalFilesDir, "bg", it) kotlin.runCatching { DocumentUtils.readBytes(requireContext(), doc.uri) }.getOrNull()?.let { byteArray -> diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt b/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt index 2cd7bdf5c..6fecd5f54 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt @@ -212,7 +212,6 @@ object FilePicker { allowExtensions.forEach { when (it) { "txt", "xml" -> types.add("text/*") - "zip" -> types.add("application/x-zip-compressed") else -> types.add("application/$it") } }