feat: 优化代码

pull/120/head
kunfei 5 years ago
parent aacdd2fefd
commit 864a7b4d09
  1. 10
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt

@ -78,16 +78,12 @@ data class SearchBook(
variable = GSON.toJson(variableMap)
}
@Ignore
@delegate:Ignore
@IgnoredOnParcel
var origins: LinkedHashSet<String>? = null
private set
val origins: LinkedHashSet<String> by lazy { linkedSetOf(origin) }
fun addOrigin(origin: String) {
if (origins == null) {
origins = linkedSetOf(this.origin)
}
origins?.add(origin)
origins.add(origin)
}
fun getDisplayLastChapterTitle(): String {

@ -30,7 +30,7 @@ class DiffCallBack(private val oldItems: List<SearchBook>, 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<SearchBook>, 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)

@ -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)

Loading…
Cancel
Save