pull/43/head
kunfei 5 years ago
parent c7540eec65
commit baf0378bbc
  1. 8
      app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/search/SearchEntity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -2,13 +2,13 @@ package io.legado.app.ui.book.search
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
class DiffCallBack : DiffUtil.ItemCallback<SearchEntry>() { class DiffCallBack : DiffUtil.ItemCallback<SearchEntity>() {
override fun areItemsTheSame(oldItem: SearchEntry, newItem: SearchEntry): Boolean { override fun areItemsTheSame(oldItem: SearchEntity, newItem: SearchEntity): Boolean {
return oldItem.name == newItem.name return oldItem.name == newItem.name
&& oldItem.author == newItem.author && oldItem.author == newItem.author
} }
override fun areContentsTheSame(oldItem: SearchEntry, newItem: SearchEntry): Boolean { override fun areContentsTheSame(oldItem: SearchEntity, newItem: SearchEntity): Boolean {
return oldItem.originCount == newItem.originCount return oldItem.originCount == newItem.originCount
&& (oldItem.coverUrl == newItem.coverUrl || !oldItem.coverUrl.isNullOrEmpty()) && (oldItem.coverUrl == newItem.coverUrl || !oldItem.coverUrl.isNullOrEmpty())
&& (oldItem.kind == newItem.kind || !oldItem.kind.isNullOrEmpty()) && (oldItem.kind == newItem.kind || !oldItem.kind.isNullOrEmpty())
@ -16,7 +16,7 @@ class DiffCallBack : DiffUtil.ItemCallback<SearchEntry>() {
&& oldItem.intro?.length ?: 0 > newItem.intro?.length ?: 0 && oldItem.intro?.length ?: 0 > newItem.intro?.length ?: 0
} }
override fun getChangePayload(oldItem: SearchEntry, newItem: SearchEntry): Any? { override fun getChangePayload(oldItem: SearchEntity, newItem: SearchEntity): Any? {
return when { return when {
oldItem.originCount != newItem.originCount -> 1 oldItem.originCount != newItem.originCount -> 1
oldItem.coverUrl != newItem.coverUrl -> 2 oldItem.coverUrl != newItem.coverUrl -> 2

@ -14,9 +14,9 @@ import kotlinx.android.synthetic.main.item_search.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class SearchAdapter(context: Context, val callBack: CallBack) : class SearchAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<SearchEntry>(context, R.layout.item_search) { SimpleRecyclerAdapter<SearchEntity>(context, R.layout.item_search) {
override fun convert(holder: ItemViewHolder, item: SearchEntry, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: SearchEntity, payloads: MutableList<Any>) {
if (payloads.isEmpty()) { if (payloads.isEmpty()) {
bind(holder.itemView, item) bind(holder.itemView, item)
} else { } else {
@ -24,7 +24,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
} }
} }
private fun bind(itemView: View, searchBook: SearchEntry) { private fun bind(itemView: View, searchBook: SearchEntity) {
with(itemView) { with(itemView) {
tv_name.text = searchBook.name tv_name.text = searchBook.name
tv_author.text = context.getString(R.string.author_show, searchBook.author) tv_author.text = context.getString(R.string.author_show, searchBook.author)
@ -79,7 +79,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
} }
} }
private fun bindChange(itemView: View, searchBook: SearchEntry, payloads: MutableList<Any>) { private fun bindChange(itemView: View, searchBook: SearchEntity, payloads: MutableList<Any>) {
with(itemView) { with(itemView) {
when (payloads[0]) { when (payloads[0]) {
1 -> bv_originCount.setBadgeCount(searchBook.originCount) 1 -> bv_originCount.setBadgeCount(searchBook.originCount)

@ -2,7 +2,7 @@ package io.legado.app.ui.book.search
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
data class SearchEntry( data class SearchEntity(
var name: String = "", var name: String = "",
var author: String = "", var author: String = "",
var kind: String? = null, var kind: String? = null,

@ -22,7 +22,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
var startTime: Long = 0 var startTime: Long = 0
var searchPage = 0 var searchPage = 0
var isLoading = false var isLoading = false
private val booksShow = arrayListOf<SearchEntry>() private val booksShow = arrayListOf<SearchEntity>()
fun search( fun search(
key: String, key: String,

Loading…
Cancel
Save