Skip to content

Commit

Permalink
teams: show member details (fixes #3546) (#3614)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
rlam20 and dogi authored Jun 17, 2024
1 parent 059918e commit 50adba9
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1589
versionName "0.15.89"
versionCode 1590
versionName "0.15.90"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import org.ole.planet.myplanet.model.RealmResourceActivity
import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.utilities.Constants.PREFS_NAME
import org.ole.planet.myplanet.utilities.Utilities
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.UUID

class UserProfileDbHandler(context: Context) {
private val settings: SharedPreferences
var mRealm: Realm
Expand All @@ -34,7 +35,7 @@ class UserProfileDbHandler(context: Context) {

val userModel: RealmUserModel?
get() {
if (mRealm.isClosed){
if (mRealm.isClosed) {
mRealm = realmService.realmInstance
}
return mRealm.where(RealmUserModel::class.java)
Expand Down Expand Up @@ -85,15 +86,27 @@ class UserProfileDbHandler(context: Context) {
val offlineVisits: Int
get() = getOfflineVisits(userModel)

fun getOfflineVisits(m: RealmUserModel?): Int {
val db_users = mRealm.where(RealmOfflineActivity::class.java).equalTo("userName", m?.name).equalTo("type", KEY_LOGIN).findAll()
fun getOfflineVisits(m: RealmUserModel?): Int { val db_users = mRealm.where(RealmOfflineActivity::class.java).equalTo("userName", m?.name).equalTo("type", KEY_LOGIN).findAll()
return if (!db_users.isEmpty()) {
db_users.size
} else {
0
}
}

fun getLastVisit(m: RealmUserModel): String {
val realm = Realm.getDefaultInstance()
realm.beginTransaction()
val lastLogoutTimestamp = realm.where(RealmOfflineActivity::class.java)
.equalTo("userName", m.name)
.max("loginTime") as Long?
realm.commitTransaction()
return if (lastLogoutTimestamp != null) {
val date = Date(lastLogoutTimestamp)
SimpleDateFormat("MMMM dd, yyyy hh:mm a", Locale.getDefault()).format(date)
} else {
"No logout record found"
}
}
fun setResourceOpenCount(item: RealmMyLibrary) {
setResourceOpenCount(item, KEY_RESOURCE_OPEN)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import org.ole.planet.myplanet.R
Expand All @@ -19,39 +20,60 @@ 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>() {
private lateinit var rowJoinedUserBinding: RowJoinedUserBinding
private val currentUser: RealmUserModel = UserProfileDbHandler(context).userModel!!
private val profileDbHandler = UserProfileDbHandler(context)
private val 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)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderUser { rowJoinedUserBinding = RowJoinedUserBinding.inflate(LayoutInflater.from(context), parent, false)
return ViewHolderUser(rowJoinedUserBinding)
}

override fun onBindViewHolder(holder: ViewHolderUser, position: Int) {
rowJoinedUserBinding.tvTitle.text = if (list[position].toString() == " ") list[position].name else list[position].toString()
rowJoinedUserBinding.tvDescription.text = "${list[position].getRoleAsString()} (${RealmTeamLog.getVisitCount(mRealm, list[position].name, teamId)} ${context.getString(R.string.visits)})"

val member = list[position]
rowJoinedUserBinding.tvTitle.text = if (member.toString() == " ") member.name else member.toString()
rowJoinedUserBinding.tvDescription.text = "${member.getRoleAsString()} (${RealmTeamLog.getVisitCount(mRealm, member.name, teamId)} ${context.getString(R.string.visits)})"
Glide.with(context)
.load(list[position].userImage)
.placeholder(R.drawable.profile)
.error(R.drawable.profile)
.into(rowJoinedUserBinding.memberImage)

val isLoggedInUserTeamLeader = teamLeaderId != null && teamLeaderId == currentUser.id

if (teamLeaderId == list[position].id) {
if (teamLeaderId == currentUser.id) {
rowJoinedUserBinding.tvIsLeader.visibility = View.VISIBLE
rowJoinedUserBinding.tvIsLeader.text = context.getString(R.string.team_leader)
} else {
rowJoinedUserBinding.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)
}
holder.itemView.setOnClickListener {
val activity = it.context as AppCompatActivity
val fragment = MemberDetailFragment.newInstance(
member.firstName.toString() + " " + member.lastName.toString(),
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.level.toString(),
member.userImage
)
activity.supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment)
.addToBackStack(null)
.commit()
}
}

private fun checkUserAndShowOverflowMenu(position: Int, overflowMenuOptions: Array<String>, isLoggedInUserTeamLeader: Boolean) {
private fun checkUserAndShowOverflowMenu(
position: Int,
overflowMenuOptions: Array<String>,
isLoggedInUserTeamLeader: Boolean
) {
if (isLoggedInUserTeamLeader) {
rowJoinedUserBinding.icMore.visibility = View.VISIBLE
rowJoinedUserBinding.icMore.setOnClickListener {
Expand Down Expand Up @@ -93,12 +115,13 @@ class AdapterJoinedMember(private val context: Context, private val list: List<R
.findFirst()
team?.deleteFromRealm()
}
list.toMutableList().removeAt(position)
(list as MutableList).removeAt(position)
notifyDataSetChanged()
Utilities.toast(context, context.getString(R.string.user_removed_from_team))
}

override fun getItemCount(): Int = list.size

class ViewHolderUser(rowJoinedUserBinding: RowJoinedUserBinding) : RecyclerView.ViewHolder(rowJoinedUserBinding.root)
class ViewHolderUser(rowJoinedUserBinding: RowJoinedUserBinding) :
RecyclerView.ViewHolder(rowJoinedUserBinding.root)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.ole.planet.myplanet.ui.team.teamMember

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.databinding.FragmentMemberDetailBinding

class MemberDetailFragment : Fragment() {
private var _binding: FragmentMemberDetailBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentMemberDetailBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
arguments?.let { args ->
val imageUrl = args.getString("profile_photo_url")
Glide.with(requireContext())
.load(imageUrl)
.placeholder(R.drawable.profile)
.error(R.drawable.profile)
.into(binding.memberImage)
binding.tvProfileName.text = args.getString("member_name")
binding.tvFullName.text = args.getString("member_name")
binding.tvProfileEmail.text = args.getString("profile_email")
binding.tvDetailDob.text = args.getString("detail_dob")
binding.tvDetailLanguage.text = args.getString("detail_language")
binding.tvProfilePhone.text = args.getString("profile_phone")
binding.tvNumberOfVisits.text = args.getString("number_of_visits")
binding.tvLastLogin.text = args.getString("last_login")
binding.tvLevel.text = args.getString("user_level")
}

binding.btnClose.setOnClickListener {
activity?.supportFragmentManager?.popBackStack()
}
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

companion object {
@JvmStatic
fun newInstance(
name: String,
email: String,
dob: String,
language: String,
phone: String,
visits: String,
lastLogin: String,
username: String,
memberLevel: String,
imageUrl: String?
) = MemberDetailFragment().apply {
arguments = Bundle().apply {
putString("member_name", name)
putString("profile_email", email)
putString("detail_dob", dob)
putString("detail_language", language)
putString("profile_phone", phone)
putString("number_of_visits", visits)
putString("last_login", lastLogin)
putString("username", username)
putString("user_level", memberLevel)
putString("profile_photo_url", imageUrl)
}
}
}
}
Loading

0 comments on commit 50adba9

Please sign in to comment.