1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-29 12:22:21 -05:00

Use message objects instead of strings

This commit is contained in:
Sebastian Kaspari 2010-03-06 17:52:22 +01:00
parent fca84d3075
commit ddf80644bd
6 changed files with 68 additions and 29 deletions

View File

@ -24,8 +24,9 @@ import java.util.HashMap;
import java.util.LinkedList;
import org.yaaic.model.Channel;
import org.yaaic.model.Message;
import android.view.Display;
import android.text.SpannableString;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
@ -183,10 +184,10 @@ public class DeckAdapter extends BaseAdapter
public View renderChannel(Channel channel, ViewGroup parent)
{
TextView canvas = new TextView(parent.getContext());
canvas.setText(channel.getName());
canvas.setText(new SpannableString(channel.getName()));
for (String message : channel.getHistory()) {
canvas.append("\n" + message);
for (Message message : channel.getHistory()) {
canvas.append(message.render());
}
canvas.setTextColor(0xff000000);

View File

@ -33,7 +33,6 @@ import android.widget.TextView;
import org.yaaic.R;
import org.yaaic.Yaaic;
import org.yaaic.model.Server;
import org.yaaic.model.Status;
/**
* Adapter for server lists

View File

@ -29,6 +29,7 @@ import org.jibble.pircbot.User;
import org.yaaic.Yaaic;
import org.yaaic.model.Broadcast;
import org.yaaic.model.Channel;
import org.yaaic.model.Message;
import org.yaaic.model.Server;
import org.yaaic.model.Status;
@ -79,7 +80,8 @@ public class IRCConnection extends PircBot
{
debug("Action", target + " " + sender + " " + action);
server.getChannel(target).addMessage("* " + sender + " " + action);
Message message = new Message(sender + " " + action);
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
@ -104,7 +106,8 @@ public class IRCConnection extends PircBot
{
debug("Deop", target + " " + recipient + "(" + sourceNick + ")");
server.getChannel(target).addMessage(sourceNick + " deoped " + recipient);
Message message = new Message(sourceNick + " deoped " + recipient);
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
@ -120,7 +123,8 @@ public class IRCConnection extends PircBot
{
debug("DeVoice", target + " " + recipient + "(" + sourceNick + ")");
server.getChannel(target).addMessage(sourceNick + " devoiced " + recipient);
Message message = new Message(sourceNick + " devoiced " + recipient);
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
@ -136,7 +140,8 @@ public class IRCConnection extends PircBot
{
debug("Invite", target + " " + targetNick + "(" + sourceNick + ")");
server.getChannel(target).addMessage(sourceNick + " invited " + targetNick);
Message message = new Message(sourceNick + " invited " + targetNick);
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
@ -161,7 +166,8 @@ public class IRCConnection extends PircBot
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
service.sendBroadcast(intent);
} else {
server.getChannel(target).addMessage(sender + " joined");
Message message = new Message(sender + " joined");
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
@ -187,7 +193,8 @@ public class IRCConnection extends PircBot
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);
} else {
server.getChannel(target).addMessage(kickerNick + " kicked " + recipientNick);
Message message = new Message(kickerNick + " kicked " + recipientNick);
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
@ -200,11 +207,12 @@ public class IRCConnection extends PircBot
* On Message
*/
@Override
protected void onMessage(String target, String sender, String login, String hostname, String message)
protected void onMessage(String target, String sender, String login, String hostname, String text)
{
debug("Message", target + " " + sender + " " + message);
debug("Message", target + " " + sender + " " + text);
server.getChannel(target).addMessage("<" + sender + "> " + message);
Message message = new Message("<" + sender + "> " + text);
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
@ -220,7 +228,8 @@ public class IRCConnection extends PircBot
{
debug("Mode", target + " " + sourceNick + " " + mode);
server.getChannel(target).addMessage(sourceNick + " sets mode " + mode);
Message message = new Message(sourceNick + " sets mode " + mode);
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
@ -235,6 +244,8 @@ public class IRCConnection extends PircBot
protected void onNickChange(String oldNick, String login, String hostname, String newNick)
{
debug("Nick", oldNick + " " + newNick);
// XXX: Add message to all channels where oldNick / newNick is present
}
/**
@ -244,6 +255,8 @@ public class IRCConnection extends PircBot
protected void onNotice(String sourceNick, String sourceLogin, String sourceHostname, String target, String notice)
{
debug("Notice", sourceNick + " " + notice);
// XXX: Where should notices be shown? Current window? All windows? Server window?
}
/**
@ -254,7 +267,8 @@ public class IRCConnection extends PircBot
{
debug("Op", target + " " + recipient + "(" + sourceNick + ")");
server.getChannel(target).addMessage(sourceNick + " oped " + recipient);
Message message = new Message(sourceNick + " oped " + recipient);
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
@ -279,7 +293,8 @@ public class IRCConnection extends PircBot
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);
} else {
server.getChannel(target).addMessage(sender + " parted");
Message message = new Message(sender + " parted");
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
@ -315,9 +330,11 @@ public class IRCConnection extends PircBot
debug("Topic", target + " " + setBy + " " + topic);
if (changed) {
server.getChannel(target).addMessage(setBy + " sets topic: " + topic);
Message message = new Message(setBy + " sets topic: " + topic);
server.getChannel(target).addMessage(message);
} else {
server.getChannel(target).addMessage("Topic: " + topic);
Message message = new Message("Topic: " + topic);
server.getChannel(target).addMessage(message);
}
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
@ -333,6 +350,8 @@ public class IRCConnection extends PircBot
protected void onUserList(String channel, User[] users)
{
debug("UserList", channel + " (" + users.length + ")");
// XXX: Store user list somewhere and keep it updated or just broadcast some event?
}
/**
@ -343,7 +362,8 @@ public class IRCConnection extends PircBot
{
debug("Voice", target + " " + recipient + "(" + sourceNick + ")");
server.getChannel(target).addMessage(sourceNick + " voiced " + recipient);
Message message = new Message(sourceNick + " voiced " + recipient);
server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());

View File

@ -32,8 +32,8 @@ public class Channel
private static final int BUFFER_SIZE = 30;
private String name;
private LinkedList<String> buffer = new LinkedList<String>();
private LinkedList<String> history = new LinkedList<String>();
private LinkedList<Message> buffer = new LinkedList<Message>();
private LinkedList<Message> history = new LinkedList<Message>();
/**
* Create a new channel object
@ -56,7 +56,7 @@ public class Channel
/**
* Add a message to the channel
*/
public void addMessage(String message)
public void addMessage(Message message)
{
buffer.addFirst(message);
history.addLast(message);
@ -71,7 +71,7 @@ public class Channel
*
* @return
*/
public LinkedList<String> getBuffer()
public LinkedList<Message> getBuffer()
{
return buffer;
}
@ -81,7 +81,7 @@ public class Channel
*
* @return
*/
public LinkedList<String> getHistory()
public LinkedList<Message> getHistory()
{
return history;
}
@ -91,7 +91,7 @@ public class Channel
*
* @return
*/
public String pollMessage()
public Message pollMessage()
{
return buffer.poll();
}

View File

@ -20,6 +20,8 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.model;
import android.text.SpannableString;
/**
* A channel or server message
*
@ -28,6 +30,7 @@ package org.yaaic.model;
public class Message {
private int icon;
private String text;
private SpannableString span;
/**
* Create a new message without an icon
@ -81,4 +84,19 @@ public class Message {
{
return text;
}
/**
* Render message as spannable string
*/
public SpannableString render()
{
if (span == null) {
span = new SpannableString(text);
if (hasIcon()) {
}
}
return span;
}
}

View File

@ -54,6 +54,7 @@ import org.yaaic.irc.IRCService;
import org.yaaic.listener.ChannelListener;
import org.yaaic.model.Broadcast;
import org.yaaic.model.Channel;
import org.yaaic.model.Message;
import org.yaaic.model.Server;
import org.yaaic.receiver.ChannelReceiver;
@ -193,18 +194,18 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
*/
public void onChannelMessage(String target)
{
String message = server.getChannel(target).pollMessage();
Message message = server.getChannel(target).pollMessage();
TextView canvas = (TextView) deckAdapter.getItemByName(target);
if (canvas != null) {
canvas.append("\n" + message);
canvas.append(message.render());
deckAdapter.notifyDataSetChanged();
Log.d(TAG, "Target: " + target + " - Switched: " + deckAdapter.getSwitchedName());
if (target.equals(deckAdapter.getSwitchedName())) {
((TextView) deckAdapter.getSwitchedView()).append("\n" + message);
((TextView) deckAdapter.getSwitchedView()).append(message.render());
}
} else {
Log.d(TAG, "No canvas found");