From 138a327258ace048049573aac30c2926c05d5b8b Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 8 Jun 2019 13:29:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt | 3 +++ .../io/legado/app/ui/main/booksource/BookSourceFragment.kt | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) 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 }