@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.archive) {
      mBuffer.archive();
      TapchatApp.goHome(getActivity(), mConnection.getId());
      return true;

    } else if (item.getItemId() == R.id.unarchive) {
      mBuffer.unarchive();
      return true;

    } else if (item.getItemId() == R.id.delete) {
      new AlertDialog.Builder(getActivity())
          .setMessage(R.string.confirm_delete_buffer)
          .setPositiveButton(
              android.R.string.yes,
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                  mBuffer.delete();
                  TapchatApp.goHome(getActivity(), mConnection.getId());
                }
              })
          .setNegativeButton(android.R.string.no, null)
          .show();
      return true;
    }
    return false;
  }
 @Override
 public void onPrepareOptionsMenu(Menu menu) {
   boolean hasBuffer = mBuffer != null && (!(mBuffer instanceof ConsoleBuffer));
   boolean isArchived = (hasBuffer && mBuffer.isArchived());
   menu.findItem(R.id.archive).setVisible(hasBuffer && !isArchived);
   menu.findItem(R.id.unarchive).setVisible(hasBuffer && isArchived);
   menu.findItem(R.id.delete).setVisible(hasBuffer);
   // menu.findItem(R.id.star).setVisible(hasBuffer);
 }
  protected void updateUI() {
    if (getView() == null) {
      return;
    }

    if (mConnectionState == TapchatService.STATE_LOADED && mBuffer != null) {
      if (getListAdapter() == null) {
        setListAdapter(new BufferEventListAdapter(mBuffer.getBacklog()));
      } else {
        ((BufferEventListAdapter) getListAdapter()).updateItems(mBuffer.getBacklog());
      }

      getView().findViewById(R.id.text_entry).setEnabled(mBuffer.isActive());
      getView().findViewById(R.id.send_button).setEnabled(mBuffer.isActive());

    } else {
      getView().findViewById(R.id.text_entry).setEnabled(false);
      getView().findViewById(R.id.send_button).setEnabled(false);
    }
  }
  private void sendMessage() {
    EditText textEntry = (EditText) getView().findViewById(R.id.text_entry);
    final String text = textEntry.getText().toString();

    if (TextUtils.isEmpty(text)) {
      return;
    }

    if (text.startsWith("/")) {
      new AlertDialog.Builder(getActivity())
          .setMessage(R.string.commands_not_supported)
          .setPositiveButton(android.R.string.ok, null)
          .show();
      return;
    }

    textEntry.setText("");

    mConnection.say(mBuffer.getName(), text, null);
  }