From da39b57e2e30b35bc0d5d50e40c30be2e66b335f Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 26 Oct 2020 13:28:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E8=A7=84=E5=88=99=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BD=AE=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/replace/ReplaceRuleActivity.kt | 15 ++++++++++----- .../legado/app/ui/replace/ReplaceRuleAdapter.kt | 2 ++ .../legado/app/ui/replace/ReplaceRuleViewModel.kt | 7 +++++++ app/src/main/res/menu/replace_rule_item.xml | 4 ++++ 4 files changed, 23 insertions(+), 5 deletions(-) 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 3e091cded..87fa9de07 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 @@ -294,27 +294,32 @@ class ReplaceRuleActivity : } override fun update(vararg rule: ReplaceRule) { - setResult(Activity.RESULT_OK) + setResult(RESULT_OK) viewModel.update(*rule) } override fun delete(rule: ReplaceRule) { - setResult(Activity.RESULT_OK) + setResult(RESULT_OK) viewModel.delete(rule) } override fun edit(rule: ReplaceRule) { - setResult(Activity.RESULT_OK) + setResult(RESULT_OK) ReplaceEditActivity.show(this, rule.id) } override fun toTop(rule: ReplaceRule) { - setResult(Activity.RESULT_OK) + setResult(RESULT_OK) viewModel.toTop(rule) } + override fun toBottom(rule: ReplaceRule) { + setResult(RESULT_OK) + viewModel.toBottom(rule) + } + override fun upOrder() { - setResult(Activity.RESULT_OK) + setResult(RESULT_OK) viewModel.upOrder() } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt index 31d0eb59f..193a82f77 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt @@ -121,6 +121,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : popupMenu.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { R.id.menu_top -> callBack.toTop(item) + R.id.menu_bottom -> callBack.toBottom(item) R.id.menu_del -> callBack.delete(item) } true @@ -187,6 +188,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : fun delete(rule: ReplaceRule) fun edit(rule: ReplaceRule) fun toTop(rule: ReplaceRule) + fun toBottom(rule: ReplaceRule) fun upOrder() fun upCountView() } diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt index a14647c82..219f4bc88 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt @@ -34,6 +34,13 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application } } + fun toBottom(rule: ReplaceRule) { + execute { + rule.order = App.db.replaceRuleDao().maxOrder + 1 + App.db.replaceRuleDao().update(rule) + } + } + fun upOrder() { execute { val rules = App.db.replaceRuleDao().all diff --git a/app/src/main/res/menu/replace_rule_item.xml b/app/src/main/res/menu/replace_rule_item.xml index 17483eeec..77c3a18cd 100644 --- a/app/src/main/res/menu/replace_rule_item.xml +++ b/app/src/main/res/menu/replace_rule_item.xml @@ -5,6 +5,10 @@ android:id="@+id/menu_top" android:title="@string/to_top" /> + +