Improved error handling

This commit is contained in:
M66B 2023-12-08 10:46:17 +01:00
parent 58ee954993
commit a6cd53b98d
1 changed files with 65 additions and 48 deletions

View File

@ -320,56 +320,73 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (view.getId() == R.id.btnHelp) if (view.getId() == R.id.btnHelp) {
Helper.viewFAQ(context, 22);
else {
int pos = getAdapterPosition(); int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION) TupleAccountEx account = (pos == RecyclerView.NO_POSITION ? null : items.get(pos));
return; if (account == null)
Helper.viewFAQ(context, 22);
TupleAccountEx account = items.get(pos); else {
if (account.tbd != null) Intent intent = new Intent(context, ActivityError.class);
return; intent.putExtra("title", "Test");
intent.putExtra("message", account.error);
if (view.getId() == R.id.ibInbox) { intent.putExtra("provider", account.provider);
Bundle args = new Bundle(); intent.putExtra("account", account.id);
args.putLong("id", account.id); intent.putExtra("protocol", account.protocol);
intent.putExtra("auth_type", account.auth_type);
new SimpleTask<EntityFolder>() { intent.putExtra("personal", "personal");
@Override intent.putExtra("address", "address");
protected EntityFolder onExecute(Context context, Bundle args) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
long id = args.getLong("id"); context.startActivity(intent);
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));
} }
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<EntityFolder>() {
@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));
} }
} }