From 492e3241e6d028bd7ae22d2c4639dafd6366d824 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Apr 2022 11:27:34 +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 --- .../association/FileAssociationViewModel.kt | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) 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 5e90e51dc..403412fd9 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 @@ -35,29 +35,33 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo } else { val file = DocumentFile.fromSingleUri(context, uri) content = file?.readText(context) ?: throw NoStackTraceException("文件不存在") - fileName = file!!.name ?: "" + fileName = file.name ?: "" } - if (content.isJson()) { - //暂时根据文件内容判断属于什么 - when { - content.contains("bookSourceUrl") -> - importBookSourceLive.postValue(content) - content.contains("sourceUrl") -> - importRssSourceLive.postValue(content) - content.contains("pattern") -> - importReplaceRuleLive.postValue(content) - content.contains("themeName") -> - importTheme(content, finally) - content.contains("name") && content.contains("rule") -> - importTextTocRule(content, finally) - content.contains("name") && content.contains("url") -> - importHttpTTS(content, finally) - else -> errorLiveData.postValue("格式不对") + when { + content.isJson() -> { + //暂时根据文件内容判断属于什么 + when { + content.contains("bookSourceUrl") -> + importBookSourceLive.postValue(content) + content.contains("sourceUrl") -> + importRssSourceLive.postValue(content) + content.contains("pattern") -> + importReplaceRuleLive.postValue(content) + content.contains("themeName") -> + importTheme(content, finally) + content.contains("name") && content.contains("rule") -> + importTextTocRule(content, finally) + content.contains("name") && content.contains("url") -> + importHttpTTS(content, finally) + else -> errorLiveData.postValue("格式不对") + } + } + fileName.matches(bookFileRegex) -> { + importBookLiveData.postValue(uri) + } + else -> { + throw NoStackTraceException("$fileName 暂未支持的本地书籍格式(TXT/UMD/EPUB)") } - } else if (fileName.matches(bookFileRegex)) { - importBookLiveData.postValue(uri) - } else { - throw NoStackTraceException("$fileName 暂未支持的本地书籍格式(TXT/UMD/EPUB)") } } else { onLineImportLive.postValue(uri)