diff --git a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt index dcab47e66..269325e5d 100644 --- a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.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 = "", diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 82d256d88..35f5ef0e1 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -175,13 +175,14 @@ object Restore { doAsync { val items: List> = jsonPath.parse(ruleFile.readText()).read("$") val existingRules = App.db.replaceRuleDao().all.map { it.pattern }.toSet() - for (item in items) { + for ((index: Int, item: Map) 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