Skip to content

Commit 9c9b0b3

Browse files
Refactor: Migrate AdapterJoinedMember to ListAdapter
I've refactored `AdapterJoinedMember` from a standard `RecyclerView.Adapter` to `ListAdapter` to leverage `DiffUtil` for more efficient list updates. - I changed the superclass to `ListAdapter<JoinedMemberData, ViewHolderUser>`. - I added a `DiffUtil.ItemCallback` to handle item and content comparisons. - I replaced manual `MutableList` management by having the adapter process new lists, which ensures they are handled immutably. - I updated the `removeMember`, `updateLeadership`, and `updateData` methods to create new lists and pass them to the adapter, which triggers efficient, fine-grained UI updates. - This change eliminates whole-list redraws caused by `notifyDataSetChanged()`, improving performance and simplifying the adapter's logic. I also fixed compilation errors by: - Updating the `AdapterJoinedMember` constructor call in `JoinedMemberFragment` to match the new signature. - Adding the missing `RecyclerView` import in `AdapterJoinedMember`.
1 parent f1429a6 commit 9c9b0b3

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.appcompat.app.AlertDialog
1010
import androidx.appcompat.app.AppCompatActivity
1111
import androidx.core.content.ContextCompat
1212
import androidx.recyclerview.widget.ListAdapter
13+
import androidx.recyclerview.widget.RecyclerView
1314
import com.bumptech.glide.Glide
1415
import org.ole.planet.myplanet.R
1516
import org.ole.planet.myplanet.databinding.RowJoinedUserBinding

app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/JoinedMemberFragment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class JoinedMemberFragment : BaseMemberFragment() {
7777
val isLeader = members.any { it.user.id == currentUserId && it.isLeader }
7878
adapterJoined = AdapterJoinedMember(
7979
requireActivity(),
80-
members.toMutableList(),
8180
isLeader,
8281
object : AdapterJoinedMember.MemberActionListener {
8382
override fun onRemoveMember(member: JoinedMemberData, position: Int) {
@@ -88,7 +87,9 @@ class JoinedMemberFragment : BaseMemberFragment() {
8887
member.user.id?.let { handleMakeLeader(it) }
8988
}
9089
}
91-
)
90+
).also {
91+
it.updateData(members, isLeader)
92+
}
9293
}
9394
return adapterJoined as AdapterJoinedMember
9495
}

0 commit comments

Comments
 (0)