mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-07 01:23:38 +02:00
Simplified alert handling
This commit is contained in:
@@ -106,11 +106,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||
static final int REQUEST_UNIFIED = 1;
|
||||
static final int REQUEST_FOLDER = 2;
|
||||
static final int REQUEST_WHY = 3;
|
||||
static final int REQUEST_THREAD = 4;
|
||||
static final int REQUEST_OUTBOX = 5;
|
||||
static final int REQUEST_ERROR = 6;
|
||||
static final int REQUEST_UPDATE = 7;
|
||||
static final int REQUEST_WIDGET = 8;
|
||||
static final int REQUEST_ALERT = 4;
|
||||
static final int REQUEST_THREAD = 5;
|
||||
static final int REQUEST_OUTBOX = 6;
|
||||
static final int REQUEST_ERROR = 7;
|
||||
static final int REQUEST_UPDATE = 8;
|
||||
static final int REQUEST_WIDGET = 9;
|
||||
|
||||
static final String ACTION_VIEW_FOLDERS = BuildConfig.APPLICATION_ID + ".VIEW_FOLDERS";
|
||||
static final String ACTION_VIEW_MESSAGES = BuildConfig.APPLICATION_ID + ".VIEW_MESSAGES";
|
||||
@@ -826,6 +827,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||
Helper.viewFAQ(this, 2);
|
||||
}
|
||||
|
||||
} else if ("alert".equals(action)) {
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||
getSupportFragmentManager().popBackStack("unified", 0);
|
||||
|
||||
Helper.viewFAQ(this, 23);
|
||||
|
||||
} else if ("outbox".equals(action))
|
||||
onMenuOutbox();
|
||||
|
||||
|
||||
@@ -244,14 +244,14 @@ public class ApplicationEx extends Application {
|
||||
nm.createNotificationChannel(update);
|
||||
}
|
||||
|
||||
// Warn
|
||||
// Warnings
|
||||
NotificationChannel warning = new NotificationChannel(
|
||||
"warning", getString(R.string.channel_warning),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
warning.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(warning);
|
||||
|
||||
// Error
|
||||
// Errors
|
||||
NotificationChannel error = new NotificationChannel(
|
||||
"error",
|
||||
getString(R.string.channel_error),
|
||||
@@ -259,6 +259,14 @@ public class ApplicationEx extends Application {
|
||||
error.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(error);
|
||||
|
||||
// Server alerts
|
||||
NotificationChannel alerts = new NotificationChannel(
|
||||
"alerts",
|
||||
getString(R.string.channel_alert),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
alerts.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(alerts);
|
||||
|
||||
// Contacts grouping
|
||||
NotificationChannelGroup group = new NotificationChannelGroup(
|
||||
"contacts",
|
||||
|
||||
@@ -3191,27 +3191,13 @@ class Core {
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setOnlyAlertOnce(true)
|
||||
.setCategory(NotificationCompat.CATEGORY_ERROR)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_SECRET);
|
||||
|
||||
builder.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(Log.formatThrowable(ex, "\n", false)));
|
||||
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(Log.formatThrowable(ex, "\n", false)));
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
static class AlertException extends Throwable {
|
||||
private String alert;
|
||||
|
||||
AlertException(String alert) {
|
||||
this.alert = alert;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return alert;
|
||||
}
|
||||
}
|
||||
|
||||
static class State {
|
||||
private ConnectionHelper.NetworkState networkState;
|
||||
private Thread thread;
|
||||
|
||||
@@ -273,7 +273,7 @@ public class Helper {
|
||||
if (question == 0)
|
||||
view(context, Uri.parse(FAQ_URI), false);
|
||||
else
|
||||
view(context, Uri.parse(Helper.FAQ_URI + "#user-content-faq" + question), false);
|
||||
view(context, Uri.parse(FAQ_URI + "#user-content-faq" + question), false);
|
||||
}
|
||||
|
||||
static Intent getIntentOpenKeychain() {
|
||||
|
||||
@@ -552,9 +552,6 @@ public class Log {
|
||||
("Not connected".equals(ex.getMessage()) ||
|
||||
"This operation is not allowed on a closed folder".equals(ex.getMessage())))
|
||||
return null;
|
||||
|
||||
if (ex instanceof Core.AlertException)
|
||||
return ex.getMessage();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -707,6 +707,31 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
return builder;
|
||||
}
|
||||
|
||||
private NotificationCompat.Builder getNotificationAlert(String account, String message) {
|
||||
// Build pending intent
|
||||
Intent alert = new Intent(this, ActivityView.class);
|
||||
alert.setAction("alert");
|
||||
PendingIntent piAlert = PendingIntent.getActivity(this, ActivityView.REQUEST_ALERT, alert, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
// Build notification
|
||||
NotificationCompat.Builder builder =
|
||||
new NotificationCompat.Builder(this, "alerts")
|
||||
.setSmallIcon(R.drawable.baseline_warning_white_24)
|
||||
.setContentTitle(getString(R.string.title_notification_alert, account))
|
||||
.setContentText(message)
|
||||
.setContentIntent(piAlert)
|
||||
.setAutoCancel(false)
|
||||
.setShowWhen(true)
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setOnlyAlertOnce(true)
|
||||
.setCategory(NotificationCompat.CATEGORY_ERROR)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(message));
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private void setUnseen(Integer unseen) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean badge = prefs.getBoolean("badge", true);
|
||||
@@ -779,21 +804,11 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
try {
|
||||
wlFolder.acquire();
|
||||
|
||||
String message = e.getMessage();
|
||||
Log.w(account.name + " alert: " + message);
|
||||
EntityLog.log(
|
||||
ServiceSynchronize.this, account.name + " " +
|
||||
Log.formatThrowable(new Core.AlertException(message), false));
|
||||
db.account().setAccountError(account.id, message);
|
||||
EntityLog.log(ServiceSynchronize.this, account.name + " " + e.getMessage());
|
||||
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify("alert:" + account.id, 1,
|
||||
Core.getNotificationError(
|
||||
ServiceSynchronize.this, "warning", account.name,
|
||||
new Core.AlertException(message))
|
||||
.build());
|
||||
|
||||
state.error(null);
|
||||
getNotificationAlert(account.name, e.getMessage()).build());
|
||||
} finally {
|
||||
wlFolder.release();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user