diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index ee977b6ff..82fb01304 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -10,6 +10,9 @@ interface BookSourceDao { @Query("select * from book_sources order by customOrder asc") fun observeAll(): DataSource.Factory + @Query("select * from book_sources where name like :searchKey or `group` like :searchKey or origin like :searchKey order by customOrder asc") + fun observeSearch(searchKey:String = ""): DataSource.Factory + @Query("select * from book_sources where origin = :key") fun findByKey(key:String): BookSource? diff --git a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt index 760920011..88ae2af00 100644 --- a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt @@ -68,13 +68,15 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour search_view.setOnQueryTextListener(this) } - private fun initDataObservers() { + private fun initDataObservers(searchKey:String = "") { bookSourceLiveDate?.removeObservers(viewLifecycleOwner) - bookSourceLiveDate = LivePagedListBuilder(App.db.bookSourceDao().observeAll(), 30).build() + val dataFactory = if (searchKey.isEmpty()) App.db.bookSourceDao().observeAll() else App.db.bookSourceDao().observeSearch(searchKey) + bookSourceLiveDate = LivePagedListBuilder(dataFactory, 30).build() bookSourceLiveDate?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) }) } override fun onQueryTextChange(newText: String?): Boolean { + newText?.let { initDataObservers("%$it%") } return false }