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.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.mapLatest
@ExperimentalCoroutinesApi /**
* 书源管理界面
*/
class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(), class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(),
PopupMenu.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener,
BookSourceAdapter.CallBack, BookSourceAdapter.CallBack,
@ -233,9 +232,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
else -> { else -> {
appDb.bookSourceDao.flowSearch("%$searchKey%") appDb.bookSourceDao.flowSearch("%$searchKey%")
} }
}.catch { }.conflate().map { data ->
AppLog.put("书源界面更新书源出错", it)
}.mapLatest { data ->
if (sortAscending) when (sort) { if (sortAscending) when (sort) {
Sort.Weight -> data.sortedBy { it.weight } Sort.Weight -> data.sortedBy { it.weight }
Sort.Name -> data.sortedWith { o1, o2 -> Sort.Name -> data.sortedWith { o1, o2 ->
@ -270,6 +267,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
else -> data.reversed() else -> data.reversed()
} }
}.catch {
AppLog.put("书源界面更新书源出错", it)
}.collectLatest { data -> }.collectLatest { data ->
adapter.setItems(data, adapter.diffItemCallback) 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.ui.main.MainViewModel
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.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.catch 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 kotlinx.coroutines.launch
import kotlin.math.max import kotlin.math.max
/** /**
* 书架界面 * 书架界面
*/ */
@ExperimentalCoroutinesApi
class BooksFragment() : BaseFragment(R.layout.fragment_books), class BooksFragment() : BaseFragment(R.layout.fragment_books),
BaseBooksAdapter.CallBack { BaseBooksAdapter.CallBack {
@ -110,9 +110,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
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)
}.catch { }.conflate().map { list ->
AppLog.put("书架更新出错", it)
}.mapLatest { list ->
when (getPrefInt(PreferKey.bookshelfSort)) { when (getPrefInt(PreferKey.bookshelfSort)) {
1 -> list.sortedByDescending { it.latestChapterTime } 1 -> list.sortedByDescending { it.latestChapterTime }
2 -> list.sortedWith { o1, o2 -> 2 -> list.sortedWith { o1, o2 ->
@ -121,7 +119,9 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
3 -> list.sortedBy { it.order } 3 -> list.sortedBy { it.order }
else -> list.sortedByDescending { it.durChapterTime } else -> list.sortedByDescending { it.durChapterTime }
} }
}.collect { list -> }.catch {
AppLog.put("书架更新出错", it)
}.collectLatest { list ->
binding.tvEmptyMsg.isGone = list.isNotEmpty() binding.tvEmptyMsg.isGone = list.isNotEmpty()
booksAdapter.setItems(list) 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.ui.main.bookshelf.BaseBookshelfFragment
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.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest 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 kotlinx.coroutines.launch
import kotlin.math.max import kotlin.math.max
/** /**
* 书架界面 * 书架界面
*/ */
@ExperimentalCoroutinesApi
class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
SearchView.OnQueryTextListener, SearchView.OnQueryTextListener,
BaseBooksAdapter.CallBack { BaseBooksAdapter.CallBack {
@ -124,9 +123,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
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)
}.catch { }.conflate().map { list ->
AppLog.put("书架更新出错", it)
}.mapLatest { list ->
when (getPrefInt(PreferKey.bookshelfSort)) { when (getPrefInt(PreferKey.bookshelfSort)) {
1 -> list.sortedByDescending { 1 -> list.sortedByDescending {
it.latestChapterTime it.latestChapterTime
@ -141,6 +138,8 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
it.durChapterTime it.durChapterTime
} }
} }
}.catch {
AppLog.put("书架更新出错", it)
}.collectLatest { list -> }.collectLatest { list ->
books = list books = list
booksAdapter.notifyDataSetChanged() booksAdapter.notifyDataSetChanged()

Loading…
Cancel
Save