pull/1625/head
kunfei 3 years ago
parent dc4d6734a4
commit 14b7e8ecb3
  1. 8
      app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt
  2. 24
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt

@ -59,6 +59,14 @@ data class ReplaceRule(
return id.hashCode()
}
fun getDisplayNameGroup(): String {
return if (group.isNullOrBlank()) {
name
} else {
String.format("%s (%s)", name, group)
}
}
fun isValid(): Boolean {
if (TextUtils.isEmpty(pattern)) {
return false

@ -57,11 +57,10 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
override fun getChangePayload(oldItem: ReplaceRule, newItem: ReplaceRule): Any? {
val payload = Bundle()
if (oldItem.name != newItem.name) {
payload.putString("name", newItem.name)
}
if (oldItem.group != newItem.group) {
payload.putString("group", newItem.group)
if (oldItem.name != newItem.name
|| oldItem.group != newItem.group
) {
payload.putBoolean("upName", true)
}
if (oldItem.isEnabled != newItem.isEnabled) {
payload.putBoolean("enabled", newItem.isEnabled)
@ -111,25 +110,14 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
val bundle = payloads.getOrNull(0) as? Bundle
if (bundle == null) {
root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f))
if (item.group.isNullOrEmpty()) {
cbName.text = item.name
} else {
cbName.text =
String.format("%s (%s)", item.name, item.group)
}
cbName.text = item.getDisplayNameGroup()
swtEnabled.isChecked = item.isEnabled
cbName.isChecked = selected.contains(item)
} else {
bundle.keySet().map {
when (it) {
"selected" -> cbName.isChecked = selected.contains(item)
"name", "group" ->
if (item.group.isNullOrEmpty()) {
cbName.text = item.name
} else {
cbName.text =
String.format("%s (%s)", item.name, item.group)
}
"upName" -> cbName.text = item.getDisplayNameGroup()
"enabled" -> swtEnabled.isChecked = item.isEnabled
}
}

Loading…
Cancel
Save