优化校验失效分组和提示

pull/1591/head
Xwite 3 years ago
parent eeb64942ad
commit dd978469f1
  1. 17
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt

@ -15,6 +15,8 @@ import io.legado.app.help.coroutine.CompositeCoroutine
import io.legado.app.model.CheckSource
import io.legado.app.model.Debug
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.ContentEmptyException
import io.legado.app.model.TocEmptyException
import io.legado.app.model.webBook.WebBook
import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.utils.activityPendingIntent
@ -173,9 +175,10 @@ class CheckSourceService : BaseService() {
if (CheckSource.checkCategory) {
val toc = WebBook.getChapterListAwait(this, source, book)
val nextChapterUrl = toc.getOrNull(1)?.url ?: toc.first().url
source.removeGroup("目录失效")
//校验正文
if (CheckSource.checkContent) {
val content = WebBook.getContentAwait(
WebBook.getContentAwait(
this,
bookSource = source,
book = book,
@ -183,9 +186,7 @@ class CheckSourceService : BaseService() {
nextChapterUrl = nextChapterUrl,
needSave = false
)
if ( !toc.first().isVolume && content.isBlank()) {
throw NoStackTraceException("正文内容为空")
}
source.removeGroup("正文失效")
}
}
}
@ -193,20 +194,22 @@ class CheckSourceService : BaseService() {
if (source.hasGroup("发现失效")) throw NoStackTraceException("发现失效")
}.timeout(CheckSource.timeout)
.onError(searchCoroutine) {
source.addGroup("失效")
when(it) {
is ContentEmptyException -> source.addGroup("正文失效")
is TocEmptyException -> source.addGroup("目录失效")
}
if (source.bookSourceComment?.contains("Error: ") == false) {
source.bookSourceComment =
"Error: ${it.localizedMessage} \n\n" + "${source.bookSourceComment}"
}
Debug.updateFinalMessage(source.bookSourceUrl, "失败:${it.localizedMessage}")
}.onSuccess(searchCoroutine) {
source.removeGroup("失效")
source.bookSourceComment = source.bookSourceComment
?.split("\n\n")
?.filterNot {
it.startsWith("Error: ")
}?.joinToString("\n")
Debug.updateFinalMessage(source.bookSourceUrl, "成功")
Debug.updateFinalMessage(source.bookSourceUrl, "校验成功")
}.onFinally(searchCoroutine) {
source.respondTime = Debug.getRespondTime(source.bookSourceUrl)
appDb.bookSourceDao.update(source)

@ -92,7 +92,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
var isFinalMessage =
ivDebugText.text.toString().contains(Regex("成功|失败"))
if (!isEmpty && !Debug.isChecking && !isFinalMessage) {
Debug.updateFinalMessage(item.bookSourceUrl, "失败")
Debug.updateFinalMessage(item.bookSourceUrl, "校验失败")
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
isFinalMessage = true
}

Loading…
Cancel
Save