diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 8515aa180..bf942b36d 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -144,4 +144,8 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi override fun toTop(rule: ReplaceRule) { viewModel.toTop(rule) } + + override fun upOrder(rules: List) { + viewModel.upOrder(rules) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt index 9d251fb01..6f41abc5a 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt @@ -50,12 +50,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : val targetItem = getItem(targetPosition) if (srcItem != null && targetItem != null) { if (srcItem.order == targetItem.order) { - if (targetPosition > srcPosition) { - srcItem.order = srcItem.order + 1 - } else { - srcItem.order = srcItem.order - 1 - } - callBack.update(srcItem) + callBack.upOrder(getItems()) } else { val srcOrder = srcItem.order srcItem.order = targetItem.order @@ -75,5 +70,6 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : fun delete(rule: ReplaceRule) fun edit(rule: ReplaceRule) fun toTop(rule: ReplaceRule) + fun upOrder(rules: List) } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index 4674ab415..755befb75 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -29,6 +29,15 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application } } + fun upOrder(rules: List) { + execute { + for ((index: Int, rule: ReplaceRule) in rules.withIndex()) { + rule.order = index + 1 + } + App.db.replaceRuleDao().update(*rules.toTypedArray()) + } + } + fun addGroup(group: String) { execute { val sources = App.db.replaceRuleDao().noGroup