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

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

@ -94,16 +94,8 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
execute {
val list = arrayListOf<BookSource>()
sources.forEach { source ->
val newGroupList = arrayListOf<String>()
source.bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.forEach {
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))
source.addGroup(groups)
list.add(source)
}
appDb.bookSourceDao.update(*list.toTypedArray())
}
@ -113,16 +105,8 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
execute {
val list = arrayListOf<BookSource>()
sources.forEach { source ->
val newGroupList = arrayListOf<String>()
source.bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.forEach {
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))
source.removeGroup(groups)
list.add(source)
}
appDb.bookSourceDao.update(*list.toTypedArray())
}

Loading…
Cancel
Save