2014-09-28 13:21:56 +00:00
|
|
|
package eu.siacs.conversations.services;
|
|
|
|
|
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2014-10-24 12:34:46 +00:00
|
|
|
import android.graphics.Bitmap;
|
2014-09-28 13:21:56 +00:00
|
|
|
import android.net.Uri;
|
2014-10-02 20:17:25 +00:00
|
|
|
import android.os.PowerManager;
|
2014-10-24 11:29:18 +00:00
|
|
|
import android.os.SystemClock;
|
2014-09-28 13:21:56 +00:00
|
|
|
import android.support.v4.app.NotificationCompat;
|
2014-10-24 16:27:53 +00:00
|
|
|
import android.support.v4.app.NotificationCompat.BigPictureStyle;
|
|
|
|
import android.support.v4.app.NotificationCompat.Builder;
|
2014-09-28 13:21:56 +00:00
|
|
|
import android.support.v4.app.TaskStackBuilder;
|
|
|
|
import android.text.Html;
|
2014-10-21 12:57:16 +00:00
|
|
|
import android.util.DisplayMetrics;
|
2014-09-28 13:21:56 +00:00
|
|
|
|
2014-11-05 20:37:40 +00:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.LinkedHashMap;
|
2014-11-18 14:26:28 +00:00
|
|
|
import java.util.List;
|
2014-11-05 20:37:40 +00:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2014-10-24 11:29:18 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2014-09-28 13:21:56 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2014-10-17 09:01:38 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2014-09-28 13:21:56 +00:00
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2014-10-24 11:29:18 +00:00
|
|
|
import eu.siacs.conversations.entities.Downloadable;
|
2014-11-15 13:40:43 +00:00
|
|
|
import eu.siacs.conversations.entities.DownloadableFile;
|
2014-09-28 13:21:56 +00:00
|
|
|
import eu.siacs.conversations.entities.Message;
|
|
|
|
import eu.siacs.conversations.ui.ConversationActivity;
|
2014-11-18 14:26:28 +00:00
|
|
|
import eu.siacs.conversations.ui.ManageAccountActivity;
|
2014-09-28 13:21:56 +00:00
|
|
|
|
|
|
|
public class NotificationService {
|
|
|
|
|
|
|
|
private XmppConnectionService mXmppConnectionService;
|
|
|
|
|
|
|
|
private LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<String, ArrayList<Message>>();
|
|
|
|
|
2014-10-24 11:29:18 +00:00
|
|
|
public static int NOTIFICATION_ID = 0x2342;
|
2014-11-12 13:41:43 +00:00
|
|
|
public static int FOREGROUND_NOTIFICATION_ID = 0x8899;
|
2014-11-18 14:26:28 +00:00
|
|
|
public static int ERROR_NOTIFICATION_ID = 0x5678;
|
|
|
|
|
2014-09-29 16:28:13 +00:00
|
|
|
private Conversation mOpenConversation;
|
|
|
|
private boolean mIsInForeground;
|
2014-10-24 11:29:18 +00:00
|
|
|
private long mLastNotification;
|
2014-10-20 19:08:33 +00:00
|
|
|
|
2014-09-28 13:21:56 +00:00
|
|
|
public NotificationService(XmppConnectionService service) {
|
|
|
|
this.mXmppConnectionService = service;
|
|
|
|
}
|
|
|
|
|
2014-11-05 20:37:40 +00:00
|
|
|
public boolean notify(Message message) {
|
|
|
|
return (message.getStatus() == Message.STATUS_RECEIVED)
|
|
|
|
&& notificationsEnabled()
|
|
|
|
&& !message.getConversation().isMuted()
|
|
|
|
&& (message.getConversation().getMode() == Conversation.MODE_SINGLE
|
|
|
|
|| conferenceNotificationsEnabled()
|
|
|
|
|| wasHighlightedOrPrivate(message)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean notificationsEnabled() {
|
|
|
|
return mXmppConnectionService.getPreferences().getBoolean("show_notification", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean conferenceNotificationsEnabled() {
|
|
|
|
return mXmppConnectionService.getPreferences().getBoolean("always_notify_in_conference", false);
|
|
|
|
}
|
|
|
|
|
2014-10-15 12:33:13 +00:00
|
|
|
public void push(Message message) {
|
2014-11-05 20:37:40 +00:00
|
|
|
if (!notify(message)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-02 20:17:25 +00:00
|
|
|
PowerManager pm = (PowerManager) mXmppConnectionService
|
|
|
|
.getSystemService(Context.POWER_SERVICE);
|
|
|
|
boolean isScreenOn = pm.isScreenOn();
|
2014-10-15 12:33:13 +00:00
|
|
|
|
2014-10-02 20:17:25 +00:00
|
|
|
if (this.mIsInForeground && isScreenOn
|
2014-09-29 16:28:13 +00:00
|
|
|
&& this.mOpenConversation == message.getConversation()) {
|
2014-10-07 11:37:50 +00:00
|
|
|
return;
|
2014-09-29 16:28:13 +00:00
|
|
|
}
|
2014-10-15 12:33:13 +00:00
|
|
|
synchronized (notifications) {
|
|
|
|
String conversationUuid = message.getConversationUuid();
|
|
|
|
if (notifications.containsKey(conversationUuid)) {
|
|
|
|
notifications.get(conversationUuid).add(message);
|
|
|
|
} else {
|
|
|
|
ArrayList<Message> mList = new ArrayList<Message>();
|
|
|
|
mList.add(message);
|
|
|
|
notifications.put(conversationUuid, mList);
|
|
|
|
}
|
2014-10-21 22:25:28 +00:00
|
|
|
Account account = message.getConversation().getAccount();
|
|
|
|
updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn)
|
2014-10-24 11:29:18 +00:00
|
|
|
&& !account.inGracePeriod()
|
|
|
|
&& !this.inMiniGracePeriod(account));
|
2014-09-28 13:21:56 +00:00
|
|
|
}
|
2014-10-21 22:25:28 +00:00
|
|
|
|
2014-09-28 13:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clear() {
|
2014-10-15 12:33:13 +00:00
|
|
|
synchronized (notifications) {
|
|
|
|
notifications.clear();
|
2014-10-21 22:25:28 +00:00
|
|
|
updateNotification(false);
|
2014-10-15 12:33:13 +00:00
|
|
|
}
|
2014-09-28 13:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clear(Conversation conversation) {
|
2014-10-15 12:33:13 +00:00
|
|
|
synchronized (notifications) {
|
|
|
|
notifications.remove(conversation.getUuid());
|
2014-10-21 22:25:28 +00:00
|
|
|
updateNotification(false);
|
2014-10-15 12:33:13 +00:00
|
|
|
}
|
2014-09-28 13:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateNotification(boolean notify) {
|
2014-10-21 12:57:16 +00:00
|
|
|
NotificationManager notificationManager = (NotificationManager) mXmppConnectionService
|
|
|
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
2014-09-28 13:21:56 +00:00
|
|
|
SharedPreferences preferences = mXmppConnectionService.getPreferences();
|
|
|
|
|
|
|
|
String ringtone = preferences.getString("notification_ringtone", null);
|
|
|
|
boolean vibrate = preferences.getBoolean("vibrate_on_notification",
|
|
|
|
true);
|
|
|
|
|
|
|
|
if (notifications.size() == 0) {
|
2014-10-21 12:57:16 +00:00
|
|
|
notificationManager.cancel(NOTIFICATION_ID);
|
2014-09-28 13:21:56 +00:00
|
|
|
} else {
|
2014-10-24 11:29:18 +00:00
|
|
|
if (notify) {
|
|
|
|
this.markLastNotification();
|
|
|
|
}
|
2014-10-24 16:27:53 +00:00
|
|
|
Builder mBuilder;
|
2014-09-28 13:21:56 +00:00
|
|
|
if (notifications.size() == 1) {
|
2014-10-24 16:27:53 +00:00
|
|
|
mBuilder = buildSingleConversations(notify);
|
2014-09-28 13:21:56 +00:00
|
|
|
} else {
|
2014-10-24 16:27:53 +00:00
|
|
|
mBuilder = buildMultipleConversation();
|
2014-09-28 13:21:56 +00:00
|
|
|
}
|
|
|
|
if (notify) {
|
|
|
|
if (vibrate) {
|
|
|
|
int dat = 70;
|
2014-11-05 20:37:40 +00:00
|
|
|
long[] pattern = {0, 3 * dat, dat, dat};
|
2014-09-28 13:21:56 +00:00
|
|
|
mBuilder.setVibrate(pattern);
|
|
|
|
}
|
|
|
|
if (ringtone != null) {
|
|
|
|
mBuilder.setSound(Uri.parse(ringtone));
|
|
|
|
}
|
|
|
|
}
|
2014-10-24 16:27:53 +00:00
|
|
|
mBuilder.setSmallIcon(R.drawable.ic_notification);
|
2014-10-02 15:36:02 +00:00
|
|
|
mBuilder.setDeleteIntent(createDeleteIntent());
|
2014-10-17 09:01:38 +00:00
|
|
|
mBuilder.setLights(0xffffffff, 2000, 4000);
|
2014-09-28 13:21:56 +00:00
|
|
|
Notification notification = mBuilder.build();
|
2014-10-21 12:57:16 +00:00
|
|
|
notificationManager.notify(NOTIFICATION_ID, notification);
|
2014-09-28 13:21:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-24 16:27:53 +00:00
|
|
|
private Builder buildMultipleConversation() {
|
|
|
|
Builder mBuilder = new NotificationCompat.Builder(
|
|
|
|
mXmppConnectionService);
|
|
|
|
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
|
|
|
|
style.setBigContentTitle(notifications.size()
|
|
|
|
+ " "
|
|
|
|
+ mXmppConnectionService
|
2014-11-05 20:37:40 +00:00
|
|
|
.getString(R.string.unread_conversations));
|
2014-10-24 16:27:53 +00:00
|
|
|
StringBuilder names = new StringBuilder();
|
|
|
|
Conversation conversation = null;
|
|
|
|
for (ArrayList<Message> messages : notifications.values()) {
|
|
|
|
if (messages.size() > 0) {
|
|
|
|
conversation = messages.get(0).getConversation();
|
|
|
|
String name = conversation.getName();
|
|
|
|
style.addLine(Html.fromHtml("<b>" + name + "</b> "
|
|
|
|
+ getReadableBody(messages.get(0))));
|
|
|
|
names.append(name);
|
|
|
|
names.append(", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (names.length() >= 2) {
|
|
|
|
names.delete(names.length() - 2, names.length());
|
|
|
|
}
|
|
|
|
mBuilder.setContentTitle(notifications.size()
|
|
|
|
+ " "
|
|
|
|
+ mXmppConnectionService
|
2014-11-05 20:37:40 +00:00
|
|
|
.getString(R.string.unread_conversations));
|
2014-10-24 16:27:53 +00:00
|
|
|
mBuilder.setContentText(names.toString());
|
|
|
|
mBuilder.setStyle(style);
|
|
|
|
if (conversation != null) {
|
|
|
|
mBuilder.setContentIntent(createContentIntent(conversation
|
|
|
|
.getUuid()));
|
|
|
|
}
|
|
|
|
return mBuilder;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Builder buildSingleConversations(boolean notify) {
|
|
|
|
Builder mBuilder = new NotificationCompat.Builder(
|
|
|
|
mXmppConnectionService);
|
|
|
|
ArrayList<Message> messages = notifications.values().iterator().next();
|
|
|
|
if (messages.size() >= 1) {
|
|
|
|
Conversation conversation = messages.get(0).getConversation();
|
|
|
|
mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
|
|
|
|
.get(conversation, getPixel(64)));
|
|
|
|
mBuilder.setContentTitle(conversation.getName());
|
|
|
|
Message message;
|
|
|
|
if ((message = getImage(messages)) != null) {
|
|
|
|
modifyForImage(mBuilder, message, messages, notify);
|
|
|
|
} else {
|
|
|
|
modifyForTextOnly(mBuilder, messages, notify);
|
|
|
|
}
|
|
|
|
mBuilder.setContentIntent(createContentIntent(conversation
|
|
|
|
.getUuid()));
|
|
|
|
}
|
|
|
|
return mBuilder;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void modifyForImage(Builder builder, Message message,
|
2014-11-05 20:37:40 +00:00
|
|
|
ArrayList<Message> messages, boolean notify) {
|
2014-10-24 16:27:53 +00:00
|
|
|
try {
|
|
|
|
Bitmap bitmap = mXmppConnectionService.getFileBackend()
|
|
|
|
.getThumbnail(message, getPixel(288), false);
|
|
|
|
ArrayList<Message> tmp = new ArrayList<Message>();
|
|
|
|
for (Message msg : messages) {
|
|
|
|
if (msg.getType() == Message.TYPE_TEXT
|
|
|
|
&& msg.getDownloadable() == null) {
|
|
|
|
tmp.add(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
|
|
|
|
bigPictureStyle.bigPicture(bitmap);
|
|
|
|
if (tmp.size() > 0) {
|
|
|
|
bigPictureStyle.setSummaryText(getMergedBodies(tmp));
|
|
|
|
builder.setContentText(getReadableBody(tmp.get(0)));
|
|
|
|
} else {
|
|
|
|
builder.setContentText(mXmppConnectionService.getString(R.string.image_file));
|
|
|
|
}
|
|
|
|
builder.setStyle(bigPictureStyle);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
modifyForTextOnly(builder, messages, notify);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void modifyForTextOnly(Builder builder,
|
2014-11-05 20:37:40 +00:00
|
|
|
ArrayList<Message> messages, boolean notify) {
|
2014-10-24 16:27:53 +00:00
|
|
|
builder.setStyle(new NotificationCompat.BigTextStyle()
|
|
|
|
.bigText(getMergedBodies(messages)));
|
|
|
|
builder.setContentText(getReadableBody(messages.get(0)));
|
|
|
|
if (notify) {
|
|
|
|
builder.setTicker(getReadableBody(messages.get(messages.size() - 1)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Message getImage(ArrayList<Message> messages) {
|
|
|
|
for (Message message : messages) {
|
|
|
|
if (message.getType() == Message.TYPE_IMAGE
|
|
|
|
&& message.getDownloadable() == null
|
|
|
|
&& message.getEncryption() != Message.ENCRYPTION_PGP) {
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getMergedBodies(ArrayList<Message> messages) {
|
|
|
|
StringBuilder text = new StringBuilder();
|
|
|
|
for (int i = 0; i < messages.size(); ++i) {
|
|
|
|
text.append(getReadableBody(messages.get(i)));
|
|
|
|
if (i != messages.size() - 1) {
|
|
|
|
text.append("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return text.toString();
|
|
|
|
}
|
|
|
|
|
2014-10-24 11:29:18 +00:00
|
|
|
private String getReadableBody(Message message) {
|
|
|
|
if (message.getDownloadable() != null
|
|
|
|
&& (message.getDownloadable().getStatus() == Downloadable.STATUS_OFFER || message
|
2014-11-05 20:37:40 +00:00
|
|
|
.getDownloadable().getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE)) {
|
2014-11-15 13:40:43 +00:00
|
|
|
if (message.getType() == Message.TYPE_FILE) {
|
|
|
|
return mXmppConnectionService.getString(R.string.file_offered_for_download);
|
|
|
|
} else {
|
|
|
|
return mXmppConnectionService.getText(
|
|
|
|
R.string.image_offered_for_download).toString();
|
|
|
|
}
|
2014-10-24 11:29:18 +00:00
|
|
|
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
|
|
|
return mXmppConnectionService.getText(
|
|
|
|
R.string.encrypted_message_received).toString();
|
|
|
|
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
|
|
|
return mXmppConnectionService.getText(R.string.decryption_failed)
|
|
|
|
.toString();
|
2014-11-15 13:40:43 +00:00
|
|
|
} else if (message.getType() == Message.TYPE_FILE) {
|
|
|
|
DownloadableFile file = mXmppConnectionService.getFileBackend().getFile(message);
|
|
|
|
return mXmppConnectionService.getString(R.string.file,file.getMimeType());
|
2014-10-24 11:29:18 +00:00
|
|
|
} else if (message.getType() == Message.TYPE_IMAGE) {
|
|
|
|
return mXmppConnectionService.getText(R.string.image_file)
|
|
|
|
.toString();
|
|
|
|
} else {
|
|
|
|
return message.getBody().trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-28 13:21:56 +00:00
|
|
|
private PendingIntent createContentIntent(String conversationUuid) {
|
|
|
|
TaskStackBuilder stackBuilder = TaskStackBuilder
|
|
|
|
.create(mXmppConnectionService);
|
|
|
|
stackBuilder.addParentStack(ConversationActivity.class);
|
|
|
|
|
|
|
|
Intent viewConversationIntent = new Intent(mXmppConnectionService,
|
|
|
|
ConversationActivity.class);
|
|
|
|
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
2014-11-12 13:41:43 +00:00
|
|
|
if (conversationUuid!=null) {
|
|
|
|
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
|
|
|
|
conversationUuid);
|
|
|
|
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
|
|
|
|
}
|
2014-09-28 13:21:56 +00:00
|
|
|
|
|
|
|
stackBuilder.addNextIntent(viewConversationIntent);
|
|
|
|
|
|
|
|
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
|
|
|
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
return resultPendingIntent;
|
|
|
|
}
|
2014-10-02 16:31:19 +00:00
|
|
|
|
2014-10-02 15:36:02 +00:00
|
|
|
private PendingIntent createDeleteIntent() {
|
2014-10-02 16:31:19 +00:00
|
|
|
Intent intent = new Intent(mXmppConnectionService,
|
|
|
|
XmppConnectionService.class);
|
2014-11-12 13:41:43 +00:00
|
|
|
intent.setAction(XmppConnectionService.ACTION_CLEAR_NOTIFICATION);
|
|
|
|
return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private PendingIntent createDisableForeground() {
|
|
|
|
Intent intent = new Intent(mXmppConnectionService,
|
|
|
|
XmppConnectionService.class);
|
|
|
|
intent.setAction(XmppConnectionService.ACTION_DISABLE_FOREGROUND);
|
2014-10-02 15:36:02 +00:00
|
|
|
return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
|
|
|
|
}
|
2014-09-28 14:33:25 +00:00
|
|
|
|
2014-11-05 20:37:40 +00:00
|
|
|
private boolean wasHighlightedOrPrivate(Message message) {
|
2014-09-28 14:33:25 +00:00
|
|
|
String nick = message.getConversation().getMucOptions().getActualNick();
|
|
|
|
Pattern highlight = generateNickHighlightPattern(nick);
|
2014-10-03 09:55:38 +00:00
|
|
|
if (message.getBody() == null || nick == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-28 14:33:25 +00:00
|
|
|
Matcher m = highlight.matcher(message.getBody());
|
|
|
|
return (m.find() || message.getType() == Message.TYPE_PRIVATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Pattern generateNickHighlightPattern(String nick) {
|
|
|
|
// We expect a word boundary, i.e. space or start of string, followed by
|
|
|
|
// the
|
|
|
|
// nick (matched in case-insensitive manner), followed by optional
|
|
|
|
// punctuation (for example "bob: i disagree" or "how are you alice?"),
|
|
|
|
// followed by another word boundary.
|
|
|
|
return Pattern.compile("\\b" + nick + "\\p{Punct}?\\b",
|
|
|
|
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
|
|
|
|
}
|
|
|
|
|
2014-09-29 16:28:13 +00:00
|
|
|
public void setOpenConversation(Conversation conversation) {
|
|
|
|
this.mOpenConversation = conversation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsInForeground(boolean foreground) {
|
|
|
|
this.mIsInForeground = foreground;
|
|
|
|
}
|
2014-10-21 12:57:16 +00:00
|
|
|
|
|
|
|
private int getPixel(int dp) {
|
|
|
|
DisplayMetrics metrics = mXmppConnectionService.getResources()
|
|
|
|
.getDisplayMetrics();
|
|
|
|
return ((int) (dp * metrics.density));
|
|
|
|
}
|
2014-10-24 11:29:18 +00:00
|
|
|
|
|
|
|
private void markLastNotification() {
|
|
|
|
this.mLastNotification = SystemClock.elapsedRealtime();
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean inMiniGracePeriod(Account account) {
|
2014-11-15 16:09:02 +00:00
|
|
|
int miniGrace = account.getStatus() == Account.State.ONLINE ? Config.MINI_GRACE_PERIOD
|
2014-10-24 11:29:18 +00:00
|
|
|
: Config.MINI_GRACE_PERIOD * 2;
|
|
|
|
return SystemClock.elapsedRealtime() < (this.mLastNotification + miniGrace);
|
|
|
|
}
|
2014-11-12 13:41:43 +00:00
|
|
|
|
|
|
|
public Notification createForegroundNotification() {
|
|
|
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
|
|
|
mBuilder.setSmallIcon(R.drawable.ic_stat_communication_import_export);
|
|
|
|
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.conversations_foreground_service));
|
|
|
|
mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_disable));
|
|
|
|
mBuilder.setContentIntent(createDisableForeground());
|
2014-11-12 16:33:24 +00:00
|
|
|
mBuilder.setWhen(0);
|
|
|
|
mBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
|
2014-11-12 13:41:43 +00:00
|
|
|
return mBuilder.build();
|
|
|
|
}
|
2014-11-18 14:26:28 +00:00
|
|
|
|
|
|
|
public void updateErrorNotification() {
|
|
|
|
NotificationManager mNotificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
List<Account> errors = new ArrayList<>();
|
|
|
|
for (Account account : mXmppConnectionService.getAccounts()) {
|
|
|
|
if (account.hasErrorStatus()) {
|
|
|
|
errors.add(account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
|
|
|
if (errors.size() == 0) {
|
|
|
|
mNotificationManager.cancel(ERROR_NOTIFICATION_ID);
|
|
|
|
return;
|
|
|
|
} else if (errors.size() == 1) {
|
|
|
|
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
|
|
|
|
mBuilder.setContentText(errors.get(0).getJid().toBareJid().toString());
|
|
|
|
} else {
|
|
|
|
mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_accounts));
|
|
|
|
mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_fix));
|
|
|
|
}
|
|
|
|
mBuilder.setOngoing(true);
|
|
|
|
mBuilder.setLights(0xffffffff, 2000, 4000);
|
|
|
|
mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
|
|
|
|
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
|
|
|
|
stackBuilder.addParentStack(ConversationActivity.class);
|
|
|
|
|
|
|
|
Intent manageAccountsIntent = new Intent(mXmppConnectionService,ManageAccountActivity.class);
|
|
|
|
stackBuilder.addNextIntent(manageAccountsIntent);
|
|
|
|
|
|
|
|
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
mBuilder.setContentIntent(resultPendingIntent);
|
|
|
|
Notification notification = mBuilder.build();
|
|
|
|
mNotificationManager.notify(ERROR_NOTIFICATION_ID, notification);
|
|
|
|
}
|
2014-09-28 13:21:56 +00:00
|
|
|
}
|