From b23100bea539b5b24b1a69fed58c09b755dce018 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 7 Mar 2020 16:28:16 +0100 Subject: [PATCH] Refactoring --- .../eu/faircode/email/AdapterMessage.java | 231 +++++++++--------- 1 file changed, 116 insertions(+), 115 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index ab894dd8e9..dca872f0ad 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -1278,6 +1278,17 @@ public class AdapterMessage extends RecyclerView.Adapter 0); + boolean hasTo = (message.to != null && message.to.length > 0); + boolean hasChannel = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O); + + String submitter = MessageHelper.formatAddresses(message.submitter); + String from = MessageHelper.formatAddresses(message.senders); + String to = MessageHelper.formatAddresses(message.to); + String replyto = MessageHelper.formatAddresses(message.reply); + String cc = MessageHelper.formatAddresses(message.cc); + String bcc = MessageHelper.formatAddresses(message.bcc); + if (compact) { tvFrom.setSingleLine(false); tvSubject.setSingleLine(false); @@ -1287,11 +1298,11 @@ public class AdapterMessage extends RecyclerView.Adapter 0); - boolean hasTo = (message.to != null && message.to.length > 0); - boolean hasChannel = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O); + ibExpanderAddress.setImageLevel(show_addresses ? 0 /* less */ : 1 /* more */); + ibExpanderAddress.setContentDescription(context.getString(show_addresses ? R.string.title_accessibility_hide_addresses : R.string.title_accessibility_show_addresses)); ivPlain.setVisibility(show_addresses && message.plain_only != null && message.plain_only ? View.VISIBLE : View.GONE); ivReceipt.setVisibility(show_addresses && message.receipt_request != null && message.receipt_request ? View.VISIBLE : View.GONE); @@ -1301,118 +1312,6 @@ public class AdapterMessage extends RecyclerView.Adapter>() { - @Override - protected void onPreExecute(Bundle args) { - ibUnsubscribe.setVisibility(View.GONE); - ibAnswer.setVisibility(View.GONE); - ibMove.setVisibility(View.GONE); - ibArchive.setVisibility(View.GONE); - ibTrash.setVisibility(View.GONE); - ibJunk.setVisibility(View.GONE); - } - - @Override - protected List onExecute(Context context, Bundle args) { - long account = args.getLong("account"); - return DB.getInstance(context).folder().getSystemFolders(account); - } - - @Override - protected void onExecuted(Bundle args, List folders) { - long id = args.getLong("id"); - TupleMessageEx amessage = getMessage(); - if (amessage == null || !amessage.id.equals(id)) - return; - - boolean hasArchive = false; - boolean hasTrash = false; - boolean hasJunk = false; - if (folders != null) - for (EntityFolder folder : folders) - if (EntityFolder.ARCHIVE.equals(folder.type)) - hasArchive = true; - else if (EntityFolder.TRASH.equals(folder.type)) - hasTrash = true; - else if (EntityFolder.JUNK.equals(folder.type)) - hasJunk = true; - - boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType); - boolean inTrash = EntityFolder.TRASH.equals(message.folderType); - boolean inJunk = EntityFolder.JUNK.equals(message.folderType); - boolean outbox = EntityFolder.OUTBOX.equals(message.folderType); - - boolean move = !(message.folderReadOnly || message.uid == null); - boolean archive = (move && (hasArchive && !inArchive)); - boolean trash = (move || outbox || debug); - boolean junk = (move && (hasJunk && !inJunk)); - boolean unjunk = (move && inJunk); - - final boolean delete = (inTrash || !hasTrash || outbox || message.uid == null); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean expand_all = prefs.getBoolean("expand_all", false); - boolean expand_one = prefs.getBoolean("expand_one", true); - - ibTrash.setTag(delete); - ibJunk.setImageResource(unjunk ? R.drawable.baseline_inbox_24 : R.drawable.baseline_flag_24); - String title = context.getString(unjunk ? R.string.title_no_junk : R.string.title_spam); - ibJunk.setContentDescription(title); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - ibJunk.setTooltipText(title); - - ibUnsubscribe.setVisibility(message.unsubscribe == null ? View.GONE : View.VISIBLE); - ibAnswer.setVisibility(outbox || (!expand_all && expand_one) ? View.GONE : View.VISIBLE); - ibMove.setVisibility(move ? View.VISIBLE : View.GONE); - ibArchive.setVisibility(archive ? View.VISIBLE : View.GONE); - ibTrash.setVisibility(trash ? View.VISIBLE : View.GONE); - ibJunk.setVisibility(junk || unjunk ? View.VISIBLE : View.GONE); - - bindBody(message); - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); - } - }.setLog(false).execute(context, owner, sargs, "message:more"); - - ibMore.setVisibility(EntityFolder.OUTBOX.equals(message.folderType) ? View.GONE : View.VISIBLE); - tvSignedData.setVisibility(View.GONE); - - // Addresses - ibExpanderAddress.setImageLevel(show_addresses ? 0 /* less */ : 1 /* more */); - ibExpanderAddress.setContentDescription(context.getString(show_addresses ? R.string.title_accessibility_hide_addresses : R.string.title_accessibility_show_addresses)); - - String submitter = MessageHelper.formatAddresses(message.submitter); - String from = MessageHelper.formatAddresses(message.senders); - String to = MessageHelper.formatAddresses(message.to); - String replyto = MessageHelper.formatAddresses(message.reply); - String cc = MessageHelper.formatAddresses(message.cc); - String bcc = MessageHelper.formatAddresses(message.bcc); - tvSubmitterTitle.setVisibility(show_addresses && !TextUtils.isEmpty(submitter) ? View.VISIBLE : View.GONE); tvSubmitter.setVisibility(show_addresses && !TextUtils.isEmpty(submitter) ? View.VISIBLE : View.GONE); tvSubmitter.setText(submitter); @@ -1493,6 +1392,15 @@ public class AdapterMessage extends RecyclerView.Adapter>() { + @Override + protected void onPreExecute(Bundle args) { + ibUnsubscribe.setVisibility(View.GONE); + ibAnswer.setVisibility(View.GONE); + ibMove.setVisibility(View.GONE); + ibArchive.setVisibility(View.GONE); + ibTrash.setVisibility(View.GONE); + ibJunk.setVisibility(View.GONE); + } + + @Override + protected List onExecute(Context context, Bundle args) { + long account = args.getLong("account"); + return DB.getInstance(context).folder().getSystemFolders(account); + } + + @Override + protected void onExecuted(Bundle args, List folders) { + long id = args.getLong("id"); + TupleMessageEx amessage = getMessage(); + if (amessage == null || !amessage.id.equals(id)) + return; + + boolean hasArchive = false; + boolean hasTrash = false; + boolean hasJunk = false; + if (folders != null) + for (EntityFolder folder : folders) + if (EntityFolder.ARCHIVE.equals(folder.type)) + hasArchive = true; + else if (EntityFolder.TRASH.equals(folder.type)) + hasTrash = true; + else if (EntityFolder.JUNK.equals(folder.type)) + hasJunk = true; + + boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType); + boolean inTrash = EntityFolder.TRASH.equals(message.folderType); + boolean inJunk = EntityFolder.JUNK.equals(message.folderType); + boolean outbox = EntityFolder.OUTBOX.equals(message.folderType); + + boolean move = !(message.folderReadOnly || message.uid == null); + boolean archive = (move && (hasArchive && !inArchive)); + boolean trash = (move || outbox || debug); + boolean junk = (move && (hasJunk && !inJunk)); + boolean unjunk = (move && inJunk); + + final boolean delete = (inTrash || !hasTrash || outbox || message.uid == null); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean expand_all = prefs.getBoolean("expand_all", false); + boolean expand_one = prefs.getBoolean("expand_one", true); + + ibTrash.setTag(delete); + ibJunk.setImageResource(unjunk ? R.drawable.baseline_inbox_24 : R.drawable.baseline_flag_24); + String title = context.getString(unjunk ? R.string.title_no_junk : R.string.title_spam); + ibJunk.setContentDescription(title); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + ibJunk.setTooltipText(title); + + ibUnsubscribe.setVisibility(message.unsubscribe == null ? View.GONE : View.VISIBLE); + ibAnswer.setVisibility(outbox || (!expand_all && expand_one) ? View.GONE : View.VISIBLE); + ibMove.setVisibility(move ? View.VISIBLE : View.GONE); + ibArchive.setVisibility(archive ? View.VISIBLE : View.GONE); + ibTrash.setVisibility(trash ? View.VISIBLE : View.GONE); + ibJunk.setVisibility(junk || unjunk ? View.VISIBLE : View.GONE); + + bindBody(message); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); + } + }.setLog(false).execute(context, owner, sargs, "message:more"); } private void bindBody(TupleMessageEx message) {