1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-11 11:44:59 -05:00

New setting: Play (notification) sound on highlight

This commit is contained in:
Sebastian Kaspari 2010-12-17 22:29:33 +01:00
parent 4b3e47c799
commit e014165a17
6 changed files with 196 additions and 154 deletions

View File

@ -32,4 +32,7 @@
<string name="key_vibrate_highlight">vibrate_highlight</string> <string name="key_vibrate_highlight">vibrate_highlight</string>
<string name="default_vibrate_highlight">true</string> <string name="default_vibrate_highlight">true</string>
<string name="key_sound_highlight">sound_highlight</string>
<string name="default_sound_highlight">false</string>
</resources> </resources>

View File

@ -161,6 +161,7 @@
<string name="settings_connection">Connection</string> <string name="settings_connection">Connection</string>
<string name="settings_reconnect_title">Reconnect</string> <string name="settings_reconnect_title">Reconnect</string>
<string name="settings_reconnect_desc">Automatically reconnect on disconnect</string> <string name="settings_reconnect_desc">Automatically reconnect on disconnect</string>
<string name="settings_chat">Chat</string> <string name="settings_chat">Chat</string>
<string name="settings_icons_title">Show icons</string> <string name="settings_icons_title">Show icons</string>
<string name="settings_icons_desc">Show icons to highlight special events</string> <string name="settings_icons_desc">Show icons to highlight special events</string>
@ -172,6 +173,13 @@
<string name="settings_timestamp_desc">Prefix all messages with a timestamp</string> <string name="settings_timestamp_desc">Prefix all messages with a timestamp</string>
<string name="settings_24h_title">24 hour format</string> <string name="settings_24h_title">24 hour format</string>
<string name="settings_24h_desc">Use 24 hour format for timestamps</string> <string name="settings_24h_desc">Use 24 hour format for timestamps</string>
<string name="settings_highlight">Highlight</string>
<string name="settings_sound_highlight_title">Play sound on highlight</string>
<string name="settings_sound_highlight_desc">Play sound when your nick is mentioned</string>
<string name="settings_vibrate_highlight_title">Vibrate on highlight</string>
<string name="settings_vibrate_highlight_desc">Vibrate when your nick is mentioned</string>
<string name="settings_misc">Misc</string> <string name="settings_misc">Misc</string>
<string name="settings_quitmessage_title">Quit message</string> <string name="settings_quitmessage_title">Quit message</string>
<string name="settings_quitmessage_desc">Message to show when you disconnect</string> <string name="settings_quitmessage_desc">Message to show when you disconnect</string>
@ -182,8 +190,6 @@
<string name="settings_fontsize_dialog_title">Font size</string> <string name="settings_fontsize_dialog_title">Font size</string>
<string name="settings_voice_recognition_title">Voice recognition</string> <string name="settings_voice_recognition_title">Voice recognition</string>
<string name="settings_voice_recognition_desc">Show button for voice recognition</string> <string name="settings_voice_recognition_desc">Show button for voice recognition</string>
<string name="settings_vibrate_highlight_title">Vibrate on highlight</string>
<string name="settings_vibrate_highlight_desc">Vibrate when your nick is mentioned</string>
<string name="settings_joinpart_title">Show join and part</string> <string name="settings_joinpart_title">Show join and part</string>
<string name="settings_joinpart_desc">Show join and part messages in channels</string> <string name="settings_joinpart_desc">Show join and part messages in channels</string>
</resources> </resources>

View File

@ -71,6 +71,19 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:key="@string/key_show_joinpart" android:key="@string/key_show_joinpart"
android:defaultValue="@string/default_show_joinpart" /> android:defaultValue="@string/default_show_joinpart" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory
android:title="@string/settings_highlight">
<CheckBoxPreference
android:title="@string/settings_sound_highlight_title"
android:summary="@string/settings_sound_highlight_desc"
android:key="@string/key_sound_highlight"
android:defaultValue="@string/default_sound_highlight" />
<CheckBoxPreference
android:title="@string/settings_vibrate_highlight_title"
android:summary="@string/settings_vibrate_highlight_desc"
android:key="@string/key_vibrate_highlight"
android:defaultValue="@string/default_vibrate_highlight" />
</PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/settings_misc"> android:title="@string/settings_misc">
<CheckBoxPreference <CheckBoxPreference
@ -85,10 +98,5 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:defaultValue="@string/default_quitmessage" android:defaultValue="@string/default_quitmessage"
android:dialogTitle="@string/settings_quitmessage_dialog_title" android:dialogTitle="@string/settings_quitmessage_dialog_title"
android:dialogMessage="@string/settings_quitmessage_dialog_desc" /> android:dialogMessage="@string/settings_quitmessage_dialog_desc" />
<CheckBoxPreference
android:title="@string/settings_vibrate_highlight_title"
android:summary="@string/settings_vibrate_highlight_desc"
android:key="@string/key_vibrate_highlight"
android:defaultValue="@string/default_vibrate_highlight" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@ -17,7 +17,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>. along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.irc; package org.yaaic.irc;
import java.util.ArrayList; import java.util.ArrayList;
@ -25,12 +25,9 @@ import java.util.Collection;
import java.util.Vector; import java.util.Vector;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import android.content.Intent;
import org.jibble.pircbot.Colors; import org.jibble.pircbot.Colors;
import org.jibble.pircbot.PircBot; import org.jibble.pircbot.PircBot;
import org.jibble.pircbot.User; import org.jibble.pircbot.User;
import org.yaaic.R; import org.yaaic.R;
import org.yaaic.Yaaic; import org.yaaic.Yaaic;
import org.yaaic.command.CommandParser; import org.yaaic.command.CommandParser;
@ -43,6 +40,8 @@ import org.yaaic.model.Server;
import org.yaaic.model.ServerInfo; import org.yaaic.model.ServerInfo;
import org.yaaic.model.Status; import org.yaaic.model.Status;
import android.content.Intent;
/** /**
* The class that actually handles the connection to an IRC server * The class that actually handles the connection to an IRC server
* *
@ -50,11 +49,11 @@ import org.yaaic.model.Status;
*/ */
public class IRCConnection extends PircBot public class IRCConnection extends PircBot
{ {
private IRCService service; private final IRCService service;
private Server server; private final Server server;
private ArrayList<String> autojoinChannels; private ArrayList<String> autojoinChannels;
private Pattern mNickMatch; private Pattern mNickMatch;
/** /**
* Create a new connection * Create a new connection
* *
@ -65,14 +64,14 @@ public class IRCConnection extends PircBot
{ {
this.server = Yaaic.getInstance().getServerById(serverId); this.server = Yaaic.getInstance().getServerById(serverId);
this.service = service; this.service = service;
// XXX: Should be configurable via settings // XXX: Should be configurable via settings
this.setAutoNickChange(true); this.setAutoNickChange(true);
this.setFinger("http://www.youtube.com/watch?v=oHg5SJYRHA0"); this.setFinger("http://www.youtube.com/watch?v=oHg5SJYRHA0");
this.updateNickMatchPattern(); this.updateNickMatchPattern();
} }
/** /**
* Set the nickname of the user * Set the nickname of the user
* *
@ -83,7 +82,7 @@ public class IRCConnection extends PircBot
this.setName(nickname); this.setName(nickname);
this.updateNickMatchPattern(); this.updateNickMatchPattern();
} }
/** /**
* Set the real name of the user * Set the real name of the user
* *
@ -92,10 +91,10 @@ public class IRCConnection extends PircBot
public void setRealName(String realname) public void setRealName(String realname)
{ {
// XXX: Pircbot uses the version for "real name" and "version". // XXX: Pircbot uses the version for "real name" and "version".
// The real "version" value is provided by onVersion() // The real "version" value is provided by onVersion()
this.setVersion(realname); this.setVersion(realname);
} }
/** /**
* Set channels to autojoin after connect * Set channels to autojoin after connect
* *
@ -115,9 +114,9 @@ public class IRCConnection extends PircBot
protected void onVersion(String sourceNick, String sourceLogin, String sourceHostname, String target) protected void onVersion(String sourceNick, String sourceLogin, String sourceHostname, String target)
{ {
this.sendRawLine( this.sendRawLine(
"NOTICE " + sourceNick + " :\u0001VERSION " + "NOTICE " + sourceNick + " :\u0001VERSION " +
"Yaaic - Yet another Android IRC client - http://www.yaaic.org" + "Yaaic - Yet another Android IRC client - http://www.yaaic.org" +
"\u0001" "\u0001"
); );
} }
@ -138,40 +137,40 @@ public class IRCConnection extends PircBot
public void onConnect() public void onConnect()
{ {
server.setStatus(Status.CONNECTED); server.setStatus(Status.CONNECTED);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createServerIntent(Broadcast.SERVER_UPDATE, server.getId()) Broadcast.createServerIntent(Broadcast.SERVER_UPDATE, server.getId())
); );
service.updateNotification(service.getString(R.string.notification_connected, server.getTitle())); service.updateNotification(service.getString(R.string.notification_connected, server.getTitle()));
Message message = new Message(service.getString(R.string.message_connected, server.getTitle())); Message message = new Message(service.getString(R.string.message_connected, server.getTitle()));
message.setColor(Message.COLOR_GREEN); message.setColor(Message.COLOR_GREEN);
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
ServerInfo.DEFAULT_NAME ServerInfo.DEFAULT_NAME
); );
service.sendBroadcast(intent); service.sendBroadcast(intent);
// execute commands // execute commands
CommandParser parser = CommandParser.getInstance(); CommandParser parser = CommandParser.getInstance();
this.updateNickMatchPattern(); this.updateNickMatchPattern();
for (String command : server.getConnectCommands()) { for (String command : server.getConnectCommands()) {
parser.parse(command, server, server.getConversation(ServerInfo.DEFAULT_NAME), service); parser.parse(command, server, server.getConversation(ServerInfo.DEFAULT_NAME), service);
} }
// delay 1 sec before auto joining channels // delay 1 sec before auto joining channels
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch(InterruptedException e) { } catch(InterruptedException e) {
// do nothing // do nothing
} }
// join channels // join channels
if (autojoinChannels != null) { if (autojoinChannels != null) {
for (String channel : autojoinChannels) { for (String channel : autojoinChannels) {
@ -184,7 +183,7 @@ public class IRCConnection extends PircBot
} }
} }
} }
/** /**
* On channel action * On channel action
*/ */
@ -196,19 +195,23 @@ public class IRCConnection extends PircBot
Message message = new Message(sender + " " + action); Message message = new Message(sender + " " + action);
message.setIcon(R.drawable.action); message.setIcon(R.drawable.action);
if (isMentioned(action)) { if (isMentioned(action)) {
// highlight // highlight
message.setColor(Message.COLOR_RED); message.setColor(Message.COLOR_RED);
service.updateNotification(target + ": " + sender + " " + action, service.getSettings().isVibrateHighlightEnabled()); service.updateNotification(
target + ": " + sender + " " + action,
service.getSettings().isVibrateHighlightEnabled(),
service.getSettings().isSoundHighlightEnabled()
);
server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT); server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT);
} }
if (target.equals(this.getNick())) { if (target.equals(this.getNick())) {
// We are the target - this is an action in a query // We are the target - this is an action in a query
Conversation conversation = server.getConversation(sender); Conversation conversation = server.getConversation(sender);
if (conversation == null) { if (conversation == null) {
// Open a query if there's none yet // Open a query if there's none yet
conversation = new Query(sender); conversation = new Query(sender);
server.addConversationl(conversation); server.addConversationl(conversation);
@ -231,7 +234,7 @@ public class IRCConnection extends PircBot
} else { } else {
// A action in a channel // A action in a channel
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -259,7 +262,7 @@ public class IRCConnection extends PircBot
message.setIcon(R.drawable.op); message.setIcon(R.drawable.op);
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -279,13 +282,13 @@ public class IRCConnection extends PircBot
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
message.setIcon(R.drawable.voice); message.setIcon(R.drawable.voice);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
target target
); );
service.sendBroadcast(intent); service.sendBroadcast(intent);
} }
@ -299,7 +302,7 @@ public class IRCConnection extends PircBot
// We are invited // We are invited
Message message = new Message(service.getString(R.string.message_invite_you, sourceNick, target)); Message message = new Message(service.getString(R.string.message_invite_you, sourceNick, target));
server.getConversation(server.getSelectedConversation()).addMessage(message); server.getConversation(server.getSelectedConversation()).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -310,7 +313,7 @@ public class IRCConnection extends PircBot
// Someone is invited // Someone is invited
Message message = new Message(service.getString(R.string.message_invite_someone, sourceNick, targetNick, target)); Message message = new Message(service.getString(R.string.message_invite_someone, sourceNick, targetNick, target));
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -329,7 +332,7 @@ public class IRCConnection extends PircBot
if (sender.equalsIgnoreCase(getNick())) { if (sender.equalsIgnoreCase(getNick())) {
// We joined a new channel // We joined a new channel
server.addConversationl(new Channel(target)); server.addConversationl(new Channel(target));
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_NEW, Broadcast.CONVERSATION_NEW,
server.getId(), server.getId(),
@ -341,7 +344,7 @@ public class IRCConnection extends PircBot
message.setIcon(R.drawable.join); message.setIcon(R.drawable.join);
message.setColor(Message.COLOR_GREEN); message.setColor(Message.COLOR_GREEN);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -360,7 +363,7 @@ public class IRCConnection extends PircBot
if (recipientNick.equals(getNick())) { if (recipientNick.equals(getNick())) {
// We are kicked // We are kicked
server.removeConversation(target); server.removeConversation(target);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_REMOVE, Broadcast.CONVERSATION_REMOVE,
server.getId(), server.getId(),
@ -377,7 +380,7 @@ public class IRCConnection extends PircBot
server.getId(), server.getId(),
target target
); );
service.sendBroadcast(intent); service.sendBroadcast(intent);
} }
} }
@ -389,19 +392,23 @@ public class IRCConnection extends PircBot
{ {
// Strip mIRC colors and formatting // Strip mIRC colors and formatting
text = Colors.removeFormattingAndColors(text); text = Colors.removeFormattingAndColors(text);
Message message = new Message(text, sender); Message message = new Message(text, sender);
if (isMentioned(text)) { if (isMentioned(text)) {
// highlight // highlight
message.setColor(Message.COLOR_RED); message.setColor(Message.COLOR_RED);
service.updateNotification(target + ": <" + sender + "> " + text, service.getSettings().isVibrateHighlightEnabled()); service.updateNotification(
target + ": <" + sender + "> " + text,
service.getSettings().isVibrateHighlightEnabled(),
service.getSettings().isSoundHighlightEnabled()
);
server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT); server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT);
} }
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -419,12 +426,12 @@ public class IRCConnection extends PircBot
/*//Disabled as it doubles events (e.g. onOp and onMode will be called) /*//Disabled as it doubles events (e.g. onOp and onMode will be called)
Message message = new Message(sourceNick + " sets mode " + mode); Message message = new Message(sourceNick + " sets mode " + mode);
server.getChannel(target).addMessage(message); server.getChannel(target).addMessage(message);
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE); Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId()); intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
intent.putExtra(Broadcast.EXTRA_CHANNEL, target); intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent); service.sendBroadcast(intent);
*/ */
} }
/** /**
@ -432,17 +439,17 @@ public class IRCConnection extends PircBot
*/ */
@Override @Override
protected void onNickChange(String oldNick, String login, String hostname, String newNick) protected void onNickChange(String oldNick, String login, String hostname, String newNick)
{ {
if (getNick().equalsIgnoreCase(newNick)) { if (getNick().equalsIgnoreCase(newNick)) {
this.updateNickMatchPattern(); this.updateNickMatchPattern();
} }
Vector<String> channels = getChannelsByNickname(newNick); Vector<String> channels = getChannelsByNickname(newNick);
for (String target : channels) { for (String target : channels) {
Message message = new Message(service.getString(R.string.message_rename, oldNick, newNick)); Message message = new Message(service.getString(R.string.message_rename, oldNick, newNick));
message.setColor(Message.COLOR_GREEN); message.setColor(Message.COLOR_GREEN);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -460,10 +467,10 @@ public class IRCConnection extends PircBot
{ {
// Strip mIRC colors and formatting // Strip mIRC colors and formatting
notice = Colors.removeFormattingAndColors(notice); notice = Colors.removeFormattingAndColors(notice);
// Post notice to currently selected conversation // Post notice to currently selected conversation
Conversation conversation = server.getConversation(server.getSelectedConversation()); Conversation conversation = server.getConversation(server.getSelectedConversation());
if (conversation == null) { if (conversation == null) {
// Fallback: Use ServerInfo view // Fallback: Use ServerInfo view
conversation = server.getConversation(ServerInfo.DEFAULT_NAME); conversation = server.getConversation(ServerInfo.DEFAULT_NAME);
@ -472,7 +479,7 @@ public class IRCConnection extends PircBot
Message message = new Message("-" + sourceNick + "- " + notice); Message message = new Message("-" + sourceNick + "- " + notice);
message.setIcon(R.drawable.info); message.setIcon(R.drawable.info);
conversation.addMessage(message); conversation.addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -491,7 +498,7 @@ public class IRCConnection extends PircBot
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
message.setIcon(R.drawable.op); message.setIcon(R.drawable.op);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -509,7 +516,7 @@ public class IRCConnection extends PircBot
if (sender.equals(getNick())) { if (sender.equals(getNick())) {
// We parted a channel // We parted a channel
server.removeConversation(target); server.removeConversation(target);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_REMOVE, Broadcast.CONVERSATION_REMOVE,
server.getId(), server.getId(),
@ -521,7 +528,7 @@ public class IRCConnection extends PircBot
message.setColor(Message.COLOR_GREEN); message.setColor(Message.COLOR_GREEN);
message.setIcon(R.drawable.part); message.setIcon(R.drawable.part);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -541,22 +548,26 @@ public class IRCConnection extends PircBot
text = Colors.removeFormattingAndColors(text); text = Colors.removeFormattingAndColors(text);
Message message = new Message("<" + sender + "> " + text); Message message = new Message("<" + sender + "> " + text);
if (isMentioned(text)) { if (isMentioned(text)) {
message.setColor(Message.COLOR_RED); message.setColor(Message.COLOR_RED);
service.updateNotification("<" + sender + "> " + text, service.getSettings().isVibrateHighlightEnabled()); service.updateNotification(
"<" + sender + "> " + text,
service.getSettings().isVibrateHighlightEnabled(),
service.getSettings().isSoundHighlightEnabled()
);
server.getConversation(sender).setStatus(Conversation.STATUS_HIGHLIGHT); server.getConversation(sender).setStatus(Conversation.STATUS_HIGHLIGHT);
} }
Conversation conversation = server.getConversation(sender); Conversation conversation = server.getConversation(sender);
if (conversation == null) { if (conversation == null) {
// Open a query if there's none yet // Open a query if there's none yet
conversation = new Query(sender); conversation = new Query(sender);
conversation.addMessage(message); conversation.addMessage(message);
server.addConversationl(conversation); server.addConversationl(conversation);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_NEW, Broadcast.CONVERSATION_NEW,
server.getId(), server.getId(),
@ -565,7 +576,7 @@ public class IRCConnection extends PircBot
service.sendBroadcast(intent); service.sendBroadcast(intent);
} else { } else {
conversation.addMessage(message); conversation.addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -583,13 +594,13 @@ public class IRCConnection extends PircBot
{ {
if (!sourceNick.equals(this.getNick())) { if (!sourceNick.equals(this.getNick())) {
Vector<String> channels = getChannelsByNickname(sourceNick); Vector<String> channels = getChannelsByNickname(sourceNick);
for (String target : channels) { 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.setColor(Message.COLOR_GREEN); message.setColor(Message.COLOR_GREEN);
message.setIcon(R.drawable.quit); message.setIcon(R.drawable.quit);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -597,16 +608,16 @@ public class IRCConnection extends PircBot
); );
service.sendBroadcast(intent); service.sendBroadcast(intent);
} }
// Look if there's a query to update // Look if there's a query to update
Conversation conversation = server.getConversation(sourceNick); Conversation conversation = server.getConversation(sourceNick);
if (conversation != null) { 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.setColor(Message.COLOR_GREEN); message.setColor(Message.COLOR_GREEN);
message.setIcon(R.drawable.quit); message.setIcon(R.drawable.quit);
conversation.addMessage(message); conversation.addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -614,7 +625,7 @@ public class IRCConnection extends PircBot
); );
service.sendBroadcast(intent); service.sendBroadcast(intent);
} }
} else { } else {
// XXX: We quitted // XXX: We quitted
} }
@ -628,7 +639,7 @@ public class IRCConnection extends PircBot
{ {
// strip mIRC colors // strip mIRC colors
topic = Colors.removeFormattingAndColors(topic); topic = Colors.removeFormattingAndColors(topic);
if (changed) { if (changed) {
Message message = new Message(service.getString(R.string.message_topic_set, setBy, topic)); Message message = new Message(service.getString(R.string.message_topic_set, setBy, topic));
message.setColor(Message.COLOR_YELLOW); message.setColor(Message.COLOR_YELLOW);
@ -638,10 +649,10 @@ public class IRCConnection extends PircBot
message.setColor(Message.COLOR_YELLOW); message.setColor(Message.COLOR_YELLOW);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
} }
// remember channel's topic // remember channel's topic
((Channel) server.getConversation(target)).setTopic(topic); ((Channel) server.getConversation(target)).setTopic(topic);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -669,7 +680,7 @@ public class IRCConnection extends PircBot
message.setIcon(R.drawable.voice); message.setIcon(R.drawable.voice);
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -677,9 +688,9 @@ public class IRCConnection extends PircBot
); );
service.sendBroadcast(intent); service.sendBroadcast(intent);
} }
/** /**
* On remove channel key * On remove channel key
*/ */
@Override @Override
protected void onRemoveChannelKey(String target, String sourceNick, String sourceLogin, String sourceHostname, String key) protected void onRemoveChannelKey(String target, String sourceNick, String sourceLogin, String sourceHostname, String key)
@ -687,7 +698,7 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_remove_channel_key, sourceNick)); Message message = new Message(service.getString(R.string.message_remove_channel_key, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
@ -702,12 +713,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_set_channel_key, sourceNick, key)); Message message = new Message(service.getString(R.string.message_set_channel_key, sourceNick, key));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On set secret * On set secret
*/ */
@ -717,12 +728,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_set_channel_secret, sourceNick)); Message message = new Message(service.getString(R.string.message_set_channel_secret, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On remove secret * On remove secret
*/ */
@ -732,12 +743,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_set_channel_public, sourceNick)); Message message = new Message(service.getString(R.string.message_set_channel_public, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On set channel limit * On set channel limit
*/ */
@ -747,12 +758,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_set_channel_limit, sourceNick, limit)); Message message = new Message(service.getString(R.string.message_set_channel_limit, sourceNick, limit));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On remove channel limit * On remove channel limit
*/ */
@ -762,7 +773,7 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_remove_channel_limit, sourceNick)); Message message = new Message(service.getString(R.string.message_remove_channel_limit, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
@ -777,12 +788,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_set_ban, sourceNick, hostmask)); Message message = new Message(service.getString(R.string.message_set_ban, sourceNick, hostmask));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On remove channel ban * On remove channel ban
*/ */
@ -792,12 +803,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_remove_ban, sourceNick, hostmask)); Message message = new Message(service.getString(R.string.message_remove_ban, sourceNick, hostmask));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On set topic protection * On set topic protection
*/ */
@ -807,12 +818,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_set_topic_protection, sourceNick)); Message message = new Message(service.getString(R.string.message_set_topic_protection, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On remove topic protection * On remove topic protection
*/ */
@ -822,7 +833,7 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_remove_topic_protection, sourceNick)); Message message = new Message(service.getString(R.string.message_remove_topic_protection, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
@ -837,7 +848,7 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_disable_external, sourceNick)); Message message = new Message(service.getString(R.string.message_disable_external, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
@ -852,12 +863,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_enable_external, sourceNick)); Message message = new Message(service.getString(R.string.message_enable_external, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On set invite only * On set invite only
*/ */
@ -867,12 +878,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_set_invite_only, sourceNick)); Message message = new Message(service.getString(R.string.message_set_invite_only, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On remove invite only * On remove invite only
*/ */
@ -882,7 +893,7 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_remove_invite_only, sourceNick)); Message message = new Message(service.getString(R.string.message_remove_invite_only, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
@ -897,12 +908,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_set_moderated, sourceNick)); Message message = new Message(service.getString(R.string.message_set_moderated, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On remove moderated * On remove moderated
*/ */
@ -912,12 +923,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_remove_moderated, sourceNick)); Message message = new Message(service.getString(R.string.message_remove_moderated, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On set private * On set private
*/ */
@ -927,12 +938,12 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_set_channel_private, sourceNick)); Message message = new Message(service.getString(R.string.message_set_channel_private, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
} }
/** /**
* On remove private * On remove private
*/ */
@ -942,7 +953,7 @@ public class IRCConnection extends PircBot
Message message = new Message(service.getString(R.string.message_set_channel_public, sourceNick)); Message message = new Message(service.getString(R.string.message_set_channel_public, sourceNick));
message.setColor(Message.COLOR_BLUE); message.setColor(Message.COLOR_BLUE);
server.getConversation(target).addMessage(message); server.getConversation(target).addMessage(message);
service.sendBroadcast( service.sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target) Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
); );
@ -958,7 +969,7 @@ public class IRCConnection extends PircBot
message.setIcon(R.drawable.action); message.setIcon(R.drawable.action);
message.setColor(Message.COLOR_GREY); message.setColor(Message.COLOR_GREY);
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -977,16 +988,16 @@ public class IRCConnection extends PircBot
// Skip MOTD // Skip MOTD
return; return;
} }
if (code >= 200 && code < 300) { if (code >= 200 && code < 300) {
// Skip 2XX responses // Skip 2XX responses
return; return;
} }
if (code == 353 || code == 366 || code == 332 || code == 333) { if (code == 353 || code == 366 || code == 332 || code == 333) {
return; return;
} }
if (code < 10) { if (code < 10) {
// Skip server info // Skip server info
return; return;
@ -996,7 +1007,7 @@ public class IRCConnection extends PircBot
Message message = new Message(response); Message message = new Message(response);
message.setColor(Message.COLOR_GREY); message.setColor(Message.COLOR_GREY);
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -1020,20 +1031,20 @@ public class IRCConnection extends PircBot
} else { } else {
server.setStatus(Status.DISCONNECTED); server.setStatus(Status.DISCONNECTED);
} }
service.updateNotification(service.getString(R.string.notification_disconnected, server.getTitle())); service.updateNotification(service.getString(R.string.notification_disconnected, server.getTitle()));
Intent sIntent = Broadcast.createServerIntent(Broadcast.SERVER_UPDATE, server.getId()); Intent sIntent = Broadcast.createServerIntent(Broadcast.SERVER_UPDATE, server.getId());
service.sendBroadcast(sIntent); service.sendBroadcast(sIntent);
Collection<Conversation> conversations = server.getConversations(); Collection<Conversation> conversations = server.getConversations();
for (Conversation conversation : conversations) { for (Conversation conversation : conversations) {
Message message = new Message(service.getString(R.string.message_disconnected)); Message message = new Message(service.getString(R.string.message_disconnected));
message.setIcon(R.drawable.error); message.setIcon(R.drawable.error);
message.setColor(Message.COLOR_RED); message.setColor(Message.COLOR_RED);
server.getConversation(conversation.getName()).addMessage(message); server.getConversation(conversation.getName()).addMessage(message);
Intent cIntent = Broadcast.createConversationIntent( Intent cIntent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
@ -1042,7 +1053,7 @@ public class IRCConnection extends PircBot
service.sendBroadcast(cIntent); service.sendBroadcast(cIntent);
} }
} }
/** /**
* Get all channels where the user with the given nickname is online * Get all channels where the user with the given nickname is online
* *
@ -1053,7 +1064,7 @@ public class IRCConnection extends PircBot
{ {
Vector<String> channels = new Vector<String>(); Vector<String> channels = new Vector<String>();
String[] channelArray = getChannels(); String[] channelArray = getChannels();
for (String channel : channelArray) { for (String channel : channelArray) {
User[] userArray = getUsers(channel); User[] userArray = getUsers(channel);
for (User user : userArray) { for (User user : userArray) {
@ -1063,10 +1074,10 @@ public class IRCConnection extends PircBot
} }
} }
} }
return channels; return channels;
} }
/** /**
* Get list of users in a channel as array of strings * Get list of users in a channel as array of strings
* *
@ -1077,15 +1088,15 @@ public class IRCConnection extends PircBot
User[] userArray = getUsers(channel); User[] userArray = getUsers(channel);
int mLength = userArray.length; int mLength = userArray.length;
String[] users = new String[mLength]; String[] users = new String[mLength];
for (int i = 0; i < mLength; i++) { for (int i = 0; i < mLength; i++) {
// Prefix disabled // Prefix disabled
users[i] = /*userArray[i].getPrefix() + */ userArray[i].getNick(); users[i] = /*userArray[i].getPrefix() + */ userArray[i].getNick();
} }
return users; return users;
} }
/** /**
* Get a user by channel and nickname * Get a user by channel and nickname
* *
@ -1097,7 +1108,7 @@ public class IRCConnection extends PircBot
{ {
User[] users = getUsers(channel); User[] users = getUsers(channel);
int mLength = users.length; int mLength = users.length;
for (int i = 0; i < mLength; i++) { for (int i = 0; i < mLength; i++) {
if (nickname.equals(users[i].getNick())) { if (nickname.equals(users[i].getNick())) {
return users[i]; return users[i];
@ -1106,10 +1117,10 @@ public class IRCConnection extends PircBot
return users[i]; return users[i];
} }
} }
return null; return null;
} }
/** /**
* Quits from the IRC server with default reason. * Quits from the IRC server with default reason.
*/ */
@ -1117,12 +1128,13 @@ public class IRCConnection extends PircBot
public void quitServer() public void quitServer()
{ {
new Thread() { new Thread() {
@Override
public void run() { public void run() {
quitServer(service.getSettings().getQuitMessage()); quitServer(service.getSettings().getQuitMessage());
} }
}.start(); }.start();
} }
/** /**
* Check whether the nickname has been mentioned. * Check whether the nickname has been mentioned.
* *
@ -1133,7 +1145,7 @@ public class IRCConnection extends PircBot
{ {
return mNickMatch.matcher(text).find(); return mNickMatch.matcher(text).find();
} }
/** /**
* Update the nick matching pattern, should be called when the nickname changes. * Update the nick matching pattern, should be called when the nickname changes.
*/ */

View File

@ -187,7 +187,7 @@ public class IRCService extends Service
*/ */
public void updateNotification(String text) public void updateNotification(String text)
{ {
updateNotification(text, false); updateNotification(text, false, false);
} }
/** /**
@ -196,7 +196,7 @@ public class IRCService extends Service
* @param text The text to display * @param text The text to display
* @param vibrate True if the device should vibrate, false otherwise * @param vibrate True if the device should vibrate, false otherwise
*/ */
public void updateNotification(String text, boolean vibrate) public void updateNotification(String text, boolean vibrate, boolean sound)
{ {
if (foreground) { if (foreground) {
notificationManager.cancel(R.string.app_name); notificationManager.cancel(R.string.app_name);

View File

@ -17,7 +17,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>. along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.model; package org.yaaic.model;
import org.yaaic.R; import org.yaaic.R;
@ -33,15 +33,15 @@ import android.preference.PreferenceManager;
* *
* Note: As this class carries a Context instance as private member, instances of * Note: As this class carries a Context instance as private member, instances of
* this class should be thrown away not later than when the Context should * this class should be thrown away not later than when the Context should
* be gone. Otherwise this could leak memory. * be gone. Otherwise this could leak memory.
* *
* @author Sebastian Kaspari <sebastian@yaaic.org> * @author Sebastian Kaspari <sebastian@yaaic.org>
*/ */
public class Settings public class Settings
{ {
private SharedPreferences preferences; private final SharedPreferences preferences;
private Resources resources; private final Resources resources;
/** /**
* Create a new Settings instance * Create a new Settings instance
* *
@ -52,7 +52,7 @@ public class Settings
this.preferences = PreferenceManager.getDefaultSharedPreferences(context); this.preferences = PreferenceManager.getDefaultSharedPreferences(context);
this.resources = context.getApplicationContext().getResources(); this.resources = context.getApplicationContext().getResources();
} }
/** /**
* Prefix all messages with a timestamp? * Prefix all messages with a timestamp?
* *
@ -65,7 +65,7 @@ public class Settings
Boolean.parseBoolean(resources.getString(R.string.default_show_timestamp)) Boolean.parseBoolean(resources.getString(R.string.default_show_timestamp))
); );
} }
/** /**
* Show icons to highlight special events * Show icons to highlight special events
* *
@ -78,7 +78,7 @@ public class Settings
Boolean.parseBoolean(resources.getString(R.string.default_show_icons)) Boolean.parseBoolean(resources.getString(R.string.default_show_icons))
); );
} }
/** /**
* Show colors to highlight special events? * Show colors to highlight special events?
* *
@ -91,7 +91,7 @@ public class Settings
Boolean.parseBoolean(resources.getString(R.string.default_show_colors)) Boolean.parseBoolean(resources.getString(R.string.default_show_colors))
); );
} }
/** /**
* Show colors to highlight nicknames? * Show colors to highlight nicknames?
* *
@ -117,11 +117,11 @@ public class Settings
Boolean.parseBoolean(resources.getString(R.string.default_24h_format)) Boolean.parseBoolean(resources.getString(R.string.default_24h_format))
); );
} }
/** /**
* Is reconnect on disconnect enabled? * Is reconnect on disconnect enabled?
* *
* @return * @return
*/ */
public boolean isReconnectEnabled() public boolean isReconnectEnabled()
{ {
@ -130,7 +130,7 @@ public class Settings
Boolean.parseBoolean(resources.getString(R.string.default_reconnect)) Boolean.parseBoolean(resources.getString(R.string.default_reconnect))
); );
} }
/** /**
* Get the quit message * Get the quit message
* *
@ -143,7 +143,7 @@ public class Settings
resources.getString(R.string.default_quitmessage) resources.getString(R.string.default_quitmessage)
); );
} }
/** /**
* Get the font size * Get the font size
* *
@ -156,7 +156,7 @@ public class Settings
resources.getString(R.string.default_fontsize) resources.getString(R.string.default_fontsize)
)); ));
} }
/** /**
* Is voice recognition enabled? * Is voice recognition enabled?
* *
@ -169,10 +169,23 @@ public class Settings
Boolean.parseBoolean(resources.getString(R.string.default_voice_recognition)) Boolean.parseBoolean(resources.getString(R.string.default_voice_recognition))
); );
} }
/**
* Play notification sound on highlight?
*
* @return True if sound should be played on highlight, false otherwise
*/
public boolean isSoundHighlightEnabled()
{
return preferences.getBoolean(
resources.getString(R.string.key_sound_highlight),
Boolean.parseBoolean(resources.getString(R.string.default_sound_highlight))
);
}
/** /**
* Vibrate on highlight? * Vibrate on highlight?
* *
* @return True if vibrate on highlight is enabled, false otherwise * @return True if vibrate on highlight is enabled, false otherwise
*/ */
public boolean isVibrateHighlightEnabled() public boolean isVibrateHighlightEnabled()