mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-26 02:42:16 -05:00
Bugfix notification system
* If there's a new message notification, keep showing the "New messages in" content text, even after a disconnect notification. * Handle the case of a channel/query name duplicated between two or more connections more gracefully in new message notifications * Fix a race in updating notifications
This commit is contained in:
parent
35609e5529
commit
06e0849c17
@ -319,6 +319,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
||||
if (conversation.getStatus() == Conversation.STATUS_SELECTED && conversation.getNewMentions() > 0) {
|
||||
Intent ackIntent = new Intent(this, IRCService.class);
|
||||
ackIntent.setAction(IRCService.ACTION_ACK_NEW_MENTIONS);
|
||||
ackIntent.putExtra(IRCService.EXTRA_ACK_SERVERID, serverId);
|
||||
ackIntent.putExtra(IRCService.EXTRA_ACK_CONVTITLE, conversation.getName());
|
||||
startService(ackIntent);
|
||||
}
|
||||
|
@ -248,6 +248,7 @@ public class IRCConnection extends PircBot
|
||||
if (mentioned || target.equals(this.getNick())) {
|
||||
if (conversation.getStatus() != Conversation.STATUS_SELECTED || !server.getIsForeground()) {
|
||||
service.addNewMention(
|
||||
server.getId(),
|
||||
conversation,
|
||||
conversation.getName() + ": " + sender + " " + action,
|
||||
service.getSettings().isVibrateHighlightEnabled(),
|
||||
@ -423,6 +424,7 @@ public class IRCConnection extends PircBot
|
||||
message.setColor(Message.COLOR_RED);
|
||||
if (conversation.getStatus() != Conversation.STATUS_SELECTED || !server.getIsForeground()) {
|
||||
service.addNewMention(
|
||||
server.getId(),
|
||||
conversation,
|
||||
target + ": <" + sender + "> " + text,
|
||||
service.getSettings().isVibrateHighlightEnabled(),
|
||||
@ -632,6 +634,7 @@ public class IRCConnection extends PircBot
|
||||
|
||||
if (conversation.getStatus() != Conversation.STATUS_SELECTED || !server.getIsForeground()) {
|
||||
service.addNewMention(
|
||||
server.getId(),
|
||||
conversation,
|
||||
"<" + sender + "> " + text,
|
||||
service.getSettings().isVibrateHighlightEnabled(),
|
||||
|
@ -70,6 +70,7 @@ public class IRCService extends Service
|
||||
public static final String ACTION_FOREGROUND = "org.yaaic.service.foreground";
|
||||
public static final String ACTION_BACKGROUND = "org.yaaic.service.background";
|
||||
public static final String ACTION_ACK_NEW_MENTIONS = "org.yaaic.service.ack_new_mentions";
|
||||
public static final String EXTRA_ACK_SERVERID = "org.yaaic.service.ack_serverid";
|
||||
public static final String EXTRA_ACK_CONVTITLE = "org.yaaic.service.ack_convtitle";
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
@ -191,7 +192,7 @@ public class IRCService extends Service
|
||||
} else if (ACTION_BACKGROUND.equals(intent.getAction()) && !foreground) {
|
||||
stopForegroundCompat(FOREGROUND_NOTIFICATION);
|
||||
} else if (ACTION_ACK_NEW_MENTIONS.equals(intent.getAction())) {
|
||||
ackNewMentions(intent.getStringExtra(EXTRA_ACK_CONVTITLE));
|
||||
ackNewMentions(intent.getIntExtra(EXTRA_ACK_SERVERID, -1), intent.getStringExtra(EXTRA_ACK_CONVTITLE));
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,7 +213,13 @@ public class IRCService extends Service
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
|
||||
|
||||
if (contentText == null) {
|
||||
if (!connectedServerTitles.isEmpty()) {
|
||||
if (newMentions >= 1) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Conversation conv : mentions.values()) {
|
||||
sb.append(conv.getName() + " (" + conv.getNewMentions() + "), ");
|
||||
}
|
||||
contentText = getString(R.string.notification_mentions, sb.substring(0, sb.length()-2));
|
||||
} else if (!connectedServerTitles.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String title : connectedServerTitles) {
|
||||
sb.append(title + ", ");
|
||||
@ -240,23 +247,10 @@ public class IRCService extends Service
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status bar notification for a new mention
|
||||
* Generates a string uniquely identifying a conversation.
|
||||
*/
|
||||
private void notifyMention(String msg, boolean vibrate, boolean sound)
|
||||
{
|
||||
String contentText = null;
|
||||
|
||||
if (newMentions == 1 && msg != null) {
|
||||
contentText = msg;
|
||||
} else if (newMentions >= 1) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Conversation conv : mentions.values()) {
|
||||
sb.append(conv.getName() + " (" + conv.getNewMentions() + "), ");
|
||||
}
|
||||
contentText = getString(R.string.notification_mentions, sb.substring(0, sb.length()-2));
|
||||
}
|
||||
|
||||
updateNotification(msg, contentText, vibrate, sound);
|
||||
public String getConversationId(int serverId, String title) {
|
||||
return "" + serverId + ":" + title;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,20 +261,23 @@ public class IRCService extends Service
|
||||
* @param vibrate Whether the notification should include vibration
|
||||
* @param sound Whether the notification should include sound
|
||||
*/
|
||||
public void addNewMention(Conversation conversation, String msg, boolean vibrate, boolean sound)
|
||||
public synchronized void addNewMention(int serverId, Conversation conversation, String msg, boolean vibrate, boolean sound)
|
||||
{
|
||||
if (conversation == null)
|
||||
return;
|
||||
|
||||
String convTitle = conversation.getName();
|
||||
|
||||
conversation.addNewMention();
|
||||
++newMentions;
|
||||
if (!mentions.containsKey(convTitle)) {
|
||||
mentions.put(convTitle, conversation);
|
||||
String convId = getConversationId(serverId, conversation.getName());
|
||||
if (!mentions.containsKey(convId)) {
|
||||
mentions.put(convId, conversation);
|
||||
}
|
||||
|
||||
notifyMention(msg, vibrate, sound);
|
||||
if (newMentions == 1) {
|
||||
updateNotification(msg, msg, vibrate, sound);
|
||||
} else {
|
||||
updateNotification(msg, null, vibrate, sound);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -288,12 +285,12 @@ public class IRCService extends Service
|
||||
*
|
||||
* @param convTitle The title of the conversation whose new mentions have been read
|
||||
*/
|
||||
public void ackNewMentions(String convTitle)
|
||||
public synchronized void ackNewMentions(int serverId, String convTitle)
|
||||
{
|
||||
if (convTitle == null)
|
||||
return;
|
||||
|
||||
Conversation conversation = mentions.remove(convTitle);
|
||||
Conversation conversation = mentions.remove(getConversationId(serverId, convTitle));
|
||||
if (conversation == null)
|
||||
return;
|
||||
newMentions -= conversation.getNewMentions();
|
||||
@ -301,7 +298,7 @@ public class IRCService extends Service
|
||||
if (newMentions < 0)
|
||||
newMentions = 0;
|
||||
|
||||
notifyMention(null, false, false);
|
||||
updateNotification(null, null, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,7 +306,7 @@ public class IRCService extends Service
|
||||
*
|
||||
* @param title The title of the newly connected server
|
||||
*/
|
||||
public void notifyConnected(String title)
|
||||
public synchronized void notifyConnected(String title)
|
||||
{
|
||||
connectedServerTitles.add(title);
|
||||
updateNotification(getString(R.string.notification_connected, title), null, false, false);
|
||||
@ -320,7 +317,7 @@ public class IRCService extends Service
|
||||
*
|
||||
* @param title The title of the disconnected server
|
||||
*/
|
||||
public void notifyDisconnected(String title)
|
||||
public synchronized void notifyDisconnected(String title)
|
||||
{
|
||||
connectedServerTitles.remove(title);
|
||||
updateNotification(getString(R.string.notification_disconnected, title), null, false, false);
|
||||
|
@ -88,6 +88,7 @@ public class ConversationSelectedListener implements OnItemSelectedListener
|
||||
if (conversation.getNewMentions() > 0) {
|
||||
Intent i = new Intent(ctx, IRCService.class);
|
||||
i.setAction(IRCService.ACTION_ACK_NEW_MENTIONS);
|
||||
i.putExtra(IRCService.EXTRA_ACK_SERVERID, server.getId());
|
||||
i.putExtra(IRCService.EXTRA_ACK_CONVTITLE, conversation.getName());
|
||||
ctx.startService(i);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user