Skip to content

Commit

Permalink
attempt with different display pfp method
Browse files Browse the repository at this point in the history
  • Loading branch information
hettysymes committed Jun 15, 2023
1 parent 019118b commit 105f5d4
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions app/src/main/java/com/example/drp25/UserProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ class UserProfileActivity : AppCompatActivity() {
val year = snapshot.child("year").value
val hasPfp = snapshot.child("pfp").value as Boolean
if (hasPfp) {
Glide.with(this@UserProfileActivity)
.load(imageRef.child("pfp_${UNI_ID}_${USER_ID}.png"))
.into(binding.profileImageView)
displayPfp()
} else {
binding.profileImageView.setImageResource(R.drawable.default_profile)
}
Expand Down Expand Up @@ -168,21 +166,25 @@ class UserProfileActivity : AppCompatActivity() {
}
}
updatePfp(UNI_ID, USER_ID, imageFile.absolutePath)
Glide.with(this@UserProfileActivity)
.load(imageRef.child("pfp_${UNI_ID}_${USER_ID}.png"))
.into(binding.profileImageView)
}

private fun getProfile() {
private fun displayPfp() {
val pfpRef = imageRef.child("pfp_${UNI_ID}_${USER_ID}.png")

val imageFile = File(filesDir, "temp.png")
val ONE_MEGABYTE: Long = 1024 * 1024 // Maximum size of the image in bytes

pfpRef.getFile(imageFile).addOnSuccessListener {
// Local temp file has been created
}.addOnFailureListener {
// Handle any errors
}
pfpRef.getBytes(ONE_MEGABYTE)
.addOnSuccessListener { imageData ->
// Convert the image data to a Bitmap
val bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.size)

// Set the Bitmap to your ImageView
binding.profileImageView.setImageBitmap(bitmap)
}
.addOnFailureListener { exception ->
// Handle any errors that occurred while retrieving the image
// e.g., display a default image or show an error message
}
}

}

0 comments on commit 105f5d4

Please sign in to comment.