Skip to content

Commit

Permalink
[simba/#28] feat:: 6주차 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
BAEK0111 committed May 19, 2024
1 parent c8c16f3 commit b4ee152
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 13 additions & 3 deletions UMC_6th/app/src/main/java/com/example/umc_6th/AlbumRVAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ class AlbumRVAdapter(private val albumList:ArrayList<Album>) : RecyclerView.Adap

interface MyItemClickListener{
fun onItemClick(album: Album)
fun onRemoveAlbum(position: Int)
}

private lateinit var mItemClickListener : MyItemClickListener
fun setMyItemClickListener(itemClickListener: MyItemClickListener){
mItemClickListener = itemClickListener
}

fun addItem(album: Album){
albumList.add(album)
notifyDataSetChanged()
}

fun removeItem(position: Int){
albumList.removeAt(position)
notifyDataSetChanged()
}

override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): AlbumRVAdapter.ViewHolder {
val binding: ItemAlbumBinding = ItemAlbumBinding.inflate(LayoutInflater.from(viewGroup.context),viewGroup,false)

Expand All @@ -24,9 +35,8 @@ class AlbumRVAdapter(private val albumList:ArrayList<Album>) : RecyclerView.Adap

override fun onBindViewHolder(holder: AlbumRVAdapter.ViewHolder, position: Int) {
holder.bind(albumList[position])
holder.itemView.setOnClickListener{
mItemClickListener.onItemClick(albumList[position])
}
holder.itemView.setOnClickListener{ mItemClickListener.onItemClick(albumList[position]) }
// holder.binding.itemAlbumTitleTv.setOnClickListener{mItemClickListener.onRemoveAlbum(position)}
}

override fun getItemCount(): Int = albumList.size
Expand Down
3 changes: 3 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class HomeFragment : Fragment() {
override fun onItemClick(album: Album) {
changeAlbumFragment(album)
}
override fun onRemoveAlbum(position: Int) {
albumRVAdapter.removeItem(position)
}
})

val bannerAdapter = BannerVPAdapter(this)
Expand Down

0 comments on commit b4ee152

Please sign in to comment.