Search in sources :

Example 56 with QueryDocumentSnapshot

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");
        }
    });
}
Also used : SplashActivity(com.example.flashgig.activities.SplashActivity) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) User(com.example.flashgig.models.User) ImageView(android.widget.ImageView) Intent(android.content.Intent) RequestListener(com.bumptech.glide.request.RequestListener) ReviewsActivity(com.example.flashgig.activities.ReviewsActivity) Drawable(android.graphics.drawable.Drawable) GlideException(com.bumptech.glide.load.engine.GlideException) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Fragment(androidx.fragment.app.Fragment) FragmentProfileBinding(com.example.flashgig.databinding.FragmentProfileBinding) View(android.view.View) JobAdderFragment(com.example.flashgig.JobAdderFragment) Log(android.util.Log) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) FirebaseStorage(com.google.firebase.storage.FirebaseStorage) GlideApp(com.example.flashgig.GlideApp) LayoutInflater(android.view.LayoutInflater) DataSource(com.bumptech.glide.load.DataSource) Target(com.bumptech.glide.request.target.Target) FirebaseUser(com.google.firebase.auth.FirebaseUser) R(com.example.flashgig.R) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ViewGroup(android.view.ViewGroup) ObjectKey(com.bumptech.glide.signature.ObjectKey) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) StorageReference(com.google.firebase.storage.StorageReference) User(com.example.flashgig.models.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) StorageReference(com.google.firebase.storage.StorageReference) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ObjectKey(com.bumptech.glide.signature.ObjectKey)

Example 57 with QueryDocumentSnapshot

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");
                            }
                        }
                    });
                }
            }
        }
    });
}
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 58 with QueryDocumentSnapshot

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;
}
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 59 with QueryDocumentSnapshot

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();
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) HorizontalRecipe(com.example.ezmeal.FindRecipes.FindRecipesModels.HorizontalRecipe) RecyclerRecipe2(com.example.ezmeal.roomDatabase.RecyclerRecipe2)

Example 60 with QueryDocumentSnapshot

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;
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) HorizontalRecipe(com.example.ezmeal.FindRecipes.FindRecipesModels.HorizontalRecipe) RecyclerRecipe2(com.example.ezmeal.roomDatabase.RecyclerRecipe2)

Aggregations

QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)73 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)33 ArrayList (java.util.ArrayList)30 View (android.view.View)22 NonNull (androidx.annotation.NonNull)19 Task (com.google.android.gms.tasks.Task)18 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)17 Intent (android.content.Intent)16 CollectionReference (com.google.firebase.firestore.CollectionReference)13 AdapterView (android.widget.AdapterView)12 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)12 TextView (android.widget.TextView)10 Bundle (android.os.Bundle)9 ListView (android.widget.ListView)9 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)9 FirebaseFirestoreException (com.google.firebase.firestore.FirebaseFirestoreException)8 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)7 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)6 FirebaseUser (com.google.firebase.auth.FirebaseUser)6 DocumentReference (com.google.firebase.firestore.DocumentReference)6