pull/32/head
gedoor 6 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") @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> 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") @Query("select * from book_sources where exploreIsEnabled = 1 order by customOrder asc")
fun observeFind(): DataSource.Factory<Int, BookSource> fun observeFind(): DataSource.Factory<Int, BookSource>

@ -51,8 +51,14 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
context?.startActivity<QrCodeActivity>() context?.startActivity<QrCodeActivity>()
} }
R.id.action_select_all -> { 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 = "") { private fun initDataObserve(searchKey: String = "") {
bookSourceLiveDate?.removeObservers(viewLifecycleOwner) bookSourceLiveDate?.removeObservers(viewLifecycleOwner)
val dataFactory = val dataFactory = App.db.bookSourceDao().observeSearch("%$searchKey%")
if (searchKey.isEmpty())
App.db.bookSourceDao().observeAll()
else
App.db.bookSourceDao().observeSearch(searchKey)
bookSourceLiveDate = LivePagedListBuilder(dataFactory, 2000).build() bookSourceLiveDate = LivePagedListBuilder(dataFactory, 2000).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 { newText?.let {
initDataObserve("%$it%") initDataObserve(it)
} }
return false return false
} }

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

Loading…
Cancel
Save