use of com.codeest.geeknews.ui.gold.fragment.GoldMainFragment 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();
}
}
}
Aggregations