content: package com.example.munche;
  
  import android.content.Intent;
  import android.os.Build;
  import android.os.Bundle;
  import android.view.View;
  import android.view.Window;
  import android.view.WindowManager;
  
  import androidx.annotation.Nullable;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.core.content.ContextCompat;
  import androidx.fragment.app.Fragment;
  
  import com.google.android.material.bottomnavigation.BottomNavigationView;
  import com.google.firebase.auth.FirebaseAuth;
  import com.google.firebase.auth.FirebaseUser;
  
  import java.util.List;
  import java.util.Objects;
  
  import fragments.FavouriteFragment;
  import fragments.MyProfileFragment;
  import fragments.RestaurantFragment;
  import fragments.SearchFragment;
  import ui.auth.LoginActivity;
  
  public class MainActivity extends AppCompatActivity {
  
      private FirebaseUser mCurrentUser;
      private BottomNavigationView bottomNav;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          changestatusbarcolor();
          init();
          bottomNav = findViewById(R.id.bottom_navigation);
          bottomNav.setOnNavigationItemSelectedListener(navListener);
          getSupportFragmentManager().beginTransaction()
                  .replace(R.id.fragmentContainer, new RestaurantFragment())
                  .commit();
      }
  
      private void init() {
          FirebaseAuth mAuth = FirebaseAuth.getInstance();
          mCurrentUser = mAuth.getCurrentUser();
      }
  
      private void changestatusbarcolor() {
          Window window = this.getWindow();
          window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
          window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
          window.setStatusBarColor(ContextCompat.getColor(this, R.color.white));
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
              getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
          }
      }
  
      private BottomNavigationView.OnNavigationItemSelectedListener navListener =
              item -> {
                  Fragment selectedFragment = null;
                  switch (item.getItemId()) {
                      case R.id.nav_restaurants:
                          selectedFragment = new RestaurantFragment();
                          break;
                      case R.id.nav_search:
                          selectedFragment = new SearchFragment();
                          break;
                      case R.id.nav_favourites:
                          selectedFragment = new FavouriteFragment();
                          break;
                      case R.id.nav_profile:
                         selectedFragment = new MyProfileFragment();
                          break;
                      case R.id.imageBadgeView:
                          bottomNav.setVisibility(View.GONE);
                          break;
  
                  }
                  getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainer,
                          Objects.requireNonNull(selectedFragment)).commit();
                  return true;
              };
  
      private void sendUserToLogin() {
          Intent intent = new Intent(this, LoginActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
          startActivity(intent);
          finish();
      }
      @Override
      protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          List<Fragment> fragments = getSupportFragmentManager().getFragments();
          for (Fragment f : fragments) {
              if (f instanceof MyProfileFragment) {
                  f.onActivityResult(requestCode, resultCode, data);
              }
          }
      }
      @Override
      protected void onStart() {
          super.onStart();
          if (mCurrentUser == null) {
              sendUserToLogin();
          }
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
      }
  }
  