// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/listfragments/MyPostsFragment.java
// public class MyPostsFragment extends PostListFragment {
// 
//     public MyPostsFragment() {}
// 
//     @Override
//     public Query getQuery(DatabaseReference databaseReference) {
//         // All my posts
//         return databaseReference.child("user-posts")
//                 .child(getUid());
//     }
// }
// 
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/listfragments/MyTopPostsFragment.java
// public class MyTopPostsFragment extends PostListFragment {
// 
//     public MyTopPostsFragment() {}
// 
//     @Override
//     public Query getQuery(DatabaseReference databaseReference) {
//         // My top posts by number of stars
//         String myUserId = getUid();
//         Query myTopPostsQuery = databaseReference.child("user-posts").child(myUserId)
//                 .orderByChild("starCount");
// 
//         return myTopPostsQuery;
//     }
// }
// 
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/listfragments/RecentPostsFragment.java
// public class RecentPostsFragment extends PostListFragment {
// 
//     public RecentPostsFragment() {}
// 
//     @Override
//     public Query getQuery(DatabaseReference databaseReference) {
//         // [START recent_posts_query]
//         // Last 100 posts, these are automatically the 100 most recent
//         // due to sorting by push() keys
//         Query recentPostsQuery = databaseReference.child("posts")
//                 .limitToFirst(100);
//         // [END recent_posts_query]
// 
//         return recentPostsQuery;
//     }
// }


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.fragment.NavHostFragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import com.google.android.material.tabs.TabLayoutMediator;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.quickstart.database.R;
import com.google.firebase.quickstart.database.databinding.FragmentMainBinding;
import com.google.firebase.quickstart.database.java.listfragments.MyPostsFragment;
import com.google.firebase.quickstart.database.java.listfragments.MyTopPostsFragment;
import com.google.firebase.quickstart.database.java.listfragments.RecentPostsFragment;
package com.google.firebase.quickstart.database.java;




public class MainFragment extends Fragment {

    private FragmentMainBinding binding;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = FragmentMainBinding.inflate(inflater, container, false);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        setHasOptionsMenu(true);

        // Create the adapter that will return a fragment for each section
        FragmentStateAdapter mPagerAdapter = new FragmentStateAdapter(getParentFragmentManager(),
                getViewLifecycleOwner().getLifecycle()) {
            private final Fragment[] mFragments = new Fragment[]{
                    new RecentPostsFragment(),
                    new MyPostsFragment(),
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/listfragments/MyPostsFragment.java
// public class MyPostsFragment extends PostListFragment {
// 
//     public MyPostsFragment() {}
// 
//     @Override
//     public Query getQuery(DatabaseReference databaseReference) {
//         // All my posts
//         return databaseReference.child("user-posts")
//                 .child(getUid());
//     }
// }
// 
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/listfragments/MyTopPostsFragment.java
// public class MyTopPostsFragment extends PostListFragment {
// 
//     public MyTopPostsFragment() {}
// 
//     @Override
//     public Query getQuery(DatabaseReference databaseReference) {
//         // My top posts by number of stars
//         String myUserId = getUid();
//         Query myTopPostsQuery = databaseReference.child("user-posts").child(myUserId)
//                 .orderByChild("starCount");
// 
//         return myTopPostsQuery;
//     }
// }
// 
// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/listfragments/RecentPostsFragment.java
// public class RecentPostsFragment extends PostListFragment {
// 
//     public RecentPostsFragment() {}
// 
//     @Override
//     public Query getQuery(DatabaseReference databaseReference) {
//         // [START recent_posts_query]
//         // Last 100 posts, these are automatically the 100 most recent
//         // due to sorting by push() keys
//         Query recentPostsQuery = databaseReference.child("posts")
//                 .limitToFirst(100);
//         // [END recent_posts_query]
// 
//         return recentPostsQuery;
//     }
// }


// Path: database/app/src/main/java/com/google/firebase/quickstart/database/java/MainFragment.java
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.fragment.NavHostFragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import com.google.android.material.tabs.TabLayoutMediator;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.quickstart.database.R;
import com.google.firebase.quickstart.database.databinding.FragmentMainBinding;
import com.google.firebase.quickstart.database.java.listfragments.MyPostsFragment;
import com.google.firebase.quickstart.database.java.listfragments.MyTopPostsFragment;
import com.google.firebase.quickstart.database.java.listfragments.RecentPostsFragment;

package com.google.firebase.quickstart.database.java;




public class MainFragment extends Fragment {

    private FragmentMainBinding binding;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = FragmentMainBinding.inflate(inflater, container, false);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        setHasOptionsMenu(true);

        // Create the adapter that will return a fragment for each section
        FragmentStateAdapter mPagerAdapter = new FragmentStateAdapter(getParentFragmentManager(),
                getViewLifecycleOwner().getLifecycle()) {
            private final Fragment[] mFragments = new Fragment[]{
                    new RecentPostsFragment(),
                    new MyPostsFragment(),
                    new MyTopPostsFragment(),