Ниже приведено действие для публикации комментария, который включает коды для публикации его в эмуляторе, который я не могу найти или выяснить, и как, где идентификатор пользователя и изображение комментатора отказались быть должным образом извлеченными из моего хранилища базы данных firebase онлайн-облако, мне действительно нужна помощь по этим вопросам, застрявшим и сбитым с толку.
[@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_details);
//Setting the status bar to be transparent
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
// THis code hides the action bar you can always come back here to disable it.
getSupportActionBar().hide();
RvComments = findViewById(R.id.rv_comment);
imagePost = findViewById(R.id.post_detail_Img);
imageUserPost = findViewById(R.id.post_detail_user_img);
imageCurrentUser = findViewById(R.id.post_detail_currentUser_img);
txtPostTittle = findViewById(R.id.post_detail_tittle);
txtPostDesc = findViewById(R.id.post_details_desc);
txtPostDataName = findViewById(R.id.post_detail_date_name);
editTextComment = findViewById(R.id.post_detail_comment);
btnAddComment = findViewById(R.id.post_detail_add_comment_btn);
mAuth = FirebaseAuth.getInstance();
firebaseUser = mAuth.getCurrentUser();
firebaseDatabase = FirebaseDatabase.getInstance();
// This code is to monitor specific user ID likes
// add the comment
btnAddComment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnAddComment.setVisibility(View.INVISIBLE);
DatabaseReference commentReference = firebaseDatabase.getReference(COMMENT_KEY ).child(PostKey).push();
String comment_content = editTextComment.getText().toString();
String uID = firebaseUser.getUid();
String uNAME = firebaseUser.getDisplayName();
String uIMG = firebaseUser.getPhotoUrl().toString();
Comments comments = new Comments(comment_content,uID,uIMG,uNAME);
commentReference.setValue(comments).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
showMessage("Comment added");
editTextComment.setText("");
btnAddComment.setVisibility(View.VISIBLE);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
showMessage("Failed to add comment : "+ e.getMessage());
}
});
}
});
//Bind all the data to into this view, then send post detail data
//To postAdapter activity
String postImage = getIntent().getExtras().getString("postImage");
Glide.with(this).load(postImage).into(imagePost);
String postTittle = getIntent().getExtras().getString("tittle");
txtPostTittle.setText(postTittle);
String postUserImage = getIntent().getExtras().getString("userPhoto");
Glide.with(this).load(postUserImage).into(imageUserPost);
String postDescription = getIntent().getExtras().getString("description");
txtPostDesc.setText(postDescription);
//Make the comment user Image
Glide.with(this).load(firebaseUser.getPhotoUrl()).into(imageCurrentUser);
//getting the post ID
PostKey = getIntent().getExtras().getString( "postKey");
String date = timestampToString(getIntent().getExtras().getLong("postDate"));
txtPostDataName.setText(date);
// Piece of code here retrieves the post from the data base
initializeRVComments();
}
private void initializeRVComments() {
RvComments.setLayoutManager(new LinearLayoutManager(this));
DatabaseReference commentsDBRef = firebaseDatabase.getReference(COMMENT_KEY).child(PostKey);
commentsDBRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
listComment = new ArrayList<>();
for (DataSnapshot snap: dataSnapshot.getChildren()){
Comments comment = snap.getValue(Comments.class);
listComment.add(comment);
}
commentsAdapter = new CommentsAdapter(getApplicationContext(),listComment);
RvComments.setAdapter(commentsAdapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
**This is the XML for the comments section**
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#CEE3B6"
android:layout_height="wrap_content"
android:paddingTop="8dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/comment_user_img"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
<TextView
android:textColor="#373131"
android:textStyle="bold"
android:id="@+id/comment_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintStart_toEndOf="@+id/comment_user_img"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/comment_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="@string/text_comment_goes_here"
android:textColor="#373131"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/comment_user_img"
app:layout_constraintTop_toBottomOf="@+id/comment_username" />
<TextView
android:textSize="12sp"
android:id="@+id/comment_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="@string/_4_00"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/comment_username"
app:layout_constraintTop_toTopOf="parent" />][1]
enter image description here.stack.imgur.com/WFHAj.png