1.校验书源:搜索为空时添加分组;2.优化书源分组管理相关代码
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user