From 3c8e02c9dd98d6c07e31edeb6a548f46f4b4dbfd Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Tue, 2 Mar 2010 19:27:35 +0100 Subject: [PATCH] First simple channel model --- src/org/yaaic/model/Channel.java | 66 ++++++++++++++++++++++++++++++++ src/org/yaaic/model/Server.java | 34 +++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/org/yaaic/model/Channel.java diff --git a/src/org/yaaic/model/Channel.java b/src/org/yaaic/model/Channel.java new file mode 100644 index 0000000..5bd7f16 --- /dev/null +++ b/src/org/yaaic/model/Channel.java @@ -0,0 +1,66 @@ +/* + Yaaic - Yet Another Android IRC Client + +Copyright 2009 Sebastian Kaspari + +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 . +*/ +package org.yaaic.model; + +import java.util.LinkedList; + +/** + * An IRC channel + * + * @author Sebastian Kaspari + */ +public class Channel +{ + private static final int BUFFER_SIZE = 30; + + private String name; + private LinkedList messages = new LinkedList(); + + /** + * Create a new channel object + * + * @param name of the channel + */ + public Channel(String name) + { + this.name = name; + } + + /** + * Get name of channel + */ + public String getName() + { + return name; + } + + /** + * Add a message to the channel + */ + public void addMessage(String message) + { + messages.add(message); + + if (messages.size() > BUFFER_SIZE) { + messages.removeFirst(); + } + } +} diff --git a/src/org/yaaic/model/Server.java b/src/org/yaaic/model/Server.java index 7e1258c..1e1febc 100644 --- a/src/org/yaaic/model/Server.java +++ b/src/org/yaaic/model/Server.java @@ -20,6 +20,8 @@ along with Yaaic. If not, see . */ package org.yaaic.model; +import java.util.ArrayList; + import org.yaaic.R; /** @@ -34,6 +36,8 @@ public class Server private String host; private int port; + private ArrayList channels = new ArrayList(); + private int status = Status.DISCONNECTED; /** @@ -139,7 +143,7 @@ public class Server /** * Is disconnected? * - * @return + * @return true if the user is disconnected, false if the user is connected or currently connecting */ public boolean isDisconnected() { @@ -148,13 +152,39 @@ public class Server /** * Is connected? - * @return + * + * @return true if the user is (successfully) connected to this server, false otherwise */ public boolean isConnected() { return status == Status.CONNECTED; } + /** + * Get all (joined) channels + * + * @return + */ + public ArrayList getChannels() + { + return channels; + } + + /** + * Add a new (joined) channel + * + * @param channel + */ + public void addChannel(Channel channel) + { + channels.add(channel); + } + + /** + * Get icon for current server status + * + * @return int Status icon ressource + */ public int getStatusIcon() { switch (status) {