// 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;
//     }
// 
// }


import android.os.Bundle;
import android.text.TextUtils;
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.navigation.fragment.NavHostFragment;
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.FragmentNewPostBinding;
import com.google.firebase.quickstart.database.java.models.Post;
import com.google.firebase.quickstart.database.java.models.User;
import java.util.HashMap;
import java.util.Map;
            }
        });
    }

    private void submitPost() {
        final String title = binding.fieldTitle.getText().toString();
        final String body = binding.fieldBody.getText().toString();

        // Title is required
        if (TextUtils.isEmpty(title)) {
            binding.fieldTitle.setError(REQUIRED);
            return;
        }

        // Body is required
        if (TextUtils.isEmpty(body)) {
            binding.fieldBody.setError(REQUIRED);
            return;
        }

        // Disable button so there are no multi-posts
        setEditingEnabled(false);
        Toast.makeText(getContext(), "Posting...", Toast.LENGTH_SHORT).show();

        final String userId = getUid();
        mDatabase.child("users").child(userId).addListenerForSingleValueEvent(
                new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        // Get user value
// 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/NewPostFragment.java
import android.os.Bundle;
import android.text.TextUtils;
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.navigation.fragment.NavHostFragment;
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.FragmentNewPostBinding;
import com.google.firebase.quickstart.database.java.models.Post;
import com.google.firebase.quickstart.database.java.models.User;
import java.util.HashMap;
import java.util.Map;

            }
        });
    }

    private void submitPost() {
        final String title = binding.fieldTitle.getText().toString();
        final String body = binding.fieldBody.getText().toString();

        // Title is required
        if (TextUtils.isEmpty(title)) {
            binding.fieldTitle.setError(REQUIRED);
            return;
        }

        // Body is required
        if (TextUtils.isEmpty(body)) {
            binding.fieldBody.setError(REQUIRED);
            return;
        }

        // Disable button so there are no multi-posts
        setEditingEnabled(false);
        Toast.makeText(getContext(), "Posting...", Toast.LENGTH_SHORT).show();

        final String userId = getUid();
        mDatabase.child("users").child(userId).addListenerForSingleValueEvent(
                new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        // Get user value
                        User user = dataSnapshot.getValue(User.class);