From 763bc1585e353d99e812d7b008eb0433cb18c127 Mon Sep 17 00:00:00 2001 From: 1552980358 <1552980358@qq.com> Date: Wed, 9 Sep 2020 13:14:33 +0800 Subject: [PATCH] SearchBook.kt: Modify function with assigning method Signed-off-by: 1552980358 <1552980358@qq.com> --- .../io/legado/app/data/entities/SearchBook.kt | 75 ++++++++----------- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt index eb7ea0c10..71bd9016f 100644 --- a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt @@ -36,54 +36,45 @@ data class SearchBook( var time: Long = System.currentTimeMillis(), var variable: String? = null, var originOrder: Int = 0 -) : Parcelable, BaseBook, Comparable { - +): Parcelable, BaseBook, Comparable { + @Ignore @IgnoredOnParcel override var infoHtml: String? = null - + @Ignore @IgnoredOnParcel override var tocHtml: String? = null - - override fun equals(other: Any?): Boolean { - if (other is SearchBook) { - if (other.bookUrl == bookUrl) { - return true - } - } - return false - } - - override fun hashCode(): Int { - return bookUrl.hashCode() - } - + + override fun equals(other: Any?) = other is SearchBook && other.bookUrl == bookUrl + + override fun hashCode() = bookUrl.hashCode() + override fun compareTo(other: SearchBook): Int { return other.originOrder - this.originOrder } - + @delegate:Transient @delegate:Ignore @IgnoredOnParcel override val variableMap by lazy { GSON.fromJsonObject>(variable) ?: HashMap() } - + override fun putVariable(key: String, value: String) { variableMap[key] = value variable = GSON.toJson(variableMap) } - + @delegate:Transient @delegate:Ignore @IgnoredOnParcel val origins: LinkedHashSet by lazy { linkedSetOf(origin) } - + fun addOrigin(origin: String) { origins.add(origin) } - + fun getDisplayLastChapterTitle(): String { latestChapterTitle?.let { if (it.isNotEmpty()) { @@ -92,26 +83,24 @@ data class SearchBook( } return "无最新章节" } - - fun toBook(): Book { - return Book( - name = name, - author = author, - kind = kind, - bookUrl = bookUrl, - origin = origin, - originName = originName, - type = type, - wordCount = wordCount, - latestChapterTitle = latestChapterTitle, - coverUrl = coverUrl, - intro = intro, - tocUrl = tocUrl, - originOrder = originOrder, - variable = variable - ).apply { - this.infoHtml = this@SearchBook.infoHtml - this.tocUrl = this@SearchBook.tocUrl - } + + fun toBook() = Book( + name = name, + author = author, + kind = kind, + bookUrl = bookUrl, + origin = origin, + originName = originName, + type = type, + wordCount = wordCount, + latestChapterTitle = latestChapterTitle, + coverUrl = coverUrl, + intro = intro, + tocUrl = tocUrl, + originOrder = originOrder, + variable = variable + ).apply { + this.infoHtml = this@SearchBook.infoHtml + this.tocUrl = this@SearchBook.tocUrl } } \ No newline at end of file