@Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    getView()
        .findViewById(R.id.rejoin_button)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                mChannel.join();
              }
            });
  }
  @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));
    }
  }
  @Subscribe
  @Override
  public void onServiceStateChanged(ServiceStateChangedEvent event) {
    super.onServiceStateChanged(event);

    TapchatService service = event.getService();

    if (service.getConnectionState() == TapchatService.STATE_LOADED) {
      mChannel = (ChannelBuffer) mBuffer;
    } else {
      mChannel = null;
    }

    updateUI();
  }
  public static BufferFragment create(int type, long connectionId, long bufferId) {
    BufferFragment fragment;

    switch (type) {
      case Buffer.CHANNEL_TYPE:
        fragment = new ChannelBufferFragment();
        break;

      case Buffer.CONVERSATION_TYPE:
        fragment = new QueryBufferFragment();
        break;

      default:
        fragment = new BufferFragment();
        break;
    }

    Bundle args = new Bundle();
    args.putLong(BufferFragment.ARG_CONNECTION_ID, connectionId);
    args.putLong(BufferFragment.ARG_BUFFER_ID, bufferId);
    fragment.setArguments(args);

    return fragment;
  }
  @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();
  }
 @Override
 public void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) {
   super.onCreateOptionsMenu(menu, inflater);
   inflater.inflate(R.menu.buffer_channel, menu);
 }
 @Subscribe
 @Override
 public void onBufferRemoved(BufferRemovedEvent event) {
   super.onBufferRemoved(event);
 }
 @Subscribe
 @Override
 public void onBufferLineAdded(BufferLineAddedEvent event) {
   super.onBufferLineAdded(event);
 }
 @Subscribe
 @Override
 public void onConnectionChanged(ConnectionChangedEvent event) {
   super.onConnectionChanged(event);
 }