From 4c2a9b0dfa6f3d4db111c86f9b952c3bf92586bf Mon Sep 17 00:00:00 2001 From: Ramharsh Dandekar Date: Thu, 24 Oct 2024 18:56:35 +0530 Subject: [PATCH] Update ProfileFragment.kt for bug #37 --- .../nextgen/profile/ProfileFragment.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/example/nextgen/profile/ProfileFragment.kt b/app/src/main/java/com/example/nextgen/profile/ProfileFragment.kt index d5b5d45..2f90c1a 100644 --- a/app/src/main/java/com/example/nextgen/profile/ProfileFragment.kt +++ b/app/src/main/java/com/example/nextgen/profile/ProfileFragment.kt @@ -61,18 +61,24 @@ class ProfileFragment : BaseFragment() { binding.viewModel = profileViewModel binding.lifecycleOwner = this - profileViewModel.profile.observe(viewLifecycleOwner) { - binding.apply { +profileViewModel.profile.observe(viewLifecycleOwner) { + binding.apply { try { - this.username.text = it.userName - this.bio.text = it.bio - if (!it.imageUrl.isBlank()) - Picasso.get().load(it.imageUrl) - .error(R.drawable.profile_placeholder).into(this.profilePic) - } catch (e: java.lang.Exception) { + this.username.text = it.userName + this.bio.text = it.bio + if (it.privacy.disableProfilePicture) { + Picasso.get().load(R.drawable.profile_placeholder).into(this.profilePic) // Default avatar + } else if (!it.imageUrl.isBlank()) { + Picasso.get().load(it.imageUrl) + .error(R.drawable.profile_placeholder).into(this.profilePic) + } else { + Picasso.get().load(R.drawable.profile_placeholder).into(this.profilePic) // Default avatar + } + } catch (e: Exception) { + e.printStackTrace() // Optional: log the error } - } } +} binding.parentProfileInfo.setOnClickListener { (activity as RouteToEditProfileActivity).routeToEditProfileActivity(