Search in sources :

Example 1 with ZhihuMainFragment

use of com.codeest.geeknews.ui.zhihu.fragment.ZhihuMainFragment in project GeekNews by codeestX.

the class MainActivity method initEventAndData.

@Override
protected void initEventAndData() {
    setToolBar(mToolbar, "知乎日报");
    mZhihuFragment = new ZhihuMainFragment();
    mGankFragment = new GankMainFragment();
    mWechatFragment = new WechatMainFragment();
    mGoldFragment = new GoldMainFragment();
    mVtexFragment = new VtexMainFragment();
    mLikeFragment = new LikeFragment();
    mSettingFragment = new SettingFragment();
    mAboutFragment = new AboutFragment();
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);
    mDrawerToggle.syncState();
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mLastMenuItem = mNavigationView.getMenu().findItem(R.id.drawer_zhihu);
    loadMultipleRootFragment(R.id.fl_main_content, 0, mZhihuFragment, mWechatFragment, mGankFragment, mGoldFragment, mVtexFragment, mLikeFragment, mSettingFragment, mAboutFragment);
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch(menuItem.getItemId()) {
                case R.id.drawer_zhihu:
                    showFragment = Constants.TYPE_ZHIHU;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_gank:
                    showFragment = Constants.TYPE_GANK;
                    mSearchMenuItem.setVisible(true);
                    break;
                case R.id.drawer_wechat:
                    showFragment = Constants.TYPE_WECHAT;
                    mSearchMenuItem.setVisible(true);
                    break;
                case R.id.drawer_gold:
                    showFragment = Constants.TYPE_GOLD;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_vtex:
                    showFragment = Constants.TYPE_VTEX;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_setting:
                    showFragment = Constants.TYPE_SETTING;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_like:
                    showFragment = Constants.TYPE_LIKE;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_about:
                    showFragment = Constants.TYPE_ABOUT;
                    mSearchMenuItem.setVisible(false);
                    break;
            }
            if (mLastMenuItem != null) {
                mLastMenuItem.setChecked(false);
            }
            mLastMenuItem = menuItem;
            SharedPreferenceUtil.setCurrentItem(showFragment);
            menuItem.setChecked(true);
            mToolbar.setTitle(menuItem.getTitle());
            mDrawerLayout.closeDrawers();
            showHideFragment(getTargetFragment(showFragment), getTargetFragment(hideFragment));
            hideFragment = showFragment;
            return true;
        }
    });
    mSearchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (showFragment == Constants.TYPE_GANK) {
                mGankFragment.doSearch(query);
            } else if (showFragment == Constants.TYPE_WECHAT) {
                RxBus.getDefault().post(new SearchEvent(query, Constants.TYPE_WECHAT));
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    if (!SharedPreferenceUtil.getVersionPoint() && SystemUtil.isWifiConnected()) {
        SharedPreferenceUtil.setVersionPoint(true);
        try {
            PackageManager pm = getPackageManager();
            PackageInfo pi = pm.getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
            String versionName = pi.versionName;
            mPresenter.checkVersion(versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}
Also used : GankMainFragment(com.codeest.geeknews.ui.gank.fragment.GankMainFragment) AboutFragment(com.codeest.geeknews.ui.main.fragment.AboutFragment) SettingFragment(com.codeest.geeknews.ui.main.fragment.SettingFragment) NavigationView(android.support.design.widget.NavigationView) PackageInfo(android.content.pm.PackageInfo) WechatMainFragment(com.codeest.geeknews.ui.wechat.fragment.WechatMainFragment) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) VtexMainFragment(com.codeest.geeknews.ui.vtex.fragment.VtexMainFragment) MenuItem(android.view.MenuItem) SearchEvent(com.codeest.geeknews.model.event.SearchEvent) PackageManager(android.content.pm.PackageManager) MaterialSearchView(com.miguelcatalan.materialsearchview.MaterialSearchView) GoldMainFragment(com.codeest.geeknews.ui.gold.fragment.GoldMainFragment) ZhihuMainFragment(com.codeest.geeknews.ui.zhihu.fragment.ZhihuMainFragment) LikeFragment(com.codeest.geeknews.ui.main.fragment.LikeFragment)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 NavigationView (android.support.design.widget.NavigationView)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 MenuItem (android.view.MenuItem)1 SearchEvent (com.codeest.geeknews.model.event.SearchEvent)1 GankMainFragment (com.codeest.geeknews.ui.gank.fragment.GankMainFragment)1 GoldMainFragment (com.codeest.geeknews.ui.gold.fragment.GoldMainFragment)1 AboutFragment (com.codeest.geeknews.ui.main.fragment.AboutFragment)1 LikeFragment (com.codeest.geeknews.ui.main.fragment.LikeFragment)1 SettingFragment (com.codeest.geeknews.ui.main.fragment.SettingFragment)1 VtexMainFragment (com.codeest.geeknews.ui.vtex.fragment.VtexMainFragment)1 WechatMainFragment (com.codeest.geeknews.ui.wechat.fragment.WechatMainFragment)1 ZhihuMainFragment (com.codeest.geeknews.ui.zhihu.fragment.ZhihuMainFragment)1 MaterialSearchView (com.miguelcatalan.materialsearchview.MaterialSearchView)1