From a50f11c0ea77ba66bd40c1b6ddf7e3796fd9c64f Mon Sep 17 00:00:00 2001 From: Deep Vora <70479785+deeppp15@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:51:20 -0500 Subject: [PATCH] teams: smoother members removal (fixes #4819) (#4829) Co-authored-by: dogi --- app/build.gradle | 4 +- .../ui/team/teamMember/AdapterJoinedMember.kt | 90 +++++++++++-------- .../team/teamMember/JoinedMemberFragment.kt | 2 +- 3 files changed, 57 insertions(+), 39 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 76daea9f36..5dad9dc7fe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 26 targetSdkVersion 34 - versionCode 2124 - versionName "0.21.24" + versionCode 2125 + versionName "0.21.25" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.kt b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.kt index 3fec35d920..1ca327fc2e 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.kt @@ -1,5 +1,6 @@ package org.ole.planet.myplanet.ui.team.teamMember +import android.annotation.SuppressLint import android.content.Context import android.view.LayoutInflater import android.view.View @@ -22,48 +23,64 @@ 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, private val mRealm: Realm, private val teamId: String) : RecyclerView.Adapter() { - private lateinit var rowJoinedUserBinding: RowJoinedUserBinding +class AdapterJoinedMember( + private val context: Context, + private val list: MutableList, + private val mRealm: Realm, + private val teamId: String +) : RecyclerView.Adapter() { + private val currentUser: RealmUserModel = UserProfileDbHandler(context).userModel!! private val profileDbHandler = UserProfileDbHandler(context) - private val teamLeaderId: String? = mRealm.where(RealmMyTeam::class.java) + private var teamLeaderId: String? = mRealm.where(RealmMyTeam::class.java) .equalTo("teamId", teamId) .equalTo("isLeader", true) .findFirst()?.userId - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderUser { rowJoinedUserBinding = RowJoinedUserBinding.inflate(LayoutInflater.from(context), parent, false) - return ViewHolderUser(rowJoinedUserBinding) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderUser { + val binding = RowJoinedUserBinding.inflate(LayoutInflater.from(context), parent, false) + return ViewHolderUser(binding) } override fun onBindViewHolder(holder: ViewHolderUser, position: Int) { val member = list[position] - rowJoinedUserBinding.tvTitle.text = if (member.toString() == " ") member.name else member.toString() - rowJoinedUserBinding.tvDescription.text = context.getString(R.string.member_description, member.getRoleAsString(), RealmTeamLog.getVisitCount(mRealm, member.name, teamId)) + val binding = holder.binding + + binding.tvTitle.text = if (member.toString() == " ") member.name else member.toString() + binding.tvDescription.text = context.getString( + R.string.member_description, + member.getRoleAsString(), + RealmTeamLog.getVisitCount(mRealm, member.name, teamId) + ) + Glide.with(context) - .load(list[position].userImage) + .load(member.userImage) .placeholder(R.drawable.profile) .error(R.drawable.profile) - .into(rowJoinedUserBinding.memberImage) + .into(binding.memberImage) + if (teamLeaderId == member.id) { - rowJoinedUserBinding.tvIsLeader.visibility = View.VISIBLE - rowJoinedUserBinding.tvIsLeader.text = context.getString(R.string.team_leader) + binding.tvIsLeader.visibility = View.VISIBLE + binding.tvIsLeader.text = context.getString(R.string.team_leader) } else { - rowJoinedUserBinding.tvIsLeader.visibility = View.GONE + binding.tvIsLeader.visibility = View.GONE } + val isLoggedInUserTeamLeader = teamLeaderId != null && teamLeaderId == currentUser.id val overflowMenuOptions = arrayOf(context.getString(R.string.remove), context.getString(R.string.make_leader)) - checkUserAndShowOverflowMenu(position, overflowMenuOptions, isLoggedInUserTeamLeader) + checkUserAndShowOverflowMenu(binding, position, overflowMenuOptions, isLoggedInUserTeamLeader) + holder.itemView.setOnClickListener { val activity = it.context as AppCompatActivity val fragment = MemberDetailFragment.newInstance( - member.firstName.toString() + " " + member.lastName.toString(), + "${member.firstName} ${member.lastName}", member.email.toString(), member.dob.toString().substringBefore("T"), member.language.toString(), member.phoneNumber.toString(), profileDbHandler.getOfflineVisits(member).toString(), profileDbHandler.getLastVisit(member), - member.firstName + " " + member.lastName, + "${member.firstName} ${member.lastName}", member.level.toString(), member.userImage ) @@ -74,14 +91,16 @@ class AdapterJoinedMember(private val context: Context, private val list: List, isLoggedInUserTeamLeader: Boolean ) { - if (isLoggedInUserTeamLeader && list.size>1) { - rowJoinedUserBinding.icMore.visibility = View.VISIBLE - rowJoinedUserBinding.icMore.setOnClickListener { + if (isLoggedInUserTeamLeader && list.size > 1) { + binding.icMore.visibility = View.VISIBLE + binding.icMore.setOnClickListener { val builder = AlertDialog.Builder(context, R.style.AlertDialogTheme) val adapter = object : ArrayAdapter( context, @@ -102,12 +121,11 @@ class AdapterJoinedMember(private val context: Context, private val list: List - val team = realm.where(RealmMyTeam::class.java) + val currentLeader = realm.where(RealmMyTeam::class.java) .equalTo("teamId", teamId) - .equalTo("userId", userModel.id) + .equalTo("isLeader", true) .findFirst() - val teamLeader = realm.where(RealmMyTeam::class.java) + val newLeader = realm.where(RealmMyTeam::class.java) .equalTo("teamId", teamId) - .equalTo("isLeader", true) + .equalTo("userId", userModel.id) .findFirst() - teamLeader?.isLeader = false - team?.isLeader = true - team?.updated=true + currentLeader?.isLeader = false + newLeader?.isLeader = true + teamLeaderId = newLeader?.userId } notifyDataSetChanged() Utilities.toast(context, context.getString(R.string.leader_selected)) @@ -177,13 +195,13 @@ class AdapterJoinedMember(private val context: Context, private val list: List 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() {