Book.kt: Modify functions into assigning style

Signed-off-by: 1552980358 <1552980358@qq.com>
pull/369/head
1552980358 5 years ago
parent d230d79bc7
commit 2bfbdef1eb
  1. 78
      app/src/main/java/io/legado/app/data/entities/Book.kt

@ -55,93 +55,91 @@ data class Book(
var originOrder: Int = 0, //书源排序 var originOrder: Int = 0, //书源排序
var useReplaceRule: Boolean = AppConfig.replaceEnableDefault, // 正文使用净化替换规则 var useReplaceRule: Boolean = AppConfig.replaceEnableDefault, // 正文使用净化替换规则
var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息) var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息)
) : Parcelable, BaseBook { ): Parcelable, BaseBook {
fun isLocalBook(): Boolean { fun isLocalBook(): Boolean {
return origin == BookType.local return origin == BookType.local
} }
fun isLocalTxt(): Boolean { fun isLocalTxt(): Boolean {
return isLocalBook() && originName.endsWith(".txt", true) return isLocalBook() && originName.endsWith(".txt", true)
} }
fun isEpub(): Boolean { fun isEpub(): Boolean {
return originName.endsWith(".epub", true) return originName.endsWith(".epub", true)
} }
fun isOnLineTxt(): Boolean { fun isOnLineTxt(): Boolean {
return !isLocalBook() && type == 0 return !isLocalBook() && type == 0
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (other is Book) { if (other is Book) {
return other.bookUrl == bookUrl return other.bookUrl == bookUrl
} }
return false return false
} }
override fun hashCode(): Int { override fun hashCode(): Int {
return bookUrl.hashCode() return bookUrl.hashCode()
} }
@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)
} }
@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
fun getRealAuthor() = author.replace(AppPattern.authorRegex, "") fun getRealAuthor() = author.replace(AppPattern.authorRegex, "")
fun getUnreadChapterNum() = max(totalChapterNum - durChapterIndex - 1, 0) fun getUnreadChapterNum() = max(totalChapterNum - durChapterIndex - 1, 0)
fun getDisplayCover() = if (customCoverUrl.isNullOrEmpty()) coverUrl else customCoverUrl fun getDisplayCover() = if (customCoverUrl.isNullOrEmpty()) coverUrl else customCoverUrl
fun getDisplayIntro() = if (customIntro.isNullOrEmpty()) intro else customIntro fun getDisplayIntro() = if (customIntro.isNullOrEmpty()) intro else customIntro
fun fileCharset(): Charset { fun fileCharset(): Charset {
return charset(charset ?: "UTF-8") return charset(charset ?: "UTF-8")
} }
fun getFolderName(): String { fun getFolderName(): String {
return name.replace(AppPattern.fileNameRegex, "") + MD5Utils.md5Encode16(bookUrl) return name.replace(AppPattern.fileNameRegex, "") + MD5Utils.md5Encode16(bookUrl)
} }
fun toSearchBook(): SearchBook { fun toSearchBook() = SearchBook(
return SearchBook( 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@Book.infoHtml
this.infoHtml = this@Book.infoHtml this.tocHtml = this@Book.tocHtml
this.tocHtml = this@Book.tocHtml
}
} }
fun changeTo(newBook: Book) { fun changeTo(newBook: Book) {
newBook.group = group newBook.group = group
newBook.order = order newBook.order = order
@ -153,7 +151,7 @@ data class Book(
delete() delete()
App.db.bookDao().insert(newBook) App.db.bookDao().insert(newBook)
} }
fun delete() { fun delete() {
if (ReadBook.book?.bookUrl == bookUrl) { if (ReadBook.book?.bookUrl == bookUrl) {
ReadBook.book = null ReadBook.book = null

Loading…
Cancel
Save