mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-04 08:08:16 +02:00
Refactoring
This commit is contained in:
@@ -20,7 +20,6 @@ package eu.faircode.email;
|
||||
*/
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
@@ -80,14 +79,10 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
import com.sun.mail.iap.BadCommandException;
|
||||
import com.sun.mail.iap.ConnectionException;
|
||||
import com.sun.mail.util.FolderClosedIOException;
|
||||
|
||||
import org.bouncycastle.asn1.x509.GeneralName;
|
||||
|
||||
@@ -123,9 +118,6 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.mail.FolderClosedException;
|
||||
import javax.mail.MessageRemovedException;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
|
||||
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
|
||||
@@ -281,7 +273,7 @@ public class Helper {
|
||||
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, uri.toString()), Toast.LENGTH_LONG).show();
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
ToastEx.makeText(context, Helper.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
|
||||
ToastEx.makeText(context, Log.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -505,141 +497,6 @@ public class Helper {
|
||||
return name;
|
||||
}
|
||||
|
||||
static String formatThrowable(Throwable ex) {
|
||||
return formatThrowable(ex, true);
|
||||
}
|
||||
|
||||
static String formatThrowable(Throwable ex, boolean santize) {
|
||||
return formatThrowable(ex, " ", santize);
|
||||
}
|
||||
|
||||
static String formatThrowable(Throwable ex, String separator, boolean sanitize) {
|
||||
if (sanitize) {
|
||||
if (ex instanceof MessageRemovedException)
|
||||
return null;
|
||||
|
||||
if (ex instanceof MessagingException &&
|
||||
ex.getCause() instanceof ConnectionException &&
|
||||
ex.getCause().getMessage() != null &&
|
||||
(ex.getCause().getMessage().contains("Read error") ||
|
||||
ex.getCause().getMessage().contains("Write error")))
|
||||
return null;
|
||||
|
||||
// javax.mail.MessagingException: AU3 BAD User is authenticated but not connected.;
|
||||
// nested exception is:
|
||||
// com.sun.mail.iap.BadCommandException: AU3 BAD User is authenticated but not connected.
|
||||
// javax.mail.MessagingException: AU3 BAD User is authenticated but not connected.;
|
||||
// nested exception is:
|
||||
// com.sun.mail.iap.BadCommandException: AU3 BAD User is authenticated but not connected.
|
||||
// at com.sun.mail.imap.IMAPFolder.logoutAndThrow(SourceFile:1156)
|
||||
// at com.sun.mail.imap.IMAPFolder.open(SourceFile:1063)
|
||||
// at com.sun.mail.imap.IMAPFolder.open(SourceFile:977)
|
||||
// at eu.faircode.email.ServiceSynchronize.monitorAccount(SourceFile:890)
|
||||
// at eu.faircode.email.ServiceSynchronize.access$1500(SourceFile:85)
|
||||
// at eu.faircode.email.ServiceSynchronize$7$1.run(SourceFile:627)
|
||||
// at java.lang.Thread.run(Thread.java:764)
|
||||
// Caused by: com.sun.mail.iap.BadCommandException: AU3 BAD User is authenticated but not connected.
|
||||
// at com.sun.mail.iap.Protocol.handleResult(SourceFile:415)
|
||||
// at com.sun.mail.imap.protocol.IMAPProtocol.select(SourceFile:1230)
|
||||
// at com.sun.mail.imap.IMAPFolder.open(SourceFile:1034)
|
||||
|
||||
if (ex instanceof MessagingException &&
|
||||
ex.getCause() instanceof BadCommandException &&
|
||||
ex.getCause().getMessage() != null &&
|
||||
ex.getCause().getMessage().contains("User is authenticated but not connected"))
|
||||
return null;
|
||||
|
||||
if (ex instanceof IOException &&
|
||||
ex.getCause() instanceof MessageRemovedException)
|
||||
return null;
|
||||
|
||||
if (ex instanceof ConnectionException)
|
||||
return null;
|
||||
|
||||
if (ex instanceof FolderClosedException || ex instanceof FolderClosedIOException)
|
||||
return null;
|
||||
|
||||
if (ex instanceof IllegalStateException &&
|
||||
("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();
|
||||
if (BuildConfig.DEBUG)
|
||||
sb.append(ex.toString());
|
||||
else
|
||||
sb.append(ex.getMessage() == null ? ex.getClass().getName() : ex.getMessage());
|
||||
|
||||
Throwable cause = ex.getCause();
|
||||
while (cause != null) {
|
||||
if (BuildConfig.DEBUG)
|
||||
sb.append(separator).append(cause.toString());
|
||||
else
|
||||
sb.append(separator).append(cause.getMessage() == null ? cause.getClass().getName() : cause.getMessage());
|
||||
cause = cause.getCause();
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static void unexpectedError(FragmentManager manager, Throwable ex) {
|
||||
Log.e(ex);
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable("ex", ex);
|
||||
|
||||
FragmentDialogUnexpected fragment = new FragmentDialogUnexpected();
|
||||
fragment.setArguments(args);
|
||||
fragment.show(manager, "error:unexpected");
|
||||
}
|
||||
|
||||
public static class FragmentDialogUnexpected extends FragmentDialogBase {
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
final Throwable ex = (Throwable) getArguments().getSerializable("ex");
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.title_unexpected_error)
|
||||
.setMessage(Helper.formatThrowable(ex, false))
|
||||
.setPositiveButton(android.R.string.cancel, null)
|
||||
.setNeutralButton(R.string.title_report, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Dialog will be dismissed
|
||||
final Context context = getContext();
|
||||
|
||||
new SimpleTask<Long>() {
|
||||
@Override
|
||||
protected Long onExecute(Context context, Bundle args) throws Throwable {
|
||||
return Log.getDebugInfo(context, R.string.title_crash_info_remark, ex, null).id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Long id) {
|
||||
context.startActivity(new Intent(context, ActivityCompose.class)
|
||||
.putExtra("action", "edit")
|
||||
.putExtra("id", id));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
if (ex instanceof IllegalArgumentException)
|
||||
ToastEx.makeText(context, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
ToastEx.makeText(context, ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}.execute(getContext(), getActivity(), new Bundle(), "error:unexpected");
|
||||
}
|
||||
})
|
||||
.create();
|
||||
}
|
||||
}
|
||||
|
||||
static void linkPro(final TextView tv) {
|
||||
if (ActivityBilling.isPro(tv.getContext()) && !BuildConfig.DEBUG)
|
||||
hide(tv);
|
||||
|
||||
Reference in New Issue
Block a user