package com.uwflow.flow_android;

import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.uwflow.flow_android.adapters.NavDrawerAdapter;
import com.uwflow.flow_android.entities.NavDrawerItem;
import com.uwflow.flow_android.fragment.AboutFragment;
import com.uwflow.flow_android.fragment.ExploreFragment;
import com.uwflow.flow_android.fragment.ProfileFragment;
import com.uwflow.flow_android.fragment.ShortlistFragment;
import com.uwflow.flow_android.network.FlowDatabaseLoader;

import java.util.ArrayList;
import java.util.List;

public class MainFlowActivity extends FlowActivity {
    private ListView mDrawerList;
    private DrawerLayout mDrawerLayout;
    private ActionBarDrawerToggle mDrawerToggle;
    private NavDrawerAdapter mNavDrawerAdapter;
    private ArrayList<NavDrawerItem> mDrawerItems;
    private String [] LIST_VALUE = {"Profile", "Explore", "Shortlist", "About"};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.flow_main);

        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerItems = new ArrayList<NavDrawerItem>();
        mDrawerItems.add(new NavDrawerItem("Profile", R.drawable.drawer_profile_icon));
        mDrawerItems.add(new NavDrawerItem("Explore", R.drawable.drawer_explore_icon));
        mDrawerItems.add(new NavDrawerItem("Shortlist", R.drawable.drawer_shortlist_icon));
        mDrawerItems.add(new NavDrawerItem("About", R.drawable.drawer_about_icon));

        mNavDrawerAdapter = new NavDrawerAdapter(mDrawerItems, this);
        mDrawerList.setAdapter(mNavDrawerAdapter);

        ArrayList<String> listValue = new ArrayList<String>();
        for (String s : LIST_VALUE){
            listValue.add(s);
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, listValue);
        mDrawerList.setAdapter(adapter);

        mDrawerToggle = new ActionBarDrawerToggle(
                this,
                mDrawerLayout,
                R.drawable.ic_drawer_am,
                R.string.drawer_open,
                R.string.drawer_close
        ) {
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);

            }
            public void onDrawerOpened(View view) {
                super.onDrawerOpened(view);
            }
        };

        // Set the drawer toggle as the DrawerListener
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        Fragment profileFrag = new ProfileFragment();

        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                .add(R.id.content_frame, profileFrag)
                .commit();

        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
        mDrawerList.setItemChecked(0, true);
    }

    /**
     * When using the ActionBarDrawerToggle, you must call it during
     * onPostCreate() and onConfigurationChanged()...
     */

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggls
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

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

    @Override
    public void setTitle(CharSequence title) {
        getActionBar().setTitle(title);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // The action bar home/up action should open or close the drawer.
        // ActionBarDrawerToggle will take care of this.
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        // Handle action buttons
        switch(item.getItemId()) {
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    /** Swaps fragments in the main content view */
    private void selectItem(int position) {
        // Create a new fragment and specify the planet to show based on position
        Fragment fragment = null;
        switch (position){
            case(0) : fragment = new ProfileFragment();break;
            case(1) : fragment = new ExploreFragment();break;
            case(2) : fragment = new ShortlistFragment();break;
            case(3) : fragment = new AboutFragment();break;
        }

        if (fragment != null){
            FragmentManager fragmentManager = getSupportFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.content_frame, fragment)
                    .commit();
            mDrawerList.setItemChecked(position, true);
            mDrawerLayout.closeDrawer(mDrawerList);
        }
    }
}

@@ -286,33 +286,8 @@
 ut;%0A
-import android.util.Log;%0A
 impo
@@ -308,24 +308,24 @@
 w.MenuItem;%0A
+
 import andro
@@ -785,67 +785,8 @@
 ent;
-%0Aimport com.uwflow.flow_android.network.FlowDatabaseLoader;
 %0A%0Aim
@@ -814,31 +814,8 @@
 ist;
-%0Aimport java.util.List;
 %0A%0Apu
@@ -1091,90 +1091,8 @@
 ms;%0A
-    private String %5B%5D LIST_VALUE = %7B%22Profile%22, %22Explore%22, %22Shortlist%22, %22About%22%7D;%0A%0A
     
@@ -1857,24 +1857,24 @@
 ems, this);%0A
+
         mDra
@@ -1917,325 +1917,8 @@
 );%0A%0A
-        ArrayList%3CString%3E listValue = new ArrayList%3CString%3E();%0A        for (String s : LIST_VALUE)%7B%0A            listValue.add(s);%0A        %7D%0A        ArrayAdapter%3CString%3E adapter = new ArrayAdapter%3CString%3E(this,%0A                android.R.layout.simple_list_item_1, listValue);%0A        mDrawerList.setAdapter(adapter);%0A%0A
     

fix flow activity