pull/1625/head
kunfei 3 years ago
parent 62acbdd280
commit 0b720d084e
  1. 15
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  2. 14
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt
  3. 11
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt

@ -42,12 +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.flow.catch
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.*
@ExperimentalCoroutinesApi
/**
* 书源管理界面
*/
class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(),
PopupMenu.OnMenuItemClickListener,
BookSourceAdapter.CallBack,
@ -233,9 +232,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
else -> {
appDb.bookSourceDao.flowSearch("%$searchKey%")
}
}.catch {
AppLog.put("书源界面更新书源出错", it)
}.mapLatest { data ->
}.conflate().map { data ->
if (sortAscending) when (sort) {
Sort.Weight -> data.sortedBy { it.weight }
Sort.Name -> data.sortedWith { o1, o2 ->
@ -270,6 +267,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
else -> data.reversed()
}
}.catch {
AppLog.put("书源界面更新书源出错", it)
}.collectLatest { data ->
adapter.setItems(data, adapter.diffItemCallback)
}

@ -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)
}

@ -25,18 +25,17 @@ import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.main.bookshelf.BaseBookshelfFragment
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.collectLatest
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlin.math.max
/**
* 书架界面
*/
@ExperimentalCoroutinesApi
class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
SearchView.OnQueryTextListener,
BaseBooksAdapter.CallBack {
@ -124,9 +123,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
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
@ -141,6 +138,8 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
it.durChapterTime
}
}
}.catch {
AppLog.put("书架更新出错", it)
}.collectLatest { list ->
books = list
booksAdapter.notifyDataSetChanged()

Loading…
Cancel
Save