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
class DiffCallBack : DiffUtil.ItemCallback<SearchEntry>() {
override fun areItemsTheSame(oldItem: SearchEntry, newItem: SearchEntry): Boolean {
class DiffCallBack : DiffUtil.ItemCallback<SearchEntity>() {
override fun areItemsTheSame(oldItem: SearchEntity, newItem: SearchEntity): Boolean {
return oldItem.name == newItem.name
&& 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
&& (oldItem.coverUrl == newItem.coverUrl || !oldItem.coverUrl.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
}
override fun getChangePayload(oldItem: SearchEntry, newItem: SearchEntry): Any? {
override fun getChangePayload(oldItem: SearchEntity, newItem: SearchEntity): Any? {
return when {
oldItem.originCount != newItem.originCount -> 1
oldItem.coverUrl != newItem.coverUrl -> 2

@ -14,9 +14,9 @@ import kotlinx.android.synthetic.main.item_search.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
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()) {
bind(holder.itemView, item)
} 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) {
tv_name.text = searchBook.name
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) {
when (payloads[0]) {
1 -> bv_originCount.setBadgeCount(searchBook.originCount)

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

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

Loading…
Cancel
Save