mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-23 01:12:17 -05:00
(Fixed issue 5) store message adapter in conversation and reuse it
This commit is contained in:
parent
876b96c358
commit
9f19c0b7ac
@ -186,7 +186,14 @@ public class DeckAdapter extends BaseAdapter
|
|||||||
public MessageListView renderConversation(Conversation conversation, ViewGroup parent)
|
public MessageListView renderConversation(Conversation conversation, ViewGroup parent)
|
||||||
{
|
{
|
||||||
MessageListView list = new MessageListView(parent.getContext());
|
MessageListView list = new MessageListView(parent.getContext());
|
||||||
list.setAdapter(new MessageListAdapter(conversation, parent.getContext()));
|
|
||||||
|
MessageListAdapter adapter = conversation.getMessageListAdapter();
|
||||||
|
if (adapter == null) {
|
||||||
|
adapter = new MessageListAdapter(conversation, parent.getContext());
|
||||||
|
conversation.setMessageListAdapter(adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
list.setAdapter(adapter);
|
||||||
|
|
||||||
list.setDivider(null);
|
list.setDivider(null);
|
||||||
list.setLayoutParams(new Gallery.LayoutParams(
|
list.setLayoutParams(new Gallery.LayoutParams(
|
||||||
|
@ -24,6 +24,8 @@ import java.util.Collections;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.yaaic.adapter.MessageListAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for conversations
|
* Base class for conversations
|
||||||
*
|
*
|
||||||
@ -44,6 +46,7 @@ public abstract class Conversation
|
|||||||
private List<Message> buffer;
|
private List<Message> buffer;
|
||||||
private List<Message> history;
|
private List<Message> history;
|
||||||
private String name;
|
private String name;
|
||||||
|
private MessageListAdapter adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of conversation (channel, query, ..)
|
* Get the type of conversation (channel, query, ..)
|
||||||
@ -131,4 +134,20 @@ public abstract class Conversation
|
|||||||
{
|
{
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store the adapter of this conversation
|
||||||
|
*/
|
||||||
|
public void setMessageListAdapter(MessageListAdapter adapter)
|
||||||
|
{
|
||||||
|
this.adapter = adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the MessageList Adapter of this conversation if known
|
||||||
|
*/
|
||||||
|
public MessageListAdapter getMessageListAdapter()
|
||||||
|
{
|
||||||
|
return adapter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,33 +232,15 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
|||||||
public void onConversationMessage(String target)
|
public void onConversationMessage(String target)
|
||||||
{
|
{
|
||||||
Conversation conversation = server.getConversation(target);
|
Conversation conversation = server.getConversation(target);
|
||||||
|
MessageListAdapter adapter = conversation.getMessageListAdapter();
|
||||||
|
|
||||||
while(conversation.hasBufferedMessages()) {
|
while(conversation.hasBufferedMessages()) {
|
||||||
// XXX: I wrote all this beautiful code but the view sometimes has
|
|
||||||
// not all children like the adapter so getChildAt() will return
|
|
||||||
// no child view or not the view that is logical connected to
|
|
||||||
// the item in the adapter at the same position. So we just
|
|
||||||
// notify the whole deck adapter (as fallback).
|
|
||||||
|
|
||||||
Message message = conversation.pollBufferedMessage();
|
Message message = conversation.pollBufferedMessage();
|
||||||
|
|
||||||
int position = deckAdapter.getPositionByName(target);
|
if (adapter != null) {
|
||||||
|
|
||||||
if (position != -1) {
|
|
||||||
MessageListView view = (MessageListView) deck.getChildAt(position);
|
|
||||||
if (view != null) {
|
|
||||||
MessageListAdapter adapter = view.getAdapter();
|
|
||||||
adapter.addMessage(message);
|
adapter.addMessage(message);
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "MessageListView Adapter is null (position: " + position + ")");
|
Log.d(TAG, "MessageListAdapter is null (conversation " + conversation.getName() + " has no adapter assigned)");
|
||||||
// Fallback: We could not get the MessageListAdapter. Notify the whole deck
|
|
||||||
deckAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deckAdapter.isSwitched() && target.equals(deckAdapter.getSwitchedName())) {
|
|
||||||
MessageListView switchedView = deckAdapter.getSwitchedView();
|
|
||||||
switchedView.getAdapter().addMessage(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user