From a6cd53b98d4d31fc83b899724a23dbc9059c683e Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 8 Dec 2023 10:46:17 +0100 Subject: [PATCH] Improved error handling --- .../eu/faircode/email/AdapterAccount.java | 113 ++++++++++-------- 1 file changed, 65 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterAccount.java b/app/src/main/java/eu/faircode/email/AdapterAccount.java index 32d23510f3..e57888a1a7 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAccount.java +++ b/app/src/main/java/eu/faircode/email/AdapterAccount.java @@ -320,56 +320,73 @@ public class AdapterAccount extends RecyclerView.Adapter() { - @Override - protected EntityFolder onExecute(Context context, Bundle args) { - long id = args.getLong("id"); - - DB db = DB.getInstance(context); - return db.folder().getFolderByType(id, EntityFolder.INBOX); - } - - @Override - protected void onExecuted(Bundle args, EntityFolder inbox) { - if (inbox == null) - return; - - LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); - lbm.sendBroadcast( - new Intent(ActivityView.ACTION_VIEW_MESSAGES) - .putExtra("account", inbox.account) - .putExtra("folder", inbox.id) - .putExtra("type", inbox.type)); - - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); - } - }.execute(context, owner, args, "account:inbox"); - } else { - LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); - lbm.sendBroadcast( - new Intent(settings ? ActivitySetup.ACTION_EDIT_ACCOUNT : ActivityView.ACTION_VIEW_FOLDERS) - .putExtra("id", account.id) - .putExtra("protocol", account.protocol)); + TupleAccountEx account = (pos == RecyclerView.NO_POSITION ? null : items.get(pos)); + if (account == null) + Helper.viewFAQ(context, 22); + else { + Intent intent = new Intent(context, ActivityError.class); + intent.putExtra("title", "Test"); + intent.putExtra("message", account.error); + intent.putExtra("provider", account.provider); + intent.putExtra("account", account.id); + intent.putExtra("protocol", account.protocol); + intent.putExtra("auth_type", account.auth_type); + intent.putExtra("personal", "personal"); + intent.putExtra("address", "address"); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); } + return; + } + + int pos = getAdapterPosition(); + if (pos == RecyclerView.NO_POSITION) + return; + + TupleAccountEx account = items.get(pos); + if (account.tbd != null) + return; + + if (view.getId() == R.id.ibInbox) { + Bundle args = new Bundle(); + args.putLong("id", account.id); + + new SimpleTask() { + @Override + protected EntityFolder onExecute(Context context, Bundle args) { + long id = args.getLong("id"); + + DB db = DB.getInstance(context); + return db.folder().getFolderByType(id, EntityFolder.INBOX); + } + + @Override + protected void onExecuted(Bundle args, EntityFolder inbox) { + if (inbox == null) + return; + + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); + lbm.sendBroadcast( + new Intent(ActivityView.ACTION_VIEW_MESSAGES) + .putExtra("account", inbox.account) + .putExtra("folder", inbox.id) + .putExtra("type", inbox.type)); + + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); + } + }.execute(context, owner, args, "account:inbox"); + } else { + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); + lbm.sendBroadcast( + new Intent(settings ? ActivitySetup.ACTION_EDIT_ACCOUNT : ActivityView.ACTION_VIEW_FOLDERS) + .putExtra("id", account.id) + .putExtra("protocol", account.protocol)); } }