优化
This commit is contained in:
@@ -151,7 +151,11 @@ open class WebDav(val path: String, val authorization: Authorization) {
|
||||
*/
|
||||
private fun parseBody(s: String): List<WebDavFile> {
|
||||
val list = ArrayList<WebDavFile>()
|
||||
val document = Jsoup.parse(s, Parser.xmlParser())
|
||||
val document = kotlin.runCatching {
|
||||
Jsoup.parse(s, Parser.xmlParser())
|
||||
}.getOrElse {
|
||||
Jsoup.parse(s)
|
||||
}
|
||||
val ns = document.findNSPrefix("DAV:")
|
||||
val elements = document.findNS("response", ns)
|
||||
val urlStr = httpUrl ?: return list
|
||||
|
||||
@@ -25,8 +25,10 @@ class AnalyzeByJSoup(doc: Any) {
|
||||
if (doc is JXNode) {
|
||||
return if (doc.isElement) doc.asElement() else Jsoup.parse(doc.toString())
|
||||
}
|
||||
if (doc.toString().startsWith("<?xml", true)) {
|
||||
return Jsoup.parse(doc.toString(), Parser.xmlParser())
|
||||
kotlin.runCatching {
|
||||
if (doc.toString().startsWith("<?xml", true)) {
|
||||
return Jsoup.parse(doc.toString(), Parser.xmlParser())
|
||||
}
|
||||
}
|
||||
return Jsoup.parse(doc.toString())
|
||||
}
|
||||
|
||||
@@ -32,8 +32,10 @@ class AnalyzeByXPath(doc: Any) {
|
||||
if (html1.endsWith("</tr>") || html1.endsWith("</tbody>")) {
|
||||
html1 = "<table>${html1}</table>"
|
||||
}
|
||||
if (html1.trim().startsWith("<?xml", true)) {
|
||||
return JXDocument.create(Jsoup.parse(html1, Parser.xmlParser()))
|
||||
kotlin.runCatching {
|
||||
if (html1.trim().startsWith("<?xml", true)) {
|
||||
return JXDocument.create(Jsoup.parse(html1, Parser.xmlParser()))
|
||||
}
|
||||
}
|
||||
return JXDocument.create(html1)
|
||||
}
|
||||
|
||||
@@ -101,10 +101,13 @@ class DownloadService : BaseService() {
|
||||
checkDownloadState()
|
||||
}
|
||||
}.onFailure {
|
||||
when (it) {
|
||||
is SecurityException -> toastOnUi("下载出错,没有存储权限")
|
||||
else -> toastOnUi("下载出错,${it.localizedMessage}")
|
||||
it.printStackTrace()
|
||||
val msg = when (it) {
|
||||
is SecurityException -> "下载出错,没有存储权限"
|
||||
else -> "下载出错,${it.localizedMessage}"
|
||||
}
|
||||
toastOnUi(msg)
|
||||
AppLog.put(msg, it)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
if (selectAll) {
|
||||
getItems().forEach {
|
||||
if (!it.isDir && !bookFileNames.contains(it.name)) {
|
||||
selectedUris.add(it.uri.toString())
|
||||
selectedUris.add(it.toString())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -118,11 +118,11 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
|
||||
fun revertSelection() {
|
||||
getItems().forEach {
|
||||
if (!it.isDir) {
|
||||
if (selectedUris.contains(it.uri.toString())) {
|
||||
selectedUris.remove(it.uri.toString())
|
||||
if (!it.isDir && !bookFileNames.contains(it.name)) {
|
||||
if (selectedUris.contains(it.toString())) {
|
||||
selectedUris.remove(it.toString())
|
||||
} else {
|
||||
selectedUris.add(it.uri.toString())
|
||||
selectedUris.add(it.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
|
||||
fun removeSelection() {
|
||||
for (i in getItems().lastIndex downTo 0) {
|
||||
if (getItem(i)?.uri.toString() in selectedUris) {
|
||||
if (getItem(i)?.toString() in selectedUris) {
|
||||
removeItem(i)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,15 @@ package io.legado.app.utils
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import io.legado.app.BuildConfig
|
||||
import io.legado.app.help.config.AppConfig
|
||||
|
||||
private var toast: Toast? = null
|
||||
|
||||
fun Context.toastOnUi(message: Int) {
|
||||
runOnUI {
|
||||
kotlin.runCatching {
|
||||
if (toast == null) {
|
||||
if (toast == null || BuildConfig.DEBUG || AppConfig.recordLog) {
|
||||
toast = Toast.makeText(this, message, Toast.LENGTH_SHORT)
|
||||
} else {
|
||||
toast?.setText(message)
|
||||
@@ -25,7 +27,7 @@ fun Context.toastOnUi(message: Int) {
|
||||
fun Context.toastOnUi(message: CharSequence?) {
|
||||
runOnUI {
|
||||
kotlin.runCatching {
|
||||
if (toast == null) {
|
||||
if (toast == null || BuildConfig.DEBUG || AppConfig.recordLog) {
|
||||
toast = Toast.makeText(this, message.toString(), Toast.LENGTH_SHORT)
|
||||
} else {
|
||||
toast?.setText(message.toString())
|
||||
@@ -39,7 +41,7 @@ fun Context.toastOnUi(message: CharSequence?) {
|
||||
fun Context.longToastOnUi(message: Int) {
|
||||
runOnUI {
|
||||
kotlin.runCatching {
|
||||
if (toast == null) {
|
||||
if (toast == null || BuildConfig.DEBUG || AppConfig.recordLog) {
|
||||
toast = Toast.makeText(this, message, Toast.LENGTH_LONG)
|
||||
} else {
|
||||
toast?.setText(message)
|
||||
@@ -53,7 +55,7 @@ fun Context.longToastOnUi(message: Int) {
|
||||
fun Context.longToastOnUi(message: CharSequence?) {
|
||||
runOnUI {
|
||||
kotlin.runCatching {
|
||||
if (toast == null) {
|
||||
if (toast == null || BuildConfig.DEBUG || AppConfig.recordLog) {
|
||||
toast = Toast.makeText(this, message.toString(), Toast.LENGTH_LONG)
|
||||
} else {
|
||||
toast?.setText(message.toString())
|
||||
|
||||
Reference in New Issue
Block a user