|
|
@@ -16,28 +16,31 @@ import com.bearya.kids.databinding.ItemSectionPreviewBinding
|
|
|
import library.OnItemClickListener
|
|
|
import library.ext.assetsPath
|
|
|
|
|
|
-class SectionPagerAdapter(private val dirName: String?) : PagedListAdapter<Section, SectionPagerViewHolder>(object : DiffUtil.ItemCallback<Section>() {
|
|
|
+class SectionPagerAdapter :
|
|
|
+ PagedListAdapter<Section, SectionPagerViewHolder>(object : DiffUtil.ItemCallback<Section>() {
|
|
|
|
|
|
- override fun areItemsTheSame(oldItem: Section, newItem: Section): Boolean = oldItem.id == newItem.id
|
|
|
+ override fun areItemsTheSame(oldItem: Section, newItem: Section): Boolean =
|
|
|
+ oldItem.id == newItem.id
|
|
|
|
|
|
- override fun areContentsTheSame(oldItem: Section, newItem: Section): Boolean =
|
|
|
+ override fun areContentsTheSame(oldItem: Section, newItem: Section): Boolean =
|
|
|
TextUtils.equals(oldItem.name, newItem.name) && oldItem.lock == newItem.lock
|
|
|
|
|
|
-}) {
|
|
|
+ }) {
|
|
|
|
|
|
var onItemClickListener: OnItemClickListener<Section>? = null
|
|
|
|
|
|
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SectionPagerViewHolder = SectionPagerViewHolder(
|
|
|
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SectionPagerViewHolder =
|
|
|
+ SectionPagerViewHolder(
|
|
|
ItemSectionBinding.inflate(LayoutInflater.from(parent.context), parent, false).root
|
|
|
- )
|
|
|
+ )
|
|
|
|
|
|
override fun onBindViewHolder(holder: SectionPagerViewHolder, position: Int) {
|
|
|
val item = getItem(position)
|
|
|
- holder.bindView?.image = "chapter/${dirName}/${item?.name}.webp".assetsPath()
|
|
|
+ holder.bindView?.image = "chapter/${item?.name}/resources/${position + 1}.webp".assetsPath()
|
|
|
holder.itemView.setOnClickListener { onItemClickListener?.invoke(it, item, position) }
|
|
|
}
|
|
|
|
|
|
- fun getItemData(position:Int) = getItem(position)
|
|
|
+ fun getItemData(position: Int) = getItem(position)
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -45,23 +48,26 @@ class SectionPagerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
|
|
|
val bindView: ItemSectionBinding? = DataBindingUtil.bind(itemView)
|
|
|
}
|
|
|
|
|
|
-class SectionPreviewAdapter(private val dirName: String?) : PagedListAdapter<Section, SectionPreviewViewHolder>(object : DiffUtil.ItemCallback<Section>() {
|
|
|
+class SectionPreviewAdapter :
|
|
|
+ PagedListAdapter<Section, SectionPreviewViewHolder>(object : DiffUtil.ItemCallback<Section>() {
|
|
|
|
|
|
- override fun areItemsTheSame(oldItem: Section, newItem: Section): Boolean = oldItem.id == newItem.id
|
|
|
+ override fun areItemsTheSame(oldItem: Section, newItem: Section): Boolean =
|
|
|
+ oldItem.id == newItem.id
|
|
|
|
|
|
- override fun areContentsTheSame(oldItem: Section, newItem: Section): Boolean =
|
|
|
+ override fun areContentsTheSame(oldItem: Section, newItem: Section): Boolean =
|
|
|
TextUtils.equals(oldItem.name, newItem.name) && oldItem.lock == newItem.lock
|
|
|
|
|
|
-}) {
|
|
|
+ }) {
|
|
|
|
|
|
var onItemClickListener: OnItemClickListener<Section>? = null
|
|
|
|
|
|
private var currentFocusItemIndex = 0
|
|
|
private var recyclerView: RecyclerView? = null
|
|
|
|
|
|
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SectionPreviewViewHolder = SectionPreviewViewHolder(
|
|
|
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SectionPreviewViewHolder =
|
|
|
+ SectionPreviewViewHolder(
|
|
|
ItemSectionPreviewBinding.inflate(LayoutInflater.from(parent.context), parent, false).root
|
|
|
- )
|
|
|
+ )
|
|
|
|
|
|
override fun onBindViewHolder(holder: SectionPreviewViewHolder, position: Int) {
|
|
|
val item = getItem(position)
|
|
|
@@ -69,10 +75,15 @@ class SectionPreviewAdapter(private val dirName: String?) : PagedListAdapter<Sec
|
|
|
val index = position + 1
|
|
|
holder.bindView?.index = "$index"
|
|
|
|
|
|
- holder.bindView?.image = "chapter/${dirName}/${item?.name}.webp".assetsPath()
|
|
|
+ holder.bindView?.image = "chapter/${item?.name}/resources/$index.webp".assetsPath()
|
|
|
|
|
|
- holder.bindView?.cover?.setBorderColor(ResourcesCompat.getColor(holder.itemView.context.resources,
|
|
|
- if (position == currentFocusItemIndex) R.color.colorBlue else R.color.colorWhite, null))
|
|
|
+ holder.bindView?.cover?.setBorderColor(
|
|
|
+ ResourcesCompat.getColor(
|
|
|
+ holder.itemView.context.resources,
|
|
|
+ if (position == currentFocusItemIndex) R.color.colorBlue else R.color.colorWhite,
|
|
|
+ null
|
|
|
+ )
|
|
|
+ )
|
|
|
|
|
|
holder.itemView.setOnClickListener { v -> onItemClickListener?.invoke(v, item, position) }
|
|
|
}
|
|
|
@@ -94,7 +105,6 @@ class SectionPreviewAdapter(private val dirName: String?) : PagedListAdapter<Sec
|
|
|
recyclerView = null
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
class SectionPreviewViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|