Improved send error

pull/182/head
M66B 4 years ago
parent 278ef1584f
commit b7bdc6410f

@ -3689,17 +3689,16 @@ class Core {
// - on connectivity problems when connecting to store
static NotificationCompat.Builder getNotificationError(Context context, String channel, String title, Throwable ex) {
// Build pending intent
Intent intent = new Intent(context, ActivityView.class);
intent.setAction("error");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(
context, ActivityView.REQUEST_ERROR, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return getNotificationError(context, channel, title, ex, pi);
}
static NotificationCompat.Builder getNotificationError(Context context, String channel, String title, Throwable ex, PendingIntent pi) {
return new NotificationCompat.Builder(context, channel)
// Build notification
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context, channel)
.setSmallIcon(R.drawable.baseline_warning_white_24)
.setContentTitle(context.getString(R.string.title_notification_failed, title))
.setContentText(Log.formatThrowable(ex, false))
@ -3712,6 +3711,8 @@ class Core {
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(Log.formatThrowable(ex, "\n", false)));
return builder;
}
static class State {

@ -204,6 +204,22 @@ public class ServiceSend extends ServiceBase {
return builder;
}
NotificationCompat.Builder getNotificationError(String recipient, Throwable ex) {
return new NotificationCompat.Builder(this, "error")
.setSmallIcon(R.drawable.baseline_warning_white_24)
.setContentTitle(getString(R.string.title_notification_sending_failed, recipient))
.setContentText(Log.formatThrowable(ex, false))
.setContentIntent(getPendingIntent(this))
.setAutoCancel(false)
.setShowWhen(true)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setOnlyAlertOnce(true)
.setCategory(NotificationCompat.CATEGORY_ERROR)
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(Log.formatThrowable(ex, "\n", false)));
}
private static PendingIntent getPendingIntent(Context context) {
Intent intent = new Intent(context, ActivityView.class);
intent.setAction("outbox");
@ -356,13 +372,10 @@ public class ServiceSend extends ServiceBase {
ops.remove(op);
if (message != null) {
String title = MessageHelper.formatAddresses(message.to);
PendingIntent pi = getPendingIntent(this);
try {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("send:" + message.id, 1,
Core.getNotificationError(this, "error", title, ex, pi).build());
nm.notify("send:" + message.id, 1, getNotificationError(
MessageHelper.formatAddressesShort(message.to), ex).build());
} catch (Throwable ex1) {
Log.w(ex1);
}
@ -535,6 +548,8 @@ public class ServiceSend extends ServiceBase {
// Connect transport
db.identity().setIdentityState(ident.id, "connecting");
iservice.connect(ident);
if (BuildConfig.DEBUG)
throw new IOException("Test");
db.identity().setIdentityState(ident.id, "connected");
Address[] to = imessage.getAllRecipients();

@ -98,6 +98,7 @@
<string name="title_notification_idle">Idle</string>
<string name="title_notification_failed">\'%1$s\' failed</string>
<string name="title_notification_alert">\'%1$s\' server alert</string>
<string name="title_notification_sending_failed">Sending to %1$s failed</string>
<string name="title_of">%1$s/%2$s</string>
<string name="title_name_count">%1$s (%2$s)</string>

Loading…
Cancel
Save