Skip to content

Commit

Permalink
๐Ÿ› Fix: ์ดˆ๋Œ€ํ•  ์นœ๊ตฌ ์•„์ดํ…œ x ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ๋ชจ๋“  ์นœ๊ตฌ ๋ชฉ๋ก์—์„œ์˜ ํ•ด๋‹น ์นœ๊ตฌ ์ฒดํฌ ํ•ด์ œ
Browse files Browse the repository at this point in the history
Related to: #347
  • Loading branch information
nahy-512 committed Jan 8, 2025
1 parent 8fae907 commit 7e90edc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ class FriendInviteActivity : BaseActivity<ActivityFriendInviteBinding>(R.layout.
}

friendToInviteAdapter.setItemClickListener(object : FriendInvitePreparatoryRVAdapter.MyItemClickListener {
override fun onDeleteBtnClick(position: Int) {
override fun onDeleteBtnClick(position: Int) { // ์ดˆ๋Œ€ํ•  ์นœ๊ตฌ ํ•ด์ œ
val friendToDelete = viewModel.friendToInviteList.value!![position]
// ์ดˆ๋Œ€ํ•  ์นœ๊ตฌ ๋ชฉ๋ก์—์„œ ์‚ญ์ œ
viewModel.updateSelectedFriend(false, friendToDelete)
// ๋ชจ๋“  ์นœ๊ตฌ ๋ชฉ๋ก์—์„œ๋„ ์ฒดํฌ ํ•ด์ œ
allFriendAdapter.uninvitedFriend(friendToDelete)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.mongmong.namo.domain.model.Friend
class FriendInviteRVAdapter: RecyclerView.Adapter<FriendInviteRVAdapter.ViewHolder>(){

private var friendList = emptyList<Friend>()
private var isFriendSelectedList = mutableListOf<Boolean>()
private lateinit var mItemClickListener: MyItemClickListener

fun setItemClickListener(itemClickListener: MyItemClickListener) {
Expand All @@ -19,9 +20,19 @@ class FriendInviteRVAdapter: RecyclerView.Adapter<FriendInviteRVAdapter.ViewHold
@SuppressLint("NotifyDataSetChanged")
fun addFriend(friendList: List<Friend>) {
this.friendList = friendList
this.isFriendSelectedList = MutableList(friendList.size) { false } // ์นœ๊ตฌ ์„ ํƒ ์—ฌ๋ถ€ ์ดˆ๊ธฐํ™”
notifyDataSetChanged()
}

// ์ดˆ๋Œ€ ํ•ด์ œ
fun uninvitedFriend(friend: Friend) {
val position = friendList.indexOf(friend)
if (position != -1) {
isFriendSelectedList[position] = false
notifyItemChanged(position)
}
}

interface MyItemClickListener {
fun onInviteButtonClick(isSelected: Boolean, position: Int)
fun onItemClick(position: Int)
Expand All @@ -38,13 +49,17 @@ class FriendInviteRVAdapter: RecyclerView.Adapter<FriendInviteRVAdapter.ViewHold
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(friendList[position])
holder.apply {
binding.itemFriendInviteBtn.isChecked = isFriendSelectedList[position]

// ์•„์ดํ…œ ์ „์ฒด ํด๋ฆญ
itemView.setOnClickListener {
mItemClickListener.onItemClick(position)
}
// ์ดˆ๋Œ€ ๋ฒ„ํŠผ ํด๋ฆญ

// ์ดˆ๋Œ€ ๋ฒ„ํŠผ ํด๋ฆญ (์ดˆ๋Œ€ํ•  ์นœ๊ตฌ์— ์ถ”๊ฐ€ or ํ•ด์ œ)
binding.itemFriendInviteBtn.setOnClickListener {
mItemClickListener.onInviteButtonClick(binding.itemFriendInviteBtn.isChecked, position)
isFriendSelectedList[position] = binding.itemFriendInviteBtn.isChecked
mItemClickListener.onInviteButtonClick(isFriendSelectedList[position], position)
}
}
}
Expand Down

0 comments on commit 7e90edc

Please sign in to comment.