Added error/alert activity

This commit is contained in:
M66B 2021-07-31 20:13:58 +02:00
parent d7eda33689
commit aa657b6547
6 changed files with 192 additions and 30 deletions

View File

@ -254,6 +254,11 @@
</intent-filter>
</activity>
<activity
android:name=".ActivityError"
android:exported="false"
android:launchMode="singleTask" />
<activity
android:name=".ActivityEML"
android:exported="true"

View 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);
}
});
}
}

View File

@ -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))

View File

@ -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;
}

View File

@ -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);

View File

@ -0,0 +1,81 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="eu.faircode.email.ActivityDSN">
<eu.faircode.email.ScrollViewEx
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingHorizontal="6dp"
android:paddingVertical="12dp"
android:scrollbarStyle="outsideOverlay"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="@+id/cardMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="3dp"
app:cardBackgroundColor="?attr/colorCardBackground"
app:cardCornerRadius="6dp"
app:cardElevation="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingVertical="12dp">
<eu.faircode.email.FixedTextView
android:id="@+id/tvTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Error"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:autoLink="all"
android:text="Error"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorError"
android:textIsSelectable="true"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
<ImageButton
android:id="@+id/ibInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:contentDescription="@string/title_info"
android:tooltipText="@string/title_info"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMessage"
app:srcCompat="@drawable/twotone_info_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>
</androidx.constraintlayout.widget.ConstraintLayout>