Search in sources :

Example 1 with AdapterCategory

use of com.example.app_restaurante.Adapter.AdapterCategory 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)

Aggregations

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 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 AdapterCategory (com.example.app_restaurante.Adapter.AdapterCategory)1 Category (com.example.app_restaurante.Model.Category)1 NavigationView (com.google.android.material.navigation.NavigationView)1 FirebaseUser (com.google.firebase.auth.FirebaseUser)1 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)1