|
|
|
@ -13,7 +13,9 @@ import io.legado.app.utils.readText |
|
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
|
class FileAssociationViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
fun dispatchIndent(uri: Uri): Intent? { |
|
|
|
|
try { |
|
|
|
|
val url: String |
|
|
|
|
//如果是普通的url,需要根据返回的内容判断是什么 |
|
|
|
|
if (uri.scheme == "file" || uri.scheme == "content") { |
|
|
|
@ -45,9 +47,9 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica |
|
|
|
|
} |
|
|
|
|
if (TextUtils.isEmpty(scheme)) { |
|
|
|
|
execute { |
|
|
|
|
if (uri.scheme == "content"){ |
|
|
|
|
if (uri.scheme == "content") { |
|
|
|
|
LocalBook.importFile(uri.toString()) |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
LocalBook.importFile(uri.path.toString()) |
|
|
|
|
} |
|
|
|
|
toast("添加本地文件成功${uri.path}") |
|
|
|
@ -59,9 +61,9 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
// content模式下,需要传递完整的路径,方便后续解析 |
|
|
|
|
url = if (uri.scheme == "content"){ |
|
|
|
|
url = if (uri.scheme == "content") { |
|
|
|
|
"yuedu://${scheme}/importonline?src=$uri" |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
"yuedu://${scheme}/importonline?src=${uri.path}" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -74,5 +76,10 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica |
|
|
|
|
val newIndent = Intent(Intent.ACTION_VIEW) |
|
|
|
|
newIndent.data = data |
|
|
|
|
return newIndent |
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
e.printStackTrace() |
|
|
|
|
toast(e.localizedMessage) |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |