pull/1625/head
kunfei 3 years ago
parent a0d6c9942d
commit 3e4b416fe7
  1. 12
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt

@ -42,7 +42,9 @@ 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.* import kotlinx.coroutines.*
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.flow
class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(), class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(),
PopupMenu.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener,
@ -208,7 +210,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private fun upBookSource(searchKey: String? = null) { private fun upBookSource(searchKey: String? = null) {
sourceFlowJob?.cancel() sourceFlowJob?.cancel()
sourceFlowJob = launch { sourceFlowJob = launch {
runCatching {
when { when {
searchKey.isNullOrEmpty() -> { searchKey.isNullOrEmpty() -> {
appDb.bookSourceDao.flowAll() appDb.bookSourceDao.flowAll()
@ -229,7 +230,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
else -> { else -> {
appDb.bookSourceDao.flowSearch("%$searchKey%") appDb.bookSourceDao.flowSearch("%$searchKey%")
} }
}.collect { data -> }.catch {
AppLog.put("书源界面更新书源出错", it)
}.collectLatest { data ->
val sourceList = val sourceList =
if (sortAscending) when (sort) { if (sortAscending) when (sort) {
Sort.Weight -> data.sortedBy { it.weight } Sort.Weight -> data.sortedBy { it.weight }
@ -267,9 +270,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
adapter.setItems(sourceList, adapter.diffItemCallback) adapter.setItems(sourceList, adapter.diffItemCallback)
} }
}.onFailure {
AppLog.put("更新书源出错", it)
}
} }
} }

Loading…
Cancel
Save