я пытаюсь отправить в firebase database пост с картинкой и данными, но почемуто загружается только картинка, а класс mDatabaseUsers.addValue... не выполняется, почему и как исправить.
button_newPost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(PostActivity.this, "Loading...", Toast.LENGTH_SHORT).show();
final String postTitle = "PostTitle";
final String postDescription = "PostDescription";
StorageReference filepath = storage.child("post_image").child(uri.getLastPathSegment());
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
final Uri downloadUri = taskSnapshot.getDownloadUrl();
Toast.makeText(PostActivity.this, "Uploaded Succesful", Toast.LENGTH_SHORT).show();
final DatabaseReference newPost = databaseReference.push();
mDatabaseUsers.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
newPost.child("title").setValue(postTitle);
newPost.child("description").setValue(postDescription);
newPost.child("imageURL").setValue(downloadUri.toString());
newPost.child("uid").setValue(mCurrentUser.getUid());
newPost.child("username").setValue(dataSnapshot.child("name").getValue()).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isComplete()) {
Intent mainIntent = new Intent(PostActivity.this,MainActivity.class);
startActivity(mainIntent);
}
}
});
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(PostActivity.this, "Canceled", Toast.LENGTH_SHORT).show();
}
});
}
});
}
});