generated from GO-SOPT-ANDROID/android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c85b7d5
commit 76374f0
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
app/src/main/java/org/android/go/sopt/presentation/main/gallery/PagerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.android.go.sopt.presentation.main.gallery | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.android.go.sopt.databinding.ItemPagerBinding | ||
|
||
class PagerAdapter(_itemList: List<Int> = listOf()) : | ||
RecyclerView.Adapter<PagerAdapter.PagerViewHolder>() { | ||
private var itemList: List<Int> = _itemList | ||
|
||
class PagerViewHolder(private val binding: ItemPagerBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun bind(src: Int) { | ||
binding.ivPager.setImageResource(src) | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PagerViewHolder { | ||
val binding = ItemPagerBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return PagerViewHolder(binding) | ||
} | ||
|
||
override fun getItemCount() = itemList.size | ||
|
||
override fun onBindViewHolder(holder: PagerViewHolder, position: Int) { | ||
holder.bind(itemList[position]) | ||
} | ||
|
||
fun setItemList(itemList: List<Int>) { | ||
this.itemList = itemList | ||
notifyDataSetChanged() | ||
} | ||
} | ||
|
||
//class PagerDiffCallBack : DiffUtil.ItemCallback<List<Int>>() { | ||
// override fun areItemsTheSame(oldItem: List<Int>, newItem: List<Int>): Boolean { | ||
// return oldItem == newItem | ||
// } | ||
// | ||
// override fun areContentsTheSame(oldItem: List<Int>, newItem: List<Int>): Boolean { | ||
// return oldItem == newItem | ||
// } | ||
//} |