From ac3c7eed22298a4456d0435da30e474bad068776 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 3 Jan 2021 21:05:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E8=A7=84=E5=88=99=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=88=86=E7=BB=84=E6=97=B6=E5=8F=AA=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/ReplaceRuleDao.kt | 3 ++ .../app/ui/replace/ReplaceRuleActivity.kt | 34 +++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt index ad374f5c9..2a0e1149c 100644 --- a/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt @@ -14,6 +14,9 @@ interface ReplaceRuleDao { @Query("SELECT * FROM replace_rules where `group` like :key or name like :key ORDER BY sortOrder ASC") fun liveDataSearch(key: String): LiveData> + @Query("SELECT * FROM replace_rules where `group` like :key ORDER BY sortOrder ASC") + fun liveDataGroupSearch(key: String): LiveData> + @get:Query("SELECT MIN(sortOrder) FROM replace_rules") val minOrder: Int diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index 5710f929a..548d9a481 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -54,6 +54,7 @@ class ReplaceRuleActivity : VMBaseActivity() private var groupMenu: SubMenu? = null private var replaceRuleLiveData: LiveData>? = null @@ -64,6 +65,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.id.search_view).let { - ATH.setTint(it, primaryTextColor) - it.onActionViewExpanded() - it.queryHint = getString(R.string.replace_purify_search) - it.clearFocus() - it.setOnQueryTextListener(this) - } + ATH.setTint(searchView, primaryTextColor) + searchView.onActionViewExpanded() + searchView.queryHint = getString(R.string.replace_purify_search) + searchView.clearFocus() + searchView.setOnQueryTextListener(this) } override fun selectAll(selectAll: Boolean) { @@ -140,13 +140,20 @@ class ReplaceRuleActivity : VMBaseActivity { + App.db.replaceRuleDao.liveDataAll() + } + searchKey.startsWith("group:") -> { + val key = searchKey.substringAfter("group:") + App.db.replaceRuleDao.liveDataGroupSearch("%$key%") + } + else -> { + App.db.replaceRuleDao.liveDataSearch("%$searchKey%") + } } replaceRuleLiveData?.observe(this, { if (dataInit) { @@ -179,8 +186,7 @@ class ReplaceRuleActivity : VMBaseActivity FilePicker .selectFile(this, importRequestCode, allowExtensions = arrayOf("txt", "json")) else -> if (item.groupId == R.id.replace_group) { - binding.titleBar.findViewById(R.id.search_view) - .setQuery(item.title, true) + searchView.setQuery("group:${item.title}", true) } } return super.onCompatOptionsItemSelected(item)