make conference notificaton optional
This commit is contained in:
parent
33f8747b87
commit
d943e218a4
|
@ -28,7 +28,8 @@
|
||||||
android:key="vibrate_on_notification"
|
android:key="vibrate_on_notification"
|
||||||
android:dependency="show_notification"
|
android:dependency="show_notification"
|
||||||
android:title="Vibrate"
|
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
|
<RingtonePreference
|
||||||
android:key="notification_ringtone"
|
android:key="notification_ringtone"
|
||||||
android:title="Sound"
|
android:title="Sound"
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class XmppConnectionService extends Service {
|
||||||
convChangedListener.onConversationListChanged();
|
convChangedListener.onConversationListChanged();
|
||||||
} else {
|
} else {
|
||||||
UIHelper.updateNotification(getApplicationContext(),
|
UIHelper.updateNotification(getApplicationContext(),
|
||||||
getConversations(), notify);
|
getConversations(), message.getConversation(), notify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class ConversationActivity extends XmppActivity {
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
if (!getSelectedConversation().isRead()) {
|
if (!getSelectedConversation().isRead()) {
|
||||||
getSelectedConversation().markRead();
|
getSelectedConversation().markRead();
|
||||||
UIHelper.updateNotification(getApplicationContext(), getConversationList(), false);
|
UIHelper.updateNotification(getApplicationContext(), getConversationList(), null, false);
|
||||||
updateConversationList();
|
updateConversationList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,7 +419,7 @@ public class ConversationFragment extends Fragment {
|
||||||
if (!activity.shouldPaneBeOpen()) {
|
if (!activity.shouldPaneBeOpen()) {
|
||||||
conversation.markRead();
|
conversation.markRead();
|
||||||
//TODO update notifications
|
//TODO update notifications
|
||||||
UIHelper.updateNotification(getActivity(), activity.getConversationList(), false);
|
UIHelper.updateNotification(getActivity(), activity.getConversationList(), null, false);
|
||||||
activity.updateConversationList();
|
activity.updateConversationList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,22 +125,41 @@ public class UIHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateNotification(Context context,
|
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
|
NotificationManager mNotificationManager = (NotificationManager) context
|
||||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
.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 = "";
|
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>();
|
List<Conversation> unread = new ArrayList<Conversation>();
|
||||||
for (Conversation conversation : conversations) {
|
for (Conversation conversation : conversations) {
|
||||||
if (!conversation.isRead()) {
|
if (!conversation.isRead()) {
|
||||||
unread.add(conversation);
|
unread.add(conversation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String ringtone = preferences.getString("notification_ringtone", null);
|
||||||
SharedPreferences sharedPref = PreferenceManager
|
|
||||||
.getDefaultSharedPreferences(context);
|
|
||||||
String ringtone = sharedPref.getString("notification_ringtone", null);
|
|
||||||
|
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
||||||
|
@ -184,7 +203,7 @@ public class UIHelper {
|
||||||
style.setBigContentTitle(unread.size() + " unread Conversations");
|
style.setBigContentTitle(unread.size() + " unread Conversations");
|
||||||
StringBuilder names = new StringBuilder();
|
StringBuilder names = new StringBuilder();
|
||||||
for (int i = 0; i < unread.size(); ++i) {
|
for (int i = 0; i < unread.size(); ++i) {
|
||||||
targetUuid = conversations.get(0).getUuid();
|
targetUuid = unread.get(i).getUuid();
|
||||||
if (i < unread.size() - 1) {
|
if (i < unread.size() - 1) {
|
||||||
names.append(unread.get(i).getName() + ", ");
|
names.append(unread.get(i).getName() + ", ");
|
||||||
} else {
|
} else {
|
||||||
|
@ -200,9 +219,11 @@ public class UIHelper {
|
||||||
if (unread.size() != 0) {
|
if (unread.size() != 0) {
|
||||||
mBuilder.setSmallIcon(R.drawable.notification);
|
mBuilder.setSmallIcon(R.drawable.notification);
|
||||||
if (notify) {
|
if (notify) {
|
||||||
|
if (vibrate) {
|
||||||
int dat = 110;
|
int dat = 110;
|
||||||
long[] pattern = {0,3*dat,dat,dat,dat,3*dat,dat,dat};
|
long[] pattern = {0,3*dat,dat,dat,dat,3*dat,dat,dat};
|
||||||
mBuilder.setVibrate(pattern);
|
mBuilder.setVibrate(pattern);
|
||||||
|
}
|
||||||
mBuilder.setLights(0xffffffff, 2000, 4000);
|
mBuilder.setLights(0xffffffff, 2000, 4000);
|
||||||
if (ringtone != null) {
|
if (ringtone != null) {
|
||||||
mBuilder.setSound(Uri.parse(ringtone));
|
mBuilder.setSound(Uri.parse(ringtone));
|
||||||
|
@ -226,7 +247,8 @@ public class UIHelper {
|
||||||
0, PendingIntent.FLAG_UPDATE_CURRENT);
|
0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
mBuilder.setContentIntent(resultPendingIntent);
|
mBuilder.setContentIntent(resultPendingIntent);
|
||||||
mNotificationManager.notify(2342, mBuilder.build());
|
Notification notification = mBuilder.build();
|
||||||
|
mNotificationManager.notify(2342, notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,6 +225,7 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
//Log.d(LOGTAG,"server ack"+ack.toString()+" ("+this.stanzasSent+")");
|
//Log.d(LOGTAG,"server ack"+ack.toString()+" ("+this.stanzasSent+")");
|
||||||
} else if (nextTag.isStart("failed")) {
|
} else if (nextTag.isStart("failed")) {
|
||||||
|
tagReader.readElement(nextTag);
|
||||||
Log.d(LOGTAG,account.getJid()+": resumption failed");
|
Log.d(LOGTAG,account.getJid()+": resumption failed");
|
||||||
streamId = null;
|
streamId = null;
|
||||||
if (account.getStatus() != Account.STATUS_ONLINE) {
|
if (account.getStatus() != Account.STATUS_ONLINE) {
|
||||||
|
|
Loading…
Reference in a new issue