2010-03-10 03:32:20 -05:00
|
|
|
/*
|
2010-03-12 14:35:25 -05:00
|
|
|
Yaaic - Yet Another Android IRC Client
|
2010-03-10 03:32:20 -05:00
|
|
|
|
2011-02-05 07:00:12 -05:00
|
|
|
Copyright 2009-2011 Sebastian Kaspari
|
2010-03-10 03:32:20 -05:00
|
|
|
|
|
|
|
This file is part of Yaaic.
|
|
|
|
|
|
|
|
Yaaic is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Yaaic is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
2011-01-25 15:02:27 -05:00
|
|
|
*/
|
2010-03-10 03:32:20 -05:00
|
|
|
package org.yaaic.model;
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
2010-03-17 14:32:27 -04:00
|
|
|
import org.yaaic.adapter.MessageListAdapter;
|
|
|
|
|
2010-03-10 03:32:20 -05:00
|
|
|
/**
|
|
|
|
* Base class for conversations
|
|
|
|
*
|
|
|
|
* A conversation can be a channel, a query or server messages
|
|
|
|
*
|
|
|
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
|
|
|
*/
|
|
|
|
public abstract class Conversation
|
|
|
|
{
|
2010-11-18 12:52:19 -05:00
|
|
|
public static final int TYPE_CHANNEL = 1;
|
|
|
|
public static final int TYPE_QUERY = 2;
|
|
|
|
public static final int TYPE_SERVER = 3;
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
public static final int STATUS_DEFAULT = 1;
|
|
|
|
public static final int STATUS_SELECTED = 2;
|
|
|
|
public static final int STATUS_MESSAGE = 3;
|
|
|
|
public static final int STATUS_HIGHLIGHT = 4;
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
public static final int HISTORY_SIZE = 30;
|
2011-01-25 15:02:27 -05:00
|
|
|
|
|
|
|
private final LinkedList<Message> buffer;
|
|
|
|
private final LinkedList<Message> history;
|
|
|
|
private final String name;
|
2010-11-18 12:52:19 -05:00
|
|
|
private MessageListAdapter adapter;
|
|
|
|
private int status = 1;
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get the type of conversation (channel, query, ..)
|
|
|
|
*
|
|
|
|
* @return See the constants: Conversation.TYPE_*
|
|
|
|
*/
|
|
|
|
public abstract int getType();
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Create a new conversation with the given name
|
|
|
|
*
|
|
|
|
* @param name The name of the conversation (channel, user)
|
|
|
|
*/
|
|
|
|
public Conversation(String name)
|
|
|
|
{
|
|
|
|
this.buffer = new LinkedList<Message>();
|
|
|
|
this.history = new LinkedList<Message>();
|
|
|
|
this.name = name.toLowerCase();
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get name of the conversation (channel, user)
|
|
|
|
*/
|
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Add a message to the channel
|
|
|
|
*/
|
|
|
|
public void addMessage(Message message)
|
|
|
|
{
|
|
|
|
buffer.add(0, message);
|
|
|
|
history.add(message);
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
if (history.size() > HISTORY_SIZE) {
|
|
|
|
history.remove(0);
|
|
|
|
}
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get the history
|
|
|
|
*/
|
|
|
|
public LinkedList<Message> getHistory()
|
|
|
|
{
|
|
|
|
return history;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get message of the history at the given position
|
|
|
|
*
|
|
|
|
* @param position
|
|
|
|
* @return The message at the given position
|
|
|
|
*/
|
|
|
|
public Message getHistoryMessage(int position)
|
|
|
|
{
|
|
|
|
return history.get(position);
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get last buffered message
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Message pollBufferedMessage()
|
|
|
|
{
|
|
|
|
Message message = buffer.get(buffer.size() - 1);
|
|
|
|
buffer.remove(buffer.size() - 1);
|
|
|
|
return message;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get the buffer
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public LinkedList<Message> getBuffer()
|
|
|
|
{
|
|
|
|
return buffer;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Does the channel have buffered messages?
|
|
|
|
*/
|
|
|
|
public boolean hasBufferedMessages()
|
|
|
|
{
|
|
|
|
return buffer.size() > 0;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Clear the message buffer
|
|
|
|
*/
|
|
|
|
public void clearBuffer()
|
|
|
|
{
|
|
|
|
buffer.clear();
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Store the adapter of this conversation
|
|
|
|
*/
|
|
|
|
public void setMessageListAdapter(MessageListAdapter adapter)
|
|
|
|
{
|
|
|
|
this.adapter = adapter;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get the MessageList Adapter of this conversation if known
|
|
|
|
*/
|
|
|
|
public MessageListAdapter getMessageListAdapter()
|
|
|
|
{
|
|
|
|
return adapter;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set status of conversation
|
|
|
|
*
|
|
|
|
* @param status
|
|
|
|
*/
|
|
|
|
public void setStatus(int status)
|
|
|
|
{
|
|
|
|
// Selected status can only be changed by deselecting
|
|
|
|
if (this.status == STATUS_SELECTED && status != STATUS_DEFAULT) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
// Highlight status can only be changed by selecting
|
|
|
|
if (this.status == STATUS_HIGHLIGHT && status != STATUS_SELECTED) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
this.status = status;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get status of conversation
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public int getStatus()
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
2010-03-10 03:32:20 -05:00
|
|
|
}
|