pull/1759/head
kunfei 3 years ago
parent 63df9baaae
commit 492e3241e6
  1. 46
      app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt

@ -35,29 +35,33 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo
} else { } else {
val file = DocumentFile.fromSingleUri(context, uri) val file = DocumentFile.fromSingleUri(context, uri)
content = file?.readText(context) ?: throw NoStackTraceException("文件不存在") content = file?.readText(context) ?: throw NoStackTraceException("文件不存在")
fileName = file!!.name ?: "" fileName = file.name ?: ""
} }
if (content.isJson()) { when {
//暂时根据文件内容判断属于什么 content.isJson() -> {
when { //暂时根据文件内容判断属于什么
content.contains("bookSourceUrl") -> when {
importBookSourceLive.postValue(content) content.contains("bookSourceUrl") ->
content.contains("sourceUrl") -> importBookSourceLive.postValue(content)
importRssSourceLive.postValue(content) content.contains("sourceUrl") ->
content.contains("pattern") -> importRssSourceLive.postValue(content)
importReplaceRuleLive.postValue(content) content.contains("pattern") ->
content.contains("themeName") -> importReplaceRuleLive.postValue(content)
importTheme(content, finally) content.contains("themeName") ->
content.contains("name") && content.contains("rule") -> importTheme(content, finally)
importTextTocRule(content, finally) content.contains("name") && content.contains("rule") ->
content.contains("name") && content.contains("url") -> importTextTocRule(content, finally)
importHttpTTS(content, finally) content.contains("name") && content.contains("url") ->
else -> errorLiveData.postValue("格式不对") 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 { } else {
onLineImportLive.postValue(uri) onLineImportLive.postValue(uri)

Loading…
Cancel
Save