pull/32/head
kunfei 5 years ago
parent fd74bcedcf
commit b5dbc04032
  1. 2
      app/src/main/java/io/legado/app/data/entities/BaseBook.kt
  2. 20
      app/src/main/java/io/legado/app/data/entities/Book.kt
  3. 20
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt

@ -3,7 +3,7 @@ package io.legado.app.data.entities
import io.legado.app.utils.splitNotBlank
interface BaseBook {
var variableMap: HashMap<String, String>?
var variableMap: HashMap<String, String>
var kind: String?
var wordCount: String?

@ -1,7 +1,6 @@
package io.legado.app.data.entities
import android.os.Parcelable
import android.text.TextUtils.isEmpty
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index
@ -50,11 +49,7 @@ data class Book(
) : Parcelable, BaseBook {
@IgnoredOnParcel
@Ignore
override var variableMap: HashMap<String, String>? = null
get() = run {
initVariableMap()
return field
}
override var variableMap: HashMap<String, String> = GSON.fromJsonObject(variable) ?: HashMap()
fun getUnreadChapterNum() = max(totalChapterNum - durChapterIndex - 1, 0)
@ -62,19 +57,8 @@ data class Book(
fun getDisplayIntro() = if (customIntro.isNullOrEmpty()) intro else customIntro
private fun initVariableMap() {
if (variableMap == null) {
variableMap = if (isEmpty(variable)) {
HashMap()
} else {
GSON.fromJsonObject(variable)
}
}
}
override fun putVariable(key: String, value: String) {
initVariableMap()
variableMap?.put(key, value)
variableMap[key] = value
variable = GSON.toJson(variableMap)
}

@ -1,7 +1,6 @@
package io.legado.app.data.entities
import android.os.Parcelable
import android.text.TextUtils
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index
@ -51,25 +50,10 @@ data class SearchBook(
@IgnoredOnParcel
@Ignore
override var variableMap: HashMap<String, String>? = null
get() = run {
initVariableMap()
return field
}
private fun initVariableMap() {
variableMap?.let {
variableMap = if (TextUtils.isEmpty(variable)) {
HashMap()
} else {
GSON.fromJsonObject(variable)
}
}
}
override var variableMap: HashMap<String, String> = GSON.fromJsonObject(variable) ?: HashMap()
override fun putVariable(key: String, value: String) {
initVariableMap()
variableMap?.put(key, value)
variableMap[key] = value
variable = GSON.toJson(variableMap)
}

Loading…
Cancel
Save