Skip to content
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

teams: smoother members removal (fixes #4819) #4829

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import io.realm.Realm
import io.realm.Sort
import org.ole.planet.myplanet.utilities.Utilities

class AdapterJoinedMember(private val context: Context, private val list: List<RealmUserModel>, private val mRealm: Realm, private val teamId: String) : RecyclerView.Adapter<AdapterJoinedMember.ViewHolderUser>() {
class AdapterJoinedMember(private val context: Context, private val list: MutableList<RealmUserModel>, private val mRealm: Realm, private val teamId: String) : RecyclerView.Adapter<AdapterJoinedMember.ViewHolderUser>() {
private lateinit var rowJoinedUserBinding: RowJoinedUserBinding
private val currentUser: RealmUserModel = UserProfileDbHandler(context).userModel!!
private val profileDbHandler = UserProfileDbHandler(context)
Expand Down Expand Up @@ -101,11 +101,15 @@ class AdapterJoinedMember(private val context: Context, private val list: List<R
0 -> {
if (currentUser.id != list[position].id) {
reject(list[position], position)
notifyItemChanged(position)
notifyItemRangeChanged(position, list.size)
} else {
val nextOfKin= getNextOfKin()
if(nextOfKin!=null){
makeLeader(nextOfKin)
reject(list[position], position)
notifyItemChanged(position)
notifyItemRangeChanged(position, list.size)
}
else {
Toast.makeText(context, R.string.cannot_remove_user, Toast.LENGTH_SHORT).show()
Expand All @@ -114,6 +118,7 @@ class AdapterJoinedMember(private val context: Context, private val list: List<R
}
1 -> {
makeLeader(list[position])
notifyItemChanged(position)
}
else -> {
Toast.makeText(context, R.string.cannot_remove_user, Toast.LENGTH_SHORT).show()
Expand Down Expand Up @@ -177,9 +182,10 @@ class AdapterJoinedMember(private val context: Context, private val list: List<R
.findFirst()
team?.deleteFromRealm()
}
(list as MutableList).removeAt(position)
notifyDataSetChanged()
Utilities.toast(context, context.getString(R.string.user_removed_from_team))
list.removeAt(position)
notifyItemRemoved(position)
notifyItemRangeChanged(position, list.size)
// Utilities.toast(context, context.getString(R.string.user_removed_from_team))
}

override fun getItemCount(): Int = list.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class JoinedMemberFragment : BaseMemberFragment() {
override val list: List<RealmUserModel>
get() = getJoinedMember(teamId, mRealm)
override val adapter: RecyclerView.Adapter<*>
get() = AdapterJoinedMember(requireActivity(), list, mRealm, teamId)
get() = AdapterJoinedMember(requireActivity(), list.toMutableList(), mRealm, teamId)

override val layoutManager: RecyclerView.LayoutManager
get() {
Expand Down
Loading