From d943e218a4678dcb5cd18233aa58193a855c3010 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 12 Mar 2014 14:55:23 +0100 Subject: [PATCH] make conference notificaton optional --- res/xml/preferences.xml | 3 +- .../services/XmppConnectionService.java | 2 +- .../ui/ConversationActivity.java | 2 +- .../ui/ConversationFragment.java | 2 +- .../siacs/conversations/utils/UIHelper.java | 48 ++++++++++++++----- .../conversations/xmpp/XmppConnection.java | 1 + 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index f64c449c9..f47439c84 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -28,7 +28,8 @@ android:key="vibrate_on_notification" android:dependency="show_notification" android:title="Vibrate" - android:summary="Also vibrate when a new message arrives"/> + android:summary="Also vibrate when a new message arrives" + android:defaultValue="true"/> conversations, boolean notify) { + List conversations, Conversation currentCon, boolean notify) { + + Log.d("xmppService","called to update notifications"); + NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); + + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + boolean showNofifications = preferences.getBoolean("show_notification",true); + boolean vibrate = preferences.getBoolean("vibrate_on_notification", true); + boolean alwaysNotify = preferences.getBoolean("notify_in_conversation_when_highlighted", false); + if (!showNofifications) { + Log.d("xmppService","notification disabled in settings. not showing"); + return; + } + String targetUuid = ""; + + if ((currentCon != null) &&(currentCon.getMode() == Conversation.MODE_MULTI)&&(!alwaysNotify)) { + String nick = currentCon.getMucOptions().getNick(); + notify = currentCon.getLatestMessage().getBody().contains(nick); + if (!notify) { + return; + } + } + List unread = new ArrayList(); for (Conversation conversation : conversations) { if (!conversation.isRead()) { unread.add(conversation); } } - - SharedPreferences sharedPref = PreferenceManager - .getDefaultSharedPreferences(context); - String ringtone = sharedPref.getString("notification_ringtone", null); + String ringtone = preferences.getString("notification_ringtone", null); Resources res = context.getResources(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( @@ -184,7 +203,7 @@ public class UIHelper { style.setBigContentTitle(unread.size() + " unread Conversations"); StringBuilder names = new StringBuilder(); for (int i = 0; i < unread.size(); ++i) { - targetUuid = conversations.get(0).getUuid(); + targetUuid = unread.get(i).getUuid(); if (i < unread.size() - 1) { names.append(unread.get(i).getName() + ", "); } else { @@ -200,9 +219,11 @@ public class UIHelper { if (unread.size() != 0) { mBuilder.setSmallIcon(R.drawable.notification); if (notify) { - int dat = 110; - long[] pattern = {0,3*dat,dat,dat,dat,3*dat,dat,dat}; - mBuilder.setVibrate(pattern); + if (vibrate) { + int dat = 110; + long[] pattern = {0,3*dat,dat,dat,dat,3*dat,dat,dat}; + mBuilder.setVibrate(pattern); + } mBuilder.setLights(0xffffffff, 2000, 4000); if (ringtone != null) { mBuilder.setSound(Uri.parse(ringtone)); @@ -219,17 +240,18 @@ public class UIHelper { targetUuid); viewConversationIntent .setType(ConversationActivity.VIEW_CONVERSATION); - + stackBuilder.addNextIntent(viewConversationIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT); - + mBuilder.setContentIntent(resultPendingIntent); - mNotificationManager.notify(2342, mBuilder.build()); + Notification notification = mBuilder.build(); + mNotificationManager.notify(2342, notification); } } - + public static void prepareContactBadge(final Activity activity, QuickContactBadge badge, final Contact contact) { if (contact.getSystemAccount() != null) { diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index be06a3a3b..00a37b76c 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -225,6 +225,7 @@ public class XmppConnection implements Runnable { } //Log.d(LOGTAG,"server ack"+ack.toString()+" ("+this.stanzasSent+")"); } else if (nextTag.isStart("failed")) { + tagReader.readElement(nextTag); Log.d(LOGTAG,account.getJid()+": resumption failed"); streamId = null; if (account.getStatus() != Account.STATUS_ONLINE) {