Search in sources :

Example 1 with Category

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

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    // System.out.println("Usuario logeado: " + user.getEmail());
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    setSupportActionBar(binding.appBarMain.toolbar);
    binding.appBarMain.fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
        }
    });
    DrawerLayout drawer = binding.drawerLayout;
    NavigationView navigationView = binding.navView;
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    mAppBarConfiguration = new AppBarConfiguration.Builder(R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow).setOpenableLayout(drawer).build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
    NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
    NavigationUI.setupWithNavController(navigationView, navController);
    // Esto es poner en el nav el nombre del usuario
    View headerView = navigationView.getHeaderView(0);
    TextView navUsername = (TextView) headerView.findViewById(R.id.usernameTextView);
    navUsername.setText(user.getEmail());
    // Insertar menu de BD
    recycler_menu = (RecyclerView) findViewById(R.id.menu);
    recycler_menu.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    recycler_menu.setLayoutManager(layoutManager);
    System.out.print("f");
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    // Read from the database
    listCategory = new ArrayList<>();
    db.collection("Category").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (QueryDocumentSnapshot document : task.getResult()) {
                    Category cat = new Category("", "");
                    cat.setName((String) document.get("Nombre"));
                    cat.setImage((String) document.get("Image"));
                    listCategory.add(cat);
                }
                AdapterCategory adapter = new AdapterCategory(listCategory, new AdapterCategory.OnItemClickListener() {

                    @Override
                    public void onItemClick(Category cat) {
                        moveToDescription(cat);
                    }
                });
                recycler_menu.setAdapter(adapter);
            }
        }
    });
}
Also used : NavigationView(com.google.android.material.navigation.NavigationView) 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) NavController(androidx.navigation.NavController) AdapterCategory(com.example.app_restaurante.Adapter.AdapterCategory) FirebaseUser(com.google.firebase.auth.FirebaseUser) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NavigationView(com.google.android.material.navigation.NavigationView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) TextView(android.widget.TextView) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) AppBarConfiguration(androidx.navigation.ui.AppBarConfiguration)

Example 2 with Category

use of com.example.app_restaurante.Model.Category 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)2 AdapterCategory (com.example.app_restaurante.Adapter.AdapterCategory)2 Category (com.example.app_restaurante.Model.Category)2 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)2 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)2 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)2 View (android.view.View)1 TextView (android.widget.TextView)1 DrawerLayout (androidx.drawerlayout.widget.DrawerLayout)1 NavController (androidx.navigation.NavController)1 AppBarConfiguration (androidx.navigation.ui.AppBarConfiguration)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 AdapterFood (com.example.app_restaurante.Adapter.AdapterFood)1 Food (com.example.app_restaurante.Model.Food)1 NavigationView (com.google.android.material.navigation.NavigationView)1 FirebaseUser (com.google.firebase.auth.FirebaseUser)1