diff --git a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt index 64978fe69..89ff581cb 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt @@ -54,7 +54,7 @@ class SearchActivity : VMBaseActivity(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 } diff --git a/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt index cbdf67def..202b37644 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt @@ -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(context, R.layout.item_search) { +class SearchAdapter : PagedListAdapter(DIFF_CALLBACK) { - init { - addItemViewDelegate(TestItemDelegate(context)) - } + companion object { + + @JvmField + val DIFF_CALLBACK = object : DiffUtil.ItemCallback() { + 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) { + 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(context, R.layout.item_search) { + var callBack: CallBack? = null - override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList) { + 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() + } } \ No newline at end of file