pull/2274/head
kunfei 2 years ago
parent 2279550666
commit 53a0e9f1f8
  1. 8
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 31
      app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt
  3. 8
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  4. 6
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt
  5. 10
      app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt
  6. 7
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt

@ -131,8 +131,8 @@ interface BookSourceDao {
@get:Query("select * from book_sources where enabled = 1 and bookSourceType = 0 order by customOrder")
val allTextEnabled: List<BookSource>
@Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
fun getAllGroupsUnProcessed(): List<String>
@get:Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
val allGroupsUnProcessed: List<String>
@Query("select * from book_sources where bookSourceUrl = :key")
fun getBookSource(key: String): BookSource?
@ -158,7 +158,7 @@ interface BookSourceDao {
@get:Query("select max(customOrder) from book_sources")
val maxOrder: Int
fun dealGroups(list: List<String>): List<String> {
private fun dealGroups(list: List<String>): List<String> {
val groups = linkedSetOf<String>()
list.forEach {
it.splitNotBlank(AppPattern.splitGroupRegex).forEach { group ->
@ -172,7 +172,7 @@ interface BookSourceDao {
val allGroups: List<String>
get() {
return dealGroups(getAllGroupsUnProcessed())
return dealGroups(allGroupsUnProcessed)
}
fun flowGroups(): Flow<List<String>> {

@ -1,8 +1,12 @@
package io.legado.app.data.dao
import androidx.room.*
import io.legado.app.constant.AppPattern
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.map
@Dao
@ -18,7 +22,7 @@ interface ReplaceRuleDao {
fun flowGroupSearch(key: String): Flow<List<ReplaceRule>>
@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")
val minOrder: Int
@ -30,7 +34,7 @@ interface ReplaceRuleDao {
val all: List<ReplaceRule>
@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")
val allEnabled: List<ReplaceRule>
@ -75,4 +79,27 @@ interface ReplaceRuleDao {
@Delete
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")
fun flowGroupEnabled(): Flow<List<String>>
@Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''")
fun getAllGroupsUnProcessed(): List<String>
@get:Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''")
val allGroupsUnProcessed: List<String>
@get:Query("select min(customOrder) from rssSources")
val minOrder: Int
@ -113,7 +113,7 @@ interface RssSourceDao {
@Query("select 1 from rssSources where sourceUrl = :key")
fun has(key: String): Boolean?
fun dealGroups(list: List<String>): List<String> {
private fun dealGroups(list: List<String>): List<String> {
val groups = linkedSetOf<String>()
list.forEach {
it.splitNotBlank(AppPattern.splitGroupRegex).forEach { group ->
@ -127,7 +127,7 @@ interface RssSourceDao {
val allGroups: List<String>
get() {
return dealGroups(getAllGroupsUnProcessed())
return dealGroups(allGroupsUnProcessed)
}
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.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.ReplaceRule
@ -134,10 +133,7 @@ class ImportReplaceRuleDialog() : BaseDialogFragment(R.layout.dialog_recycler_vi
private fun alertCustomGroup(item: MenuItem) {
alert(R.string.diy_edit_source_group) {
val alertBinding = DialogCustomGroupBinding.inflate(layoutInflater).apply {
val groups = linkedSetOf<String>()
appDb.replaceRuleDao.allGroup.forEach { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
val groups = appDb.replaceRuleDao.allGroups
textInputLayout.setHint(R.string.group_name)
editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dpToPx()

@ -13,7 +13,6 @@ import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.databinding.DialogEditTextBinding
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.requestInputMethod
import io.legado.app.utils.setLayout
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch
@ -62,12 +60,8 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
private fun initData() {
launch {
appDb.replaceRuleDao.flowGroup().conflate().collect {
val groups = linkedSetOf<String>()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
adapter.setItems(groups.toList())
appDb.replaceRuleDao.flowGroups().conflate().collect {
adapter.setItems(it)
}
}
}

@ -15,7 +15,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppLog
import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityReplaceRuleBinding
@ -205,11 +204,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private fun observeGroupData() {
launch {
appDb.replaceRuleDao.flowGroup().collect {
appDb.replaceRuleDao.flowGroups().collect {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
groups.addAll(it)
upGroupMenu()
}
}

Loading…
Cancel
Save