SearchBook.kt: Modify function with assigning method

Signed-off-by: 1552980358 <1552980358@qq.com>
pull/369/head
1552980358 5 years ago
parent e6bb108818
commit 763bc1585e
  1. 75
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt

@ -36,54 +36,45 @@ data class SearchBook(
var time: Long = System.currentTimeMillis(), var time: Long = System.currentTimeMillis(),
var variable: String? = null, var variable: String? = null,
var originOrder: Int = 0 var originOrder: Int = 0
) : Parcelable, BaseBook, Comparable<SearchBook> { ): Parcelable, BaseBook, Comparable<SearchBook> {
@Ignore @Ignore
@IgnoredOnParcel @IgnoredOnParcel
override var infoHtml: String? = null override var infoHtml: String? = null
@Ignore @Ignore
@IgnoredOnParcel @IgnoredOnParcel
override var tocHtml: String? = null override var tocHtml: String? = null
override fun equals(other: Any?): Boolean { override fun equals(other: Any?) = other is SearchBook && other.bookUrl == bookUrl
if (other is SearchBook) {
if (other.bookUrl == bookUrl) { override fun hashCode() = bookUrl.hashCode()
return true
}
}
return false
}
override fun hashCode(): Int {
return bookUrl.hashCode()
}
override fun compareTo(other: SearchBook): Int { override fun compareTo(other: SearchBook): Int {
return other.originOrder - this.originOrder return other.originOrder - this.originOrder
} }
@delegate:Transient @delegate:Transient
@delegate:Ignore @delegate:Ignore
@IgnoredOnParcel @IgnoredOnParcel
override val variableMap by lazy { override val variableMap by lazy {
GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap() GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
} }
override fun putVariable(key: String, value: String) { override fun putVariable(key: String, value: String) {
variableMap[key] = value variableMap[key] = value
variable = GSON.toJson(variableMap) variable = GSON.toJson(variableMap)
} }
@delegate:Transient @delegate:Transient
@delegate:Ignore @delegate:Ignore
@IgnoredOnParcel @IgnoredOnParcel
val origins: LinkedHashSet<String> by lazy { linkedSetOf(origin) } val origins: LinkedHashSet<String> by lazy { linkedSetOf(origin) }
fun addOrigin(origin: String) { fun addOrigin(origin: String) {
origins.add(origin) origins.add(origin)
} }
fun getDisplayLastChapterTitle(): String { fun getDisplayLastChapterTitle(): String {
latestChapterTitle?.let { latestChapterTitle?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
@ -92,26 +83,24 @@ data class SearchBook(
} }
return "无最新章节" return "无最新章节"
} }
fun toBook(): Book { fun toBook() = Book(
return Book( name = name,
name = name, author = author,
author = author, kind = kind,
kind = kind, bookUrl = bookUrl,
bookUrl = bookUrl, origin = origin,
origin = origin, originName = originName,
originName = originName, type = type,
type = type, wordCount = wordCount,
wordCount = wordCount, latestChapterTitle = latestChapterTitle,
latestChapterTitle = latestChapterTitle, coverUrl = coverUrl,
coverUrl = coverUrl, intro = intro,
intro = intro, tocUrl = tocUrl,
tocUrl = tocUrl, originOrder = originOrder,
originOrder = originOrder, variable = variable
variable = variable ).apply {
).apply { this.infoHtml = this@SearchBook.infoHtml
this.infoHtml = this@SearchBook.infoHtml this.tocUrl = this@SearchBook.tocUrl
this.tocUrl = this@SearchBook.tocUrl
}
} }
} }
Loading…
Cancel
Save