use of com.google.firebase.firestore.QueryDocumentSnapshot in project FIREBASE_TEST_JAVA by essantos8.
the class ProfileFragment method retrieveInfo.
private void retrieveInfo(Boolean refresh) {
StorageReference userRef = storageRef.child("media/images/profile_pictures/" + currentUser.getUid());
userRef.getMetadata().addOnSuccessListener(storageMetadata -> {
// Snackbar.make(binding.getRoot(), "File exists!", Snackbar.LENGTH_SHORT).show();
if (refresh) {
//
} else {
GlideApp.with(this).load(userRef).signature(new ObjectKey(String.valueOf(storageMetadata.getCreationTimeMillis()))).fitCenter().into(profilePicture);
}
progressBar.setVisibility(View.GONE);
}).addOnFailureListener(e -> {
Log.d("Profile", "retrieveInfo: " + e.toString());
// Snackbar.make(binding.getRoot(), "File does not exist!", Snackbar.LENGTH_SHORT).show();
});
db.collection("users").document(currentUser.getUid()).get().addOnCompleteListener(task -> {
user = task.getResult().toObject(User.class);
binding.textName.setText(user.getFullName());
if (user.getAbout() != "") {
binding.tvdesc.setText(user.getAbout());
}
if (user.getSkills().size() > 0) {
// binding.
}
});
db.collection("users").whereEqualTo("email", mAuth.getCurrentUser().getEmail()).get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
QueryDocumentSnapshot user;
if (!task.getResult().iterator().hasNext()) {
Toast.makeText(getContext(), "User not found in database!", Toast.LENGTH_SHORT).show();
Log.d("Profile", "user not in database");
return;
}
user = task.getResult().iterator().next();
textName.setText(user.getString("fullName"));
textEmail.setText(user.getString("email"));
textPhone.setText(user.getString("phone"));
} else {
Log.d("Profile", "Database error");
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot 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.QueryDocumentSnapshot 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.QueryDocumentSnapshot in project EZMeal by Jake-Sokol2.
the class FeaturedFragmentRepository method retrieveHorizontal.
// returns number of recipes that were actually retrieved
private int retrieveHorizontal(String category, String typeOfRecyclerItem, Task<QuerySnapshot> task) {
Log.i("active categories", "Repository - start of retrieveHorizontal");
// delete all existing featured recipes in SQL
deleteAllRecycler2();
int numRetrieved = 0;
for (QueryDocumentSnapshot document : task.getResult()) {
String imageUrl = document.getString("imageUrl");
String title = document.getString("title");
String highRatedRecipeId = document.getId();
Double highRatedRecipeIdDouble = document.getDouble("recipeId");
Integer highRatedRecipeIdInt = highRatedRecipeIdDouble.intValue();
Double countRating = document.getDouble("countRating");
Double avgRating;
if (countRating != null) {
avgRating = document.getDouble("rating") / countRating;
} else {
countRating = 0.0;
avgRating = 0.0;
}
if (Double.isNaN(avgRating)) {
avgRating = 0.0;
}
Integer totalRating = countRating.intValue();
int sizeOfSet = setOfUniqueHighlyRatedRecipes.size();
setOfUniqueHighlyRatedRecipes.add(highRatedRecipeIdInt);
// the current recipe is not a duplicate - it may be added to the recyclerview
if (sizeOfSet != setOfUniqueHighlyRatedRecipes.size()) {
numRetrieved = numRetrieved + 1;
// viewModel.incrementNumOfRetrievedHighRatedRecipes(1);
HorizontalRecipe newRecipe = new HorizontalRecipe(title, imageUrl, highRatedRecipeId, avgRating);
// add this recipe to the most recently added vertical item
horizontalLists.add(newRecipe);
// horizontalList.add(newRecipe);
RecyclerRecipe2 recyclerRecipePopular2 = new RecyclerRecipe2(category, highRatedRecipeId, title, imageUrl, avgRating, typeOfRecyclerItem, true, totalRating);
insertRecycler2(recyclerRecipePopular2);
}
}
Log.i("active categories", "Repository - end of retrieveHorizontal");
return horizontalLists.size();
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project EZMeal by Jake-Sokol2.
the class FeaturedFragmentRepository method retrieveHorizontalNew.
// returns number of recipes that were actually retrieved
private HorizontalQueryResult retrieveHorizontalNew(String category, String typeOfRecyclerItem, Task<QuerySnapshot> task, HorizontalQueryResult recipeList) {
// delete all existing featured recipes in SQL
deleteAllRecycler2();
int numRetrieved = 0;
for (QueryDocumentSnapshot document : task.getResult()) {
String imageUrl = document.getString("imageUrl");
String title = document.getString("title");
String highRatedRecipeId = document.getId();
Double highRatedRecipeIdDouble = document.getDouble("recipeId");
Integer highRatedRecipeIdInt = highRatedRecipeIdDouble.intValue();
Double countRating = document.getDouble("countRating");
Double avgRating;
if (countRating != null) {
avgRating = document.getDouble("rating") / countRating;
} else {
countRating = 0.0;
avgRating = 0.0;
}
if (Double.isNaN(avgRating)) {
avgRating = 0.0;
}
Integer totalRating = countRating.intValue();
int sizeOfSet = recipeList.getSetOfUniqueRecipes().size();
recipeList.appendSetOfUniqueRecipes(highRatedRecipeIdInt);
// the current recipe is not a duplicate - it may be added to the recyclerview
if ((sizeOfSet != recipeList.getSetOfUniqueRecipes().size())) {
numRetrieved = numRetrieved + 1;
// viewModel.incrementNumOfRetrievedHighRatedRecipes(1);
HorizontalRecipe newRecipe = new HorizontalRecipe(title, imageUrl, highRatedRecipeId, avgRating);
// add this recipe to the most recently added vertical item
recipeList.appendHorizontalRecipeList(newRecipe);
// horizontalList.add(newRecipe);
RecyclerRecipe2 recyclerRecipePopular2 = new RecyclerRecipe2(category, highRatedRecipeId, title, imageUrl, avgRating, typeOfRecyclerItem, true, totalRating);
insertRecycler2(recyclerRecipePopular2);
}
}
return recipeList;
}
Aggregations