pull/32/head
kunfei 5 years ago
parent 862d151365
commit 49616f8d07
  1. 2
      app/src/main/java/io/legado/app/ui/search/SearchActivity.kt
  2. 48
      app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt

@ -54,7 +54,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
private fun initRecyclerView() {
ATH.applyEdgeEffectColor(rv_search_list)
adapter = SearchAdapter(this)
adapter = SearchAdapter()
rv_search_list.layoutManager = LinearLayoutManager(this)
rv_search_list.adapter = adapter
}

@ -1,26 +1,52 @@
package io.legado.app.ui.search
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewDelegate
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SearchBook
class SearchAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(context, R.layout.item_search) {
class SearchAdapter : PagedListAdapter<SearchBook, SearchAdapter.MyViewHolder>(DIFF_CALLBACK) {
init {
addItemViewDelegate(TestItemDelegate(context))
}
companion object {
@JvmField
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<SearchBook>() {
override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean =
oldItem.name == newItem.name
&& oldItem.author == newItem.author
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) {
override fun areContentsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean =
oldItem.name == newItem.name
&& oldItem.author == newItem.author
&& oldItem.originCount == newItem.originCount
}
}
internal class TestItemDelegate(context: Context) : ItemViewDelegate<SearchBook>(context, R.layout.item_search) {
var callBack: CallBack? = null
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) {
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) {
getItem(position)?.let {
holder.bind(it, callBack)
}
}
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(searchBook: SearchBook, callBack: CallBack?) {
}
}
interface CallBack {
fun showBookInfo()
}
}
Loading…
Cancel
Save