|
|
|
@ -1,11 +1,10 @@ |
|
|
|
|
package io.legado.app.ui.book.search |
|
|
|
|
|
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.content.Context |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import androidx.paging.PagedListAdapter |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
|
|
|
|
import io.legado.app.data.entities.SearchShow |
|
|
|
|
import io.legado.app.help.ImageLoader |
|
|
|
|
import io.legado.app.utils.gone |
|
|
|
@ -15,33 +14,19 @@ import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name |
|
|
|
|
import kotlinx.android.synthetic.main.item_search.view.* |
|
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
|
|
|
|
|
class SearchAdapter(val callBack: CallBack) : |
|
|
|
|
PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(DiffCallBack()) { |
|
|
|
|
class SearchAdapter(context: Context, val callBack: CallBack) : |
|
|
|
|
SimpleRecyclerAdapter<SearchShow>(context, R.layout.item_search) { |
|
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { |
|
|
|
|
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_search, parent, false)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int, payloads: MutableList<Any>) { |
|
|
|
|
override fun convert(holder: ItemViewHolder, item: SearchShow, payloads: MutableList<Any>) { |
|
|
|
|
if (payloads.isEmpty()) { |
|
|
|
|
super.onBindViewHolder(holder, position, payloads) |
|
|
|
|
bind(holder.itemView, item) |
|
|
|
|
} else { |
|
|
|
|
getItem(position)?.let { |
|
|
|
|
holder.bindChange(it, payloads) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { |
|
|
|
|
getItem(position)?.let { |
|
|
|
|
holder.bind(it, callBack) |
|
|
|
|
bindChange(holder.itemView, item, payloads) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { |
|
|
|
|
|
|
|
|
|
fun bind(searchBook: SearchShow, callBack: CallBack?) = with(itemView) { |
|
|
|
|
private fun bind(itemView: View, searchBook: SearchShow) { |
|
|
|
|
with(itemView) { |
|
|
|
|
tv_name.text = searchBook.name |
|
|
|
|
tv_author.text = context.getString(R.string.author_show, searchBook.author) |
|
|
|
|
bv_originCount.setBadgeCount(searchBook.originCount) |
|
|
|
@ -90,11 +75,12 @@ class SearchAdapter(val callBack: CallBack) : |
|
|
|
|
.setAsDrawable(iv_cover) |
|
|
|
|
} |
|
|
|
|
onClick { |
|
|
|
|
callBack?.showBookInfo(searchBook.name, searchBook.author) |
|
|
|
|
callBack.showBookInfo(searchBook.name, searchBook.author) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun bindChange(searchBook: SearchShow, payloads: MutableList<Any>) = |
|
|
|
|
private fun bindChange(itemView: View, searchBook: SearchShow, payloads: MutableList<Any>) { |
|
|
|
|
with(itemView) { |
|
|
|
|
when (payloads[0]) { |
|
|
|
|
1 -> bv_originCount.setBadgeCount(searchBook.originCount) |
|
|
|
|