Skip to content

Commit

Permalink
added additional checks
Browse files Browse the repository at this point in the history
  • Loading branch information
deeppp15 committed Jan 9, 2025
1 parent 516a848 commit 7706488
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ class AdapterJoinedMember(

holder.itemView.setOnClickListener {
val activity = it.context as AppCompatActivity
val userName = if ("${member.firstName} ${member.lastName}".trim().isBlank()) {
member.name
} else {
"${member.firstName} ${member.lastName}".trim()
}
val fragment = MemberDetailFragment.newInstance(
"${member.firstName} ${member.lastName}",
userName.toString(),
member.email.toString(),
member.dob.toString().substringBefore("T"),
member.language.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,60 @@ class MemberDetailFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

arguments?.let { args ->
val fullName = args.getString("member_name")?.trim()
val username = args.getString("username")?.trim()
val imageUrl = args.getString("profile_photo_url")
binding.tvProfileName.text = if (fullName.isNullOrEmpty()) username else fullName
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")

setFieldOrHide(binding.tvFullName, fullName)
setFieldOrHide(binding.tvProfileEmail, args.getString("profile_email"))
setFieldOrHide(binding.tvDetailDob, args.getString("detail_dob"))
setFieldOrHide(binding.tvDetailLanguage, args.getString("detail_language"))
setFieldOrHide(binding.tvProfilePhone, args.getString("profile_phone"))
setFieldOrHide(binding.tvNumberOfVisits, args.getString("number_of_visits"))
setFieldOrHide(binding.tvLastLogin, args.getString("last_login"))
setFieldOrHide(binding.tvLevel, args.getString("user_level"))
}

binding.btnClose.setOnClickListener {
activity?.supportFragmentManager?.popBackStack()
}
}

private fun setFieldOrHide(view: View, value: String?) {
if (!value.isNullOrEmpty()) {
when (view) {
is androidx.appcompat.widget.AppCompatTextView -> view.text = value
}
view.visibility = View.VISIBLE
(view.parent as? View)?.visibility = View.VISIBLE
} else {
(view.parent as? View)?.visibility = View.GONE
}
}


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 {
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)
Expand Down

0 comments on commit 7706488

Please sign in to comment.