From 7feac257d12e082bbbc186971f886999424c347e Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 2 Aug 2018 20:45:16 +0000 Subject: [PATCH] Catch exceptions --- .../eu/faircode/email/AdapterMessage.java | 34 ++--- .../eu/faircode/email/FragmentCompose.java | 121 +++++++++--------- .../eu/faircode/email/FragmentMessage.java | 81 +++++++----- 3 files changed, 132 insertions(+), 104 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index ae596148..6f04e246 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -86,22 +86,26 @@ public class AdapterMessage extends RecyclerView.Adapter addresses = new ArrayList<>(); - addresses.addAll(Arrays.asList(reply.length == 0 ? from : reply)); - addresses.addAll(Arrays.asList(cc)); - to = MessageHelper.encodeAddresses(addresses.toArray(new Address[0])); - } catch (Throwable ex) { - Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); + } else if ("reply".equals(action)) { + String to = null; + if (msg != null) + try { + Address[] reply = MessageHelper.decodeAddresses(msg.reply); + to = (reply.length == 0 ? msg.from : msg.reply); + } catch (Throwable ex) { + Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); + } + result.putLong("rid", msg.id); + result.putString("from", msg.to); + result.putString("to", to); + } else if ("reply_all".equals(action)) { + String to = null; + if (msg != null) { + try { + Address[] from = MessageHelper.decodeAddresses(msg.from); + Address[] reply = MessageHelper.decodeAddresses(msg.reply); + Address[] cc = MessageHelper.decodeAddresses(msg.cc); + List
addresses = new ArrayList<>(); + addresses.addAll(Arrays.asList(reply.length == 0 ? from : reply)); + addresses.addAll(Arrays.asList(cc)); + to = MessageHelper.encodeAddresses(addresses.toArray(new Address[0])); + } catch (Throwable ex) { + Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); + } } + result.putLong("rid", msg.id); + result.putString("from", msg.to); + result.putString("to", to); + } else if ("forward".equals(action)) { + result.putString("from", msg.to); + result.putString("to", null); } - result.putLong("rid", msg.id); - result.putString("from", msg.to); - result.putString("to", to); - } else if ("forward".equals(action)) { - result.putString("from", msg.to); - result.putString("to", null); + } catch (Throwable ex) { + Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); } - return result; } } @@ -405,15 +408,19 @@ public class FragmentCompose extends Fragment { @Override public Throwable loadInBackground() { - long id = args.getLong("id"); - DaoMessage message = DB.getInstance(getContext()).message(); - EntityMessage draft = message.getMessage(id); - if (draft != null) { - draft.ui_hide = true; - message.updateMessage(draft); - EntityOperation.queue(getContext(), draft, EntityOperation.DELETE); + try { + long id = args.getLong("id"); + DaoMessage message = DB.getInstance(getContext()).message(); + EntityMessage draft = message.getMessage(id); + if (draft != null) { + draft.ui_hide = true; + message.updateMessage(draft); + EntityOperation.queue(getContext(), draft, EntityOperation.DELETE); + } + return null; + } catch (Throwable ex) { + return ex; } - return null; } } diff --git a/app/src/main/java/eu/faircode/email/FragmentMessage.java b/app/src/main/java/eu/faircode/email/FragmentMessage.java index 336554ba..e72c0f4f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessage.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessage.java @@ -35,6 +35,7 @@ import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.text.Html; import android.text.method.LinkMovementMethod; +import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -213,11 +214,15 @@ public class FragmentMessage extends Fragment { executor.submit(new Runnable() { @Override public void run() { - DB db = DB.getInstance(getContext()); - EntityMessage message = db.message().getMessage(id); - message.ui_seen = !message.ui_seen; - db.message().updateMessage(message); - EntityOperation.queue(getContext(), message, EntityOperation.SEEN, message.ui_seen); + try { + DB db = DB.getInstance(getContext()); + EntityMessage message = db.message().getMessage(id); + message.ui_seen = !message.ui_seen; + db.message().updateMessage(message); + EntityOperation.queue(getContext(), message, EntityOperation.SEEN, message.ui_seen); + } catch (Throwable ex) { + Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); + } } }); } @@ -259,12 +264,16 @@ public class FragmentMessage extends Fragment { executor.submit(new Runnable() { @Override public void run() { - DB db = DB.getInstance(getContext()); - EntityMessage message = db.message().getMessage(id); - message.ui_hide = true; - db.message().updateMessage(message); - - EntityOperation.queue(getContext(), message, EntityOperation.DELETE); + try { + DB db = DB.getInstance(getContext()); + EntityMessage message = db.message().getMessage(id); + message.ui_hide = true; + db.message().updateMessage(message); + + EntityOperation.queue(getContext(), message, EntityOperation.DELETE); + } catch (Throwable ex) { + Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); + } } }); } @@ -282,18 +291,22 @@ public class FragmentMessage extends Fragment { executor.submit(new Runnable() { @Override public void run() { - DB db = DB.getInstance(getContext()); - EntityMessage message = db.message().getMessage(id); - EntityFolder spam = db.folder().getSpamFolder(message.account); - if (spam == null) { - Toast.makeText(getContext(), R.string.title_no_spam, Toast.LENGTH_LONG).show(); - return; + try { + DB db = DB.getInstance(getContext()); + EntityMessage message = db.message().getMessage(id); + EntityFolder spam = db.folder().getSpamFolder(message.account); + if (spam == null) { + Toast.makeText(getContext(), R.string.title_no_spam, Toast.LENGTH_LONG).show(); + return; + } + + message.ui_hide = true; + db.message().updateMessage(message); + + EntityOperation.queue(getContext(), message, EntityOperation.MOVE, spam.id); + } catch (Throwable ex) { + Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); } - - message.ui_hide = true; - db.message().updateMessage(message); - - EntityOperation.queue(getContext(), message, EntityOperation.MOVE, spam.id); } }); } @@ -305,18 +318,22 @@ public class FragmentMessage extends Fragment { executor.submit(new Runnable() { @Override public void run() { - DB db = DB.getInstance(getContext()); - EntityMessage message = db.message().getMessage(id); - EntityFolder archive = db.folder().getArchiveFolder(message.account); - if (archive == null) { - Toast.makeText(getContext(), R.string.title_no_archive, Toast.LENGTH_LONG).show(); - return; - } + try { + DB db = DB.getInstance(getContext()); + EntityMessage message = db.message().getMessage(id); + EntityFolder archive = db.folder().getArchiveFolder(message.account); + if (archive == null) { + Toast.makeText(getContext(), R.string.title_no_archive, Toast.LENGTH_LONG).show(); + return; + } - message.ui_hide = true; - db.message().updateMessage(message); + message.ui_hide = true; + db.message().updateMessage(message); - EntityOperation.queue(getContext(), message, EntityOperation.MOVE, archive.id); + EntityOperation.queue(getContext(), message, EntityOperation.MOVE, archive.id); + } catch (Throwable ex) { + Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); + } } }); }