Browse Source

Catch exceptions

main
M66B 6 years ago
parent
commit
7feac257d1
3 changed files with 132 additions and 104 deletions
  1. +19
    -15
      app/src/main/java/eu/faircode/email/AdapterMessage.java
  2. +64
    -57
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  3. +49
    -32
      app/src/main/java/eu/faircode/email/FragmentMessage.java

+ 19
- 15
app/src/main/java/eu/faircode/email/AdapterMessage.java View File

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


+ 64
- 57
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -257,63 +257,66 @@ public class FragmentCompose extends Fragment {
@Nullable
@Override
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();
result.putString("action", action);
if (msg != null) {
if (msg.identity != null)
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);
}
try {
String action = args.getString("action");
long id = args.getLong("id", -1);
EntityMessage msg = DB.getInstance(getContext()).message().getMessage(id);
result.putString("action", action);
if (TextUtils.isEmpty(action)) {
if (msg != null) {
result.putString("from", msg.from);
result.putString("to", msg.to);
if (msg.identity != null)
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 (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));
if (TextUtils.isEmpty(action)) {
if (msg != null) {
result.putString("from", msg.from);
result.putString("to", msg.to);
}
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<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));
} 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<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);
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;
}
}


+ 49
- 32
app/src/main/java/eu/faircode/email/FragmentMessage.java View File

@ -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));
}
}
});
}


Loading…
Cancel
Save