feat: 优化

pull/201/head
kunfei 5 years ago
parent 7c23e54250
commit f9ae176688
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  2. 5
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt

@ -189,7 +189,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
rootView?.apply { rootView?.apply {
tocRule.name = tv_rule_name.text.toString() tocRule.name = tv_rule_name.text.toString()
tocRule.rule = tv_rule_regex.text.toString() tocRule.rule = tv_rule_regex.text.toString()
viewModel.saveRule(tocRule, rule) viewModel.saveRule(tocRule)
} }
} }
cancelButton() cancelButton()

@ -11,14 +11,11 @@ import io.legado.app.utils.fromJsonArray
class TocRegexViewModel(application: Application) : BaseViewModel(application) { class TocRegexViewModel(application: Application) : BaseViewModel(application) {
fun saveRule(rule: TxtTocRule, oldRule: TxtTocRule? = null) { fun saveRule(rule: TxtTocRule) {
execute { execute {
if (rule.serialNumber < 0) { if (rule.serialNumber < 0) {
rule.serialNumber = App.db.txtTocRule().lastOrderNum + 1 rule.serialNumber = App.db.txtTocRule().lastOrderNum + 1
} }
oldRule?.let {
App.db.txtTocRule().delete(oldRule)
}
App.db.txtTocRule().insert(rule) App.db.txtTocRule().insert(rule)
} }
} }

Loading…
Cancel
Save