So , I am working on small chat application that can load images stored in Firebase cloud.
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
// Code for text message
}
else if(requestCode==RC_PHOTO_PICKER && resultCode==RESULT_OK){
Uri selectedImageUri=data.getData();
StorageReference photoRef=mChatPhotoReference.child(selectedImageUri.getLastPathSegment());
photoRef.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
String downloadUrl=taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();
FriendlyMessage friendlyMessage=new FriendlyMessage(null,mUsername,downloadUrl);
mDatabaseReference.push().setValue(friendlyMessage);
Log.e("WWWWWWWWWWWWWWWWWWWWWWW",downloadUrl);
}
});
}
}
and here is get view .
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.item_message, parent, false);
}
ImageView photoImageView = (ImageView) convertView.findViewById(R.id.photoImageView);
TextView messageTextView = (TextView) convertView.findViewById(R.id.messageTextView);
TextView authorTextView = (TextView) convertView.findViewById(R.id.nameTextView);
FriendlyMessage message = getItem(position);
//FriendlyMessage is class that stores text , username and image url
boolean isPhoto = message.getPhotoUrl() != null;
if (isPhoto) {
Log.e("VVVVVVVVVVVVVVVVVVVV",message.getPhotoUrl());
messageTextView.setVisibility(View.GONE);
photoImageView.setVisibility(View.VISIBLE);
Glide.with(photoImageView.getContext())
.load(message.getPhotoUrl())
.into(photoImageView);
} else {
Load text..
}
authorTextView.setText(message.getName());
return convertView;
}
I a am using
glidle : 4.11.0
firebase-storage:19.1.0