-
Notifications
You must be signed in to change notification settings - Fork 0
[Mission] 4주차 미션제출 #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: Bongbak/main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.example.mission2 | ||
|
|
||
| data class Album( | ||
| var title:String?="", | ||
| var singer:String?="", | ||
| var coverImg : Int? =null, | ||
| var songs: ArrayList<Song>?=null | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package com.example.mission2 | ||
|
|
||
| import android.view.LayoutInflater | ||
| import android.view.ViewGroup | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.example.mission2.databinding.ItemAlbumBinding | ||
|
|
||
| class AlbumRVAdapter(private val albumList:ArrayList<Album>): RecyclerView.Adapter<AlbumRVAdapter.ViewHolder>(){ | ||
|
|
||
| interface MyItemClickListener{ | ||
| fun onItemClick(album: Album) | ||
| fun onRemoveAlbum(position:Int) | ||
| fun onPlayClick(album: Album) | ||
| } | ||
|
|
||
| private lateinit var myItemClickListener: MyItemClickListener | ||
| fun setMyItemClickListener(itemClickListener: MyItemClickListener){ | ||
| myItemClickListener=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) | ||
|
|
||
| return ViewHolder(binding) | ||
| } | ||
|
|
||
| override fun onBindViewHolder(holder: AlbumRVAdapter.ViewHolder, position: Int) { | ||
| holder.bind(albumList[position]) | ||
| holder.itemView.setOnClickListener { myItemClickListener.onItemClick(albumList[position])} | ||
| // holder.binding.itemAlbumTitleTv.setOnClickListener { myItemClickListener.onRemoveAlbum(position) } | ||
| } | ||
|
|
||
| override fun getItemCount(): Int=albumList.size | ||
| inner class ViewHolder(val binding: ItemAlbumBinding): RecyclerView.ViewHolder(binding.root){ | ||
|
|
||
| fun bind(album:Album){ | ||
| binding.itemAlbumTitleTv.text=album.title | ||
| binding.itemAlbumSingerNameTv.text=album.singer | ||
| binding.itemAlbumCoverImgIv.setImageResource(album.coverImg!!) | ||
|
|
||
| binding.itemAlbumPlayImgIv.setOnClickListener { | ||
| myItemClickListener.onPlayClick(album) | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.example.mission2 | ||
|
|
||
| data class Included( | ||
| var title:String?="", | ||
| var singer:String?="" | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package com.example.mission2 | ||
|
|
||
| import android.view.LayoutInflater | ||
| import android.view.ViewGroup | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.example.mission2.databinding.ItemSavedBinding | ||
|
|
||
| class LockerRVAdapter(private val savedList:ArrayList<Saved>): RecyclerView.Adapter<LockerRVAdapter.ViewHolder>() { | ||
| interface OnItemClickListener { | ||
| fun onRemoveItem(position: Int) | ||
| } | ||
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
| val binding: ItemSavedBinding = | ||
| ItemSavedBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
| return ViewHolder(binding) | ||
| } | ||
| private lateinit var myItemClickListener: OnItemClickListener | ||
|
|
||
| fun setOnItemClickListener(itemClickListener: OnItemClickListener){ | ||
| myItemClickListener=itemClickListener | ||
| } | ||
|
|
||
|
|
||
| fun removeItem(position:Int){ | ||
| savedList.removeAt(position) | ||
| notifyItemRemoved(position) | ||
| notifyItemRangeChanged(position, savedList.size) | ||
| } | ||
|
|
||
| override fun onBindViewHolder(holder: LockerRVAdapter.ViewHolder, position: Int) { | ||
|
|
||
| holder.bind(savedList[position]) | ||
| holder.binding.itemSavedMore01Iv.setOnClickListener { | ||
| myItemClickListener.onRemoveItem(position) | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 클릭 리스너가 |
||
|
|
||
| override fun getItemCount(): Int=savedList.size | ||
|
|
||
| inner class ViewHolder(val binding: ItemSavedBinding) : RecyclerView.ViewHolder(binding.root) { | ||
| fun bind(saved: Saved) { | ||
| binding.itemSavedMusicTitle01Tv.text = saved.title | ||
| binding.itemSavedSingerName01Tv.text = saved.singer | ||
| binding.itemSavedCoverIv.setImageResource(saved.coverImg!!) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재
removeItem()에서 연속으로 호출하고 있는데,notifyItemRemoved(position)만 호출해도 이후 아이템들의 위치가 자동으로 재계산되므로, 일반적으로notifyItemRangeChanged()는 불필요합니다.