public abstract class MySupportActivity<P extends IPresenter> extends BaseActivity<P> implements ISupportActivity {

    final SupportActivityDelegate mDelegate = new SupportActivityDelegate(this);

    @Override
    public SupportActivityDelegate getSupportDelegate() {
        return mDelegate;
    }

    /**
     * Perform some extra transactions.
     * 额外的事务：自定义Tag，添加SharedElement动画，操作非回退栈Fragment
     */
    @Override
    public ExtraTransaction extraTransaction() {
        return mDelegate.extraTransaction();
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        mDelegate.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onPostCreate(@Nullable Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mDelegate.onPostCreate(savedInstanceState);
    }

    @Override
    protected void onDestroy() {
        mDelegate.onDestroy();
        super.onDestroy();
    }

    /**
     * Note： return mDelegate.dispatchTouchEvent(ev) || super.dispatchTouchEvent(ev);
     */
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return mDelegate.dispatchTouchEvent(ev) || super.dispatchTouchEvent(ev);
    }

    /**
     * 不建议复写该方法,请使用 {@link #onBackPressedSupport} 代替
     */
    @Override
    final public void onBackPressed() {
        mDelegate.onBackPressed();
    }

    /**
     * 该方法回调时机为,Activity回退栈内Fragment的数量 小于等于1 时,默认finish Activity
     * 请尽量复写该方法,避免复写onBackPress(),以保证SupportFragment内的onBackPressedSupport()回退事件正常执行
     */
    @Override
    public void onBackPressedSupport() {
        mDelegate.onBackPressedSupport();
    }

    /**
     * 获取设置的全局动画 copy
     *
     * @return FragmentAnimator
     */
    @Override
    public FragmentAnimator getFragmentAnimator() {
        return mDelegate.getFragmentAnimator();
    }

    /**
     * Set all fragments animation.
     * 设置Fragment内的全局动画
     */
    @Override
    public void setFragmentAnimator(FragmentAnimator fragmentAnimator) {
        mDelegate.setFragmentAnimator(fragmentAnimator);
    }

    /**
     * Set all fragments animation.
     * 构建Fragment转场动画
     * <p/>
     * 如果是在Activity内实现,则构建的是Activity内所有Fragment的转场动画,
     * 如果是在Fragment内实现,则构建的是该Fragment的转场动画,此时优先级 > Activity的onCreateFragmentAnimator()
     *
     * @return FragmentAnimator对象
     */
    @Override
    public FragmentAnimator onCreateFragmentAnimator() {
        return mDelegate.onCreateFragmentAnimator();
    }

    /****************************************以下为可选方法(Optional methods)******************************************************/

    // 选择性拓展其他方法
    public void loadRootFragment(int containerId, @NonNull ISupportFragment toFragment) {
        mDelegate.loadRootFragment(containerId, toFragment);
    }

    public void start(ISupportFragment toFragment) {
        mDelegate.start(toFragment);
    }

    /**
     * @param launchMode Same as Activity's LaunchMode.
     */
    public void start(ISupportFragment toFragment, @ISupportFragment.LaunchMode int launchMode) {
        mDelegate.start(toFragment, launchMode);
    }

    /**
     * Pop the fragment.
     */
    public void pop() {
        mDelegate.pop();
    }

    /**
     * Pop the last fragment transition from the manager's fragment
     * back stack.
     */
    public void popTo(Class<?> targetFragmentClass, boolean includeTargetFragment) {
        mDelegate.popTo(targetFragmentClass, includeTargetFragment);
    }

    /**
     * If you want to begin another FragmentTransaction immediately after popTo(), use this method.
     * 如果你想在出栈后, 立刻进行FragmentTransaction操作，请使用该方法
     */
    public void popTo(Class<?> targetFragmentClass, boolean includeTargetFragment, Runnable afterPopTransactionRunnable) {
        mDelegate.popTo(targetFragmentClass, includeTargetFragment, afterPopTransactionRunnable);
    }

    public void popTo(Class<?> targetFragmentClass, boolean includeTargetFragment, Runnable afterPopTransactionRunnable, int popAnim) {
        mDelegate.popTo(targetFragmentClass, includeTargetFragment, afterPopTransactionRunnable, popAnim);
    }

    /**
     * 得到位于栈顶Fragment
     */
    public ISupportFragment getTopFragment() {
        return SupportHelper.getTopFragment(getSupportFragmentManager());
    }

    /**
     * 获取栈内的fragment对象
     */
    public <T extends ISupportFragment> T findFragment(Class<T> fragmentClass) {
        return SupportHelper.findFragment(getSupportFragmentManager(), fragmentClass);
    }
} public class MainTag {

} @Module
public class MainModule {
    private MainContract.View view;

    /**
     * 构建MainModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public MainModule(MainContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    MainContract.View provideMainView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    MainContract.Model provideMainModel(MainModel model) {
        return model;
    }
} public interface MainContract {
    //对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
    interface View extends IView {

    }

    //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
    interface Model extends IModel {

    }
} @ActivityScope
public class MainPresenter extends BasePresenter<MainContract.Model, MainContract.View> {
    private RxErrorHandler mErrorHandler;
    private Application mApplication;
    private ImageLoader mImageLoader;
    private AppManager mAppManager;

    @Inject
    public MainPresenter(MainContract.Model model, MainContract.View rootView
            , RxErrorHandler handler, Application application
            , ImageLoader imageLoader, AppManager appManager) {
        super(model, rootView);
        this.mErrorHandler = handler;
        this.mApplication = application;
        this.mImageLoader = imageLoader;
        this.mAppManager = appManager;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
    }

} public class NavFreeFowFragment extends MySupportFragment {

    public static NavFreeFowFragment newInstance() {
        return new NavFreeFowFragment();
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_free_fow_nav, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void setData(Object data) {

    }
} public class NavHistoryFragment extends MySupportFragment {

    public static NavHistoryFragment newInstance() {
        return new NavHistoryFragment();
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_history_nav, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void setData(Object data) {

    }
} public class NavHomeFragment extends MySupportFragment {

    private ISupportFragment[] mFragments = new ISupportFragment[4];

    @BindView(R.id.bottom_bar)
    CommonTabLayout mBottomBar;

    public static NavHomeFragment newInstance() {
        return new NavHomeFragment();
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home_nav, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        setHasOptionsMenu(true);
        initFragmentation();
        initBottomBar();
    }


    @Override
    public void setData(Object data) {
    }

    private void initFragmentation() {
        ISupportFragment homeFragment = findChildFragment(MainHomeFragment.class);
        if (homeFragment == null) {
            mFragments[0] = MainHomeFragment.newInstance();
            mFragments[1] = MainCategoryFragment.newInstance();
            mFragments[2] = MainDynamicFragment.newInstance();
            mFragments[3] = MainCommunicateFragment.newInstance();
            loadMultipleRootFragment(R.id.fl_content, 0, mFragments);
        } else {
            mFragments[0] = findChildFragment(MainHomeFragment.class);
            mFragments[1] = findChildFragment(MainCategoryFragment.class);
            mFragments[2] = findChildFragment(MainDynamicFragment.class);
            mFragments[3] = findChildFragment(MainCommunicateFragment.class);
        }
    }

    private void initBottomBar() {
        ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
        mTabEntities.add(new TabEntity(ArmsUtils.getString(_mActivity, R.string.main_home), R.mipmap.ic_home_selected, R.mipmap.ic_home_unselected));
        mTabEntities.add(new TabEntity(ArmsUtils.getString(_mActivity, R.string.main_category), R.mipmap.ic_category_selected, R.mipmap.ic_category_unselected));
        mTabEntities.add(new TabEntity(ArmsUtils.getString(_mActivity, R.string.main_dynamic), R.mipmap.ic_dynamic_selected, R.mipmap.ic_dynamic_unselected));
        mTabEntities.add(new TabEntity(ArmsUtils.getString(_mActivity, R.string.main_communicate), R.mipmap.ic_communicate_selected, R.mipmap.ic_communicate_unselected));
        mBottomBar.setTabData(mTabEntities);
        mBottomBar.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
//                Timber.e("position = " + position);
                showHideFragment(mFragments[position]);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }
} public class NavLiveCenterFragment extends MySupportFragment {

    public static NavLiveCenterFragment newInstance() {
        return new NavLiveCenterFragment();
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_live_center_nav, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void setData(Object data) {

    }
} public class NavLookLaterFragment extends MySupportFragment {

    public static NavLookLaterFragment newInstance() {
        return new NavLookLaterFragment();
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_look_later_nav, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void setData(Object data) {

    }
} public class NavMyCollectFragment extends MySupportFragment {

    public static NavMyCollectFragment newInstance() {
        return new NavMyCollectFragment();
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my_collect_nav, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void setData(Object data) {

    }
} public class NavMyFollowFragment extends MySupportFragment {

    public static NavMyFollowFragment newInstance() {
        return new NavMyFollowFragment();
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my_follow_nav, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void setData(Object data) {

    }
} public class NavMyVipFragment extends MySupportFragment {

    public static NavMyVipFragment newInstance() {
        return new NavMyVipFragment();
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my_vip_nav, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void setData(Object data) {

    }
} public class NavOfflineCacheFragment extends MySupportFragment {

    public static NavOfflineCacheFragment newInstance() {
        return new NavOfflineCacheFragment();
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_offline_cache_nav, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void setData(Object data) {

    }
} public class NavVipOrderFragment extends MySupportFragment {

    public static NavVipOrderFragment newInstance() {
        return new NavVipOrderFragment();
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_vip_order_nav, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void setData(Object data) {

    }
}
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.internal.NavigationMenuView;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.MenuItem;
import android.widget.LinearLayout;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.flyco.systembar.SystemBarHelper;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.lqr.biliblili.R;
import com.lqr.biliblili.app.base.MySupportActivity;
import com.lqr.biliblili.app.tag.MainTag;
import com.lqr.biliblili.di.component.DaggerMainComponent;
import com.lqr.biliblili.di.module.MainModule;
import com.lqr.biliblili.mvp.contract.MainContract;
import com.lqr.biliblili.mvp.presenter.MainPresenter;
import com.lqr.biliblili.mvp.ui.fragment.nav.NavFreeFowFragment;
import com.lqr.biliblili.mvp.ui.fragment.nav.NavHistoryFragment;
import com.lqr.biliblili.mvp.ui.fragment.nav.NavHomeFragment;
import com.lqr.biliblili.mvp.ui.fragment.nav.NavLiveCenterFragment;
import com.lqr.biliblili.mvp.ui.fragment.nav.NavLookLaterFragment;
import com.lqr.biliblili.mvp.ui.fragment.nav.NavMyCollectFragment;
import com.lqr.biliblili.mvp.ui.fragment.nav.NavMyFollowFragment;
import com.lqr.biliblili.mvp.ui.fragment.nav.NavMyVipFragment;
import com.lqr.biliblili.mvp.ui.fragment.nav.NavOfflineCacheFragment;
import com.lqr.biliblili.mvp.ui.fragment.nav.NavVipOrderFragment;
import org.simple.eventbus.Subscriber;
import java.util.TimerTask;
import butterknife.BindView;
import butterknife.OnClick;
import me.yokeyword.fragmentation.ISupportFragment;
import me.yokeyword.fragmentation.SupportFragment;
import static com.jess.arms.utils.Preconditions.checkNotNull;
        mNav.setBackgroundColor(ArmsUtils.getColor(this, R.color.nav_menu_bg));
        removeNavigationViewScrollbar(mNav);
        mNav.setCheckedItem(R.id.nav_home);
        mNav.setNavigationItemSelectedListener(this);
    }


    private void removeNavigationViewScrollbar(NavigationView navigationView) {
        if (navigationView != null) {
            NavigationMenuView navigationMenuView = (NavigationMenuView) navigationView.getChildAt(0);
            if (navigationMenuView != null) {
                navigationMenuView.setVerticalScrollBarEnabled(false);
            }
        }
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        closeDrawer();
        switch (item.getItemId()) {
            case R.id.nav_home:
                NavHomeFragment homeFragment = findFragment(NavHomeFragment.class);
                if (homeFragment == null) {
                    start(NavHomeFragment.newInstance(), SupportFragment.SINGLETASK);
                } else {
                    popTo(NavHomeFragment.class, false);
                }
                break;
            case R.id.nav_history:
                NavHistoryFragment historyFragment = findFragment(NavHistoryFragment.class);
                if (historyFragment == null) {
                    popTo(NavHomeFragment.class, false, new TimerTask() {
                        @Override
                        public void run() {
                            start(NavHistoryFragment.newInstance());
                        }
                    });
                } else {
                    popTo(NavHistoryFragment.class, false);
                }
                break;
            case R.id.nav_offline_cache:
                NavOfflineCacheFragment offlineCacheFragment = findFragment(NavOfflineCacheFragment.class);
                if (offlineCacheFragment == null) {
                    popTo(NavHomeFragment.class, false, new TimerTask() {
                        @Override
                        public void run() {
                            start(NavOfflineCacheFragment.newInstance());
                        }
                    });
                } else {
                    popTo(NavOfflineCacheFragment.class, false);
                }
                break;
            case R.id.nav_my_collect:
                NavMyCollectFragment myCollectFragment = findFragment(NavMyCollectFragment.class);
                if (myCollectFragment == null) {
                    popTo(NavHomeFragment.class, false, new TimerTask() {
                        @Override
                        public void run() {
                            start(NavMyCollectFragment.newInstance());
                        }
                    });
                } else {
                    popTo(NavMyCollectFragment.class, false);
                }
                break;
            case R.id.nav_my_follow:
                NavMyFollowFragment myFollowFragment = findFragment(NavMyFollowFragment.class);
                if (myFollowFragment == null) {
                    popTo(NavHomeFragment.class, false, new TimerTask() {
                        @Override
                        public void run() {
                            start(NavMyFollowFragment.newInstance());
                        }
                    });
                } else {
                    popTo(NavMyFollowFragment.class, false);
                }
                break;
            case R.id.nav_look_later:
                NavLookLaterFragment lookLaterFragment = findFragment(NavLookLaterFragment.class);
                if (lookLaterFragment == null) {
                    popTo(NavHomeFragment.class, false, new TimerTask() {
                        @Override
                        public void run() {
                            start(NavLookLaterFragment.newInstance());
                        }
                    });
                } else {
                    popTo(NavLookLaterFragment.class, false);
                }
                break;
            case R.id.nav_live_center:
                NavLiveCenterFragment liveCenterFragment = findFragment(NavLiveCenterFragment.class);
                if (liveCenterFragment == null) {
                    popTo(NavHomeFragment.class, false, new TimerTask() {
                        @Override
                        public void run() {
                            start(NavLiveCenterFragment.newInstance());
                        }
                    });
                } else {
                    popTo(NavLiveCenterFragment.class, false);
                }
                break;
            case R.id.nav_my_vip:
                NavMyVipFragment myVipFragment = findFragment(NavMyVipFragment.class);
                if (myVipFragment == null) {
                    popTo(NavHomeFragment.class, false, new TimerTask() {
                        @Override
                        public void run() {
                            start(NavMyVipFragment.newInstance());
                        }
                    });
                } else {
                    popTo(NavMyVipFragment.class, false);
                }
                break;
            case R.id.nav_free_fow:
                NavFreeFowFragment freeFowFragment = findFragment(NavFreeFowFragment.class);