private void setupMenu(Bundle savedInstanceState) { if (savedInstanceState == null) { int menuId = MenuFragment.MENU_MAIN; Intent intent = getIntent(); if (intent != null && !TextUtils.isEmpty(intent.getAction())) { menuId = getActionType(intent, intent.getAction()); } if (menuId == MenuFragment.MENU_MD) { menuFragment = MenuFragment.newInstance(MenuFragment.MENU_MD); getFragmentManager() .beginTransaction() .add(R.id.menu_frame, menuFragment, "MenuFragment") .commit(); } else if (menuId == MenuFragment.MENU_FRIENDSHIP) { menuFragment = MenuFragment.newInstance(MenuFragment.MENU_MAIN); getFragmentManager() .beginTransaction() .add(R.id.menu_frame, menuFragment, "MenuFragment") .commit(); FriendshipPagerFragment.launch(this, AppContext.getAccount().getUser(), 1); } else { menuFragment = MenuFragment.newInstance(menuId); getFragmentManager() .beginTransaction() .add(R.id.menu_frame, menuFragment, "MenuFragment") .commit(); } } else { menuFragment = (MenuFragment) getFragmentManager().findFragmentByTag("MenuFragment"); } }
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intent == null) return; String action = intent.getAction(); // 切换账号 if (ACTION_LOGIN.equals(action)) { setupFab(null); menuFragment.changeAccount(); } else { if (ACTION_NOTIFICATION.equals(action) && MenuFragment.MENU_FRIENDSHIP == Integer.parseInt(intent.getStringExtra("type"))) { FriendshipPagerFragment.launch(this, AppContext.getAccount().getUser(), 1); } else { int menuId = getActionType(intent, action); menuFragment.triggerMenuClick(menuId); } } }
@Override public boolean onPrepareOptionsMenu(Menu menu) { menu.findItem(R.id.publish).setVisible(AppSettings.getFabBtnType() == 1); if (OfflineService.getInstance() == null || OfflineService.getInstance().getStatus() == OfflineService.OfflineStatus.init || OfflineService.getInstance().getStatus() == OfflineService.OfflineStatus.finished) { menu.findItem(R.id.toggle_offline).setVisible(true); menu.findItem(R.id.stop_offline).setVisible(false); } else { menu.findItem(R.id.toggle_offline).setVisible(false); menu.findItem(R.id.stop_offline).setVisible(true); } menu.findItem(R.id.notification_settings) .setVisible(menuFragment.getSelectedId() == MenuFragment.MENU_NOTIFICATION); return super.onPrepareOptionsMenu(menu); }
@Override protected void onResume() { super.onResume(); // 修复偶尔Fab按钮不见了 if (menuFragment != null && menuFragment.getSelectedId() == 1) { if (fabBtn.getVisibility() != View.VISIBLE) { fabBtn.setVisibility(View.VISIBLE); } } if (!AppContext.isLoggedIn()) { finish(); return; } if (AppContext.getAccount().getAccessToken().isExpired()) { requestLogin(this, AppContext.getAccount()); } invalidateOptionsMenu(); }