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 import io.legado.app.utils.splitNotBlank
interface BaseBook { interface BaseBook {
var variableMap: HashMap<String, String>? var variableMap: HashMap<String, String>
var kind: String? var kind: String?
var wordCount: String? var wordCount: String?

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

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

Loading…
Cancel
Save