From cfb921df4da74c67dc1a710dfe7667b0df3b4a10 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Fri, 21 Jan 2022 20:58:50 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=A0=A1=E9=AA=8C=E4=B9=A6=E6=BA=90:?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E4=B8=BA=E7=A9=BA=E6=97=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E7=BB=84=EF=BC=9B2.=E4=BC=98=E5=8C=96=E4=B9=A6?= =?UTF-8?q?=E6=BA=90=E5=88=86=E7=BB=84=E7=AE=A1=E7=90=86=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/BookSource.kt | 12 ++++------ .../legado/app/service/CheckSourceService.kt | 1 + .../book/source/manage/BookSourceViewModel.kt | 24 ++++--------------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 12cf72bb9..db4fedb1f 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.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) } diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index ceb4a9993..13a1695fa 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -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) { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index bacacf4f4..ea3c1c4dc 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -94,16 +94,8 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) execute { val list = arrayListOf() sources.forEach { source -> - val newGroupList = arrayListOf() - 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() sources.forEach { source -> - val newGroupList = arrayListOf() - 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()) }