From 00c757582f7051683e9d825243f722df5cd5e3c3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 10:40:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/config/FileAssociationViewModel.kt | 76 +++++++++---------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt index 11705c537..bed99c025 100644 --- a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt @@ -11,53 +11,49 @@ import io.legado.app.utils.isJsonObject import java.io.File class FileAssociationViewModel(application: Application) : BaseViewModel(application) { - fun dispatchIndent(uri:Uri):Intent?{ - val url:String - //如果是普通的url,需要根据返回的内容判断是什么 - if(uri.scheme == "file" || uri.scheme == "content"){ - val file = File(uri.path.toString()) - var scheme = "" - if (file.exists()) { - val content = file.readText() - if (content.isJsonObject() || content.isJsonArray()){ - //暂时根据文件内容判断属于什么 - when { - content.contains("bookSourceUrl") -> { - scheme = "booksource" - } - content.contains("sourceUrl") -> { - scheme = "rsssource" - } - content.contains("pattern") -> { - scheme = "replace" - } + fun dispatchIndent(uri: Uri): Intent? { + val url: String + //如果是普通的url,需要根据返回的内容判断是什么 + if (uri.scheme == "file" || uri.scheme == "content") { + val file = File(uri.path.toString()) + var scheme = "" + if (file.exists()) { + val content = file.readText() + if (content.isJsonObject() || content.isJsonArray()) { + //暂时根据文件内容判断属于什么 + when { + content.contains("bookSourceUrl") -> { + scheme = "booksource" } - } - if (TextUtils.isEmpty(scheme)){ - execute{ - LocalBook.importFile(uri.path.toString()) - toast("添加本地文件成功${uri.path}") + content.contains("sourceUrl") -> { + scheme = "rsssource" + } + content.contains("pattern") -> { + scheme = "replace" } - - return null } } - else{ - toast("文件不存在") + if (TextUtils.isEmpty(scheme)) { + execute { + LocalBook.importFile(uri.path.toString()) + toast("添加本地文件成功${uri.path}") + } return null } - - url = "yuedu://${scheme}/importonline?src=${uri.path}" - } - else if (uri.scheme == "yuedu"){ - url = uri.toString() + } else { + toast("文件不存在") + return null } - else{ - url = "yuedu://booksource/importonline?src=${uri.path}" - } - val data = Uri.parse(url) - val newIndent = Intent(Intent.ACTION_VIEW) + + url = "yuedu://${scheme}/importonline?src=${uri.path}" + } else if (uri.scheme == "yuedu") { + url = uri.toString() + } else { + url = "yuedu://booksource/importonline?src=${uri.path}" + } + val data = Uri.parse(url) + val newIndent = Intent(Intent.ACTION_VIEW) newIndent.data = data - return newIndent + return newIndent } } \ No newline at end of file