Catch exceptions

pull/12/head
M66B 7 years ago
parent 8c1ad78caf
commit 7feac257d1

@ -86,22 +86,26 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
if (EntityFolder.TYPE_DRAFTS.equals(message.folderType)) try {
context.startActivity( if (EntityFolder.TYPE_DRAFTS.equals(message.folderType))
new Intent(context, ActivityCompose.class) context.startActivity(
.putExtra("id", message.id)); new Intent(context, ActivityCompose.class)
else { .putExtra("id", message.id));
if (!message.seen && !message.ui_seen) { else {
message.ui_seen = !message.ui_seen; if (!message.seen && !message.ui_seen) {
DB.getInstance(context).message().updateMessage(message); message.ui_seen = !message.ui_seen;
EntityOperation.queue(context, message, EntityOperation.SEEN, message.ui_seen); DB.getInstance(context).message().updateMessage(message);
EntityOperation.queue(context, message, EntityOperation.SEEN, message.ui_seen);
}
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGE)
.putExtra("folder", message.folder)
.putExtra("id", message.id));
} }
} catch (Throwable ex) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGE)
.putExtra("folder", message.folder)
.putExtra("id", message.id));
} }
} }
}); });

@ -257,63 +257,66 @@ public class FragmentCompose extends Fragment {
@Nullable @Nullable
@Override @Override
public Bundle loadInBackground() { public Bundle loadInBackground() {
String action = args.getString("action");
long id = args.getLong("id", -1);
EntityMessage msg = DB.getInstance(getContext()).message().getMessage(id);
Bundle result = new Bundle(); Bundle result = new Bundle();
result.putString("action", action); try {
String action = args.getString("action");
if (msg != null) { long id = args.getLong("id", -1);
if (msg.identity != null) EntityMessage msg = DB.getInstance(getContext()).message().getMessage(id);
result.putLong("iid", msg.identity);
if (msg.replying != null) result.putString("action", action);
result.putLong("rid", msg.replying);
result.putString("thread", msg.thread);
result.putString("subject", msg.subject);
result.putString("body", msg.body);
}
if (TextUtils.isEmpty(action)) {
if (msg != null) { if (msg != null) {
result.putString("from", msg.from); if (msg.identity != null)
result.putString("to", msg.to); result.putLong("iid", msg.identity);
if (msg.replying != null)
result.putLong("rid", msg.replying);
result.putString("thread", msg.thread);
result.putString("subject", msg.subject);
result.putString("body", msg.body);
} }
} else if ("reply".equals(action)) {
String to = null; if (TextUtils.isEmpty(action)) {
if (msg != null) if (msg != null) {
try { result.putString("from", msg.from);
Address[] reply = MessageHelper.decodeAddresses(msg.reply); result.putString("to", msg.to);
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); } else if ("reply".equals(action)) {
result.putString("from", msg.to); String to = null;
result.putString("to", to); if (msg != null)
} else if ("reply_all".equals(action)) { try {
String to = null; Address[] reply = MessageHelper.decodeAddresses(msg.reply);
if (msg != null) { to = (reply.length == 0 ? msg.from : msg.reply);
try { } catch (Throwable ex) {
Address[] from = MessageHelper.decodeAddresses(msg.from); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
Address[] reply = MessageHelper.decodeAddresses(msg.reply); }
Address[] cc = MessageHelper.decodeAddresses(msg.cc); result.putLong("rid", msg.id);
List<Address> addresses = new ArrayList<>(); result.putString("from", msg.to);
addresses.addAll(Arrays.asList(reply.length == 0 ? from : reply)); result.putString("to", to);
addresses.addAll(Arrays.asList(cc)); } else if ("reply_all".equals(action)) {
to = MessageHelper.encodeAddresses(addresses.toArray(new Address[0])); String to = null;
} catch (Throwable ex) { if (msg != null) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); try {
Address[] from = MessageHelper.decodeAddresses(msg.from);
Address[] reply = MessageHelper.decodeAddresses(msg.reply);
Address[] cc = MessageHelper.decodeAddresses(msg.cc);
List<Address> 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); } catch (Throwable ex) {
result.putString("from", msg.to); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
result.putString("to", to);
} else if ("forward".equals(action)) {
result.putString("from", msg.to);
result.putString("to", null);
} }
return result; return result;
} }
} }
@ -405,15 +408,19 @@ public class FragmentCompose extends Fragment {
@Override @Override
public Throwable loadInBackground() { public Throwable loadInBackground() {
long id = args.getLong("id"); try {
DaoMessage message = DB.getInstance(getContext()).message(); long id = args.getLong("id");
EntityMessage draft = message.getMessage(id); DaoMessage message = DB.getInstance(getContext()).message();
if (draft != null) { EntityMessage draft = message.getMessage(id);
draft.ui_hide = true; if (draft != null) {
message.updateMessage(draft); draft.ui_hide = true;
EntityOperation.queue(getContext(), draft, EntityOperation.DELETE); message.updateMessage(draft);
EntityOperation.queue(getContext(), draft, EntityOperation.DELETE);
}
return null;
} catch (Throwable ex) {
return ex;
} }
return null;
} }
} }

@ -35,6 +35,7 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -213,11 +214,15 @@ public class FragmentMessage extends Fragment {
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
DB db = DB.getInstance(getContext()); try {
EntityMessage message = db.message().getMessage(id); DB db = DB.getInstance(getContext());
message.ui_seen = !message.ui_seen; EntityMessage message = db.message().getMessage(id);
db.message().updateMessage(message); message.ui_seen = !message.ui_seen;
EntityOperation.queue(getContext(), message, EntityOperation.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() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
DB db = DB.getInstance(getContext()); try {
EntityMessage message = db.message().getMessage(id); DB db = DB.getInstance(getContext());
message.ui_hide = true; EntityMessage message = db.message().getMessage(id);
db.message().updateMessage(message); message.ui_hide = true;
db.message().updateMessage(message);
EntityOperation.queue(getContext(), message, EntityOperation.DELETE);
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() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
DB db = DB.getInstance(getContext()); try {
EntityMessage message = db.message().getMessage(id); DB db = DB.getInstance(getContext());
EntityFolder spam = db.folder().getSpamFolder(message.account); EntityMessage message = db.message().getMessage(id);
if (spam == null) { EntityFolder spam = db.folder().getSpamFolder(message.account);
Toast.makeText(getContext(), R.string.title_no_spam, Toast.LENGTH_LONG).show(); if (spam == null) {
return; 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() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
DB db = DB.getInstance(getContext()); try {
EntityMessage message = db.message().getMessage(id); DB db = DB.getInstance(getContext());
EntityFolder archive = db.folder().getArchiveFolder(message.account); EntityMessage message = db.message().getMessage(id);
if (archive == null) { EntityFolder archive = db.folder().getArchiveFolder(message.account);
Toast.makeText(getContext(), R.string.title_no_archive, Toast.LENGTH_LONG).show(); if (archive == null) {
return; Toast.makeText(getContext(), R.string.title_no_archive, Toast.LENGTH_LONG).show();
} return;
}
message.ui_hide = true; message.ui_hide = true;
db.message().updateMessage(message); 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));
}
} }
}); });
} }

Loading…
Cancel
Save