From e1966b573a750360aed2706536169bb6946a91c1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 20 Feb 2023 17:05:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/DictRuleDao.kt | 3 + .../app/ui/dict/rule/DictRuleActivity.kt | 9 +- .../app/ui/dict/rule/DictRuleEditDialog.kt | 60 +++++++++++++ .../main/res/layout/dialog_dict_rule_edit.xml | 86 +++++++++++++++++++ .../main/res/layout/dialog_toc_regex_edit.xml | 1 + app/src/main/res/values-es-rES/strings.xml | 2 + app/src/main/res/values-ja-rJP/strings.xml | 2 + app/src/main/res/values-pt-rBR/strings.xml | 2 + app/src/main/res/values-zh-rHK/strings.xml | 2 + app/src/main/res/values-zh-rTW/strings.xml | 2 + app/src/main/res/values-zh/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 12 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/dict/rule/DictRuleEditDialog.kt create mode 100644 app/src/main/res/layout/dialog_dict_rule_edit.xml diff --git a/app/src/main/java/io/legado/app/data/dao/DictRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/DictRuleDao.kt index a35d04f23..bcb824ef4 100644 --- a/app/src/main/java/io/legado/app/data/dao/DictRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/DictRuleDao.kt @@ -20,6 +20,9 @@ interface DictRuleDao { @Query("select * from dictRules where enabled = 1 order by sortNumber") fun flowAll(): Flow> + @Query("select * from dictRules where name = :name") + fun getByName(name: String): DictRule? + @Upsert fun upsert(vararg dictRule: DictRule) diff --git a/app/src/main/java/io/legado/app/ui/dict/rule/DictRuleActivity.kt b/app/src/main/java/io/legado/app/ui/dict/rule/DictRuleActivity.kt index d7b78952a..b1e80c9b6 100644 --- a/app/src/main/java/io/legado/app/ui/dict/rule/DictRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/dict/rule/DictRuleActivity.kt @@ -18,6 +18,7 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.setEdgeEffectColor +import io.legado.app.utils.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.launch @@ -77,7 +78,7 @@ class DictRuleActivity : VMBaseActivity {} + R.id.menu_create -> showDialogFragment() } return super.onContextItemSelected(item) } @@ -91,9 +92,9 @@ class DictRuleActivity : VMBaseActivity() + val binding by viewBinding(DialogDictRuleEditBinding::bind) + + constructor(name: String) : this() { + arguments = Bundle().apply { + putString("name", name) + } + } + + override fun onStart() { + super.onStart() + setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) + } + + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + binding.toolBar.setBackgroundColor(primaryColor) + viewModel.initData(arguments?.getString("name")) { + binding.tvRuleName.setText(viewModel.dictRule?.name) + binding.tvUrlRule.setText(viewModel.dictRule?.urlRule) + binding.tvShowRule.setText(viewModel.dictRule?.showRule) + } + } + + + class DictRuleEditViewModel(application: Application) : BaseViewModel(application) { + + var dictRule: DictRule? = null + + fun initData(name: String?, onFinally: () -> Unit) { + execute { + if (dictRule == null && name != null) { + dictRule = appDb.dictRuleDao.getByName(name) + } + }.onFinally { + onFinally.invoke() + } + } + + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_dict_rule_edit.xml b/app/src/main/res/layout/dialog_dict_rule_edit.xml new file mode 100644 index 000000000..26133beee --- /dev/null +++ b/app/src/main/res/layout/dialog_dict_rule_edit.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_toc_regex_edit.xml b/app/src/main/res/layout/dialog_toc_regex_edit.xml index 865b1fd24..2d4457c84 100644 --- a/app/src/main/res/layout/dialog_toc_regex_edit.xml +++ b/app/src/main/res/layout/dialog_toc_regex_edit.xml @@ -30,6 +30,7 @@ 字典规则 配置字典规则 新建 + url规则(urlRule) + 显示规则(showRule) diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 5902b0fae..fad7fa81f 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1078,4 +1078,6 @@ 字典规则 配置字典规则 新建 + url规则(urlRule) + 显示规则(showRule) diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index af27b4d7d..ba3a0dd19 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1078,4 +1078,6 @@ 字典规则 配置字典规则 新建 + url规则(urlRule) + 显示规则(showRule) diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 86bb59bf0..f1eea6b4c 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1075,4 +1075,6 @@ 字典规则 配置字典规则 新建 + url规则(urlRule) + 显示规则(showRule) diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index bb7d56445..5f2776a5e 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1077,4 +1077,6 @@ 字典规则 配置字典规则 新建 + url规则(urlRule) + 显示规则(showRule) diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 3df87db2e..0783480b5 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1077,4 +1077,6 @@ 字典规则 配置字典规则 新建 + url规则(urlRule) + 显示规则(showRule) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 04735657c..40c7b1f91 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1078,4 +1078,6 @@ Dict rule Config dict rule 新建 + url规则(urlRule) + 显示规则(showRule)