-
Notifications
You must be signed in to change notification settings - Fork 0
[Mission] 4주차 과제 제출 #35
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: Nick/main
Are you sure you want to change the base?
Changes from all commits
a57410f
8218c5f
a028668
cbe1533
2679cfa
f1dd4ee
8796705
6302674
62455b4
702cfe1
e4ca385
2ba1a60
e3dd680
9040093
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.example.imreallystupid | ||
|
|
||
| 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,62 @@ | ||
| package com.example.imreallystupid | ||
|
|
||
| import android.content.Context | ||
| import android.content.Intent | ||
| import android.view.LayoutInflater | ||
| import android.view.ViewGroup | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.example.imreallystupid.databinding.ItemAlbumBinding | ||
|
|
||
| class AlbumRVAdapter(private val albumlist: ArrayList<Album>): RecyclerView.Adapter<AlbumRVAdapter.ViewHolder>() { | ||
|
|
||
|
|
||
| interface AlbumListItemClickListener{ | ||
| fun onItemClick(album: Album) | ||
| } | ||
| private lateinit var mItemClickListener: AlbumListItemClickListener | ||
| fun setMyItemClickListener(itemClickListener: AlbumListItemClickListener){ | ||
| mItemClickListener = itemClickListener | ||
| } | ||
|
|
||
|
|
||
|
|
||
| interface AlbumPlayListener{ | ||
| fun changeText(album: Album) | ||
| } | ||
| private lateinit var sendMiniPlayer : AlbumPlayListener | ||
|
|
||
| fun sendToMiniPlayer(sendTodayAlbum : AlbumPlayListener) { | ||
| sendMiniPlayer = sendTodayAlbum | ||
| } | ||
|
|
||
|
|
||
|
|
||
| override fun onCreateViewHolder( | ||
| parent: ViewGroup, | ||
| viewType: Int | ||
| ): AlbumRVAdapter.ViewHolder { | ||
| val binding: ItemAlbumBinding = ItemAlbumBinding.inflate(LayoutInflater.from(parent.context), parent,false) | ||
|
|
||
| return ViewHolder(binding) | ||
| } | ||
|
|
||
| override fun onBindViewHolder(holder: AlbumRVAdapter.ViewHolder, position: Int) { | ||
| holder.bind(albumlist[position]) | ||
| holder.itemView.setOnClickListener { mItemClickListener.onItemClick(albumlist[position]) } | ||
| holder.binding.homeTodayAlbumArrowIv.setOnClickListener { sendMiniPlayer.changeText(albumlist[position]) } | ||
| // holder.binding.homeTodayAlbumTitleTv.setOnClickListener { mItemClickListner.onRemoveAlbum(position) } | ||
| } | ||
|
|
||
| override fun getItemCount(): Int = albumlist.size | ||
|
|
||
|
|
||
| inner class ViewHolder(val binding: ItemAlbumBinding): RecyclerView.ViewHolder(binding.root){ | ||
|
|
||
| fun bind(album: Album){ | ||
| binding.homeTodayAlbumTitleTv.text = album.title | ||
| binding.homeTodayAlbumSingerTv.text = album.singer | ||
| binding.homeTodayAlbumIv.setImageResource(album.coverImg!!) | ||
|
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. 널 강제 언래핑을 하면 NPE 위험이 있으니까 모델을 Int로 보장하거나 플레이스 홀더 처리를 고려해 봐도 좋을 것 같습니다! |
||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.example.imreallystupid | ||
|
|
||
| import android.view.LayoutInflater | ||
| import android.view.ViewGroup | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.example.imreallystupid.databinding.ItemLockerBinding | ||
|
|
||
| class LockerRVAdapter( private val albumlist : ArrayList<Album> ) : RecyclerView.Adapter<LockerRVAdapter.ViewHolder>() { | ||
|
|
||
| private lateinit var mItemClickListener: LockerRVAdapter.AlbumListItemClickListener | ||
|
|
||
| interface AlbumListItemClickListener{ | ||
| fun onRemoveAlbum(position: Int) | ||
| } | ||
|
|
||
| fun setMyItemClickListener(itemClickListener: LockerRVAdapter.AlbumListItemClickListener){ | ||
| mItemClickListener = itemClickListener | ||
| } | ||
|
|
||
| fun removeitem(position: Int){ | ||
| albumlist.removeAt(position) | ||
| notifyDataSetChanged() | ||
| } | ||
|
Comment on lines
+20
to
+23
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 onCreateViewHolder( | ||
| parent: ViewGroup, | ||
| viewType: Int | ||
| ): LockerRVAdapter.ViewHolder { | ||
| val binding = ItemLockerBinding.inflate(LayoutInflater.from(parent.context),parent,false) | ||
|
|
||
| return ViewHolder(binding) | ||
| } | ||
|
|
||
| override fun onBindViewHolder(holder: LockerRVAdapter.ViewHolder, position: Int) { | ||
| holder.bind(albumlist[position]) | ||
| holder.binding.lockerSavedMoreIv.setOnClickListener { mItemClickListener.onRemoveAlbum(position) } | ||
| } | ||
|
|
||
| override fun getItemCount(): Int = albumlist.size | ||
|
|
||
| inner class ViewHolder(val binding: ItemLockerBinding) : RecyclerView.ViewHolder(binding.root) { | ||
|
|
||
| fun bind(album: Album) { | ||
| binding.lockerSavedTitleTv.text = album.title | ||
| binding.lockerSavedSingerTv.text = album.singer | ||
| binding.lockerSavedCoverImgIv.setImageResource(album.coverImg!!) | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file was deleted.
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.
현재 클릭 리스너가
bind()함수 내부에 설정되어 있는데,onBindViewHolder가 호출되어bind()가 실행될 때마다, 즉 아이템이 화면에 나타날 때마다 리스너 객체를 새로 생성하여 설정하게 되고 이로 인해 불필요한 객체를 생성하게 된다고 생각합니다. 따라서ViewHolder의init블록을 사용하여 클릭 리스너를 한 번만 설정하면 좋을 것 같습니다.