From 2992ecab9d76521410dcf932471fa730982c1248 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 18 Mar 2023 09:07:22 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20=E6=9C=AC=E5=9C=B0=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=8C=85=E5=90=AB=E5=9C=A8=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E5=86=85=E7=9A=84=E5=8D=95=E4=B8=AA=E4=B9=A6=E6=BA=90=E6=97=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/help/source/SourceAnalyzer.kt | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt index 7a55a41f4..98e76434e 100644 --- a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt @@ -2,6 +2,7 @@ package io.legado.app.help.source import androidx.annotation.Keep import com.jayway.jsonpath.JsonPath +import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.constant.AppLog import io.legado.app.constant.BookSourceType @@ -11,6 +12,8 @@ import io.legado.app.exception.NoStackTraceException import io.legado.app.utils.* import java.io.InputStream import java.util.regex.Pattern +import splitties.init.appCtx + @Suppress("RegExpRedundantEscape") object SourceAnalyzer { @@ -36,7 +39,7 @@ object SourceAnalyzer { } } else -> { - throw NoStackTraceException("格式不对") + throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) } } bookSources @@ -46,21 +49,24 @@ object SourceAnalyzer { fun jsonToBookSources(inputStream: InputStream): Result> { return kotlin.runCatching { val bookSources = mutableListOf() -// kotlin.runCatching { - val items: List> = jsonPath.parse(inputStream).read("$") + val documentContext = jsonPath.parse(inputStream) + kotlin.runCatching { + val items: List = documentContext.read("$") for (item in items) { val jsonItem = jsonPath.parse(item) jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { bookSources.add(it) } } -// }.onFailure { -// val item: Map = jsonPath.parse(inputStream).read("$") -// val jsonItem = jsonPath.parse(item) -// jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { -// bookSources.add(it) -// } -// } + }.onFailure { + val item: Map = documentContext.read("$") + val jsonItem = jsonPath.parse(item) + jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { + bookSources.add(it) + } + }.onFailure { + throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) + } bookSources } } @@ -69,14 +75,14 @@ object SourceAnalyzer { val source = BookSource() val sourceAny = GSON.fromJsonObject(json.trim()) .onFailure { - AppLog.put("转化书源出错", it) + AppLog.put(appCtx.getString(R.string.wrong_format), it) }.getOrNull() return kotlin.runCatching { if (sourceAny?.ruleToc == null) { source.apply { val jsonItem = jsonPath.parse(json.trim()) bookSourceUrl = jsonItem.readString("bookSourceUrl") - ?: throw NoStackTraceException("格式不对") + ?: throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) bookSourceName = jsonItem.readString("bookSourceName") ?: "" bookSourceGroup = jsonItem.readString("bookSourceGroup") loginUrl = jsonItem.readString("loginUrl") From dda6abdfc3cf05e4ba5e10ab4814fc0a63a3319d Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 18 Mar 2023 09:17:06 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20=E6=9C=AC=E5=9C=B0=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=8C=85=E5=90=AB=E5=9C=A8=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E5=86=85=E7=9A=84=E5=8D=95=E4=B8=AA=E4=B9=A6=E6=BA=90=E6=97=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index edf0ac21d..9d54376e8 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -17,6 +17,7 @@ * 一些带有搜索框的界面自动隐藏软键盘 * 本地书籍和远程书籍导入界面支持压缩包 * 内置了两个直链上传配置,可以通过导入默认切换 +* 修复无法导入不在数组内的单个书源的本地文件 **2023/03/14** diff --git a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt index 98e76434e..d14bc4daa 100644 --- a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt @@ -51,7 +51,7 @@ object SourceAnalyzer { val bookSources = mutableListOf() val documentContext = jsonPath.parse(inputStream) kotlin.runCatching { - val items: List = documentContext.read("$") + val items: List> = documentContext.read("$") for (item in items) { val jsonItem = jsonPath.parse(item) jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { From 311932d30394cadb49a29821bbfee2137fc79745 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 18 Mar 2023 10:03:02 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=E6=9C=AC=E5=9C=B0=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=8C=85=E5=90=AB=E5=9C=A8=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E5=86=85=E7=9A=84=E5=8D=95=E4=B8=AA=E4=B9=A6=E6=BA=90=E6=97=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/source/SourceAnalyzer.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt index d14bc4daa..d2300ffec 100644 --- a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt @@ -50,7 +50,7 @@ object SourceAnalyzer { return kotlin.runCatching { val bookSources = mutableListOf() val documentContext = jsonPath.parse(inputStream) - kotlin.runCatching { + try { val items: List> = documentContext.read("$") for (item in items) { val jsonItem = jsonPath.parse(item) @@ -58,13 +58,13 @@ object SourceAnalyzer { bookSources.add(it) } } - }.onFailure { + } catch { val item: Map = documentContext.read("$") val jsonItem = jsonPath.parse(item) jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { bookSources.add(it) } - }.onFailure { + } catch { throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) } bookSources From 368e63514b50961923c6c1d00154b63d8038ae6f Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 18 Mar 2023 10:11:25 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=E6=9C=AC=E5=9C=B0=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=8C=85=E5=90=AB=E5=9C=A8=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E5=86=85=E7=9A=84=E5=8D=95=E4=B8=AA=E4=B9=A6=E6=BA=90=E6=97=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt index d2300ffec..dcd7a0fd3 100644 --- a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt @@ -58,13 +58,13 @@ object SourceAnalyzer { bookSources.add(it) } } - } catch { + } catch (_: Exception) { val item: Map = documentContext.read("$") val jsonItem = jsonPath.parse(item) jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { bookSources.add(it) } - } catch { + } catch (_: Exception) { throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) } bookSources From 06034fd8e23ca20be5c3b25df5050e51f91cd060 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 18 Mar 2023 11:20:04 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/help/source/SourceAnalyzer.kt | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt index dcd7a0fd3..17802511c 100644 --- a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt @@ -52,22 +52,19 @@ object SourceAnalyzer { val documentContext = jsonPath.parse(inputStream) try { val items: List> = documentContext.read("$") - for (item in items) { - val jsonItem = jsonPath.parse(item) - jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { - bookSources.add(it) - } + items.map { + val jsonItem = jsonPath.parse(it) + jsonToBookSource(jsonItem.jsonString()).getOrThrow() } } catch (_: Exception) { val item: Map = documentContext.read("$") val jsonItem = jsonPath.parse(item) - jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { - bookSources.add(it) - } - } catch (_: Exception) { - throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) + mutableListOf( + jsonToBookSource(jsonItem.jsonString()).getOrThrow() + ) } - bookSources + }.onFailure { + throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) } } From 7982c699587bfdf0a19f463ad29c724e503c8b6a Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 18 Mar 2023 11:38:57 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/source/SourceAnalyzer.kt | 13 ++++++++----- app/src/main/res/values-es-rES/strings.xml | 1 - app/src/main/res/values-ja-rJP/strings.xml | 1 - app/src/main/res/values-pt-rBR/strings.xml | 1 - app/src/main/res/values-zh-rHK/strings.xml | 1 - app/src/main/res/values-zh-rTW/strings.xml | 1 - app/src/main/res/values-zh/strings.xml | 1 - app/src/main/res/values/strings.xml | 1 - 8 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt index 17802511c..3f614acd0 100644 --- a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt @@ -52,17 +52,20 @@ object SourceAnalyzer { val documentContext = jsonPath.parse(inputStream) try { val items: List> = documentContext.read("$") - items.map { + items.forEach { val jsonItem = jsonPath.parse(it) - jsonToBookSource(jsonItem.jsonString()).getOrThrow() + jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { + bookSources.add(it) + } } } catch (_: Exception) { val item: Map = documentContext.read("$") val jsonItem = jsonPath.parse(item) - mutableListOf( - jsonToBookSource(jsonItem.jsonString()).getOrThrow() - ) + jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { + bookSources.add(it) + } } + bookSources }.onFailure { throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) } diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 927902142..7c44c70bb 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -372,7 +372,6 @@ Simulación Desplazado Ninguno - La fuente de este libro utiliza funciones avanzadas, para desbloquear diríjase a Donaciones y toque el código de búsqueda del sobre rojo de Alipay para recibir ese sobre. Actualiza el último capítulo después del cambio de fuente en segundo plano si está habilitado, la actualización comenzará 1 minuto después de que se abra la aplicación Ocultar automáticamente la barra de herramientas diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index a54be5b30..6fca90a60 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -376,7 +376,6 @@ Simulation Scroll None - This book source uses advanced features, please go to the Donations and tap the Alipay red envelope search code to receive the red envelope,then you can use it. Update the latest chapter after changed origin in the background if enabled,the update will start 1 minute later when the software is run Auto hide ToolBar diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 1b0012e37..69bcc61bc 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -374,7 +374,6 @@ Simulação Deslizar Nenhum - Esta fonte de livro usa recursos avançados, por favor vá até Doações e toque no código de busca do envelope vermelho Alipay para receber o envelope vermelho, depois você pode usá-lo. Atualizar o último capítulo após a alteração de origem em segundo plano se ativado, a atualização será iniciada 1 minuto depois o App for aberto Auto esconder a barra de ferramentas diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 8f31bac58..ba49aa66d 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -373,7 +373,6 @@ 仿真 滾動 無動畫 - 此書源使用了高級功能,請到捐贈裏點擊支付寶紅包搜索碼領取紅包開啟。 後台更新換源最新章節 開啟則會在軟件打開 1 分鐘後開始更新 書架 ToolBar 自動隱藏 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c90d71c01..8a453ec29 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -375,7 +375,6 @@ 模擬 滾動 無動畫 - 此書源使用了進階功能,請到捐贈裡點擊支付寶紅包搜尋碼領取紅包開啟。 後台更新換源最新章節 開啟則會在軟體打開1分鐘後開始更新 書架ToolBar自動隱藏 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index f7b42db3f..d8b424f59 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -375,7 +375,6 @@ 仿真 滚动 无动画 - 此书源使用了高级功能,请到捐赠里点击支付宝红包搜索码领取红包开启。 后台更新换源最新章节 开启则会在软件打开 1 分钟后开始更新 书架工具栏自动隐藏 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aa1f00d8c..db99d95a6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -376,7 +376,6 @@ Simulation Scroll None - This book source uses advanced features, please go to the Donations and tap the Alipay red envelope search code to receive the red envelope,then you can use it. Update the latest chapter after changed origin in the background if enabled,the update will start 1 minute later when the software is run Auto hide ToolBar