pull/32/head
gedoor 6 years ago
parent 01d23aacf1
commit 138a327258
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 6
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt

@ -10,6 +10,9 @@ interface BookSourceDao {
@Query("select * from book_sources order by customOrder asc") @Query("select * from book_sources order by customOrder asc")
fun observeAll(): DataSource.Factory<Int, BookSource> fun observeAll(): DataSource.Factory<Int, BookSource>
@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<Int, BookSource>
@Query("select * from book_sources where origin = :key") @Query("select * from book_sources where origin = :key")
fun findByKey(key:String): BookSource? fun findByKey(key:String): BookSource?

@ -68,13 +68,15 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
search_view.setOnQueryTextListener(this) search_view.setOnQueryTextListener(this)
} }
private fun initDataObservers() { private fun initDataObservers(searchKey:String = "") {
bookSourceLiveDate?.removeObservers(viewLifecycleOwner) 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) }) bookSourceLiveDate?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) })
} }
override fun onQueryTextChange(newText: String?): Boolean { override fun onQueryTextChange(newText: String?): Boolean {
newText?.let { initDataObservers("%$it%") }
return false return false
} }

Loading…
Cancel
Save