// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/models/Comment.java
// @IgnoreExtraProperties
// public class Comment {
// 
//     public String uid;
//     public String author;
//     public String text;
// 
//     public Comment() {
//         // Default constructor required for calls to DataSnapshot.getValue(Comment.class)
//     }
// 
//     public Comment(String uid, String author, String text) {
//         this.uid = uid;
//         this.author = author;
//         this.text = text;
//     }
// 
// }
// 
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/models/Post.java
// @IgnoreExtraProperties
// public class Post {
// 
//     public String uid;
//     public String author;
//     public String title;
//     public String body;
//     public int starCount = 0;
//     public Map<String, Boolean> stars = new HashMap<>();
// 
//     public Post() {
//         // Default constructor required for calls to DataSnapshot.getValue(Post.class)
//     }
// 
//     public Post(String uid, String author, String title, String body) {
//         this.uid = uid;
//         this.author = author;
//         this.title = title;
//         this.body = body;
//     }
// 
//     @Exclude
//     public Map<String, Object> toMap() {
//         HashMap<String, Object> result = new HashMap<>();
//         result.put("uid", uid);
//         result.put("author", author);
//         result.put("title", title);
//         result.put("body", body);
//         result.put("starCount", starCount);
//         result.put("stars", stars);
// 
//         return result;
//     }
// 
// }
// 
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/models/User.java
// @IgnoreExtraProperties
// public class User {
// 
//     public String username;
//     public String email;
// 
//     public User() {
//         // Default constructor required for calls to DataSnapshot.getValue(User.class)
//     }
// 
//     public User(String username, String email) {
//         this.username = username;
//         this.email = email;
//     }
// 
// }
// 
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/viewholder/CommentViewHolder.java
// public class CommentViewHolder extends RecyclerView.ViewHolder {
//     public TextView authorView;
//     public TextView bodyView;
// 
//     public CommentViewHolder(View itemView) {
//         super(itemView);
//         authorView = itemView.findViewById(R.id.commentAuthor);
//         bodyView = itemView.findViewById(R.id.commentBody);
//     }
// }


import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.quickstart.database.R;
import com.google.firebase.quickstart.database.databinding.FragmentPostDetailBinding;
import com.google.firebase.quickstart.database.java.models.Comment;
import com.google.firebase.quickstart.database.java.models.Post;
import com.google.firebase.quickstart.database.java.models.User;
import com.google.firebase.quickstart.database.java.viewholder.CommentViewHolder;
import java.util.ArrayList;
import java.util.List;
    }

    private void postComment() {
        final String uid = getUid();
        FirebaseDatabase.getInstance().getReference().child("users").child(uid)
                .addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        // Get user information
                        User user = dataSnapshot.getValue(User.class);
                        String authorName = user.username;

                        // Create new comment object
                        String commentText = binding.fieldCommentText.getText().toString();
                        Comment comment = new Comment(uid, authorName, commentText);

                        // Push the comment, it will appear in the list
                        mCommentsReference.push().setValue(comment);

                        // Clear the field
                        binding.fieldCommentText.setText(null);
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });
    }

// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/models/Comment.java
// @IgnoreExtraProperties
// public class Comment {
// 
//     public String uid;
//     public String author;
//     public String text;
// 
//     public Comment() {
//         // Default constructor required for calls to DataSnapshot.getValue(Comment.class)
//     }
// 
//     public Comment(String uid, String author, String text) {
//         this.uid = uid;
//         this.author = author;
//         this.text = text;
//     }
// 
// }
// 
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/models/Post.java
// @IgnoreExtraProperties
// public class Post {
// 
//     public String uid;
//     public String author;
//     public String title;
//     public String body;
//     public int starCount = 0;
//     public Map<String, Boolean> stars = new HashMap<>();
// 
//     public Post() {
//         // Default constructor required for calls to DataSnapshot.getValue(Post.class)
//     }
// 
//     public Post(String uid, String author, String title, String body) {
//         this.uid = uid;
//         this.author = author;
//         this.title = title;
//         this.body = body;
//     }
// 
//     @Exclude
//     public Map<String, Object> toMap() {
//         HashMap<String, Object> result = new HashMap<>();
//         result.put("uid", uid);
//         result.put("author", author);
//         result.put("title", title);
//         result.put("body", body);
//         result.put("starCount", starCount);
//         result.put("stars", stars);
// 
//         return result;
//     }
// 
// }
// 
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/models/User.java
// @IgnoreExtraProperties
// public class User {
// 
//     public String username;
//     public String email;
// 
//     public User() {
//         // Default constructor required for calls to DataSnapshot.getValue(User.class)
//     }
// 
//     public User(String username, String email) {
//         this.username = username;
//         this.email = email;
//     }
// 
// }
// 
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/viewholder/CommentViewHolder.java
// public class CommentViewHolder extends RecyclerView.ViewHolder {
//     public TextView authorView;
//     public TextView bodyView;
// 
//     public CommentViewHolder(View itemView) {
//         super(itemView);
//         authorView = itemView.findViewById(R.id.commentAuthor);
//         bodyView = itemView.findViewById(R.id.commentBody);
//     }
// }


// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/PostDetailFragment.java
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.quickstart.database.R;
import com.google.firebase.quickstart.database.databinding.FragmentPostDetailBinding;
import com.google.firebase.quickstart.database.java.models.Comment;
import com.google.firebase.quickstart.database.java.models.Post;
import com.google.firebase.quickstart.database.java.models.User;
import com.google.firebase.quickstart.database.java.viewholder.CommentViewHolder;
import java.util.ArrayList;
import java.util.List;

    }

    private void postComment() {
        final String uid = getUid();
        FirebaseDatabase.getInstance().getReference().child("users").child(uid)
                .addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        // Get user information
                        User user = dataSnapshot.getValue(User.class);
                        String authorName = user.username;

                        // Create new comment object
                        String commentText = binding.fieldCommentText.getText().toString();
                        Comment comment = new Comment(uid, authorName, commentText);

                        // Push the comment, it will appear in the list
                        mCommentsReference.push().setValue(comment);

                        // Clear the field
                        binding.fieldCommentText.setText(null);
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });
    }

    private static class CommentAdapter extends RecyclerView.Adapter<CommentViewHolder> {