Skip to content

Commit

Permalink
首页返回自欧东切换到妹子一栏
Browse files Browse the repository at this point in the history
  • Loading branch information
maning0303 committed Oct 16, 2020
1 parent a0c117d commit d229aa8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public class MainActivity extends BaseActivity implements IMainView, View.OnClic

private TextView header_tv_weather;
private WeatherInfoBean weatherInfoBean;
//0,1,2,3
private int currentPosition = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -201,6 +203,9 @@ public boolean onCreateOptionsMenu(Menu menu) {
* 设置默认的Fragment显示:如果savedInstanceState不是空,证明activity被后台销毁重建了,之前有fragment,就不再创建了
*/
private void setDefaultFragment() {
navigationCheckedItemId = R.id.nav_girl;
navigationCheckedTitle = "妹纸";
navigationView.setCheckedItem(navigationCheckedItemId);
setMenuSelection(navigationCheckedItemId);
}

Expand All @@ -213,6 +218,7 @@ private void setMenuSelection(int flag) {
hideFragments(fragmentTransaction);
switch (flag) {
case R.id.nav_girl:
currentPosition = 0;
if (girlsFragment == null) {
girlsFragment = GirlsFragment.newInstance();
fragmentTransaction.add(R.id.frame_content, girlsFragment);
Expand All @@ -221,6 +227,7 @@ private void setMenuSelection(int flag) {
}
break;
case R.id.nav_history:
currentPosition = 1;
if (timeFragment == null) {
timeFragment = HistoryFragment.newInstance();
fragmentTransaction.add(R.id.frame_content, timeFragment);
Expand All @@ -229,6 +236,7 @@ private void setMenuSelection(int flag) {
}
break;
case R.id.nav_category_ganhuo:
currentPosition = 2;
if (categoryFragmentGanhuo == null) {
categoryFragmentGanhuo = CategoryFragment.newInstance(Constants.Catrgory_GankHuo);
fragmentTransaction.add(R.id.frame_content, categoryFragmentGanhuo);
Expand All @@ -237,6 +245,7 @@ private void setMenuSelection(int flag) {
}
break;
case R.id.nav_category_article:
currentPosition = 3;
if (categoryFragmentArticle == null) {
categoryFragmentArticle = CategoryFragment.newInstance(Constants.Catrgory_Article);
fragmentTransaction.add(R.id.frame_content, categoryFragmentArticle);
Expand Down Expand Up @@ -378,6 +387,11 @@ public void onBackPressed() {
drawerLayout.closeDrawers();
return;
}
//判断当前是不是在妹子页面
if (currentPosition != 0) {
setDefaultFragment();
return;
}
long currtTime = System.currentTimeMillis();
if (currtTime - exitTime > 2000) {
MySnackbar.makeSnackBarBlack(toolbar, getString(R.string.gank_hint_exit_app));
Expand Down

0 comments on commit d229aa8

Please sign in to comment.