From cbcbd3bb11948cae71dc9fcb0c81ed35f8138880 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 31 Mar 2022 14:01:51 +0800 Subject: [PATCH] =?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/model/localBook/LocalBook.kt | 1 + .../ui/association/FileAssociationViewModel.kt | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index 972e6fc24..59a2221da 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -22,6 +22,7 @@ import javax.script.SimpleBindings object LocalBook { private val nameAuthorPatterns = arrayOf( + Pattern.compile("(.*?)《([^《》]+)》.*?作者:(.*)"), Pattern.compile("(.*?)《([^《》]+)》(.*)"), Pattern.compile("(^)(.+) 作者:(.+)$"), Pattern.compile("(^)(.+) by (.+)$") diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt index 85ac06534..017baa943 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt @@ -31,9 +31,8 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo } else { DocumentFile.fromSingleUri(context, uri)?.readText(context) } ?: throw NoStackTraceException("文件不存在") - if (content.isJson()) { - //暂时根据文件内容判断属于什么 - when { + when { + content.isJson() -> when { content.contains("bookSourceUrl") -> importBookSourceLive.postValue(content) content.contains("sourceUrl") -> @@ -48,10 +47,12 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo importHttpTTS(content, finally) else -> errorLiveData.postValue("格式不对") } - } else if (uri.toString().matches(bookFileRegex)) { - importBookLiveData.postValue(uri) - } else { - throw NoStackTraceException("暂未支持的本地书籍格式(TXT/UMD/EPUB)") + uri.toString().matches(bookFileRegex) -> { + importBookLiveData.postValue(uri) + } + else -> { + throw NoStackTraceException("暂未支持的本地书籍格式(TXT/UMD/EPUB)") + } } } else { onLineImportLive.postValue(uri)