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