-
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?
Conversation
yangjiae12
left a comment
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.
4주차 미션도 수고하셨습니다~!
| fun bind(album: Album){ | ||
| binding.homeTodayAlbumTitleTv.text = album.title | ||
| binding.homeTodayAlbumSingerTv.text = album.singer | ||
| binding.homeTodayAlbumIv.setImageResource(album.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.
널 강제 언래핑을 하면 NPE 위험이 있으니까 모델을 Int로 보장하거나 플레이스 홀더 처리를 고려해 봐도 좋을 것 같습니다!
| 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) } | ||
| } |
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 블록을 사용하여 클릭 리스너를 한 번만 설정하면 좋을 것 같습니다.
| fun removeitem(position: Int){ | ||
| albumlist.removeAt(position) | ||
| notifyDataSetChanged() | ||
| } |
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.
현재 notifyDataSetChanged()를 통한 전체 갱신을 하고 있는데, addItem, removeItem에서 전체 갱신은 성능 저하를 유발할 수도 있기 때문에, notifyItemInserted(lastIndex), notifyItemRemoved(position)로 바꾸어 부분 갱신을 사용하는 것을 고려해 봐도 좋을 것 같습니다.
📌 PR 제목
4주차 미션 제출 : FLO 클론 코딩
✅ 변경 사항
📷 영상 및 스크린샷
로직 실행 사진
🔗 알게 된 사항
RecyclerView를 이용하는 방법과 interface를 이용하는 방법에 대하여 알 수 있었습니다.
📝 질문 사항
콜백에 대하여 더 알아보고 싶어요