From 864a7b4d09501dc351a070f8a7632d13c19e671c Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 10:26:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/SearchBook.kt | 10 +++------- .../java/io/legado/app/ui/book/search/DiffCallBack.kt | 6 +++--- .../java/io/legado/app/ui/book/search/SearchAdapter.kt | 4 ++-- 3 files changed, 8 insertions(+), 12 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 edd6f6e56..27f666547 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 @@ -78,16 +78,12 @@ data class SearchBook( variable = GSON.toJson(variableMap) } - @Ignore + @delegate:Ignore @IgnoredOnParcel - var origins: LinkedHashSet? = null - private set + val origins: LinkedHashSet by lazy { linkedSetOf(origin) } fun addOrigin(origin: String) { - if (origins == null) { - origins = linkedSetOf(this.origin) - } - origins?.add(origin) + origins.add(origin) } fun getDisplayLastChapterTitle(): String { diff --git a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt index 5dc166987..2bba67405 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt @@ -30,7 +30,7 @@ class DiffCallBack(private val oldItems: List, private val newItems: override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] - if (oldItem.origins?.size != newItem.origins?.size) { + if (oldItem.origins.size != newItem.origins.size) { return false } if (oldItem.coverUrl != newItem.coverUrl) { @@ -58,8 +58,8 @@ class DiffCallBack(private val oldItems: List, private val newItems: if (oldItem.author != newItem.author) { payload.putString("author", newItem.author) } - if (oldItem.origins?.size != newItem.origins?.size) { - payload.putInt("origins", newItem.origins?.size ?: 1) + if (oldItem.origins.size != newItem.origins.size) { + payload.putInt("origins", newItem.origins.size) } if (oldItem.coverUrl != newItem.coverUrl) { payload.putString("group", newItem.coverUrl) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index fbdcb99cf..38d1154d6 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -40,7 +40,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : with(itemView) { tv_name.text = searchBook.name tv_author.text = context.getString(R.string.author_show, searchBook.author) - bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1) + bv_originCount.setBadgeCount(searchBook.origins.size) upLasted(itemView, searchBook.latestChapterTitle) tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro) upKind(itemView, searchBook.getKindList()) @@ -56,7 +56,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : "name" -> tv_name.text = searchBook.name "author" -> tv_author.text = context.getString(R.string.author_show, searchBook.author) - "originCount" -> bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1) + "originCount" -> bv_originCount.setBadgeCount(searchBook.origins.size) "lasted" -> upLasted(itemView, searchBook.latestChapterTitle) "introduce" -> tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro)