mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-18 15:03:15 +02:00
Added error/alert activity
This commit is contained in:
65
app/src/main/java/eu/faircode/email/ActivityError.java
Normal file
65
app/src/main/java/eu/faircode/email/ActivityError.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FairEmail is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ActivityError extends ActivityBase {
|
||||
static final int PI_ERROR = 1;
|
||||
static final int PI_ALERT = 2;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getSupportActionBar().setSubtitle(getString(R.string.title_setup_error));
|
||||
|
||||
View view = LayoutInflater.from(this).inflate(R.layout.activity_error, null);
|
||||
setContentView(view);
|
||||
|
||||
TextView tvTitle = view.findViewById(R.id.tvTitle);
|
||||
TextView tvMessage = view.findViewById(R.id.tvMessage);
|
||||
ImageButton ibInfo = view.findViewById(R.id.ibInfo);
|
||||
|
||||
Intent intent = getIntent();
|
||||
String type = intent.getStringExtra("type");
|
||||
String title = intent.getStringExtra("title");
|
||||
String message = intent.getStringExtra("message");
|
||||
int faq = intent.getIntExtra("faq", -1);
|
||||
|
||||
tvTitle.setText(title);
|
||||
tvMessage.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
tvMessage.setText(message);
|
||||
|
||||
ibInfo.setVisibility(faq > 0 ? View.VISIBLE : View.GONE);
|
||||
ibInfo.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Helper.viewFAQ(view.getContext(), faq);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,10 @@ package eu.faircode.email;
|
||||
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
|
||||
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_OPEN;
|
||||
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_UNLOCKED;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.app.NotificationManager;
|
||||
@@ -81,10 +85,6 @@ import java.util.List;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
|
||||
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_OPEN;
|
||||
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_UNLOCKED;
|
||||
|
||||
public class ActivityView extends ActivityBilling implements FragmentManager.OnBackStackChangedListener {
|
||||
private String startup;
|
||||
|
||||
@@ -121,13 +121,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||
|
||||
static final int PI_UNIFIED = 1;
|
||||
static final int PI_WHY = 2;
|
||||
static final int PI_ALERT = 3;
|
||||
static final int PI_THREAD = 4;
|
||||
static final int PI_OUTBOX = 5;
|
||||
static final int PI_ERROR = 6;
|
||||
static final int PI_UPDATE = 7;
|
||||
static final int PI_WIDGET = 8;
|
||||
static final int PI_POWER = 9;
|
||||
static final int PI_THREAD = 3;
|
||||
static final int PI_OUTBOX = 4;
|
||||
static final int PI_ERROR = 5;
|
||||
static final int PI_UPDATE = 6;
|
||||
static final int PI_WIDGET = 7;
|
||||
static final int PI_POWER = 8;
|
||||
|
||||
static final String ACTION_VIEW_FOLDERS = BuildConfig.APPLICATION_ID + ".VIEW_FOLDERS";
|
||||
static final String ACTION_VIEW_MESSAGES = BuildConfig.APPLICATION_ID + ".VIEW_MESSAGES";
|
||||
@@ -1166,11 +1165,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||
Helper.viewFAQ(this, 2);
|
||||
}
|
||||
|
||||
} else if ("alert".equals(action) || "error".equals(action)) {
|
||||
} else if ("error".equals(action)) {
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||
getSupportFragmentManager().popBackStack("unified", 0);
|
||||
|
||||
Helper.viewFAQ(this, "alert".equals(action) ? 23 : 22);
|
||||
Helper.viewFAQ(this, 22);
|
||||
|
||||
} else if ("outbox".equals(action)) {
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||
|
||||
@@ -632,7 +632,7 @@ class Core {
|
||||
String title = (resid == 0 ? null : context.getString(resid));
|
||||
if (title != null) {
|
||||
NotificationCompat.Builder builder =
|
||||
getNotificationError(context, "warning", title, ex);
|
||||
getNotificationError(context, "warning", account, message.id, new Throwable(title, ex));
|
||||
nm.notify(op.name + ":" + op.message,
|
||||
NotificationHelper.NOTIFICATION_TAGGED,
|
||||
builder.build());
|
||||
@@ -4852,19 +4852,26 @@ class Core {
|
||||
// MailConnectException
|
||||
// - on connectivity problems when connecting to store
|
||||
|
||||
static NotificationCompat.Builder getNotificationError(Context context, String channel, String title, Throwable ex) {
|
||||
static NotificationCompat.Builder getNotificationError(Context context, String channel, EntityAccount account, long id, Throwable ex) {
|
||||
String title = context.getString(R.string.title_notification_failed, account.name);
|
||||
String message = Log.formatThrowable(ex, "\n", false);
|
||||
|
||||
// Build pending intent
|
||||
Intent intent = new Intent(context, ActivityView.class);
|
||||
intent.setAction("error");
|
||||
Intent intent = new Intent(context, ActivityError.class);
|
||||
intent.setAction(channel + ":" + account.id + ":" + id);
|
||||
intent.putExtra("type", channel);
|
||||
intent.putExtra("title", title);
|
||||
intent.putExtra("message", message);
|
||||
intent.putExtra("faq", 22);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
PendingIntent pi = PendingIntentCompat.getActivity(
|
||||
context, ActivityView.PI_ERROR, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
context, ActivityError.PI_ERROR, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
// 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))
|
||||
.setContentTitle(title)
|
||||
.setContentText(Log.formatThrowable(ex, false))
|
||||
.setContentIntent(pi)
|
||||
.setAutoCancel(false)
|
||||
@@ -4873,8 +4880,7 @@ class Core {
|
||||
.setOnlyAlertOnce(true)
|
||||
.setCategory(NotificationCompat.CATEGORY_ERROR)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(Log.formatThrowable(ex, "\n", false)));
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -1160,19 +1160,25 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
return builder;
|
||||
}
|
||||
|
||||
private NotificationCompat.Builder getNotificationAlert(String account, String message) {
|
||||
private NotificationCompat.Builder getNotificationAlert(EntityAccount account, String message) {
|
||||
String title = getString(R.string.title_notification_alert, account.name);
|
||||
|
||||
// Build pending intent
|
||||
Intent alert = new Intent(this, ActivityView.class);
|
||||
alert.setAction("alert");
|
||||
alert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Intent intent = new Intent(this, ActivityError.class);
|
||||
intent.setAction("alert:" + account.id);
|
||||
intent.putExtra("type", "alert");
|
||||
intent.putExtra("title", title);
|
||||
intent.putExtra("message", message);
|
||||
intent.putExtra("faq", 23);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
PendingIntent piAlert = PendingIntentCompat.getActivity(
|
||||
this, ActivityView.PI_ALERT, alert, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
this, ActivityError.PI_ALERT, intent, 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))
|
||||
.setContentTitle(title)
|
||||
.setContentText(message)
|
||||
.setContentIntent(piAlert)
|
||||
.setAutoCancel(false)
|
||||
@@ -1275,7 +1281,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify("alert:" + account.id,
|
||||
NotificationHelper.NOTIFICATION_TAGGED,
|
||||
getNotificationAlert(account.name, message).build());
|
||||
getNotificationAlert(account, message).build());
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
@@ -1309,7 +1315,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify("receive:" + account.id,
|
||||
NotificationHelper.NOTIFICATION_TAGGED,
|
||||
Core.getNotificationError(this, "error", account.name, ex)
|
||||
Core.getNotificationError(this, "error", account, 0, ex)
|
||||
.build());
|
||||
} catch (Throwable ex1) {
|
||||
Log.w(ex1);
|
||||
@@ -2035,7 +2041,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify("receive:" + account.id,
|
||||
NotificationHelper.NOTIFICATION_TAGGED,
|
||||
Core.getNotificationError(this, "warning", account.name, warning)
|
||||
Core.getNotificationError(this, "warning", account, 0, warning)
|
||||
.build());
|
||||
} catch (Throwable ex1) {
|
||||
Log.w(ex1);
|
||||
|
||||
Reference in New Issue
Block a user