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);
}
}
});
}
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);
}
}
});
}
Aggregations