put error notification into notification service
This commit is contained in:
parent
1122e084a0
commit
66087cb360
|
@ -20,6 +20,7 @@ import android.util.DisplayMetrics;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -31,6 +32,7 @@ import eu.siacs.conversations.entities.Downloadable;
|
|||
import eu.siacs.conversations.entities.DownloadableFile;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.ui.ConversationActivity;
|
||||
import eu.siacs.conversations.ui.ManageAccountActivity;
|
||||
|
||||
public class NotificationService {
|
||||
|
||||
|
@ -40,6 +42,8 @@ public class NotificationService {
|
|||
|
||||
public static int NOTIFICATION_ID = 0x2342;
|
||||
public static int FOREGROUND_NOTIFICATION_ID = 0x8899;
|
||||
public static int ERROR_NOTIFICATION_ID = 0x5678;
|
||||
|
||||
private Conversation mOpenConversation;
|
||||
private boolean mIsInForeground;
|
||||
private long mLastNotification;
|
||||
|
@ -380,4 +384,39 @@ public class NotificationService {
|
|||
mBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
|
||||
return mBuilder.build();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,8 +204,7 @@ public class XmppConnectionService extends Service {
|
|||
scheduleWakeupCall((int) (next * 1.2), false);
|
||||
}
|
||||
}
|
||||
UIHelper.showErrorNotification(getApplicationContext(),
|
||||
getAccounts());
|
||||
getNotificationService().updateErrorNotification();
|
||||
}
|
||||
};
|
||||
private Integer accountChangedListenerCount = 0;
|
||||
|
@ -1071,7 +1070,7 @@ public class XmppConnectionService extends Service {
|
|||
databaseBackend.updateAccount(account);
|
||||
reconnectAccount(account, false);
|
||||
updateAccountUi();
|
||||
UIHelper.showErrorNotification(getApplicationContext(), getAccounts());
|
||||
getNotificationService().updateErrorNotification();
|
||||
}
|
||||
|
||||
public void deleteAccount(Account account) {
|
||||
|
@ -1092,7 +1091,7 @@ public class XmppConnectionService extends Service {
|
|||
databaseBackend.deleteAccount(account);
|
||||
this.accounts.remove(account);
|
||||
updateAccountUi();
|
||||
UIHelper.showErrorNotification(getApplicationContext(), getAccounts());
|
||||
getNotificationService().updateErrorNotification();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,48 +106,6 @@ public class UIHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void showErrorNotification(Context context,
|
||||
List<Account> accounts) {
|
||||
NotificationManager mNotificationManager = (NotificationManager) context
|
||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
List<Account> accountsWproblems = new ArrayList<>();
|
||||
for (Account account : accounts) {
|
||||
if (account.hasErrorStatus()) {
|
||||
accountsWproblems.add(account);
|
||||
}
|
||||
}
|
||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
||||
context);
|
||||
if (accountsWproblems.size() == 0) {
|
||||
mNotificationManager.cancel(1111);
|
||||
return;
|
||||
} else if (accountsWproblems.size() == 1) {
|
||||
mBuilder.setContentTitle(context
|
||||
.getString(R.string.problem_connecting_to_account));
|
||||
mBuilder.setContentText(accountsWproblems.get(0).getJid().toBareJid().toString());
|
||||
} else {
|
||||
mBuilder.setContentTitle(context
|
||||
.getString(R.string.problem_connecting_to_accounts));
|
||||
mBuilder.setContentText(context.getString(R.string.touch_to_fix));
|
||||
}
|
||||
mBuilder.setOngoing(true);
|
||||
mBuilder.setLights(0xffffffff, 2000, 4000);
|
||||
mBuilder.setSmallIcon(R.drawable.ic_notification);
|
||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
|
||||
stackBuilder.addParentStack(ConversationActivity.class);
|
||||
|
||||
Intent manageAccountsIntent = new Intent(context,
|
||||
ManageAccountActivity.class);
|
||||
stackBuilder.addNextIntent(manageAccountsIntent);
|
||||
|
||||
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
mBuilder.setContentIntent(resultPendingIntent);
|
||||
Notification notification = mBuilder.build();
|
||||
mNotificationManager.notify(1111, notification);
|
||||
}
|
||||
|
||||
private final static class EmoticonPattern {
|
||||
Pattern pattern;
|
||||
String replacement;
|
||||
|
|
BIN
src/main/res/drawable-hdpi/ic_stat_alert_warning.png
Normal file
BIN
src/main/res/drawable-hdpi/ic_stat_alert_warning.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 757 B |
BIN
src/main/res/drawable-mdpi/ic_stat_alert_warning.png
Normal file
BIN
src/main/res/drawable-mdpi/ic_stat_alert_warning.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 425 B |
BIN
src/main/res/drawable-xhdpi/ic_stat_alert_warning.png
Normal file
BIN
src/main/res/drawable-xhdpi/ic_stat_alert_warning.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
src/main/res/drawable-xxhdpi/ic_stat_alert_warning.png
Normal file
BIN
src/main/res/drawable-xxhdpi/ic_stat_alert_warning.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
Loading…
Reference in a new issue