|
|
|
@ -23,17 +23,17 @@ import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
|
import io.legado.app.ui.main.MainViewModel |
|
|
|
|
import io.legado.app.utils.* |
|
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
|
import kotlinx.coroutines.ExperimentalCoroutinesApi |
|
|
|
|
import kotlinx.coroutines.Job |
|
|
|
|
import kotlinx.coroutines.flow.catch |
|
|
|
|
import kotlinx.coroutines.flow.mapLatest |
|
|
|
|
import kotlinx.coroutines.flow.collectLatest |
|
|
|
|
import kotlinx.coroutines.flow.conflate |
|
|
|
|
import kotlinx.coroutines.flow.map |
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
import kotlin.math.max |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 书架界面 |
|
|
|
|
*/ |
|
|
|
|
@ExperimentalCoroutinesApi |
|
|
|
|
class BooksFragment() : BaseFragment(R.layout.fragment_books), |
|
|
|
|
BaseBooksAdapter.CallBack { |
|
|
|
|
|
|
|
|
@ -110,9 +110,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books), |
|
|
|
|
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() |
|
|
|
|
AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() |
|
|
|
|
else -> appDb.bookDao.flowByGroup(groupId) |
|
|
|
|
}.catch { |
|
|
|
|
AppLog.put("书架更新出错", it) |
|
|
|
|
}.mapLatest { list -> |
|
|
|
|
}.conflate().map { list -> |
|
|
|
|
when (getPrefInt(PreferKey.bookshelfSort)) { |
|
|
|
|
1 -> list.sortedByDescending { it.latestChapterTime } |
|
|
|
|
2 -> list.sortedWith { o1, o2 -> |
|
|
|
@ -121,7 +119,9 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books), |
|
|
|
|
3 -> list.sortedBy { it.order } |
|
|
|
|
else -> list.sortedByDescending { it.durChapterTime } |
|
|
|
|
} |
|
|
|
|
}.collect { list -> |
|
|
|
|
}.catch { |
|
|
|
|
AppLog.put("书架更新出错", it) |
|
|
|
|
}.collectLatest { list -> |
|
|
|
|
binding.tvEmptyMsg.isGone = list.isNotEmpty() |
|
|
|
|
booksAdapter.setItems(list) |
|
|
|
|
} |
|
|
|
|