package com.example.jourdanrodrigues.controk;

import android.app.Fragment;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.example.jourdanrodrigues.controk.Client.ClientListFragment;

public class MainActivity extends AppCompatActivity implements BaseFragment.OnFragmentInteractionListener {
    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;

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

        String[] menuEntries = getResources().getStringArray(R.array.menu_entries);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        mDrawerList.setAdapter(new ArrayAdapter<>(this, R.layout.drawer_list_item, menuEntries));
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close);

        mDrawerLayout.addDrawerListener(mDrawerToggle);

        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeButtonEnabled(true);
        }
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

    private class DrawerItemClickListener implements ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }

        private void selectItem(int position) {
            // update the main content by replacing fragments
            if (position == ClientListFragment.ARG_MENU_POSITION) {
                setFragmentManager(new ClientListFragment());
            } else if (position == EmployeeFragment.ARG_MENU_POSITION) {
                setFragmentManager(new EmployeeFragment());
            } else if (position == SupplierFragment.ARG_MENU_POSITION) {
                setFragmentManager(new SupplierFragment());
            } else if (position == ProductFragment.ARG_MENU_POSITION) {
                setFragmentManager(new ProductFragment());
            } else if (position == StockFragment.ARG_MENU_POSITION) {
                setFragmentManager(new StockFragment());
            }

            mDrawerList.setItemChecked(position, true);
            mDrawerLayout.closeDrawer(mDrawerList);
        }

        private void setFragmentManager(Fragment fragment) {
            getFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return mDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
    }

    @Override
    public void onFragmentInteraction(String string) {

    }
}

@@ -2463,35 +2463,38 @@
             
-set
+update
 Fragment
 Manager(new 
@@ -2477,31 +2477,24 @@
 dateFragment
-Manager
 (new ClientL
@@ -2594,35 +2594,38 @@
             
-set
+update
 Fragment
 Manager(new 
@@ -2608,31 +2608,24 @@
 dateFragment
-Manager
 (new Employe
@@ -2723,35 +2723,38 @@
             
-set
+update
 Fragment
 Manager(new 
@@ -2737,31 +2737,24 @@
 dateFragment
-Manager
 (new Supplie
@@ -2851,35 +2851,38 @@
             
-set
+update
 Fragment
 Manager(new 
@@ -2865,31 +2865,24 @@
 dateFragment
-Manager
 (new Product
@@ -2980,27 +2980,30 @@
         
-set
+update
 Fragment
 Manager(
@@ -2994,23 +2994,16 @@
 Fragment
-Manager
 (new Sto
@@ -3142,37 +3142,39 @@
 ist);%0A        %7D%0A
-%0A
     
+%7D%0A%0A
     private void
@@ -3178,19 +3178,22 @@
 oid 
-set
+update
 Fragment
 Mana
@@ -3188,23 +3188,16 @@
 Fragment
-Manager
 (Fragmen
@@ -3206,28 +3206,24 @@
 fragment) %7B%0A
-    
         getF
@@ -3306,26 +3306,16 @@
 mmit();%0A
-        %7D%0A
     %7D%0A%0A 

Change "setFragmentManager" to "updateFragment".