From 6e03649e7d597743bf6086eb63a2bf4732576cd6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 3 Jan 2021 20:48:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=BA=90=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=88=86=E7=BB=84=E6=97=B6=E5=8F=AA=E6=90=9C=E7=B4=A2=E5=88=86?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/RssSourceDao.kt | 3 +++ .../ui/rss/source/manage/RssSourceActivity.kt | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index c2d1b80ee..ad2b25706 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -25,6 +25,9 @@ interface RssSourceDao { @Query("SELECT * FROM rssSources where sourceName like :key or sourceUrl like :key or sourceGroup like :key order by customOrder") fun liveSearch(key: String): LiveData> + @Query("SELECT * FROM rssSources where sourceGroup like :key order by customOrder") + fun liveGroupSearch(key: String): LiveData> + @Query("SELECT * FROM rssSources where enabled = 1 and (sourceName like '%'||:searchKey||'%' or sourceGroup like '%'||:searchKey||'%' or sourceUrl like '%'||:searchKey||'%') order by customOrder") fun liveEnabled(searchKey: String): LiveData> diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 717278bd8..0f7d10e8d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -95,7 +95,7 @@ class RssSourceActivity : VMBaseActivity showHelp() else -> if (item.groupId == R.id.source_group) { binding.titleBar.findViewById(R.id.search_view) - .setQuery(item.title, true) + .setQuery("group:${item.title}", true) } } return super.onCompatOptionsItemSelected(item) @@ -197,13 +197,20 @@ class RssSourceActivity : VMBaseActivity { + App.db.rssSourceDao.liveAll() + } + searchKey.startsWith("group:") -> { + val key = searchKey.substringAfter("group:") + App.db.rssSourceDao.liveGroupSearch("%$key%") + } + else -> { + App.db.rssSourceDao.liveSearch("%$searchKey%") + } } sourceLiveData?.observe(this, { adapter.setItems(it, adapter.diffItemCallback)