pull/32/head
gedoor 5 years ago
parent 397e64a84a
commit 998ee9b92f
  1. 6
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 18
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt
  3. 3
      app/src/main/res/layout/item_book_source.xml

@ -13,6 +13,12 @@ interface BookSourceDao {
@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 distinct isEnabled from book_sources where name like :searchKey or `group` like :searchKey or origin like :searchKey")
fun searchIsEnable(searchKey: String = ""): List<Boolean>
@Query("UPDATE book_sources SET isEnabled = :enable where name like :searchKey or `group` like :searchKey or origin like :searchKey")
fun enableAllSearch(searchKey: String = "", enable: String = "1")
@Query("select * from book_sources where exploreIsEnabled = 1 order by customOrder asc")
fun observeFind(): DataSource.Factory<Int, BookSource>

@ -51,8 +51,14 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
context?.startActivity<QrCodeActivity>()
}
R.id.action_select_all -> {
launch {
launch(IO) {
val isEnableList =
App.db.bookSourceDao().searchIsEnable("%${search_view.query}%")
if (isEnableList.contains(false)) {
App.db.bookSourceDao().enableAllSearch("%${search_view.query}%", "1")
} else {
App.db.bookSourceDao().enableAllSearch("%${search_view.query}%", "0")
}
}
}
}
@ -85,18 +91,14 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
private fun initDataObserve(searchKey: String = "") {
bookSourceLiveDate?.removeObservers(viewLifecycleOwner)
val dataFactory =
if (searchKey.isEmpty())
App.db.bookSourceDao().observeAll()
else
App.db.bookSourceDao().observeSearch(searchKey)
val dataFactory = App.db.bookSourceDao().observeSearch("%$searchKey%")
bookSourceLiveDate = LivePagedListBuilder(dataFactory, 2000).build()
bookSourceLiveDate?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) })
}
override fun onQueryTextChange(newText: String?): Boolean {
newText?.let {
initDataObserve("%$it%")
initDataObserve(it)
}
return false
}

@ -23,7 +23,6 @@
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/bg_ib_pre_round"
android:contentDescription="@string/edit"
android:padding="8dp"
@ -35,7 +34,6 @@
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/bg_ib_pre_round"
android:contentDescription="@string/to_top"
android:padding="8dp"
@ -47,7 +45,6 @@
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/bg_ib_pre_round"
android:contentDescription="@string/delete"
android:padding="8dp"

Loading…
Cancel
Save