content: package id.merahmuda.bcd;
  
  import android.os.Bundle;
  import android.support.design.widget.BottomNavigationView;
  import android.support.design.widget.NavigationView;
  import android.support.v4.app.Fragment;
  import android.support.v4.view.GravityCompat;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBar;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuItem;
  
  import id.merahmuda.bcd.activity.BaseActivity;
  import id.merahmuda.bcd.fragment.EventFragment;
  import id.merahmuda.bcd.fragment.HomeFragment;
  import id.merahmuda.bcd.fragment.MapFragment;
  
  public class MainActivity extends BaseActivity implements BottomNavigationView.OnNavigationItemSelectedListener, NavigationView.OnNavigationItemSelectedListener{
      Toolbar toolbar;
      BottomNavigationView navigation;
      NavigationView navigationView;
      DrawerLayout drawer;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          findViews();
          initViews();
          initListeners();
      }
  
      @Override
      public void findViews() {
          toolbar = findViewById(R.id.toolbar);
          navigation = findViewById(R.id.navigation);
          navigationView = findViewById(R.id.nav_view);
          drawer = findViewById(R.id.drawer_layout);
  
      }
  
      @Override
      public void initViews() {
          setupToolbar();
          loadFragment(new HomeFragment());
      }
  
      @Override
      public void initListeners() {
          navigation.setOnNavigationItemSelectedListener(this);
          ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                  this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
          drawer.addDrawerListener(toggle);
          toggle.syncState();
          navigationView.setNavigationItemSelectedListener(this);
  
      }
  
      protected void setupToolbar() {
          setSupportActionBar(toolbar);
          ActionBar actionBar = getSupportActionBar();
          if (actionBar != null) {
              actionBar.setDisplayHomeAsUpEnabled(false);
              actionBar.setDisplayShowHomeEnabled(true);
              actionBar.setTitle(R.string.app_name);
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int id = item.getItemId();
  
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      private boolean loadFragment(Fragment fragment) {
          //switching fragment
          if (fragment != null) {
              getSupportFragmentManager()
                      .beginTransaction()
                      .replace(R.id.fragment_container, fragment)
                      .commit();
              return true;
          }
          return false;
      }
  
      @Override
      public void onBackPressed() {
          if (drawer.isDrawerOpen(GravityCompat.START)) {
              drawer.closeDrawer(GravityCompat.START);
          } else {
              super.onBackPressed();
          }
      }
  
      @Override
      public boolean onNavigationItemSelected(MenuItem item) {
          Fragment fragment = null;
  
          switch (item.getItemId()) {
              case R.id.navigation_home:
                  fragment = new HomeFragment();
                  break;
  
              case R.id.navigation_map:
                  fragment = new MapFragment();
                  break;
  
              case R.id.navigation_event:
                  fragment = new EventFragment();
                  break;
          }
  
          return loadFragment(fragment);
      }
  }
  