mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -18,6 +18,21 @@ interface BookmarkDao {
|
||||
@Query("select * from bookmarks order by bookName collate localized, bookAuthor collate localized, chapterIndex, chapterPos")
|
||||
fun flowAll(): Flow<List<Bookmark>>
|
||||
|
||||
@Query(
|
||||
"""select * from bookmarks
|
||||
where bookName = :bookName and bookAuthor = :bookAuthor
|
||||
order by chapterIndex"""
|
||||
)
|
||||
fun flowByBook(bookName: String, bookAuthor: String): Flow<List<Bookmark>>
|
||||
|
||||
@Query(
|
||||
"""SELECT * FROM bookmarks
|
||||
where bookName = :bookName and bookAuthor = :bookAuthor
|
||||
and chapterName like '%'||:key||'%' or content like '%'||:key||'%'
|
||||
order by chapterIndex"""
|
||||
)
|
||||
fun flowSearch(bookName: String, bookAuthor: String, key: String): Flow<List<Bookmark>>
|
||||
|
||||
@Query(
|
||||
"""select * from bookmarks
|
||||
where bookName = :bookName and bookAuthor = :bookAuthor
|
||||
|
||||
@@ -18,7 +18,6 @@ import io.legado.app.utils.setEdgeEffectColor
|
||||
import io.legado.app.utils.showDialogFragment
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@@ -51,12 +50,10 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark
|
||||
override fun upBookmark(searchKey: String?) {
|
||||
val book = viewModel.bookData.value ?: return
|
||||
launch {
|
||||
withContext(IO) {
|
||||
when {
|
||||
searchKey.isNullOrBlank() -> appDb.bookmarkDao.getByBook(book.name, book.author)
|
||||
else -> appDb.bookmarkDao.search(book.name, book.author, searchKey)
|
||||
}
|
||||
}.let {
|
||||
when {
|
||||
searchKey.isNullOrBlank() -> appDb.bookmarkDao.flowByBook(book.name, book.author)
|
||||
else -> appDb.bookmarkDao.flowSearch(book.name, book.author, searchKey)
|
||||
}.collect {
|
||||
adapter.setItems(it)
|
||||
var scrollPos = 0
|
||||
withContext(Dispatchers.Default) {
|
||||
|
||||
Reference in New Issue
Block a user