Search in sources :

Example 1 with Food

use of com.example.app_restaurante.Model.Food in project MDA_APP_RESTAURANTE by karlaogh99.

the class FoodListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_food_list);
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    // Read from the database
    listFood = new ArrayList<>();
    recycler_menu = (RecyclerView) findViewById(R.id.recycler_food);
    recycler_menu.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    recycler_menu.setLayoutManager(layoutManager);
    db.collection("Food").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful() && getIntent() != null) {
                Category catId = (Category) getIntent().getSerializableExtra("Categoria");
                for (QueryDocumentSnapshot document : task.getResult()) {
                    if (catId.getName().equals((String) document.get("IdCategoria"))) {
                        Food food = new Food("", "", "", "", "");
                        food.setName((String) document.get("Nombre"));
                        food.setDescripcion((String) document.get("Descripcion"));
                        food.setId((String) document.get("IdCategoria"));
                        food.setPrice((String) document.get("Precio"));
                        food.setImage((String) document.get("Image"));
                        listFood.add(food);
                    }
                }
                AdapterFood adapter = new AdapterFood(listFood);
                recycler_menu.setAdapter(adapter);
            }
        }
    });
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) Category(com.example.app_restaurante.Model.Category) AdapterCategory(com.example.app_restaurante.Adapter.AdapterCategory) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) AdapterFood(com.example.app_restaurante.Adapter.AdapterFood) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) AdapterFood(com.example.app_restaurante.Adapter.AdapterFood) Food(com.example.app_restaurante.Model.Food)

Aggregations

LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 AdapterCategory (com.example.app_restaurante.Adapter.AdapterCategory)1 AdapterFood (com.example.app_restaurante.Adapter.AdapterFood)1 Category (com.example.app_restaurante.Model.Category)1 Food (com.example.app_restaurante.Model.Food)1 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)1