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)