Refactoring

This commit is contained in:
M66B 2018-10-16 10:48:37 +00:00
parent 18db93b632
commit 519580532a
1 changed files with 45 additions and 42 deletions

View File

@ -544,48 +544,8 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
expanded.put(message.id, !expanded.get(message.id)); expanded.put(message.id, !expanded.get(message.id));
notifyItemChanged(pos); notifyItemChanged(pos);
if (expanded.get(message.id)) { if (expanded.get(message.id))
Bundle args = new Bundle(); handleExpand(message.id);
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);
}
} }
private SimpleTask<Spanned> bodyTask = new SimpleTask<Spanned>() { private SimpleTask<Spanned> bodyTask = new SimpleTask<Spanned>() {
@ -1317,6 +1277,49 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
this.debug = prefs.getBoolean("debug", false); 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 = private static final DiffUtil.ItemCallback<TupleMessageEx> DIFF_CALLBACK =
new DiffUtil.ItemCallback<TupleMessageEx>() { new DiffUtil.ItemCallback<TupleMessageEx>() {
@Override @Override