feat: 优化

pull/226/head
gedoor 5 years ago
parent 50c5385889
commit 4d1cbda379
  1. 2
      app/src/main/java/io/legado/app/data/entities/BaseBook.kt
  2. 22
      app/src/main/java/io/legado/app/data/entities/Book.kt
  3. 14
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt

@ -4,7 +4,7 @@ import io.legado.app.utils.splitNotBlank
interface BaseBook { interface BaseBook {
var bookUrl: String var bookUrl: String
var variableMap: HashMap<String, String>? val variableMap: HashMap<String, String>
var kind: String? var kind: String?
var wordCount: String? var wordCount: String?

@ -71,15 +71,16 @@ data class Book(
return bookUrl.hashCode() return bookUrl.hashCode()
} }
@Ignore @delegate:Ignore
@IgnoredOnParcel @IgnoredOnParcel
override var variableMap: HashMap<String, String>? = null override val variableMap by lazy {
get() { GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
if (field == null) { }
field = GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
} override fun putVariable(key: String, value: String) {
return field variableMap[key] = value
} variable = GSON.toJson(variableMap)
}
@Ignore @Ignore
@IgnoredOnParcel @IgnoredOnParcel
@ -97,11 +98,6 @@ data class Book(
fun getDisplayIntro() = if (customIntro.isNullOrEmpty()) intro else customIntro fun getDisplayIntro() = if (customIntro.isNullOrEmpty()) intro else customIntro
override fun putVariable(key: String, value: String) {
variableMap?.put(key, value)
variable = GSON.toJson(variableMap)
}
fun fileCharset(): Charset { fun fileCharset(): Charset {
return charset(charset ?: "UTF-8") return charset(charset ?: "UTF-8")
} }

@ -63,18 +63,14 @@ data class SearchBook(
return other.originOrder - this.originOrder return other.originOrder - this.originOrder
} }
@Ignore @delegate:Ignore
@IgnoredOnParcel @IgnoredOnParcel
override var variableMap: HashMap<String, String>? = null override val variableMap by lazy {
get() { GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
if (field == null) { }
field = GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
}
return field
}
override fun putVariable(key: String, value: String) { override fun putVariable(key: String, value: String) {
variableMap?.put(key, value) variableMap[key] = value
variable = GSON.toJson(variableMap) variable = GSON.toJson(variableMap)
} }

Loading…
Cancel
Save