make conference notificaton optional

This commit is contained in:
Daniel Gultsch 2014-03-12 14:55:23 +01:00
parent 33f8747b87
commit d943e218a4
6 changed files with 41 additions and 17 deletions

View file

@ -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"/>
<RingtonePreference
android:key="notification_ringtone"
android:title="Sound"

View file

@ -173,7 +173,7 @@ public class XmppConnectionService extends Service {
convChangedListener.onConversationListChanged();
} else {
UIHelper.updateNotification(getApplicationContext(),
getConversations(), notify);
getConversations(), message.getConversation(), notify);
}
}
};

View file

@ -233,7 +233,7 @@ public class ConversationActivity extends XmppActivity {
invalidateOptionsMenu();
if (!getSelectedConversation().isRead()) {
getSelectedConversation().markRead();
UIHelper.updateNotification(getApplicationContext(), getConversationList(), false);
UIHelper.updateNotification(getApplicationContext(), getConversationList(), null, false);
updateConversationList();
}
}

View file

@ -419,7 +419,7 @@ public class ConversationFragment extends Fragment {
if (!activity.shouldPaneBeOpen()) {
conversation.markRead();
//TODO update notifications
UIHelper.updateNotification(getActivity(), activity.getConversationList(), false);
UIHelper.updateNotification(getActivity(), activity.getConversationList(), null, false);
activity.updateConversationList();
}
}

View file

@ -125,22 +125,41 @@ public class UIHelper {
}
public static void updateNotification(Context context,
List<Conversation> conversations, boolean notify) {
List<Conversation> 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<Conversation> unread = new ArrayList<Conversation>();
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) {

View file

@ -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) {