1.校验书源:搜索为空时添加分组;2.优化书源分组管理相关代码

pull/1545/head
Xwite 3 years ago
parent cb9289dc14
commit cfb921df4d
  1. 12
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 1
      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) {

@ -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