替换规则添加置底

pull/457/head
gedoor 4 years ago
parent 507f8fdd6f
commit da39b57e2e
  1. 15
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt
  3. 7
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt
  4. 4
      app/src/main/res/menu/replace_rule_item.xml

@ -294,27 +294,32 @@ class ReplaceRuleActivity :
} }
override fun update(vararg rule: ReplaceRule) { override fun update(vararg rule: ReplaceRule) {
setResult(Activity.RESULT_OK) setResult(RESULT_OK)
viewModel.update(*rule) viewModel.update(*rule)
} }
override fun delete(rule: ReplaceRule) { override fun delete(rule: ReplaceRule) {
setResult(Activity.RESULT_OK) setResult(RESULT_OK)
viewModel.delete(rule) viewModel.delete(rule)
} }
override fun edit(rule: ReplaceRule) { override fun edit(rule: ReplaceRule) {
setResult(Activity.RESULT_OK) setResult(RESULT_OK)
ReplaceEditActivity.show(this, rule.id) ReplaceEditActivity.show(this, rule.id)
} }
override fun toTop(rule: ReplaceRule) { override fun toTop(rule: ReplaceRule) {
setResult(Activity.RESULT_OK) setResult(RESULT_OK)
viewModel.toTop(rule) viewModel.toTop(rule)
} }
override fun toBottom(rule: ReplaceRule) {
setResult(RESULT_OK)
viewModel.toBottom(rule)
}
override fun upOrder() { override fun upOrder() {
setResult(Activity.RESULT_OK) setResult(RESULT_OK)
viewModel.upOrder() viewModel.upOrder()
} }
} }

@ -121,6 +121,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
popupMenu.setOnMenuItemClickListener { menuItem -> popupMenu.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.menu_top -> callBack.toTop(item) R.id.menu_top -> callBack.toTop(item)
R.id.menu_bottom -> callBack.toBottom(item)
R.id.menu_del -> callBack.delete(item) R.id.menu_del -> callBack.delete(item)
} }
true true
@ -187,6 +188,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
fun delete(rule: ReplaceRule) fun delete(rule: ReplaceRule)
fun edit(rule: ReplaceRule) fun edit(rule: ReplaceRule)
fun toTop(rule: ReplaceRule) fun toTop(rule: ReplaceRule)
fun toBottom(rule: ReplaceRule)
fun upOrder() fun upOrder()
fun upCountView() fun upCountView()
} }

@ -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() { fun upOrder() {
execute { execute {
val rules = App.db.replaceRuleDao().all val rules = App.db.replaceRuleDao().all

@ -5,6 +5,10 @@
android:id="@+id/menu_top" android:id="@+id/menu_top"
android:title="@string/to_top" /> android:title="@string/to_top" />
<item
android:id="@+id/menu_bottom"
android:title="@string/to_bottom" />
<item <item
android:id="@+id/menu_del" android:id="@+id/menu_del"
android:title="@string/delete" /> android:title="@string/delete" />

Loading…
Cancel
Save