pull/32/head
kunfei 5 years ago
parent 27a2785be4
commit 17ca8ad645
  1. 2
      app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt
  2. 11
      app/src/main/java/io/legado/app/help/storage/Restore.kt

@ -14,7 +14,7 @@ import kotlinx.android.parcel.Parcelize
)
data class ReplaceRule(
@PrimaryKey(autoGenerate = true)
var id: Int = 0,
var id: Long = System.currentTimeMillis(),
var name: String = "",
var group: String? = null,
var pattern: String = "",

@ -175,13 +175,14 @@ object Restore {
doAsync {
val items: List<Map<String, Any>> = jsonPath.parse(ruleFile.readText()).read("$")
val existingRules = App.db.replaceRuleDao().all.map { it.pattern }.toSet()
for (item in items) {
for ((index: Int, item: Map<String, Any>) in items.withIndex()) {
val jsonItem = jsonPath.parse(item)
val rule = ReplaceRule()
rule.pattern = jsonItem.readString("$.regex")
if (rule.pattern.isNullOrEmpty() || rule.pattern in existingRules) continue
rule.name = jsonItem.readString("$.replaceSummary")
rule.replacement = jsonItem.readString("$.replacement")
rule.id = jsonItem.readLong("$.id") ?: System.currentTimeMillis().plus(index)
rule.pattern = jsonItem.readString("$.regex") ?: ""
if (rule.pattern.isEmpty() || rule.pattern in existingRules) continue
rule.name = jsonItem.readString("$.replaceSummary") ?: ""
rule.replacement = jsonItem.readString("$.replacement") ?: ""
rule.isRegex = jsonItem.readBool("$.isRegex") == true
rule.scope = jsonItem.readString("$.useTo")
rule.isEnabled = jsonItem.readBool("$.enable") == true

Loading…
Cancel
Save