Browse Source

Auto expand

main
M66B 6 years ago
parent
commit
8a1f1a14a7
2 changed files with 79 additions and 47 deletions
  1. +0
    -45
      app/src/main/java/eu/faircode/email/AdapterMessage.java
  2. +79
    -2
      app/src/main/java/eu/faircode/email/FragmentMessages.java

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

@ -538,8 +538,6 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private void onExpandMessage(int pos, EntityMessage message) {
boolean expanded = !properties.isExpanded(message.id);
properties.setExpanded(message.id, expanded);
if (expanded)
handleExpand(message.id);
notifyItemChanged(pos);
}
@ -1314,49 +1312,6 @@ 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


+ 79
- 2
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -86,6 +86,7 @@ public class FragmentMessages extends FragmentEx {
private AdapterMessage.ViewType viewType;
private LiveData<PagedList<TupleMessageEx>> messages = null;
private boolean autoExpand = true;
private List<Long> expanded = new ArrayList<>();
private List<Long> headers = new ArrayList<>();
private List<Long> images = new ArrayList<>();
@ -178,9 +179,10 @@ public class FragmentMessages extends FragmentEx {
adapter = new AdapterMessage(getContext(), getViewLifecycleOwner(), viewType, new AdapterMessage.IProperties() {
@Override
public void setExpanded(long id, boolean expand) {
if (expand)
if (expand) {
expanded.add(id);
else
handleExpand(id);
} else
expanded.remove(id);
}
@ -797,6 +799,38 @@ public class FragmentMessages extends FragmentEx {
return;
}
if (viewType == AdapterMessage.ViewType.THREAD && autoExpand) {
autoExpand = false;
int count = 0;
int unseen = 0;
TupleMessageEx single = null;
TupleMessageEx see = null;
for (int i = 0; i < messages.size(); i++) {
TupleMessageEx message = messages.get(i);
if (!EntityFolder.ARCHIVE.equals(message.folderType)) {
count++;
single = message;
if (!message.ui_seen) {
unseen++;
see = message;
}
}
}
TupleMessageEx expand = null;
if (count == 1)
expand = single;
else if (unseen == 1)
expand = see;
if (expand != null) {
expanded.add(expand.id);
if (!expand.ui_seen)
handleExpand(expand.id);
}
}
Log.i(Helper.TAG, "Submit messages=" + messages.size());
adapter.submitList(messages);
@ -818,4 +852,47 @@ public class FragmentMessages extends FragmentEx {
});
}
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(getContext(), ex);
}
}.load(this, args);
}
}

Loading…
Cancel
Save