|
|
|
@ -1,54 +1,38 @@ |
|
|
|
|
package io.legado.app.ui.book.toc |
|
|
|
|
|
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.content.Context |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import androidx.paging.PagedListAdapter |
|
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
|
import io.legado.app.base.adapter.RecyclerAdapter |
|
|
|
|
import io.legado.app.data.entities.Bookmark |
|
|
|
|
import io.legado.app.databinding.ItemBookmarkBinding |
|
|
|
|
import splitties.views.onLongClick |
|
|
|
|
|
|
|
|
|
class BookmarkAdapter(val callback: Callback) : PagedListAdapter<Bookmark, BookmarkAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
|
class BookmarkAdapter(context: Context, val callback: Callback) : |
|
|
|
|
RecyclerAdapter<Bookmark, ItemBookmarkBinding>(context) { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
@JvmField |
|
|
|
|
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Bookmark>() { |
|
|
|
|
override fun areItemsTheSame(oldItem: Bookmark, newItem: Bookmark): Boolean = |
|
|
|
|
oldItem.time == newItem.time |
|
|
|
|
|
|
|
|
|
override fun areContentsTheSame(oldItem: Bookmark, newItem: Bookmark): Boolean = |
|
|
|
|
oldItem.time == newItem.time |
|
|
|
|
&& oldItem.bookUrl == newItem.bookUrl |
|
|
|
|
&& oldItem.chapterName == newItem.chapterName |
|
|
|
|
&& oldItem.content == newItem.content |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { |
|
|
|
|
val binding = |
|
|
|
|
ItemBookmarkBinding.inflate(LayoutInflater.from(parent.context), parent, false) |
|
|
|
|
return MyViewHolder(binding) |
|
|
|
|
override fun getViewBinding(parent: ViewGroup): ItemBookmarkBinding { |
|
|
|
|
return ItemBookmarkBinding.inflate(inflater, parent, false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { |
|
|
|
|
getItem(position)?.let { |
|
|
|
|
holder.bind(it, callback) |
|
|
|
|
} |
|
|
|
|
override fun convert( |
|
|
|
|
holder: ItemViewHolder, |
|
|
|
|
binding: ItemBookmarkBinding, |
|
|
|
|
item: Bookmark, |
|
|
|
|
payloads: MutableList<Any> |
|
|
|
|
) { |
|
|
|
|
binding.tvChapterName.text = item.chapterName |
|
|
|
|
binding.tvBookText.text = item.bookText |
|
|
|
|
binding.tvContent.text = item.content |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class MyViewHolder(val binding: ItemBookmarkBinding) : RecyclerView.ViewHolder(binding.root) { |
|
|
|
|
|
|
|
|
|
fun bind(bookmark: Bookmark, callback: Callback?) = with(binding) { |
|
|
|
|
tvChapterName.text = bookmark.chapterName |
|
|
|
|
tvBookText.text = bookmark.bookText |
|
|
|
|
tvContent.text = bookmark.content |
|
|
|
|
itemView.setOnClickListener { |
|
|
|
|
callback?.onClick(bookmark) |
|
|
|
|
override fun registerListener(holder: ItemViewHolder, binding: ItemBookmarkBinding) { |
|
|
|
|
getItem(holder.layoutPosition)?.let { bookmark -> |
|
|
|
|
binding.root.setOnClickListener { |
|
|
|
|
callback.onClick(bookmark) |
|
|
|
|
} |
|
|
|
|
itemView.onLongClick { |
|
|
|
|
callback?.onLongClick(bookmark) |
|
|
|
|
binding.root.onLongClick { |
|
|
|
|
callback.onLongClick(bookmark) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -57,4 +41,5 @@ class BookmarkAdapter(val callback: Callback) : PagedListAdapter<Bookmark, Bookm |
|
|
|
|
fun onClick(bookmark: Bookmark) |
|
|
|
|
fun onLongClick(bookmark: Bookmark) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |