pull/32/head
kunfei 5 years ago
parent fa73b91d1d
commit 518353117e
  1. 4
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt
  3. 3
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt

@ -145,7 +145,7 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
viewModel.toTop(rule) viewModel.toTop(rule)
} }
override fun upOrder(rules: List<ReplaceRule>) { override fun upOrder() {
viewModel.upOrder(rules) viewModel.upOrder()
} }
} }

@ -50,7 +50,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
val targetItem = getItem(targetPosition) val targetItem = getItem(targetPosition)
if (srcItem != null && targetItem != null) { if (srcItem != null && targetItem != null) {
if (srcItem.order == targetItem.order) { if (srcItem.order == targetItem.order) {
callBack.upOrder(getItems()) callBack.upOrder()
} else { } else {
val srcOrder = srcItem.order val srcOrder = srcItem.order
srcItem.order = targetItem.order srcItem.order = targetItem.order
@ -70,6 +70,6 @@ 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 upOrder(rules: List<ReplaceRule>) fun upOrder()
} }
} }

@ -29,8 +29,9 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
} }
} }
fun upOrder(rules: List<ReplaceRule>) { fun upOrder() {
execute { execute {
val rules = App.db.replaceRuleDao().all
for ((index: Int, rule: ReplaceRule) in rules.withIndex()) { for ((index: Int, rule: ReplaceRule) in rules.withIndex()) {
rule.order = index + 1 rule.order = index + 1
} }

Loading…
Cancel
Save