Browse Source

Refactoring

main
M66B 6 years ago
parent
commit
519580532a
1 changed files with 45 additions and 42 deletions
  1. +45
    -42
      app/src/main/java/eu/faircode/email/AdapterMessage.java

+ 45
- 42
app/src/main/java/eu/faircode/email/AdapterMessage.java View File

@ -544,48 +544,8 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
expanded.put(message.id, !expanded.get(message.id));
notifyItemChanged(pos);
if (expanded.get(message.id)) {
Bundle args = new Bundle();
args.putLong("id", message.id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
EntityFolder folder = db.folder().getFolder(message.folder);
if (!EntityFolder.OUTBOX.equals(folder.type)) {
if (!message.content)
EntityOperation.queue(db, message, EntityOperation.BODY);
if (!message.ui_seen) {
db.message().setMessageUiSeen(message.id, true);
EntityOperation.queue(db, message, EntityOperation.SEEN, true);
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
EntityOperation.process(context);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, ex);
}
}.load(context, owner, args);
}
if (expanded.get(message.id))
handleExpand(message.id);
}
private SimpleTask<Spanned> bodyTask = new SimpleTask<Spanned>() {
@ -1317,6 +1277,49 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
this.debug = prefs.getBoolean("debug", false);
}
private void handleExpand(long id) {
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
EntityFolder folder = db.folder().getFolder(message.folder);
if (!EntityFolder.OUTBOX.equals(folder.type)) {
if (!message.content)
EntityOperation.queue(db, message, EntityOperation.BODY);
if (!message.ui_seen) {
db.message().setMessageUiSeen(message.id, true);
EntityOperation.queue(db, message, EntityOperation.SEEN, true);
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
EntityOperation.process(context);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, ex);
}
}.load(context, owner, args);
}
private static final DiffUtil.ItemCallback<TupleMessageEx> DIFF_CALLBACK =
new DiffUtil.ItemCallback<TupleMessageEx>() {
@Override


Loading…
Cancel
Save