Search in sources :

Example 26 with CollectionReference

use of com.google.firebase.firestore.CollectionReference in project turtleparties by CMPUT301W22T21.

the class LeaderboardActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.leaderboards_screen);
    db = FirebaseFirestore.getInstance();
    PlayerController pc = new PlayerController();
    final CollectionReference collectionReference = db.collection("Users");
    identifyAllButtons();
    choosePrompt.setVisibility(View.VISIBLE);
    highestSumMap = new HashMap<>();
    highestQRScanMap = new HashMap<>();
    highestScoreMap = new HashMap<>();
    scoresList = new ArrayList<>();
    peopleNames = new ArrayList<>();
    personAdapter = new LeaderboardAdapter(this, peopleNames, scoresList, currentUser);
    leaderboardList.setAdapter(personAdapter);
    collectionReference.addSnapshotListener(new EventListener<QuerySnapshot>() {

        @Override
        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException error) {
            highestSumMap = pc.getLeaderboardStatsFromFireBase("sum");
            highestScoreMap = pc.getLeaderboardStatsFromFireBase("score");
            highestQRScanMap = pc.getLeaderboardStatsFromFireBase("qr");
            // pc.getLeaderboardStatsFromFireBase(highestQRScanMap,highestScoreMap,highestSumMap);
            personAdapter.notifyDataSetChanged();
        }
    });
}
Also used : FirebaseFirestoreException(com.google.firebase.firestore.FirebaseFirestoreException) CollectionReference(com.google.firebase.firestore.CollectionReference) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

Example 27 with CollectionReference

use of com.google.firebase.firestore.CollectionReference in project InClassDemo by KyleBastien.

the class FirebaseTodoModel method addTodoItem.

public void addTodoItem(TodoItem item) {
    CollectionReference todoItemsRef = db.collection("todoItems");
    todoItemsRef.add(item);
}
Also used : CollectionReference(com.google.firebase.firestore.CollectionReference)

Example 28 with CollectionReference

use of com.google.firebase.firestore.CollectionReference in project EZMeal by Jake-Sokol2.

the class GroupListsFragmentModel method fillGroceryList.

public void fillGroceryList() {
    // String currentListName = groupList.get(getCurrentSelected());
    String currentListName = "Tristan";
    // List<List<String>> tmpListOfLists = new ArrayList<>();
    String email = mAuth.getCurrentUser().getEmail();
    db.collection("Groups").whereEqualTo("ListName", currentListName).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                if (task.getResult().getDocuments().size() > 0) {
                    DocumentSnapshot tmpDoc = task.getResult().getDocuments().get(0);
                    String tmpDocName = tmpDoc.getId();
                    CollectionReference dbShoppingList = db.collection("Groups").document(tmpDocName).collection("Items");
                    dbShoppingList.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

                        @Override
                        public void onComplete(@NonNull Task<QuerySnapshot> task) {
                            if (task.isSuccessful()) {
                                for (QueryDocumentSnapshot docBoi : task.getResult()) {
                                    List<String> tmpList = new ArrayList<>();
                                    brandName = docBoi.getString("brand");
                                    itemName = docBoi.getString("name");
                                    tmpList.add(itemName);
                                    tmpList.add(brandName);
                                    tmpList.add("1");
                                    shoppingList.add(tmpList);
                                }
                                Log.i("Query", "Finished filling shopping list");
                            }
                        }
                    });
                }
            }
        }
    });
}
Also used : Task(com.google.android.gms.tasks.Task) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) CollectionReference(com.google.firebase.firestore.CollectionReference) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) NonNull(androidx.annotation.NonNull)

Example 29 with CollectionReference

use of com.google.firebase.firestore.CollectionReference in project EZMeal by Jake-Sokol2.

the class AddListItemRepository method getDataFirebase.

public void getDataFirebase(GetItemCallBack aCallback, String groupListName) {
    /*
        sqlDb.testDao().updateAllIdentifiersIsNotActive();

        String email = mAuth.getCurrentUser().getEmail();
        db.collection("Items")
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>()
                {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task)
                    {
                        List<List<String>> tmpListList = new ArrayList<List<String>>();
                        if (task.isSuccessful())
                        {
                            for (QueryDocumentSnapshot document : task.getResult())
                            {
                                Log.d("MYDEBUG", document.getId() + " => " + document.getData());
                                brandName = document.getString("brand");
                                itemName = document.getString("name");
                                //quantity = document.getDouble("quantity");
                                if (Objects.equals(document.getString("user"), email))
                                {
                                    doSomething();
                                    for (String identifier:identifiers)
                                    {
                                        if(brandName!= null) {
                       Í                     if (brandName.toLowerCase().contains(identifier)) {
                                                // mark the identifier as active - tells Find Recipes to query recipes for the category belonging to this identifier
                                                sqlDb.testDao().updateIdentifierIsActive(identifier);

                                            }
                                        }
                                    }
                                    List<String> tmpList = new ArrayList<>();
                                    tmpList.add(itemName);
                                    tmpList.add(brandName);
                                    tmpList.add("1");
                                    tmpListList.add(tmpList);
                                }

                            }
                        }
                        else
                        {
                            Log.w("MYDEBUG", "Error getting documents.", task.getException());
                        }

                        beep.callback(tmpListList);
                    }
                });

        */
    List<List<String>> tmpListOfLists = new ArrayList<List<String>>();
    String email = mAuth.getCurrentUser().getEmail();
    db.collection("Groups").whereEqualTo("ListName", groupListName).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                if (task.getResult().getDocuments().size() > 0) {
                    DocumentSnapshot tmpDoc = task.getResult().getDocuments().get(0);
                    String tmpDocName = tmpDoc.getId();
                    CollectionReference dbShoppingList = db.collection("Groups").document(tmpDocName).collection("Items");
                    dbShoppingList.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

                        @Override
                        public void onComplete(@NonNull Task<QuerySnapshot> task) {
                            if (task.isSuccessful()) {
                                for (QueryDocumentSnapshot docBoi : task.getResult()) {
                                    // add the items (sub documents) to a list and return it as the shopping list
                                    List<String> tmpList = new ArrayList<>();
                                    brandName = docBoi.getString("brand");
                                    itemName = docBoi.getString("name");
                                    tmpList.add(itemName);
                                    tmpList.add(brandName);
                                    tmpList.add("1");
                                    tmpListOfLists.add(tmpList);
                                // tmpList.clear();
                                }
                            } else {
                                Log.i("Retrieval", "Error getting documents", task.getException());
                            }
                            aCallback.onCallback(tmpListOfLists);
                        }
                    });
                } else {
                    Log.i("Retrieval", "There are no lists for some reason.");
                }
            }
        }
    });
// return tmpListOfLists;
}
Also used : Task(com.google.android.gms.tasks.Task) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) CollectionReference(com.google.firebase.firestore.CollectionReference) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List)

Example 30 with CollectionReference

use of com.google.firebase.firestore.CollectionReference in project EZMeal by Jake-Sokol2.

the class FindRecipesFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_group_recipes, container, false);
    viewModel = new ViewModelProvider(requireActivity()).get(FindRecipesViewModel.class);
    rvHorizontal = (RecyclerView) view.findViewById(R.id.rvHorizontalSelector);
    RecyclerView.LayoutManager horizontalLayoutManager = new LinearLayoutManager(this.getActivity(), LinearLayoutManager.HORIZONTAL, false);
    rvHorizontal.setLayoutManager(horizontalLayoutManager);
    // horizontalAdapter = new FindRecipesFragmentHorizontalRecyclerAdapter(findRecipesFragmentModel.getCategoryList(), findRecipesFragmentModel.getIsSelectedList());
    horizontalAdapter = new FindRecipesFragmentHorizontalRecyclerAdapter(categories, isSelected);
    // horizontalAdapter.setData(model.getCategoryList(), model.getIsSelectedList());
    rvHorizontal.setAdapter(horizontalAdapter);
    viewModel.getHorizontalRecyclerModel().observe(getViewLifecycleOwner(), model -> {
        categories = model.getCategoryList();
        isSelected = model.getIsSelectedList();
        horizontalAdapter.setData(model.getCategoryList(), model.getIsSelectedList());
        horizontalAdapter.notifyDataSetChanged();
    });
    if (savedInstanceState == null) {
        FindRecipesFragmentModel fm = new FindRecipesFragmentModel();
        List<String> categoryList = new ArrayList<String>();
        List<Boolean> isSelectedList = new ArrayList<Boolean>();
        fm.setCategoryList(categoryList);
        fm.setIsSelectedList(isSelectedList);
        viewModel.setHorizontalRecyclerModel(fm);
        /*Fragment oldFragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainerView4);
                if (oldFragment instanceof FeaturedFragment)
                {
                    ((FeaturedFragment) oldFragment).cleanUpFragmentInstanceState();
                }*/
        // categories.add("Featured");
        // findRecipesFragmentModel.addItem(categories.get(0), true);
        db = FirebaseFirestore.getInstance();
        // todo: RecipesRating
        CollectionReference dbRecipes = db.collection("Recipes");
        db.collection("RecipeCategoryRatingList").document("categories").get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {

            @Override
            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                viewModel.addItem("Featured", true);
                categories = (ArrayList<String>) task.getResult().get("categories");
                for (int i = 0; i < categories.size(); i++) {
                    viewModel.addItem(categories.get(i), false);
                // findRecipesFragmentModel.addItem(categories.get(i), false);
                }
                // retrieve categories from SQL here
                horizontalAdapter.notifyDataSetChanged();
            }
        });
    } else {
    // viewModel.getListSize();
    // horizontalAdapter = viewModel.getHorizontalRecyclerModel().getValue();
    }
    return view;
}
Also used : FindRecipesViewModel(com.example.ezmeal.FindRecipes.FindRecipesViewModels.FindRecipesViewModel) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CollectionReference(com.google.firebase.firestore.CollectionReference) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) RecyclerView(androidx.recyclerview.widget.RecyclerView) FindRecipesFragmentHorizontalRecyclerAdapter(com.example.ezmeal.FindRecipes.FindRecipesAdapters.FindRecipesFragmentHorizontalRecyclerAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider) FindRecipesFragmentModel(com.example.ezmeal.FindRecipes.FindRecipesModels.FindRecipesFragmentModel)

Aggregations

CollectionReference (com.google.firebase.firestore.CollectionReference)43 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)15 Intent (android.content.Intent)14 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)14 View (android.view.View)13 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)13 NonNull (androidx.annotation.NonNull)10 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)10 DocumentReference (com.google.firebase.firestore.DocumentReference)10 FirebaseFirestoreException (com.google.firebase.firestore.FirebaseFirestoreException)10 ArrayList (java.util.ArrayList)8 Bundle (android.os.Bundle)7 ListView (android.widget.ListView)7 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)7 AdapterView (android.widget.AdapterView)6 TextView (android.widget.TextView)6 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)5 Task (com.google.android.gms.tasks.Task)5 List (java.util.List)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)4