From 59b590a2ee1b0f539717c08a041222d9ab57062e Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Mon, 8 Mar 2010 21:59:38 +0100 Subject: [PATCH] Clear message buffer if view has been build from history --- src/org/yaaic/adapter/MessageListAdapter.java | 2 ++ src/org/yaaic/model/Channel.java | 18 ++++++++++++- src/org/yaaic/view/ServerActivity.java | 25 +++++++++++-------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/org/yaaic/adapter/MessageListAdapter.java b/src/org/yaaic/adapter/MessageListAdapter.java index de81964..971bdc5 100644 --- a/src/org/yaaic/adapter/MessageListAdapter.java +++ b/src/org/yaaic/adapter/MessageListAdapter.java @@ -54,6 +54,8 @@ public class MessageListAdapter extends BaseAdapter for (Message message : channel.getHistory()) { messages.add(message.renderTextView(context)); } + + channel.clearBuffer(); } /** diff --git a/src/org/yaaic/model/Channel.java b/src/org/yaaic/model/Channel.java index fb1e926..1802986 100644 --- a/src/org/yaaic/model/Channel.java +++ b/src/org/yaaic/model/Channel.java @@ -91,8 +91,24 @@ public class Channel * * @return */ - public Message pollMessage() + public Message pollBufferedMessage() { return buffer.poll(); } + + /** + * Does the channel have buffered messages? + */ + public boolean hasBufferedMessages() + { + return buffer.size() > 0; + } + + /** + * Clear the message buffer + */ + public void clearBuffer() + { + buffer.clear(); + } } diff --git a/src/org/yaaic/view/ServerActivity.java b/src/org/yaaic/view/ServerActivity.java index 9e1fffa..8ac078c 100644 --- a/src/org/yaaic/view/ServerActivity.java +++ b/src/org/yaaic/view/ServerActivity.java @@ -218,18 +218,21 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann public void onChannelMessage(String target) { Log.d(TAG, "Message for target " + target); + Channel channel = server.getChannel(target); - Message message = server.getChannel(target).pollMessage(); - MessageListView view = (MessageListView) deckAdapter.getItemByName(target); - - if (view != null) { - MessageListAdapter adapter = view.getAdapter(); - adapter.addMessage(message); - } - - if (deckAdapter.isSwitched()) { - MessageListView switchedView = deckAdapter.getSwitchedView(); - switchedView.getAdapter().addMessage(message); + while(channel.hasBufferedMessages()) { + Message message = channel.pollBufferedMessage(); + MessageListView view = (MessageListView) deckAdapter.getItemByName(target); + + if (view != null) { + MessageListAdapter adapter = view.getAdapter(); + adapter.addMessage(message); + } + + if (deckAdapter.isSwitched()) { + MessageListView switchedView = deckAdapter.getSwitchedView(); + switchedView.getAdapter().addMessage(message); + } } }