content: package com.androidavanzado.duckhuntproject.ui;
  
  import android.content.Context;
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.support.v4.app.Fragment;
  import android.support.v7.widget.GridLayoutManager;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import com.androidavanzado.duckhuntproject.R;
  import com.androidavanzado.duckhuntproject.models.User;
  import com.google.android.gms.tasks.OnCompleteListener;
  import com.google.android.gms.tasks.Task;
  import com.google.firebase.firestore.DocumentChange;
  import com.google.firebase.firestore.DocumentSnapshot;
  import com.google.firebase.firestore.EventListener;
  import com.google.firebase.firestore.FirebaseFirestore;
  import com.google.firebase.firestore.FirebaseFirestoreException;
  import com.google.firebase.firestore.Query;
  import com.google.firebase.firestore.QuerySnapshot;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class UserRankingFragment extends Fragment {
  
      // TODO: Customize parameter argument names
      private static final String ARG_COLUMN_COUNT = "column-count";
      // TODO: Customize parameters
      private int mColumnCount = 1;
      List<User> userList;
      MyUserRecyclerViewAdapter adapter;
      FirebaseFirestore db;
      RecyclerView recyclerView;
  
      public UserRankingFragment() {
      }
  
      // TODO: Customize parameter initialization
      @SuppressWarnings("unused")
      public static UserRankingFragment newInstance(int columnCount) {
          UserRankingFragment fragment = new UserRankingFragment();
          Bundle args = new Bundle();
          args.putInt(ARG_COLUMN_COUNT, columnCount);
          fragment.setArguments(args);
          return fragment;
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          db = FirebaseFirestore.getInstance();
  
          if (getArguments() != null) {
              mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
          }
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_user_list, container, false);
  
          // Set the adapter
          if (view instanceof RecyclerView) {
              Context context = view.getContext();
              recyclerView = (RecyclerView) view;
              if (mColumnCount <= 1) {
                  recyclerView.setLayoutManager(new LinearLayoutManager(context));
              } else {
                  recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
              }
  
              userList = new ArrayList<>();
  
              adapter = new MyUserRecyclerViewAdapter(userList);
              recyclerView.setAdapter(adapter);
  
              db.collection("users")
                      .orderBy("ducks", Query.Direction.DESCENDING)
                      .limit(10)
                      .get()
                      .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                          @Override
                          public void onComplete(@NonNull Task<QuerySnapshot> task) {
                              userList = new ArrayList<>();
                              for(DocumentSnapshot document: task.getResult()) {
                                  User userItem = document.toObject(User.class);
                                  userList.add(userItem);
                              }
  
                              adapter.putUsers(userList);
                          }
                      });
  
  
  
          }
          return view;
      }
  }
  