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 69aa284fd..c61a76f3f 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 @@ -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 + @Query("select distinct isEnabled from book_sources where name like :searchKey or `group` like :searchKey or origin like :searchKey") + fun searchIsEnable(searchKey: String = ""): List + + @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 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 b7208af8b..cf53170f9 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 @@ -51,8 +51,14 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour context?.startActivity() } 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 } diff --git a/app/src/main/res/layout/item_book_source.xml b/app/src/main/res/layout/item_book_source.xml index 31775c35d..9e3c0df00 100644 --- a/app/src/main/res/layout/item_book_source.xml +++ b/app/src/main/res/layout/item_book_source.xml @@ -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"