diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index 4014b8069..145745c89 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.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> @Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''") - fun flowGroup(): Flow> + fun flowGroupsUnProcessed(): Flow> @Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> '' and enabled = 1") fun flowGroupEnabled(): Flow> - @get:Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''") - val allGroup: List + @Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''") + fun getAllGroupsUnProcessed(): List @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): List { + val groups = linkedSetOf() + list.forEach { + it.splitNotBlank(AppPattern.splitGroupRegex).forEach { group -> + groups.add(group) + } + } + return groups.sortedWith { o1, o2 -> + o1.cnCompare(o2) + } + } + + val allGroups: List + get() { + return dealGroups(getAllGroupsUnProcessed()) + } + + fun flowGroups(): Flow> { + return flowGroupsUnProcessed().map { list -> + dealGroups(list) + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt index a664f142c..2ff1ead19 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt @@ -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() - 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() diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt index bb49cf6f9..198d43072 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt @@ -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() - 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) } } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index fce866579..50581448e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -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 - groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) - } + groups.addAll(it) upGroupMenu() } }