Merge pull request #1545 from Xwite/master

校验书源优化;书源分组管理优化
pull/1551/head
kunfei 3 years ago committed by GitHub
commit bec4afe309
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 11
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  3. 24
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt

@ -3,6 +3,7 @@ package io.legado.app.data.entities
import android.os.Parcelable import android.os.Parcelable
import android.text.TextUtils import android.text.TextUtils
import androidx.room.* import androidx.room.*
import io.legado.app.constant.AppPattern
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.entities.rule.* import io.legado.app.data.entities.rule.*
import io.legado.app.help.SourceAnalyzer import io.legado.app.help.SourceAnalyzer
@ -118,17 +119,14 @@ data class BookSource(
fun getContentRule() = ruleContent ?: ContentRule() fun getContentRule() = ruleContent ?: ContentRule()
fun addGroup(group: String) { fun addGroup(group: String) {
bookSourceGroup?.let { bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
if (!it.contains(group)) { it.add(group)
bookSourceGroup = "$it,$group" bookSourceGroup = TextUtils.join(",", it)
}
} ?: let {
bookSourceGroup = group
} }
} }
fun removeGroup(group: String) { fun removeGroup(group: String) {
bookSourceGroup?.splitNotBlank("[,;,;]".toRegex())?.toHashSet()?.let { bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
it.remove(group) it.remove(group)
bookSourceGroup = TextUtils.join(",", it) bookSourceGroup = TextUtils.join(",", it)
} }

@ -120,6 +120,7 @@ class CheckSourceService : BaseService() {
} }
var books = WebBook.searchBookAwait(this, source, searchWord) var books = WebBook.searchBookAwait(this, source, searchWord)
if (books.isEmpty()) { if (books.isEmpty()) {
source.addGroup("搜索失效")
val exs = source.exploreKinds val exs = source.exploreKinds
var url: String? = null var url: String? = null
for (ex in exs) { for (ex in exs) {
@ -133,7 +134,11 @@ class CheckSourceService : BaseService() {
} }
books = WebBook.exploreBookAwait(this, source, url) books = WebBook.exploreBookAwait(this, source, url)
} }
val book = WebBook.getBookInfoAwait(this, source, books.first().toBook()) source.removeGroup("搜索失效")
var book = books.first().toBook()
if (book.tocUrl.isBlank()) {
book = WebBook.getBookInfoAwait(this, source, book)
}
val toc = WebBook.getChapterListAwait(this, source, book) val toc = WebBook.getChapterListAwait(this, source, book)
val nextChapterUrl = toc.getOrNull(1)?.url ?: toc.first().url val nextChapterUrl = toc.getOrNull(1)?.url ?: toc.first().url
val content = WebBook.getContentAwait( val content = WebBook.getContentAwait(
@ -155,8 +160,6 @@ class CheckSourceService : BaseService() {
"Error: ${it.localizedMessage} \n\n" + "${source.bookSourceComment}" "Error: ${it.localizedMessage} \n\n" + "${source.bookSourceComment}"
} }
Debug.updateFinalMessage(source.bookSourceUrl, "失败:${it.localizedMessage}") Debug.updateFinalMessage(source.bookSourceUrl, "失败:${it.localizedMessage}")
source.respondTime = Debug.getRespondTime(source.bookSourceUrl)
appDb.bookSourceDao.update(source)
}.onSuccess(searchCoroutine) { }.onSuccess(searchCoroutine) {
source.removeGroup("失效") source.removeGroup("失效")
source.bookSourceComment = source.bookSourceComment source.bookSourceComment = source.bookSourceComment
@ -165,9 +168,9 @@ class CheckSourceService : BaseService() {
it.startsWith("Error: ") it.startsWith("Error: ")
}?.joinToString("\n") }?.joinToString("\n")
Debug.updateFinalMessage(source.bookSourceUrl, "成功") Debug.updateFinalMessage(source.bookSourceUrl, "成功")
}.onFinally(searchCoroutine) {
source.respondTime = Debug.getRespondTime(source.bookSourceUrl) source.respondTime = Debug.getRespondTime(source.bookSourceUrl)
appDb.bookSourceDao.update(source) appDb.bookSourceDao.update(source)
}.onFinally(searchCoroutine) {
onNext(source.bookSourceUrl, source.bookSourceName) onNext(source.bookSourceUrl, source.bookSourceName)
} }
} }

@ -94,16 +94,8 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
execute { execute {
val list = arrayListOf<BookSource>() val list = arrayListOf<BookSource>()
sources.forEach { source -> sources.forEach { source ->
val newGroupList = arrayListOf<String>() source.addGroup(groups)
source.bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.forEach { list.add(source)
newGroupList.add(it)
}
groups.splitNotBlank(",", ";", "").forEach {
newGroupList.add(it)
}
val lh = LinkedHashSet(newGroupList)
val newGroup = ArrayList(lh).joinToString(separator = ",")
list.add(source.copy(bookSourceGroup = newGroup))
} }
appDb.bookSourceDao.update(*list.toTypedArray()) appDb.bookSourceDao.update(*list.toTypedArray())
} }
@ -113,16 +105,8 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
execute { execute {
val list = arrayListOf<BookSource>() val list = arrayListOf<BookSource>()
sources.forEach { source -> sources.forEach { source ->
val newGroupList = arrayListOf<String>() source.removeGroup(groups)
source.bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.forEach { list.add(source)
newGroupList.add(it)
}
groups.splitNotBlank(",", ";", "").forEach {
newGroupList.remove(it)
}
val lh = LinkedHashSet(newGroupList)
val newGroup = ArrayList(lh).joinToString(separator = ",")
list.add(source.copy(bookSourceGroup = newGroup))
} }
appDb.bookSourceDao.update(*list.toTypedArray()) appDb.bookSourceDao.update(*list.toTypedArray())
} }

Loading…
Cancel
Save