|
|
@ -54,6 +54,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu |
|
|
|
private val importRequestCode = 132 |
|
|
|
private val importRequestCode = 132 |
|
|
|
private val exportRequestCode = 65 |
|
|
|
private val exportRequestCode = 65 |
|
|
|
private lateinit var adapter: ReplaceRuleAdapter |
|
|
|
private lateinit var adapter: ReplaceRuleAdapter |
|
|
|
|
|
|
|
private lateinit var searchView: SearchView |
|
|
|
private var groups = hashSetOf<String>() |
|
|
|
private var groups = hashSetOf<String>() |
|
|
|
private var groupMenu: SubMenu? = null |
|
|
|
private var groupMenu: SubMenu? = null |
|
|
|
private var replaceRuleLiveData: LiveData<List<ReplaceRule>>? = null |
|
|
|
private var replaceRuleLiveData: LiveData<List<ReplaceRule>>? = null |
|
|
@ -64,6 +65,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
|
|
|
|
searchView = binding.titleBar.findViewById(R.id.search_view) |
|
|
|
initRecyclerView() |
|
|
|
initRecyclerView() |
|
|
|
initSearchView() |
|
|
|
initSearchView() |
|
|
|
initSelectActionView() |
|
|
|
initSelectActionView() |
|
|
@ -101,13 +103,11 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initSearchView() { |
|
|
|
private fun initSearchView() { |
|
|
|
binding.titleBar.findViewById<SearchView>(R.id.search_view).let { |
|
|
|
ATH.setTint(searchView, primaryTextColor) |
|
|
|
ATH.setTint(it, primaryTextColor) |
|
|
|
searchView.onActionViewExpanded() |
|
|
|
it.onActionViewExpanded() |
|
|
|
searchView.queryHint = getString(R.string.replace_purify_search) |
|
|
|
it.queryHint = getString(R.string.replace_purify_search) |
|
|
|
searchView.clearFocus() |
|
|
|
it.clearFocus() |
|
|
|
searchView.setOnQueryTextListener(this) |
|
|
|
it.setOnQueryTextListener(this) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun selectAll(selectAll: Boolean) { |
|
|
|
override fun selectAll(selectAll: Boolean) { |
|
|
@ -140,13 +140,20 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu |
|
|
|
}.show() |
|
|
|
}.show() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun observeReplaceRuleData(key: String? = null) { |
|
|
|
private fun observeReplaceRuleData(searchKey: String? = null) { |
|
|
|
dataInit = false |
|
|
|
dataInit = false |
|
|
|
replaceRuleLiveData?.removeObservers(this) |
|
|
|
replaceRuleLiveData?.removeObservers(this) |
|
|
|
replaceRuleLiveData = if (key.isNullOrEmpty()) { |
|
|
|
replaceRuleLiveData = when { |
|
|
|
App.db.replaceRuleDao.liveDataAll() |
|
|
|
searchKey.isNullOrEmpty() -> { |
|
|
|
} else { |
|
|
|
App.db.replaceRuleDao.liveDataAll() |
|
|
|
App.db.replaceRuleDao.liveDataSearch(key) |
|
|
|
} |
|
|
|
|
|
|
|
searchKey.startsWith("group:") -> { |
|
|
|
|
|
|
|
val key = searchKey.substringAfter("group:") |
|
|
|
|
|
|
|
App.db.replaceRuleDao.liveDataGroupSearch("%$key%") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
App.db.replaceRuleDao.liveDataSearch("%$searchKey%") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
replaceRuleLiveData?.observe(this, { |
|
|
|
replaceRuleLiveData?.observe(this, { |
|
|
|
if (dataInit) { |
|
|
|
if (dataInit) { |
|
|
@ -179,8 +186,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu |
|
|
|
R.id.menu_import_source_local -> FilePicker |
|
|
|
R.id.menu_import_source_local -> FilePicker |
|
|
|
.selectFile(this, importRequestCode, allowExtensions = arrayOf("txt", "json")) |
|
|
|
.selectFile(this, importRequestCode, allowExtensions = arrayOf("txt", "json")) |
|
|
|
else -> if (item.groupId == R.id.replace_group) { |
|
|
|
else -> if (item.groupId == R.id.replace_group) { |
|
|
|
binding.titleBar.findViewById<SearchView>(R.id.search_view) |
|
|
|
searchView.setQuery("group:${item.title}", true) |
|
|
|
.setQuery(item.title, true) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return super.onCompatOptionsItemSelected(item) |
|
|
|
return super.onCompatOptionsItemSelected(item) |
|
|
|