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();
}
});
}
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);
}
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");
}
}
});
}
}
}
});
}
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;
}
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;
}
Aggregations