优化
This commit is contained in:
@@ -131,8 +131,8 @@ interface BookSourceDao {
|
|||||||
@get:Query("select * from book_sources where enabled = 1 and bookSourceType = 0 order by customOrder")
|
@get:Query("select * from book_sources where enabled = 1 and bookSourceType = 0 order by customOrder")
|
||||||
val allTextEnabled: List<BookSource>
|
val allTextEnabled: List<BookSource>
|
||||||
|
|
||||||
@Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
|
@get:Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
|
||||||
fun getAllGroupsUnProcessed(): List<String>
|
val allGroupsUnProcessed: List<String>
|
||||||
|
|
||||||
@Query("select * from book_sources where bookSourceUrl = :key")
|
@Query("select * from book_sources where bookSourceUrl = :key")
|
||||||
fun getBookSource(key: String): BookSource?
|
fun getBookSource(key: String): BookSource?
|
||||||
@@ -158,7 +158,7 @@ interface BookSourceDao {
|
|||||||
@get:Query("select max(customOrder) from book_sources")
|
@get:Query("select max(customOrder) from book_sources")
|
||||||
val maxOrder: Int
|
val maxOrder: Int
|
||||||
|
|
||||||
fun dealGroups(list: List<String>): List<String> {
|
private fun dealGroups(list: List<String>): List<String> {
|
||||||
val groups = linkedSetOf<String>()
|
val groups = linkedSetOf<String>()
|
||||||
list.forEach {
|
list.forEach {
|
||||||
it.splitNotBlank(AppPattern.splitGroupRegex).forEach { group ->
|
it.splitNotBlank(AppPattern.splitGroupRegex).forEach { group ->
|
||||||
@@ -172,7 +172,7 @@ interface BookSourceDao {
|
|||||||
|
|
||||||
val allGroups: List<String>
|
val allGroups: List<String>
|
||||||
get() {
|
get() {
|
||||||
return dealGroups(getAllGroupsUnProcessed())
|
return dealGroups(allGroupsUnProcessed)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun flowGroups(): Flow<List<String>> {
|
fun flowGroups(): Flow<List<String>> {
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package io.legado.app.data.dao
|
package io.legado.app.data.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
|
import io.legado.app.constant.AppPattern
|
||||||
import io.legado.app.data.entities.ReplaceRule
|
import io.legado.app.data.entities.ReplaceRule
|
||||||
|
import io.legado.app.utils.cnCompare
|
||||||
|
import io.legado.app.utils.splitNotBlank
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@@ -18,7 +22,7 @@ interface ReplaceRuleDao {
|
|||||||
fun flowGroupSearch(key: String): Flow<List<ReplaceRule>>
|
fun flowGroupSearch(key: String): Flow<List<ReplaceRule>>
|
||||||
|
|
||||||
@Query("select `group` from replace_rules where `group` is not null and `group` <> ''")
|
@Query("select `group` from replace_rules where `group` is not null and `group` <> ''")
|
||||||
fun flowGroup(): Flow<List<String>>
|
fun flowGroupsUnProcessed(): Flow<List<String>>
|
||||||
|
|
||||||
@get:Query("SELECT MIN(sortOrder) FROM replace_rules")
|
@get:Query("SELECT MIN(sortOrder) FROM replace_rules")
|
||||||
val minOrder: Int
|
val minOrder: Int
|
||||||
@@ -30,7 +34,7 @@ interface ReplaceRuleDao {
|
|||||||
val all: List<ReplaceRule>
|
val all: List<ReplaceRule>
|
||||||
|
|
||||||
@get:Query("select distinct `group` from replace_rules where trim(`group`) <> ''")
|
@get:Query("select distinct `group` from replace_rules where trim(`group`) <> ''")
|
||||||
val allGroup: List<String>
|
val allGroupsUnProcessed: List<String>
|
||||||
|
|
||||||
@get:Query("SELECT * FROM replace_rules WHERE isEnabled = 1 ORDER BY sortOrder ASC")
|
@get:Query("SELECT * FROM replace_rules WHERE isEnabled = 1 ORDER BY sortOrder ASC")
|
||||||
val allEnabled: List<ReplaceRule>
|
val allEnabled: List<ReplaceRule>
|
||||||
@@ -75,4 +79,27 @@ interface ReplaceRuleDao {
|
|||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
fun delete(vararg replaceRules: ReplaceRule)
|
fun delete(vararg replaceRules: ReplaceRule)
|
||||||
|
|
||||||
|
private fun dealGroups(list: List<String>): List<String> {
|
||||||
|
val groups = linkedSetOf<String>()
|
||||||
|
list.forEach {
|
||||||
|
it.splitNotBlank(AppPattern.splitGroupRegex).forEach { group ->
|
||||||
|
groups.add(group)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups.sortedWith { o1, o2 ->
|
||||||
|
o1.cnCompare(o2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val allGroups: List<String>
|
||||||
|
get() {
|
||||||
|
return dealGroups(allGroupsUnProcessed)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun flowGroups(): Flow<List<String>> {
|
||||||
|
return flowGroupsUnProcessed().map { list ->
|
||||||
|
dealGroups(list)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -83,8 +83,8 @@ interface RssSourceDao {
|
|||||||
@Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> '' and enabled = 1")
|
@Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> '' and enabled = 1")
|
||||||
fun flowGroupEnabled(): Flow<List<String>>
|
fun flowGroupEnabled(): Flow<List<String>>
|
||||||
|
|
||||||
@Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''")
|
@get:Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''")
|
||||||
fun getAllGroupsUnProcessed(): List<String>
|
val allGroupsUnProcessed: List<String>
|
||||||
|
|
||||||
@get:Query("select min(customOrder) from rssSources")
|
@get:Query("select min(customOrder) from rssSources")
|
||||||
val minOrder: Int
|
val minOrder: Int
|
||||||
@@ -113,7 +113,7 @@ interface RssSourceDao {
|
|||||||
@Query("select 1 from rssSources where sourceUrl = :key")
|
@Query("select 1 from rssSources where sourceUrl = :key")
|
||||||
fun has(key: String): Boolean?
|
fun has(key: String): Boolean?
|
||||||
|
|
||||||
fun dealGroups(list: List<String>): List<String> {
|
private fun dealGroups(list: List<String>): List<String> {
|
||||||
val groups = linkedSetOf<String>()
|
val groups = linkedSetOf<String>()
|
||||||
list.forEach {
|
list.forEach {
|
||||||
it.splitNotBlank(AppPattern.splitGroupRegex).forEach { group ->
|
it.splitNotBlank(AppPattern.splitGroupRegex).forEach { group ->
|
||||||
@@ -127,7 +127,7 @@ interface RssSourceDao {
|
|||||||
|
|
||||||
val allGroups: List<String>
|
val allGroups: List<String>
|
||||||
get() {
|
get() {
|
||||||
return dealGroups(getAllGroupsUnProcessed())
|
return dealGroups(allGroupsUnProcessed)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun flowGroups(): Flow<List<String>> {
|
fun flowGroups(): Flow<List<String>> {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import io.legado.app.R
|
|||||||
import io.legado.app.base.BaseDialogFragment
|
import io.legado.app.base.BaseDialogFragment
|
||||||
import io.legado.app.base.adapter.ItemViewHolder
|
import io.legado.app.base.adapter.ItemViewHolder
|
||||||
import io.legado.app.base.adapter.RecyclerAdapter
|
import io.legado.app.base.adapter.RecyclerAdapter
|
||||||
import io.legado.app.constant.AppPattern
|
|
||||||
import io.legado.app.constant.PreferKey
|
import io.legado.app.constant.PreferKey
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.ReplaceRule
|
import io.legado.app.data.entities.ReplaceRule
|
||||||
@@ -134,10 +133,7 @@ class ImportReplaceRuleDialog() : BaseDialogFragment(R.layout.dialog_recycler_vi
|
|||||||
private fun alertCustomGroup(item: MenuItem) {
|
private fun alertCustomGroup(item: MenuItem) {
|
||||||
alert(R.string.diy_edit_source_group) {
|
alert(R.string.diy_edit_source_group) {
|
||||||
val alertBinding = DialogCustomGroupBinding.inflate(layoutInflater).apply {
|
val alertBinding = DialogCustomGroupBinding.inflate(layoutInflater).apply {
|
||||||
val groups = linkedSetOf<String>()
|
val groups = appDb.replaceRuleDao.allGroups
|
||||||
appDb.replaceRuleDao.allGroup.forEach { group ->
|
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
|
||||||
}
|
|
||||||
textInputLayout.setHint(R.string.group_name)
|
textInputLayout.setHint(R.string.group_name)
|
||||||
editView.setFilterValues(groups.toList())
|
editView.setFilterValues(groups.toList())
|
||||||
editView.dropDownHeight = 180.dpToPx()
|
editView.dropDownHeight = 180.dpToPx()
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import io.legado.app.R
|
|||||||
import io.legado.app.base.BaseDialogFragment
|
import io.legado.app.base.BaseDialogFragment
|
||||||
import io.legado.app.base.adapter.ItemViewHolder
|
import io.legado.app.base.adapter.ItemViewHolder
|
||||||
import io.legado.app.base.adapter.RecyclerAdapter
|
import io.legado.app.base.adapter.RecyclerAdapter
|
||||||
import io.legado.app.constant.AppPattern
|
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.databinding.DialogEditTextBinding
|
import io.legado.app.databinding.DialogEditTextBinding
|
||||||
import io.legado.app.databinding.DialogRecyclerViewBinding
|
import io.legado.app.databinding.DialogRecyclerViewBinding
|
||||||
@@ -25,7 +24,6 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
|
|||||||
import io.legado.app.utils.applyTint
|
import io.legado.app.utils.applyTint
|
||||||
import io.legado.app.utils.requestInputMethod
|
import io.legado.app.utils.requestInputMethod
|
||||||
import io.legado.app.utils.setLayout
|
import io.legado.app.utils.setLayout
|
||||||
import io.legado.app.utils.splitNotBlank
|
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import kotlinx.coroutines.flow.conflate
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -62,12 +60,8 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.replaceRuleDao.flowGroup().conflate().collect {
|
appDb.replaceRuleDao.flowGroups().conflate().collect {
|
||||||
val groups = linkedSetOf<String>()
|
adapter.setItems(it)
|
||||||
it.map { group ->
|
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
|
||||||
}
|
|
||||||
adapter.setItems(groups.toList())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.VMBaseActivity
|
import io.legado.app.base.VMBaseActivity
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.constant.AppPattern
|
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.ReplaceRule
|
import io.legado.app.data.entities.ReplaceRule
|
||||||
import io.legado.app.databinding.ActivityReplaceRuleBinding
|
import io.legado.app.databinding.ActivityReplaceRuleBinding
|
||||||
@@ -205,11 +204,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
|
|||||||
|
|
||||||
private fun observeGroupData() {
|
private fun observeGroupData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.replaceRuleDao.flowGroup().collect {
|
appDb.replaceRuleDao.flowGroups().collect {
|
||||||
groups.clear()
|
groups.clear()
|
||||||
it.map { group ->
|
groups.addAll(it)
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
|
||||||
}
|
|
||||||
upGroupMenu()
|
upGroupMenu()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user