Skip to content

Commit

Permalink
pfp shown for matches from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
hettysymes committed Jun 15, 2023
1 parent 4b72514 commit 4e8ba91
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
16 changes: 16 additions & 0 deletions app/src/main/java/com/example/drp25/Database.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.drp25

import android.graphics.BitmapFactory
import android.net.Uri
import android.widget.ImageView
import com.example.drp25.matchers.MyMatcher
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
Expand All @@ -18,6 +20,20 @@ val matchObservers = mutableListOf<Observer>()
val storage = Firebase.storage
val imageRef = storage.reference.child("images")

fun displayPfp(uniId: String, userId: String, imageView: ImageView) {
val pfpRef = imageRef.child("pfp_${uniId}_${userId}.png")

pfpRef.getBytes(Long.MAX_VALUE).addOnSuccessListener {imageData ->
// Use the bytes to display the image
// Convert the image data to a Bitmap
val bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.size)
// Set the Bitmap to your ImageView
imageView.setImageBitmap(bitmap)
}.addOnFailureListener {
// Handle any errors
}
}

fun sendStamp(uniId: String, userId: String, stampName: String) {
val stampsRef = unisRef.child(uniId).child("users").child(userId).child("stamps")
stampsRef.push().setValue(stampName)
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/com/example/drp25/MatchActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ class MatchActivity : AppCompatActivity() {
val course = snapshot.child("course").value
val year = snapshot.child("year").value

val pfpUri = snapshot.child("pfp").value
if (pfpUri != null) {
Glide.with(this@MatchActivity)
.load(pfpUri as String)
.into(pfpImage)
val hasPfp = snapshot.child("pfp").value as Boolean
if (hasPfp) {
displayPfp(UNI_ID, matchId, pfpImage)
} else {
pfpImage.setImageResource(R.drawable.default_profile)
}
Expand Down
16 changes: 1 addition & 15 deletions app/src/main/java/com/example/drp25/UserProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class UserProfileActivity : AppCompatActivity() {
val year = snapshot.child("year").value
val hasPfp = snapshot.child("pfp").value as Boolean
if (hasPfp) {
displayPfp()
displayPfp(UNI_ID, USER_ID, binding.profileImageView)
} else {
binding.profileImageView.setImageResource(R.drawable.default_profile)
}
Expand Down Expand Up @@ -155,18 +155,4 @@ class UserProfileActivity : AppCompatActivity() {
}
}

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

pfpRef.getBytes(Long.MAX_VALUE).addOnSuccessListener {imageData ->
// Use the bytes to display the image
// 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 {
// Handle any errors
}
}

}

0 comments on commit 4e8ba91

Please sign in to comment.