package com.azhuoinfo.cqurity.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.azhuoinfo.cqurity.AccountVerify;
import com.azhuoinfo.cqurity.R;
import com.azhuoinfo.cqurity.view.ActionTabManager;

import mobi.cangol.mobile.actionbar.ActionMenu;
import mobi.cangol.mobile.actionbar.ActionMenuItem;
import mobi.cangol.mobile.actionbar.ActionTab;
import mobi.cangol.mobile.actionbar.ActionTabItem;
import mobi.cangol.mobile.actionbar.view.ActionTabView;
import mobi.cangol.mobile.base.BaseContentFragment;
import mobi.cangol.mobile.base.FragmentInfo;

public class DiscoveryFragment extends BaseContentFragment {
	private AccountVerify mAccountVerify;
    private ActionTabManager mActionTabManager;
    private ActionTab mActionTab;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mAccountVerify = AccountVerify.getInstance(getActivity());
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		View v = inflater.inflate(R.layout.fragment_discovery, container, false);
		return v;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		findViews(view);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		initViews(savedInstanceState);
		initData(savedInstanceState);
	}

	@Override
	protected void findViews(View view) {
        mActionTabManager=new ActionTabManager(this.getActivity(),this.getChildFragmentManager(),R.id.layout_discovery);
        mActionTab=this.getCustomActionBar().createdActionTab();
	}
	
	@Override
	protected void initViews(Bundle savedInstanceState) {
		this.setTitle(R.string.title_discovery);
        mActionTabManager.addTab(mActionTab.newTab(1, getString(R.string.title_project), 1).getId(), ProjectFragment.class, "ProjectFragment", null);
        mActionTabManager.addTab(mActionTab.newTab(2, getString(R.string.title_people), 0).getId(), PeopleFragment.class, "PeopleFragment", null);
        mActionTab.setOnTabSelectedListener(new ActionTabView.OnTabSelectedListener() {
			@Override
			public boolean onTabSelected(ActionTabItem tab) {
				mActionTabManager.setTabSelected("" + tab.getId());
				return true;
			}
		});

	}

	@Override
	protected void initData(Bundle savedInstanceState) {
		
	}
    @Override
    public void onDestroyView() {
        getCustomActionBar().clearActionTabs();
        super.onDestroyView();
    }
	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

	@Override
	protected FragmentInfo getNavigtionUpToFragment() {
		return null;
	}

	@Override
	protected boolean onMenuActionCreated(ActionMenu actionMenu) {
		actionMenu.add(new ActionMenuItem(3,null,R.drawable.actionbar_search,1));
		return super.onMenuActionCreated(actionMenu);
	}

	@Override
	protected boolean onMenuActionSelected(ActionMenuItem action) {
		switch (action.getId()){
			case 3:
				replaceFragment(SearchFragment.class,"SearchFragment",null);
				break;
		}
		return super.onMenuActionSelected(action);
	}

	@Override
	public boolean isCleanStack() {
		return true;
	}

}

@@ -817,16 +817,46 @@
 ionTab;%0A
+    private int mCurrentId=1;%0A
 %09public 
@@ -2344,24 +2344,42 @@
 ) %7B%0A
-%09%09%09@Override%0A%09%09%09
+            @Override%0A            
 publ
@@ -2424,20 +2424,74 @@
  tab) %7B%0A
-%09%09%09%09
+                mCurrentId = tab.getId();%0A                
 mActionT
@@ -2538,37 +2538,63 @@
 ));%0A
-%09%09%09%09return true;%0A%09%09%09%7D%0A%09%09
+                return true;%0A            %7D%0A        
 %7D);%0A
-%0A
 %09%7D%0A%0A
@@ -2658,18 +2658,183 @@
 tate) %7B%0A
-%09%09
+        if(savedInstanceState!=null)%7B%0A            mCurrentId=savedInstanceState.getInt(%22currentId%22);%0A        %7D%0A        mActionTabManager.setTabSelected(%22%22+mCurrentId);
 %0A%09%7D%0A    
@@ -3056,32 +3056,81 @@
 tate(outState);%0A
+        outState.putInt(%22currentId%22,mCurrentId);%0A
 %09%7D%0A%0A%09@Override%0A%09

update tab select