@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RC_SIGN_IN){
if (resultCode == RESULT_OK){
Toast.makeText(this,"Signed In !",Toast.LENGTH_LONG).show();
}else if (resultCode == RESULT_CANCELED){
Toast.makeText(this,"SignIn Cancelled !",Toast.LENGTH_LONG).show();
finish();
}
}
else if(requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){
Uri selectedImageUri = data.getData();
StorageReference photoImageRef = mchatphotoStorageRef.child(selectedImageUri.getLastPathSegment());
//set the path of uri e.g: image/pic. jpeg
//upload a file to firebase database.
photoImageRef.putFile(selectedImageUri).
addOnSuccessListener
(this, new OnSuccessListener<UploadTask.TaskSnapshot>()
{
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Get a URL to the uploaded content
String downUrl=taskSnapshot.getMetadata().getReference().getDownloadUrl().getResult ().toString ();
// Uri downUrl = Uri.parse (taskSnapshot.getMetadata ().getReference ().getDownloadUrl ().getResult().toString ());
// taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()
// Uri downUrl = taskSnapshot.getMetadata ().getReference ().getDownloadUrl ().getResult ();
FriendlyMessage friendlyMessage = new FriendlyMessage(null,mUsername,downUrl);
myRef.push().setValue(friendlyMessage);
}
});
}
}
Код адаптера сообщения:
@Override
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(nameTextView);
FriendlyMessage message = getItem(position);
boolean isPhoto = message.getPhotoUrl() != null;
if (isPhoto) {
messageTextView.setVisibility(View.GONE);
photoImageView.setVisibility(View.VISIBLE);
Glide.with(photoImageView.getContext())
.load(message.getPhotoUrl())
.into(photoImageView);
} else {
messageTextView.setVisibility(View.VISIBLE);
photoImageView.setVisibility(View.GONE);
messageTextView.setText(message.getText());
}
authorTextView.setText(message.getName());
return convertView;
}
}