From 17ca8ad64569a8af369a5a77132923aca1757d8b Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 2 Sep 2019 17:40:00 +0800 Subject: [PATCH] up --- .../java/io/legado/app/data/entities/ReplaceRule.kt | 2 +- .../main/java/io/legado/app/help/storage/Restore.kt | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) 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