From f4637ac58280094bd539d282cbe0373cb0a0524d Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Tue, 22 Feb 2011 17:31:51 +0100 Subject: [PATCH] Use a different color for join/part/quit for the circles in the ConversationSwitcher view. This makes it easier to ignore unintersting messages wihout turning off the setting to show joins/parts/quits. Once circle is colored for a new message, the join/part/quit cannot override it anymore. --- .../yaaic/activity/ConversationActivity.java | 23 ++++++--- .../src/org/yaaic/irc/IRCConnection.java | 12 +++-- .../src/org/yaaic/model/Conversation.java | 7 +++ application/src/org/yaaic/model/Message.java | 50 +++++++++++++++++-- .../org/yaaic/view/ConversationSwitcher.java | 2 + 5 files changed, 79 insertions(+), 15 deletions(-) diff --git a/application/src/org/yaaic/activity/ConversationActivity.java b/application/src/org/yaaic/activity/ConversationActivity.java index 79d9048..65aafbc 100644 --- a/application/src/org/yaaic/activity/ConversationActivity.java +++ b/application/src/org/yaaic/activity/ConversationActivity.java @@ -72,8 +72,8 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.View.OnKeyListener; import android.view.Window; +import android.view.View.OnKeyListener; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; @@ -388,19 +388,28 @@ public class ConversationActivity extends Activity implements ServiceConnection, MessageListAdapter adapter = conversation.getMessageListAdapter(); - conversation.setStatus(Conversation.STATUS_MESSAGE); - - if (dots != null) { - dots.invalidate(); - } - while(conversation.hasBufferedMessages()) { Message message = conversation.pollBufferedMessage(); if (adapter != null) { adapter.addMessage(message); + int status; + switch (message.getType()) + { + case Message.TYPE_MISC: + status = Conversation.STATUS_MISC; + break; + default: + status = Conversation.STATUS_MESSAGE; + break; + } + conversation.setStatus(status); } } + + if (dots != null) { + dots.invalidate(); + } } /** diff --git a/application/src/org/yaaic/irc/IRCConnection.java b/application/src/org/yaaic/irc/IRCConnection.java index 8c883d8..f310f44 100644 --- a/application/src/org/yaaic/irc/IRCConnection.java +++ b/application/src/org/yaaic/irc/IRCConnection.java @@ -340,7 +340,8 @@ public class IRCConnection extends PircBot ); service.sendBroadcast(intent); } else if (service.getSettings().showJoinAndPart()) { - Message message = new Message(service.getString(R.string.message_join, sender)); + Message message = new Message(service.getString(R.string.message_join, sender), + Message.TYPE_MISC); message.setIcon(R.drawable.join); message.setColor(Message.COLOR_GREEN); server.getConversation(target).addMessage(message); @@ -524,7 +525,8 @@ public class IRCConnection extends PircBot ); service.sendBroadcast(intent); } else if (service.getSettings().showJoinAndPart()) { - Message message = new Message(service.getString(R.string.message_part, sender)); + Message message = new Message(service.getString(R.string.message_part, sender), + Message.TYPE_MISC); message.setColor(Message.COLOR_GREEN); message.setIcon(R.drawable.part); server.getConversation(target).addMessage(message); @@ -596,7 +598,8 @@ public class IRCConnection extends PircBot Vector channels = getChannelsByNickname(sourceNick); for (String target : channels) { - Message message = new Message(service.getString(R.string.message_quit, sourceNick, reason)); + Message message = new Message(service.getString(R.string.message_quit, sourceNick, reason), + Message.TYPE_MISC); message.setColor(Message.COLOR_GREEN); message.setIcon(R.drawable.quit); server.getConversation(target).addMessage(message); @@ -613,7 +616,8 @@ public class IRCConnection extends PircBot Conversation conversation = server.getConversation(sourceNick); if (conversation != null) { - Message message = new Message(service.getString(R.string.message_quit, sourceNick, reason)); + Message message = new Message(service.getString(R.string.message_quit, sourceNick, reason), + Message.TYPE_MISC); message.setColor(Message.COLOR_GREEN); message.setIcon(R.drawable.quit); conversation.addMessage(message); diff --git a/application/src/org/yaaic/model/Conversation.java b/application/src/org/yaaic/model/Conversation.java index f6ae7e3..868dd56 100644 --- a/application/src/org/yaaic/model/Conversation.java +++ b/application/src/org/yaaic/model/Conversation.java @@ -41,6 +41,8 @@ public abstract class Conversation public static final int STATUS_SELECTED = 2; public static final int STATUS_MESSAGE = 3; public static final int STATUS_HIGHLIGHT = 4; + /* join/part/quit */ + public static final int STATUS_MISC = 5; public static final int HISTORY_SIZE = 30; @@ -180,6 +182,11 @@ public abstract class Conversation return; } + // Misc cannot change any other than default + if (this.status != STATUS_DEFAULT && status == STATUS_MISC) { + return; + } + this.status = status; } diff --git a/application/src/org/yaaic/model/Message.java b/application/src/org/yaaic/model/Message.java index 51ac794..56fc11e 100644 --- a/application/src/org/yaaic/model/Message.java +++ b/application/src/org/yaaic/model/Message.java @@ -44,6 +44,11 @@ public class Message { public static final int COLOR_GREY = 0xFFaaaaaa; public static final int COLOR_DEFAULT = 0xFFeeeeee; + /* normal message, this is the default */ + public static final int TYPE_MESSAGE = 0; + /* join, part or quit */ + public static final int TYPE_MISC = 1; + /* Some are light versions because dark colors hardly readable on * Yaaic's dark background */ public static final int[] colors = { @@ -65,6 +70,7 @@ public class Message { 0xFF000000, // Black }; + private int type = -1; private int icon = -1; private final String text; private final String sender; @@ -73,25 +79,51 @@ public class Message { private final long timestamp; /** - * Create a new message without an icon + * Create a new message without an icon defaulting to TYPE_MESSAGE * * @param text */ public Message(String text) { - this(text, null); + this(text, null, TYPE_MESSAGE); } + /** - * Create a new message sent by a user without an icon - * + * Create a new message without an icon with a specific type + * + * @param text + * @param type Message type + */ + public Message(String text, int type) + { + this(text, null, type); + } + + /** + * Create a new message sent by a user, without an icon, + * defaulting to TYPE_MESSAGE + * * @param text * @param sender */ public Message(String text, String sender) + { + this(text, sender, TYPE_MESSAGE); + } + + /** + * Create a new message sent by a user without an icon + * + * @param text + * @param sender + * @param type Message type + */ + public Message(String text, String sender, int type) { this.text = text; this.sender = sender; this.timestamp = new Date().getTime(); + this.type = type; } /** @@ -122,6 +154,16 @@ public class Message { return text; } + /** + * Get the type of this message + * + * @return One of Message.TYPE_* + */ + public int getType() + { + return type; + } + /** * Set the color of this message */ diff --git a/application/src/org/yaaic/view/ConversationSwitcher.java b/application/src/org/yaaic/view/ConversationSwitcher.java index b3276b9..b16531e 100644 --- a/application/src/org/yaaic/view/ConversationSwitcher.java +++ b/application/src/org/yaaic/view/ConversationSwitcher.java @@ -110,6 +110,8 @@ public class ConversationSwitcher extends View case Conversation.STATUS_SELECTED: paint.setColor(0xFFFFFFFF); break; + case Conversation.STATUS_MISC: + paint.setColor(0xFF3333AA); } canvas.drawCircle(startX + 12 * i, height / 2, 4, paint);