|
|
@ -11,53 +11,49 @@ import io.legado.app.utils.isJsonObject |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
|
|
|
class FileAssociationViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
class FileAssociationViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
fun dispatchIndent(uri:Uri):Intent?{ |
|
|
|
fun dispatchIndent(uri: Uri): Intent? { |
|
|
|
val url:String |
|
|
|
val url: String |
|
|
|
//如果是普通的url,需要根据返回的内容判断是什么 |
|
|
|
//如果是普通的url,需要根据返回的内容判断是什么 |
|
|
|
if(uri.scheme == "file" || uri.scheme == "content"){ |
|
|
|
if (uri.scheme == "file" || uri.scheme == "content") { |
|
|
|
val file = File(uri.path.toString()) |
|
|
|
val file = File(uri.path.toString()) |
|
|
|
var scheme = "" |
|
|
|
var scheme = "" |
|
|
|
if (file.exists()) { |
|
|
|
if (file.exists()) { |
|
|
|
val content = file.readText() |
|
|
|
val content = file.readText() |
|
|
|
if (content.isJsonObject() || content.isJsonArray()){ |
|
|
|
if (content.isJsonObject() || content.isJsonArray()) { |
|
|
|
//暂时根据文件内容判断属于什么 |
|
|
|
//暂时根据文件内容判断属于什么 |
|
|
|
when { |
|
|
|
when { |
|
|
|
content.contains("bookSourceUrl") -> { |
|
|
|
content.contains("bookSourceUrl") -> { |
|
|
|
scheme = "booksource" |
|
|
|
scheme = "booksource" |
|
|
|
} |
|
|
|
|
|
|
|
content.contains("sourceUrl") -> { |
|
|
|
|
|
|
|
scheme = "rsssource" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
content.contains("pattern") -> { |
|
|
|
|
|
|
|
scheme = "replace" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
content.contains("sourceUrl") -> { |
|
|
|
if (TextUtils.isEmpty(scheme)){ |
|
|
|
scheme = "rsssource" |
|
|
|
execute{ |
|
|
|
} |
|
|
|
LocalBook.importFile(uri.path.toString()) |
|
|
|
content.contains("pattern") -> { |
|
|
|
toast("添加本地文件成功${uri.path}") |
|
|
|
scheme = "replace" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
if (TextUtils.isEmpty(scheme)) { |
|
|
|
toast("文件不存在") |
|
|
|
execute { |
|
|
|
|
|
|
|
LocalBook.importFile(uri.path.toString()) |
|
|
|
|
|
|
|
toast("添加本地文件成功${uri.path}") |
|
|
|
|
|
|
|
} |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
url = "yuedu://${scheme}/importonline?src=${uri.path}" |
|
|
|
toast("文件不存在") |
|
|
|
} |
|
|
|
return null |
|
|
|
else if (uri.scheme == "yuedu"){ |
|
|
|
|
|
|
|
url = uri.toString() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
|
|
|
|
url = "yuedu://booksource/importonline?src=${uri.path}" |
|
|
|
url = "yuedu://${scheme}/importonline?src=${uri.path}" |
|
|
|
} |
|
|
|
} else if (uri.scheme == "yuedu") { |
|
|
|
val data = Uri.parse(url) |
|
|
|
url = uri.toString() |
|
|
|
val newIndent = Intent(Intent.ACTION_VIEW) |
|
|
|
} else { |
|
|
|
|
|
|
|
url = "yuedu://booksource/importonline?src=${uri.path}" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
val data = Uri.parse(url) |
|
|
|
|
|
|
|
val newIndent = Intent(Intent.ACTION_VIEW) |
|
|
|
newIndent.data = data |
|
|
|
newIndent.data = data |
|
|
|
return newIndent |
|
|
|
return newIndent |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |