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 560a92a76..3655e0117 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 @@ -29,6 +29,9 @@ interface BookSourceDao { @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc") fun liveExplore(key: String): LiveData> + @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key) order by customOrder asc") + fun liveGroupExplore(key: String): LiveData> + @Query("select bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") fun liveGroup(): LiveData> @@ -36,7 +39,7 @@ interface BookSourceDao { fun liveGroupEnabled(): LiveData> @Query("select bookSourceGroup from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and trim(bookSourceGroup) <> ''") - fun liveGroupExplore(): LiveData> + fun liveExploreGroup(): LiveData> @Query("select distinct enabled from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey") fun searchIsEnable(searchKey: String = ""): List diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index e4ea63bd7..ff311f503 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -97,7 +97,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo private fun initGroupData() { liveGroup?.removeObservers(viewLifecycleOwner) - liveGroup = App.db.bookSourceDao.liveGroupExplore() + liveGroup = App.db.bookSourceDao.liveExploreGroup() liveGroup?.observe(viewLifecycleOwner, { groups.clear() it.map { group -> @@ -107,12 +107,19 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo }) } - private fun initExploreData(key: String? = null) { + private fun initExploreData(searchKey: String? = null) { liveExplore?.removeObservers(viewLifecycleOwner) - liveExplore = if (key.isNullOrBlank()) { - App.db.bookSourceDao.liveExplore() - } else { - App.db.bookSourceDao.liveExplore("%$key%") + liveExplore = when { + searchKey.isNullOrBlank() -> { + App.db.bookSourceDao.liveExplore() + } + searchKey.startsWith("group:") -> { + val key = searchKey.substringAfter("group:") + App.db.bookSourceDao.liveGroupExplore("%$key%") + } + else -> { + App.db.bookSourceDao.liveExplore("%$searchKey%") + } } liveExplore?.observe(viewLifecycleOwner, { binding.tvEmptyMsg.isGone = it.isNotEmpty() || searchView.query.isNotEmpty() @@ -135,7 +142,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo override fun onCompatOptionsItemSelected(item: MenuItem) { super.onCompatOptionsItemSelected(item) if (item.groupId == R.id.menu_group_text) { - searchView.setQuery(item.title, true) + searchView.setQuery("group:${item.title}", true) } }