mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
3a67b22fdb
commit
0f3ab21a81
@ -44,6 +44,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
@ -204,7 +205,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
|
||||
}
|
||||
}
|
||||
launch {
|
||||
appDb.bookSourceDao.flowEnabledGroups().conflate().collect {
|
||||
appDb.bookSourceDao.flowEnabledGroups().flowOn(IO).conflate().collect {
|
||||
groups.clear()
|
||||
groups.addAll(it)
|
||||
upGroupMenu()
|
||||
|
@ -47,8 +47,10 @@ import io.legado.app.utils.startActivity
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import io.legado.app.utils.visible
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
@ -230,7 +232,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
||||
}
|
||||
}
|
||||
launch {
|
||||
appDb.bookSourceDao.flowEnabledGroups().conflate().collect {
|
||||
appDb.bookSourceDao.flowEnabledGroups().flowOn(IO).conflate().collect {
|
||||
groups.clear()
|
||||
groups.addAll(it)
|
||||
upGroupMenu()
|
||||
|
@ -31,6 +31,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import splitties.init.appCtx
|
||||
@ -279,7 +280,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
adapter.setItems(it)
|
||||
}
|
||||
launch {
|
||||
appDb.bookSourceDao.flowEnabledGroups().collect {
|
||||
appDb.bookSourceDao.flowEnabledGroups().flowOn(IO).collect {
|
||||
groups = it
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +42,11 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
/**
|
||||
@ -321,7 +323,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
}
|
||||
}.catch {
|
||||
AppLog.put("书源界面更新书源出错", it)
|
||||
}.conflate().collect { data ->
|
||||
}.flowOn(IO).conflate().collect { data ->
|
||||
adapter.setItems(data, adapter.diffItemCallback)
|
||||
itemTouchCallback.isCanDrag = sort == BookSourceSort.Default
|
||||
delay(500)
|
||||
@ -336,10 +338,11 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
|
||||
private fun initLiveDataGroup() {
|
||||
launch {
|
||||
appDb.bookSourceDao.flowGroups().conflate().collect {
|
||||
appDb.bookSourceDao.flowGroups().flowOn(IO).conflate().collect {
|
||||
groups.clear()
|
||||
groups.addAll(it)
|
||||
upGroupMenu()
|
||||
delay(500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ 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 kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
@ -55,7 +57,7 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
|
||||
private fun initData() {
|
||||
launch {
|
||||
appDb.bookSourceDao.flowGroups().collect {
|
||||
appDb.bookSourceDao.flowGroups().flowOn(IO).collect {
|
||||
adapter.setItems(it)
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +29,11 @@ import io.legado.app.utils.setEdgeEffectColor
|
||||
import io.legado.app.utils.startActivity
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
@ -107,7 +109,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
|
||||
|
||||
private fun initGroupData() {
|
||||
launch {
|
||||
appDb.bookSourceDao.flowExploreGroups().conflate().collect {
|
||||
appDb.bookSourceDao.flowExploreGroups().flowOn(IO).conflate().collect {
|
||||
groups.clear()
|
||||
groups.addAll(it)
|
||||
upGroupsMenu()
|
||||
|
Loading…
Reference in New Issue
Block a user