pull/2274/head
kunfei 2 years ago
parent e4d9f4ebb8
commit 2279550666
  1. 33
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  2. 6
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt
  3. 18
      app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt
  4. 7
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@ -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.RssSource
import io.legado.app.utils.cnCompare
import io.legado.app.utils.splitNotBlank
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
@Dao
interface RssSourceDao {
@ -74,13 +78,13 @@ interface RssSourceDao {
fun flowEnabledByGroup(searchKey: String): Flow<List<RssSource>>
@Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''")
fun flowGroup(): Flow<List<String>>
fun flowGroupsUnProcessed(): Flow<List<String>>
@Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> '' and enabled = 1")
fun flowGroupEnabled(): Flow<List<String>>
@get:Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''")
val allGroup: List<String>
@Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''")
fun getAllGroupsUnProcessed(): List<String>
@get:Query("select min(customOrder) from rssSources")
val minOrder: Int
@ -108,4 +112,27 @@ interface RssSourceDao {
@Query("select 1 from rssSources where sourceUrl = :key")
fun has(key: String): Boolean?
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(getAllGroupsUnProcessed())
}
fun flowGroups(): Flow<List<String>> {
return flowGroupsUnProcessed().map { list ->
dealGroups(list)
}
}
}

@ -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.RssSource
@ -157,10 +156,7 @@ class ImportRssSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_view
private fun alertCustomGroup(item: MenuItem) {
alert(R.string.diy_edit_source_group) {
val alertBinding = DialogCustomGroupBinding.inflate(layoutInflater).apply {
val groups = linkedSetOf<String>()
appDb.rssSourceDao.allGroup.forEach { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
val groups = appDb.rssSourceDao.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
@ -23,8 +22,11 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.applyTint
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.setLayout
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch
@ -60,16 +62,8 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
private fun initData() {
launch {
appDb.rssSourceDao.flowGroup().conflate().collect {
val groups = linkedSetOf<String>()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
adapter.setItems(
groups.sortedWith { o1, o2 ->
o1.cnCompare(o2)
}
)
appDb.rssSourceDao.flowGroups().conflate().collect {
adapter.setItems(it)
}
}
}

@ -12,7 +12,6 @@ import androidx.recyclerview.widget.ItemTouchHelper
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.RssSource
import io.legado.app.databinding.ActivityRssSourceBinding
@ -206,11 +205,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
private fun initGroupFlow() {
launch {
appDb.rssSourceDao.flowGroup().conflate().collect {
appDb.rssSourceDao.flowGroups().conflate().collect {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
groups.addAll(it)
upGroupMenu()
}
}

Loading…
Cancel
Save