|
|
|
@ -16,10 +16,10 @@ import io.legado.app.ui.widget.recycler.VerticalDivider |
|
|
|
|
import io.legado.app.utils.setEdgeEffectColor |
|
|
|
|
import io.legado.app.utils.showDialogFragment |
|
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
|
import kotlinx.coroutines.Job |
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
import kotlinx.coroutines.delay |
|
|
|
|
import kotlinx.coroutines.flow.conflate |
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark), |
|
|
|
@ -28,7 +28,6 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark |
|
|
|
|
override val viewModel by activityViewModels<TocViewModel>() |
|
|
|
|
private val binding by viewBinding(FragmentBookmarkBinding::bind) |
|
|
|
|
private val adapter by lazy { BookmarkAdapter(requireContext(), this) } |
|
|
|
|
private var bookmarkFlowJob: Job? = null |
|
|
|
|
|
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
viewModel.bookMarkCallBack = this |
|
|
|
@ -47,12 +46,13 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark |
|
|
|
|
|
|
|
|
|
override fun upBookmark(searchKey: String?) { |
|
|
|
|
val book = viewModel.bookData.value ?: return |
|
|
|
|
bookmarkFlowJob?.cancel() |
|
|
|
|
bookmarkFlowJob = launch { |
|
|
|
|
when { |
|
|
|
|
searchKey.isNullOrBlank() -> appDb.bookmarkDao.flowByBook(book.name, book.author) |
|
|
|
|
else -> appDb.bookmarkDao.flowSearch(book.name, book.author, searchKey) |
|
|
|
|
}.conflate().collect { |
|
|
|
|
launch { |
|
|
|
|
withContext(IO) { |
|
|
|
|
when { |
|
|
|
|
searchKey.isNullOrBlank() -> appDb.bookmarkDao.getByBook(book.name, book.author) |
|
|
|
|
else -> appDb.bookmarkDao.search(book.name, book.author, searchKey) |
|
|
|
|
} |
|
|
|
|
}.let { |
|
|
|
|
adapter.setItems(it) |
|
|
|
|
delay(100) |
|
|
|
|
} |
|
|
|
|