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