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

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

@ -50,12 +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) {
if (targetPosition > srcPosition) { callBack.upOrder(getItems())
srcItem.order = srcItem.order + 1
} else {
srcItem.order = srcItem.order - 1
}
callBack.update(srcItem)
} else { } else {
val srcOrder = srcItem.order val srcOrder = srcItem.order
srcItem.order = targetItem.order srcItem.order = targetItem.order
@ -75,5 +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>)
} }
} }

@ -29,6 +29,15 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
} }
} }
fun upOrder(rules: List<ReplaceRule>) {
execute {
for ((index: Int, rule: ReplaceRule) in rules.withIndex()) {
rule.order = index + 1
}
App.db.replaceRuleDao().update(*rules.toTypedArray())
}
}
fun addGroup(group: String) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.replaceRuleDao().noGroup val sources = App.db.replaceRuleDao().noGroup

Loading…
Cancel
Save