Search in sources :

Example 31 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project Unknown-food-delivery by a47894785.

the class HomeFragment 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_home, container, false);
    tvCurrentAddress = view.findViewById(R.id.home_frag_address);
    lvShop = view.findViewById(R.id.lv_shop);
    if (getArguments() != null) {
        String currentAddress = this.getArguments().getString("address");
        tvCurrentAddress.setText(currentAddress);
    }
    fAuth = FirebaseAuth.getInstance();
    db = FirebaseFirestore.getInstance();
    userId = fAuth.getCurrentUser().getUid();
    ArrayList<String> shopIdList = new ArrayList<>();
    // 
    db.collection("shops").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            count = String.valueOf(task.getResult().size());
            ArrayList<HomeShopItem> homeShopLists = new ArrayList<>();
            for (QueryDocumentSnapshot document : task.getResult()) {
                Log.d("documents", document.getId() + " => " + document.getData());
                if (document.getData().get("shopName") != "") {
                    shopIdList.add(document.getId());
                    Log.d("documents", String.valueOf(document.getData().get("shopName")));
                    String shopName = String.valueOf(document.getData().get("shopName"));
                    String shopAddress = String.valueOf(document.getData().get("shopAddress"));
                    String shopImgName = String.valueOf(document.getData().get("shopImage"));
                    homeShopLists.add(new HomeShopItem(shopName, shopAddress, shopImgName));
                }
            }
            HomShopAdapter adapter = new HomShopAdapter(getContext(), R.layout.layout_home, homeShopLists);
            lvShop.setAdapter(adapter);
            for (int i = 0; i < shopIdList.size(); i++) {
                Log.d("ShopInfo", shopIdList.get(i));
            }
        }
    });
    lvShop.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int index, long l) {
            String selectedId = shopIdList.get(index);
            ShopInfoFragment shopInfoFragment = new ShopInfoFragment();
            Bundle bundle = new Bundle();
            bundle.putString("shopId", selectedId);
            shopInfoFragment.setArguments(bundle);
            ImageView imBack = getActivity().findViewById(R.id.im_back_arrow);
            EditText etSearch = getActivity().findViewById(R.id.et_search);
            etSearch.setVisibility(View.GONE);
            // imBack.setVisibility(View.VISIBLE);
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.btn_nav_container, shopInfoFragment).commit();
        }
    });
    return view;
}
Also used : EditText(android.widget.EditText) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) HomeShopItem(fcu.app.unknownfooddelivery.item.HomeShopItem) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction) HomShopAdapter(fcu.app.unknownfooddelivery.adapter.HomShopAdapter) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView)

Example 32 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project Unknown-food-delivery by a47894785.

the class ShopInfoFragment 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_shop_info, container, false);
    if (getArguments() != null) {
        shopId = this.getArguments().getString("shopId");
    }
    db = FirebaseFirestore.getInstance();
    imShopImage = view.findViewById(R.id.im_shop_image);
    tvShopName = view.findViewById(R.id.tv_shop_info_name);
    tvShopPhone = view.findViewById(R.id.tv_shop_info_phone);
    lvMenu = view.findViewById(R.id.lv_show_menu);
    DocumentReference documentReference = db.collection("shops").document(shopId);
    documentReference.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {

        @Override
        public void onSuccess(DocumentSnapshot documentSnapshot) {
            if (documentSnapshot.exists()) {
                shopName = documentSnapshot.getString("shopName");
                shopPhone = documentSnapshot.getString("shopPhone");
                shopImgUrl = documentSnapshot.getString("shopImage");
                Picasso.get().load(shopImgUrl).into(imShopImage);
                tvShopName.setText(shopName);
                tvShopPhone.setText(shopPhone);
            }
        }
    });
    db.collection("shops").document(shopId).collection("menu").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            ArrayList<MealItem> mealList = new ArrayList<>();
            for (QueryDocumentSnapshot document : task.getResult()) {
                Log.d("menuInfo", document.getId());
                String mealName = String.valueOf(document.getData().get("mealName"));
                String mealPrice = String.valueOf(document.getData().get("mealPrice"));
                String photoName = String.valueOf(document.getData().get("photoName"));
                mealList.add(new MealItem(mealName, mealPrice, photoName));
            }
            MenuAdapter adapter = new MenuAdapter(getContext(), R.layout.listitem_shop_page, mealList);
            lvMenu.setAdapter(adapter);
        }
    });
    return view;
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) MenuAdapter(fcu.app.unknownfooddelivery.adapter.MenuAdapter) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) MealItem(fcu.app.unknownfooddelivery.item.MealItem) DocumentReference(com.google.firebase.firestore.DocumentReference)

Example 33 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project M3 by iatharva.

the class SeeRanking method getUserList.

private void getUserList() {
    db.collection("Users").get().addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            List<String> usersList = new ArrayList<>();
            List<String> usersNameList = new ArrayList<>();
            for (QueryDocumentSnapshot document : task.getResult()) {
                usersList.add(document.getId());
                usersNameList.add(document.getString("FName") + " " + document.getString("LName"));
            }
            getCounts(usersList, usersNameList);
            Log.d(TAG, usersList.toString());
        } else {
            Log.d(TAG, "Error getting documents: ", task.getException());
        }
    });
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList)

Example 34 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project AlphaTour by Frank99DG.

the class CreateConstraintsWizard method saveObjects.

/*public boolean inputControl(String Prova){

        Boolean errorFlag = false;

        if (Prova.isEmpty()) {
            prova.setError(getString(R.string.campo_obbligatorio));
            prova.requestFocus();
            errorFlag = true;
        }

        return errorFlag;

    }*/
private void saveObjects(List<Element> elementlist) {
    db.collection("Zones").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (int i = 0; i < elementlist.size(); i++) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        Element newElement = elementlist.get(i);
                        Zone zon = document.toObject(Zone.class);
                        if (zon.getName().matches(newElement.getZoneRif())) {
                            newElement.setIdZone(document.getId());
                            id = generateidPhotoAndQrCode();
                            elm.put("idZone", newElement.getIdZone());
                            elm.put("title", newElement.getTitle());
                            elm.put("description", newElement.getDescription());
                            elm.put("photo", null);
                            elm.put("qrCode", null);
                            elm.put("idPhotoAndQrCode", id);
                            elm.put("idUser", user.getUid());
                            elm.put("qrData", newElement.getQrData());
                            db.collection("Elements").add(elm).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {

                                @Override
                                public void onSuccess(DocumentReference documentReference) {
                                    success = true;
                                // String id=documentReference.getId();
                                }
                            });
                            savePhoto(newElement.getPhoto(), newElement, i, id);
                            saveQrCode(newElement.getQrCode(), newElement, i, id);
                        }
                    }
                }
            }
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            success = false;
            Toast.makeText(getContext(), "Non è stato possibile salvare le zone e gli oggetti creati!!!", Toast.LENGTH_LONG).show();
        }
    });
}
Also used : OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) UploadTask(com.google.firebase.storage.UploadTask) Task(com.google.android.gms.tasks.Task) StorageTask(com.google.firebase.storage.StorageTask) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) Zone(com.example.alphatour.oggetti.Zone) NonNull(androidx.annotation.NonNull) Element(com.example.alphatour.oggetti.Element) Constraint(com.example.alphatour.oggetti.Constraint) DocumentReference(com.google.firebase.firestore.DocumentReference) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 35 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project AlphaTour by Frank99DG.

the class Step3 method setUserVisibleHint.

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (isVisibleToUser) {
        zone_selected.setText(DashboardActivity.getZona_scelta());
        String scelta = DashboardActivity.getZona_scelta();
        db.collection("Zones").whereEqualTo("name", scelta).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        String idZone = document.getId();
                        db.collection("Elements").whereEqualTo("idZone", idZone).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

                            @Override
                            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                                if (task.isSuccessful()) {
                                    for (QueryDocumentSnapshot document : task.getResult()) {
                                        ElementString element = document.toObject(ElementString.class);
                                        View object = getLayoutInflater().inflate(R.layout.row_selection_zones_elements, null, false);
                                        CheckableTextView textZone1 = (CheckableTextView) object.findViewById(R.id.textObjectss);
                                        textZone1.setText(element.getTitle());
                                        arrayStringElement.add(element.getTitle());
                                        // arrayObjectElement.add(element);
                                        arrayMonumenti.add(textZone1);
                                        delete_view.add(object);
                                        list_object.addView(object);
                                    }
                                } else {
                                    Toast.makeText(getContext(), "Non è stato possibile caricare le zone !!!", Toast.LENGTH_LONG).show();
                                }
                            }
                        });
                    }
                } else {
                    Toast.makeText(getContext(), "Non è stato possibile caricare le zone !!!", Toast.LENGTH_LONG).show();
                }
            }
        });
    } else {
    }
}
Also used : OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) Task(com.google.android.gms.tasks.Task) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) CheckableTextView(com.devzone.checkabletextview.CheckableTextView) NonNull(androidx.annotation.NonNull) ElementString(com.example.alphatour.oggetti.ElementString) ElementString(com.example.alphatour.oggetti.ElementString) View(android.view.View) CheckableTextView(com.devzone.checkabletextview.CheckableTextView) TextView(android.widget.TextView) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

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