优化
This commit is contained in:
@@ -31,6 +31,8 @@ import io.legado.app.utils.showDialogFragment
|
|||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@@ -110,7 +112,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
|
|||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun initGroupData() {
|
private fun initGroupData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.bookGroupDao.flowAll().collect {
|
appDb.bookGroupDao.flowAll().conflate().collect {
|
||||||
groupList.clear()
|
groupList.clear()
|
||||||
groupList.addAll(it)
|
groupList.addAll(it)
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
@@ -128,15 +130,16 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
|
|||||||
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
|
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
|
||||||
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup()
|
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup()
|
||||||
else -> appDb.bookDao.flowByGroup(groupId)
|
else -> appDb.bookDao.flowByGroup(groupId)
|
||||||
}.collect { list ->
|
}.conflate().map { books ->
|
||||||
val books = when (getPrefInt(PreferKey.bookshelfSort)) {
|
when (getPrefInt(PreferKey.bookshelfSort)) {
|
||||||
1 -> list.sortedByDescending { it.latestChapterTime }
|
1 -> books.sortedByDescending { it.latestChapterTime }
|
||||||
2 -> list.sortedWith { o1, o2 ->
|
2 -> books.sortedWith { o1, o2 ->
|
||||||
o1.name.cnCompare(o2.name)
|
o1.name.cnCompare(o2.name)
|
||||||
}
|
}
|
||||||
3 -> list.sortedBy { it.order }
|
3 -> books.sortedBy { it.order }
|
||||||
else -> list.sortedByDescending { it.durChapterTime }
|
else -> books.sortedByDescending { it.durChapterTime }
|
||||||
}
|
}
|
||||||
|
}.conflate().collect { books ->
|
||||||
adapter.setItems(books)
|
adapter.setItems(books)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@@ -156,11 +158,11 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
|
|||||||
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
|
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
|
||||||
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup()
|
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup()
|
||||||
else -> appDb.bookDao.flowByGroup(groupId)
|
else -> appDb.bookDao.flowByGroup(groupId)
|
||||||
}.collect { list ->
|
}.conflate().map { books ->
|
||||||
val booksDownload = list.filter {
|
val booksDownload = books.filter {
|
||||||
it.type == 0
|
it.type == 0
|
||||||
}
|
}
|
||||||
val books = when (getPrefInt(PreferKey.bookshelfSort)) {
|
when (getPrefInt(PreferKey.bookshelfSort)) {
|
||||||
1 -> booksDownload.sortedByDescending { it.latestChapterTime }
|
1 -> booksDownload.sortedByDescending { it.latestChapterTime }
|
||||||
2 -> booksDownload.sortedWith { o1, o2 ->
|
2 -> booksDownload.sortedWith { o1, o2 ->
|
||||||
o1.name.cnCompare(o2.name)
|
o1.name.cnCompare(o2.name)
|
||||||
@@ -168,6 +170,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
|
|||||||
3 -> booksDownload.sortedBy { it.order }
|
3 -> booksDownload.sortedBy { it.order }
|
||||||
else -> booksDownload.sortedByDescending { it.durChapterTime }
|
else -> booksDownload.sortedByDescending { it.durChapterTime }
|
||||||
}
|
}
|
||||||
|
}.conflate().collect { books ->
|
||||||
adapter.setItems(books)
|
adapter.setItems(books)
|
||||||
initCacheSize(books)
|
initCacheSize(books)
|
||||||
}
|
}
|
||||||
@@ -177,7 +180,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
|
|||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun initGroupData() {
|
private fun initGroupData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.bookGroupDao.flowAll().collect {
|
appDb.bookGroupDao.flowAll().conflate().collect {
|
||||||
groupList.clear()
|
groupList.clear()
|
||||||
groupList.addAll(it)
|
groupList.addAll(it)
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
|
|||||||
@@ -67,12 +67,10 @@ class ChangeCoverDialog() : BaseDialogFragment(R.layout.dialog_change_cover),
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
viewModel.dataFlow
|
viewModel.dataFlow.conflate().collect {
|
||||||
.conflate()
|
adapter.setItems(it)
|
||||||
.collect {
|
delay(1000)
|
||||||
adapter.setItems(it)
|
}
|
||||||
delay(1000)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,15 +145,13 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
|
|||||||
binding.toolBar.menu.applyTint(requireContext())
|
binding.toolBar.menu.applyTint(requireContext())
|
||||||
}
|
}
|
||||||
launch {
|
launch {
|
||||||
viewModel.searchDataFlow
|
viewModel.searchDataFlow.conflate().collect {
|
||||||
.conflate()
|
adapter.setItems(it)
|
||||||
.collect {
|
delay(1000)
|
||||||
adapter.setItems(it)
|
}
|
||||||
delay(1000)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
launch {
|
launch {
|
||||||
appDb.bookSourceDao.flowGroupEnabled().collect {
|
appDb.bookSourceDao.flowGroupEnabled().conflate().collect {
|
||||||
groups.clear()
|
groups.clear()
|
||||||
it.map { group ->
|
it.map { group ->
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
||||||
|
|||||||
@@ -177,15 +177,13 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
|||||||
binding.toolBar.menu.applyTint(requireContext())
|
binding.toolBar.menu.applyTint(requireContext())
|
||||||
}
|
}
|
||||||
launch {
|
launch {
|
||||||
viewModel.searchDataFlow
|
viewModel.searchDataFlow.conflate().collect {
|
||||||
.conflate()
|
searchBookAdapter.setItems(it)
|
||||||
.collect {
|
delay(1000)
|
||||||
searchBookAdapter.setItems(it)
|
}
|
||||||
delay(1000)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
launch {
|
launch {
|
||||||
appDb.bookSourceDao.flowGroupEnabled().collect {
|
appDb.bookSourceDao.flowGroupEnabled().conflate().collect {
|
||||||
groups.clear()
|
groups.clear()
|
||||||
it.map { group ->
|
it.map { group ->
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import io.legado.app.utils.setLayout
|
|||||||
import io.legado.app.utils.showDialogFragment
|
import io.legado.app.utils.showDialogFragment
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import io.legado.app.utils.visible
|
import io.legado.app.utils.visible
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.bookGroupDao.flowAll().collect {
|
appDb.bookGroupDao.flowAll().conflate().collect {
|
||||||
adapter.setItems(it)
|
adapter.setItems(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import io.legado.app.utils.applyTint
|
|||||||
import io.legado.app.utils.setLayout
|
import io.legado.app.utils.setLayout
|
||||||
import io.legado.app.utils.showDialogFragment
|
import io.legado.app.utils.showDialogFragment
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ class GroupSelectDialog() : BaseDialogFragment(R.layout.dialog_book_group_picker
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.bookGroupDao.flowSelect().collect {
|
appDb.bookGroupDao.flowSelect().conflate().collect {
|
||||||
adapter.setItems(it)
|
adapter.setItems(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import io.legado.app.utils.*
|
|||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -121,7 +122,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.bookDao.flowLocalUri().collect {
|
appDb.bookDao.flowLocalUri().conflate().collect {
|
||||||
adapter.upBookHas(it)
|
adapter.upBookHas(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import io.legado.app.utils.setEdgeEffectColor
|
|||||||
import io.legado.app.utils.snackbar
|
import io.legado.app.utils.snackbar
|
||||||
import io.legado.app.utils.splitNotBlank
|
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.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class TxtTocRuleActivity : VMBaseActivity<ActivityTxtTocRuleBinding, TxtTocRuleViewModel>(),
|
class TxtTocRuleActivity : VMBaseActivity<ActivityTxtTocRuleBinding, TxtTocRuleViewModel>(),
|
||||||
@@ -66,7 +67,7 @@ class TxtTocRuleActivity : VMBaseActivity<ActivityTxtTocRuleBinding, TxtTocRuleV
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.txtTocRuleDao.observeAll().collect { tocRules ->
|
appDb.txtTocRuleDao.observeAll().conflate().collect { tocRules ->
|
||||||
adapter.setItems(tocRules)
|
adapter.setItems(tocRules)
|
||||||
upCountView()
|
upCountView()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import io.legado.app.ui.document.HandleFileContract
|
|||||||
import io.legado.app.ui.login.SourceLoginActivity
|
import io.legado.app.ui.login.SourceLoginActivity
|
||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.*
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,7 +134,7 @@ class SpeakEngineDialog(val callBack: CallBack) : BaseDialogFragment(R.layout.di
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.httpTTSDao.flowAll().collect {
|
appDb.httpTTSDao.flowAll().conflate().collect {
|
||||||
adapter.setItems(it)
|
adapter.setItems(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
|
|||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.*
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class TocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex),
|
class TocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex),
|
||||||
@@ -89,7 +90,7 @@ class TocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex),
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.txtTocRuleDao.observeAll().collect { tocRules ->
|
appDb.txtTocRuleDao.observeAll().conflate().collect { tocRules ->
|
||||||
initSelectedName(tocRules)
|
initSelectedName(tocRules)
|
||||||
adapter.setItems(tocRules)
|
adapter.setItems(tocRules)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,15 +197,13 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
viewModel.searchDataFlow
|
viewModel.searchDataFlow.conflate().collect {
|
||||||
.conflate()
|
adapter.setItems(it)
|
||||||
.collect {
|
delay(1000)
|
||||||
adapter.setItems(it)
|
}
|
||||||
delay(1000)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
launch {
|
launch {
|
||||||
appDb.bookSourceDao.flowGroupEnabled().collect {
|
appDb.bookSourceDao.flowGroupEnabled().conflate().collect {
|
||||||
groups.clear()
|
groups.clear()
|
||||||
it.map { group ->
|
it.map { group ->
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
||||||
@@ -287,8 +285,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
binding.tvBookShow.gone()
|
binding.tvBookShow.gone()
|
||||||
binding.rvBookshelfSearch.gone()
|
binding.rvBookshelfSearch.gone()
|
||||||
} else {
|
} else {
|
||||||
val bookFlow = appDb.bookDao.flowSearch(key)
|
appDb.bookDao.flowSearch(key).conflate().collect {
|
||||||
bookFlow.collect {
|
|
||||||
if (it.isEmpty()) {
|
if (it.isEmpty()) {
|
||||||
binding.tvBookShow.gone()
|
binding.tvBookShow.gone()
|
||||||
binding.rvBookshelfSearch.gone()
|
binding.rvBookshelfSearch.gone()
|
||||||
@@ -305,7 +302,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
when {
|
when {
|
||||||
key.isNullOrBlank() -> appDb.searchKeywordDao.flowByUsage()
|
key.isNullOrBlank() -> appDb.searchKeywordDao.flowByUsage()
|
||||||
else -> appDb.searchKeywordDao.flowSearch(key)
|
else -> appDb.searchKeywordDao.flowSearch(key)
|
||||||
}.collect {
|
}.conflate().collect {
|
||||||
historyKeyAdapter.setItems(it)
|
historyKeyAdapter.setItems(it)
|
||||||
if (it.isEmpty()) {
|
if (it.isEmpty()) {
|
||||||
binding.tvClearHistory.invisible()
|
binding.tvClearHistory.invisible()
|
||||||
|
|||||||
@@ -295,14 +295,13 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|||||||
|
|
||||||
private fun initLiveDataGroup() {
|
private fun initLiveDataGroup() {
|
||||||
launch {
|
launch {
|
||||||
appDb.bookSourceDao.flowGroup()
|
appDb.bookSourceDao.flowGroup().conflate().collect {
|
||||||
.collect {
|
groups.clear()
|
||||||
groups.clear()
|
it.forEach { group ->
|
||||||
it.forEach { group ->
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
|
||||||
}
|
|
||||||
upGroupMenu()
|
|
||||||
}
|
}
|
||||||
|
upGroupMenu()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
|||||||
}
|
}
|
||||||
}.catch {
|
}.catch {
|
||||||
AppLog.put("书架更新出错", it)
|
AppLog.put("书架更新出错", it)
|
||||||
}.collect { list ->
|
}.conflate().collect { list ->
|
||||||
binding.tvEmptyMsg.isGone = list.isNotEmpty()
|
binding.tvEmptyMsg.isGone = list.isNotEmpty()
|
||||||
booksAdapter.setItems(list)
|
booksAdapter.setItems(list)
|
||||||
delay(100)
|
delay(100)
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
|||||||
}
|
}
|
||||||
}.catch {
|
}.catch {
|
||||||
AppLog.put("书架更新出错", it)
|
AppLog.put("书架更新出错", it)
|
||||||
}.collect { list ->
|
}.conflate().collect { list ->
|
||||||
books = list
|
books = list
|
||||||
booksAdapter.notifyDataSetChanged()
|
booksAdapter.notifyDataSetChanged()
|
||||||
binding.tvEmptyMsg.isGone = getItemCount() > 0
|
binding.tvEmptyMsg.isGone = getItemCount() > 0
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,21 +103,20 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
|
|||||||
|
|
||||||
private fun initGroupData() {
|
private fun initGroupData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.bookSourceDao.flowExploreGroup()
|
appDb.bookSourceDao.flowExploreGroup().conflate().collect {
|
||||||
.collect {
|
groups.clear()
|
||||||
groups.clear()
|
it.map { group ->
|
||||||
it.map { group ->
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
|
||||||
}
|
|
||||||
upGroupsMenu()
|
|
||||||
}
|
}
|
||||||
|
upGroupsMenu()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun upExploreData(searchKey: String? = null) {
|
private fun upExploreData(searchKey: String? = null) {
|
||||||
exploreFlowJob?.cancel()
|
exploreFlowJob?.cancel()
|
||||||
exploreFlowJob = launch {
|
exploreFlowJob = launch {
|
||||||
val exploreFlow = when {
|
when {
|
||||||
searchKey.isNullOrBlank() -> {
|
searchKey.isNullOrBlank() -> {
|
||||||
appDb.bookSourceDao.flowExplore()
|
appDb.bookSourceDao.flowExplore()
|
||||||
}
|
}
|
||||||
@@ -127,10 +127,9 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
|
|||||||
else -> {
|
else -> {
|
||||||
appDb.bookSourceDao.flowExplore("%$searchKey%")
|
appDb.bookSourceDao.flowExplore("%$searchKey%")
|
||||||
}
|
}
|
||||||
}
|
}.catch {
|
||||||
exploreFlow.catch {
|
|
||||||
AppLog.put("发现界面更新数据出错", it)
|
AppLog.put("发现界面更新数据出错", it)
|
||||||
}.collect {
|
}.conflate().collect {
|
||||||
binding.tvEmptyMsg.isGone = it.isNotEmpty() || searchView.query.isNotEmpty()
|
binding.tvEmptyMsg.isGone = it.isNotEmpty() || searchView.query.isNotEmpty()
|
||||||
adapter.setItems(it, diffItemCallBack)
|
adapter.setItems(it, diffItemCallBack)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import io.legado.app.utils.*
|
|||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
@@ -121,7 +122,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
|
|||||||
private fun initGroupData() {
|
private fun initGroupData() {
|
||||||
groupsFlowJob?.cancel()
|
groupsFlowJob?.cancel()
|
||||||
groupsFlowJob = launch {
|
groupsFlowJob = launch {
|
||||||
appDb.rssSourceDao.flowGroup().collect {
|
appDb.rssSourceDao.flowGroup().conflate().collect {
|
||||||
groups.clear()
|
groups.clear()
|
||||||
it.map { group ->
|
it.map { group ->
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ 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.splitNotBlank
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.replaceRuleDao.flowGroup().collect {
|
appDb.replaceRuleDao.flowGroup().conflate().collect {
|
||||||
val groups = linkedSetOf<String>()
|
val groups = linkedSetOf<String>()
|
||||||
it.map { group ->
|
it.map { group ->
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
||||||
|
|||||||
@@ -194,9 +194,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
|
|||||||
else -> {
|
else -> {
|
||||||
appDb.replaceRuleDao.flowSearch("%$searchKey%")
|
appDb.replaceRuleDao.flowSearch("%$searchKey%")
|
||||||
}
|
}
|
||||||
}.conflate().catch {
|
}.catch {
|
||||||
AppLog.put("替换规则管理界面更新数据出错", it)
|
AppLog.put("替换规则管理界面更新数据出错", it)
|
||||||
}.collect {
|
}.conflate().collect {
|
||||||
if (dataInit) {
|
if (dataInit) {
|
||||||
setResult(Activity.RESULT_OK)
|
setResult(Activity.RESULT_OK)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import io.legado.app.ui.rss.read.ReadRssActivity
|
|||||||
import io.legado.app.ui.widget.recycler.VerticalDivider
|
import io.legado.app.ui.widget.recycler.VerticalDivider
|
||||||
import io.legado.app.utils.startActivity
|
import io.legado.app.utils.startActivity
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>(),
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.rssStarDao.liveAll().collect {
|
appDb.rssStarDao.liveAll().conflate().collect {
|
||||||
adapter.setItems(it)
|
adapter.setItems(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import io.legado.app.lib.theme.primaryColor
|
|||||||
import io.legado.app.ui.widget.recycler.VerticalDivider
|
import io.legado.app.ui.widget.recycler.VerticalDivider
|
||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.*
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.rssSourceDao.flowGroup().collect {
|
appDb.rssSourceDao.flowGroup().conflate().collect {
|
||||||
val groups = linkedSetOf<String>()
|
val groups = linkedSetOf<String>()
|
||||||
it.map { group ->
|
it.map { group ->
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
|
|||||||
|
|
||||||
private fun initGroupFlow() {
|
private fun initGroupFlow() {
|
||||||
launch {
|
launch {
|
||||||
appDb.rssSourceDao.flowGroup().collect {
|
appDb.rssSourceDao.flowGroup().conflate().collect {
|
||||||
groups.clear()
|
groups.clear()
|
||||||
it.map { group ->
|
it.map { group ->
|
||||||
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
|
||||||
@@ -247,9 +247,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
|
|||||||
else -> {
|
else -> {
|
||||||
appDb.rssSourceDao.flowSearch("%$searchKey%")
|
appDb.rssSourceDao.flowSearch("%$searchKey%")
|
||||||
}
|
}
|
||||||
}.conflate().catch {
|
}.catch {
|
||||||
AppLog.put("订阅源管理界面更新数据出错", it)
|
AppLog.put("订阅源管理界面更新数据出错", it)
|
||||||
}.collect {
|
}.conflate().collect {
|
||||||
adapter.setItems(it, adapter.diffItemCallback)
|
adapter.setItems(it, adapter.diffItemCallback)
|
||||||
delay(100)
|
delay(100)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import io.legado.app.utils.showDialogFragment
|
|||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
|
|||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
launch {
|
launch {
|
||||||
appDb.ruleSubDao.flowAll().collect {
|
appDb.ruleSubDao.flowAll().conflate().collect {
|
||||||
binding.tvEmptyMsg.isGone = it.isNotEmpty()
|
binding.tvEmptyMsg.isGone = it.isNotEmpty()
|
||||||
adapter.setItems(it)
|
adapter.setItems(it)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user