public void setBuffer(int bufferId) { Log.d(TAG, "Setting buffer and chat is visible: " + getUserVisibleHint()); this.bufferId = bufferId; if (adapter != null && networks != null) { if (adapter.buffer != null && bufferId != adapter.buffer.getInfo().id) { updateMarkerLine(); } adapter.clearBuffer(); Buffer buffer = networks.getBufferById(bufferId); if (buffer != null) { adapter.setBuffer(buffer, networks); nickCompletionHelper = new NickCompletionHelper(buffer.getUsers().getUniqueUsers()); autoCompleteButton.setEnabled(true); inputField.setEnabled(true); if (getUserVisibleHint() == true) buffer.setDisplayed(true); BusProvider.getInstance() .post(new ManageChannelEvent(buffer.getInfo().id, ChannelAction.HIGHLIGHTS_READ)); // Move list to correct position if (adapter.buffer.getTopMessageShown() == 0) { backlogList.setSelection(adapter.getCount() - 1); } else { adapter.setListTopMessage(adapter.buffer.getTopMessageShown()); } } else { resetFragment(); } } }
private void updateMarkerLine() { BusProvider.getInstance() .post( new ManageMessageEvent( adapter.getBufferId(), adapter.buffer.getLastSeenMessage(), MessageAction.MARKER_LINE)); }
@Override public void onStop() { Log.d(TAG, "Stopping fragment"); super.onStop(); if (Quasseldroid.status == ConnectionChangedEvent.Status.Connected && getUserVisibleHint()) updateRead(); adapter.clearBuffer(); BusProvider.getInstance().unregister(this); setUserVisibleHint(false); }
@Subscribe public void onBufferOpened(BufferOpenedEvent event) { if (event.bufferId != -1) { this.bufferId = event.bufferId; if (networks != null) { observer.setBuffer(networks.getBufferById(bufferId)); updateUsers(); BusProvider.getInstance().post(new BufferDetailsChangedEvent(bufferId)); } } }
@Subscribe public void onNetworksAvailable(NetworksAvailableEvent event) { if (event.networks != null) { this.networks = event.networks; if (bufferId != -1) { observer.setBuffer(networks.getBufferById(bufferId)); updateUsers(); BusProvider.getInstance().post(new BufferDetailsChangedEvent(bufferId)); } } }
@Override public void onStart() { Log.d(TAG, "Starting fragment"); super.onStart(); dynamicBacklogAmount = Integer.parseInt( preferences.getString(getString(R.string.preference_dynamic_backlog), "10")); autoCompleteButton.setEnabled(false); inputField.setEnabled(false); BusProvider.getInstance().register(this); setUserVisibleHint(true); }
@Override public void update(Observable observable, Object data) { if (data == null) { return; } switch ((Integer) data) { case R.id.BUFFERUPDATE_TOPICCHANGED: BusProvider.getInstance().post(new BufferDetailsChangedEvent(bufferId)); break; default: } }
private void updateRead() { Log.d(TAG, "Updating buffer read, chat is visible: " + getUserVisibleHint()); if (adapter.buffer != null) { // Don't save position if list is at bottom if (backlogList.getLastVisiblePosition() == adapter.getCount() - 1) { adapter.buffer.setTopMessageShown(0); } else { adapter.buffer.setTopMessageShown(adapter.getListTopMessageId()); } if (adapter.buffer.getUnfilteredSize() != 0) { BusProvider.getInstance() .post(new ManageChannelEvent(adapter.getBufferId(), ChannelAction.MARK_AS_READ)); BusProvider.getInstance() .post( new ManageMessageEvent( adapter.getBufferId(), adapter.buffer.getUnfilteredBacklogEntry(adapter.buffer.getUnfilteredSize() - 1) .messageId, MessageAction.LAST_SEEN)); } } }
public void getMoreBacklog() { adapter.buffer.setBacklogPending(true); BusProvider.getInstance() .post(new GetBacklogEvent(adapter.getBufferId(), dynamicBacklogAmount)); }
private void queryUser(String nick) { BusProvider.getInstance().post(new UserClickedEvent(bufferId, nick)); }
@Override public void onStop() { super.onStop(); adapter.stopObserving(); BusProvider.getInstance().unregister(this); }
@Override public void onStart() { super.onStart(); BusProvider.getInstance().register(this); }