@Override
  public void onPrepareOptionsMenu(android.view.Menu menu) {
    super.onPrepareOptionsMenu(menu);
    boolean isJoined = (mChannel != null) && mChannel.isJoined();
    menu.findItem(R.id.info).setVisible(isJoined);
    menu.findItem(R.id.members).setVisible(isJoined);
    menu.findItem(R.id.part_channel).setVisible(isJoined);

    // User must part channel before archiving/deleting
    for (int id : new int[] {R.id.archive, R.id.delete}) {
      MenuItem item = menu.findItem(id);
      item.setVisible(item.isVisible() && (!isJoined));
    }
  }
  @Override
  protected void updateUI() {
    super.updateUI();
    if (getView() == null) {
      // View not yet created.
      return;
    }

    boolean isConnected =
        (mConnection != null && mConnection.getState() == Connection.STATE_CONNECTED);
    boolean isJoined = (mChannel != null && mChannel.isJoined());

    View notInChannelView = getView().findViewById(R.id.not_in_channel);
    notInChannelView.setVisibility((!isConnected) || isJoined ? View.GONE : View.VISIBLE);

    getActivity().invalidateOptionsMenu();
  }