mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
bec4afe309
commit
e00907ba33
@ -118,18 +118,20 @@ data class BookSource(
|
||||
|
||||
fun getContentRule() = ruleContent ?: ContentRule()
|
||||
|
||||
fun addGroup(group: String) {
|
||||
fun addGroup(group: String): BookSource {
|
||||
bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
|
||||
it.add(group)
|
||||
bookSourceGroup = TextUtils.join(",", it)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun removeGroup(group: String) {
|
||||
fun removeGroup(group: String): BookSource {
|
||||
bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
|
||||
it.remove(group)
|
||||
bookSourceGroup = TextUtils.join(",", it)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun equal(source: BookSource) =
|
||||
|
@ -3,7 +3,6 @@ package io.legado.app.ui.book.source.manage
|
||||
import android.app.Application
|
||||
import android.text.TextUtils
|
||||
import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.utils.*
|
||||
@ -94,8 +93,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
|
||||
execute {
|
||||
val list = arrayListOf<BookSource>()
|
||||
sources.forEach { source ->
|
||||
source.addGroup(groups)
|
||||
list.add(source)
|
||||
list.add(source.copy().addGroup(groups))
|
||||
}
|
||||
appDb.bookSourceDao.update(*list.toTypedArray())
|
||||
}
|
||||
@ -105,8 +103,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
|
||||
execute {
|
||||
val list = arrayListOf<BookSource>()
|
||||
sources.forEach { source ->
|
||||
source.removeGroup(groups)
|
||||
list.add(source)
|
||||
list.add(source.copy().removeGroup(groups))
|
||||
}
|
||||
appDb.bookSourceDao.update(*list.toTypedArray())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user