package io.exponential.mdnavigationview;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends AppCompatActivity implements MainFragment.Callbacks {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (findViewById(R.id.container) != null) {

            // Return immediately if the activity is being restored from a previous state so that
            // we avoid overlapping fragment instances.
            if (savedInstanceState != null) {
                return;
            }

            getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.container, MainFragment.newInstance("Placeholder"))
                .commit();
        }
    }


    @Override
    protected void onStart() {
        super.onStart();

        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void passDataToActivity(String data) {
        // Do nothing yet...
    }
}

@@ -61,16 +61,162 @@
 Bundle;%0A
+import android.support.design.widget.NavigationView;%0Aimport android.support.v4.view.GravityCompat;%0Aimport android.support.v4.widget.DrawerLayout;%0A
 import a
@@ -482,24 +482,64 @@
 allbacks %7B%0A%0A
+    private DrawerLayout drawerLayout;%0A%0A
     @Overrid
@@ -762,26 +762,61 @@
  // 
-Return immediately
+Guard against creating overlapping fragment instances
  if 
@@ -836,16 +836,31 @@
 is being
+%0A            //
  restore
@@ -886,197 +886,602 @@
 tate
- so that%0A            // we avoid overlapping f
+.%0A            if (savedInstanceState == null) %7B%0A                getSupportFragmentManager()%0A                    .beginTransaction()%0A                    .add(R.id.container, MainF
 ragment
- i
+.newI
 nstance
-s.%0A            if (savedInstanceState != null) %7B%0A                return;%0A            %7D%0A%0A            getSupportFragmentManag
+(%22Placeholder%22))%0A                    .commit();%0A            %7D%0A        %7D%0A%0A        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);%0A        NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);%0A%0A        // Define an event listener via an anonymous class%0A        if (navigationView != null) %7B%0A            navigationView.setNavigationItemSelectedListen
 er(
-)
 %0A   
@@ -1497,130 +1497,579 @@
     
-.beginTransaction()%0A                .add(R.id.container, MainFragment.newInstance(%22Placeholder%22))%0A                .commit(
+new NavigationView.OnNavigationItemSelectedListener() %7B%0A                    @Override%0A                    public boolean onNavigationItemSelected(MenuItem menuItem) %7B%0A                        // Set the selected menu item in the drawer to checked%0A                        menuItem.setChecked(true);%0A                        // Close the NavigationView drawer%0A                        drawerLayout.closeDrawers();%0A                        // Inform Android that we have handled the event%0A                        return true;%0A                    %7D%0A                %7D%0A            
 );%0A 
@@ -3052,89 +3052,315 @@
     
-//noinspection SimplifiableIfStatement%0A        if (id == R.id.action_settings) %7B%0A
+switch(id) %7B%0A            case android.R.id.home:%0A                // Open the NavigationView drawer when the home icon is clicked%0A                drawerLayout.openDrawer(GravityCompat.START);%0A                return true;%0A            case R.id.action_settings:%0A                // TODO: Implement settings%0A    
     

add DrawerLayout in MainActivity