1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-04 06:20:26 +00:00

Boundary fixes/improvements

This commit is contained in:
M66B 2020-04-09 21:19:44 +02:00
parent 2e1eb95d78
commit 1e4f726dd5
2 changed files with 37 additions and 19 deletions

View file

@ -81,11 +81,11 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
private IBoundaryCallbackMessages intf; private IBoundaryCallbackMessages intf;
private Handler handler; private Handler handler;
private ExecutorService executor = Helper.getBackgroundExecutor(1, "boundary");
private State state; private State state;
private static final int SEARCH_LIMIT = 1000; private static final int SEARCH_LIMIT = 1000;
private static ExecutorService executor = Helper.getBackgroundExecutor(1, "boundary");
interface IBoundaryCallbackMessages { interface IBoundaryCallbackMessages {
void onLoading(); void onLoading();
@ -321,28 +321,25 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
int count = state.ifolder.getMessageCount(); int count = state.ifolder.getMessageCount();
db.folder().setFolderTotal(browsable.id, count < 0 ? null : count); db.folder().setFolderTotal(browsable.id, count < 0 ? null : count);
Log.i("Boundary server query=" + criteria.query);
if (criteria == null) { if (criteria == null) {
boolean filter_seen = prefs.getBoolean("filter_seen", false); boolean filter_seen = prefs.getBoolean("filter_seen", false);
boolean filter_unflagged = prefs.getBoolean("filter_unflagged", false); boolean filter_unflagged = prefs.getBoolean("filter_unflagged", false);
Log.i("Boundary filter seen=" + filter_seen + " unflagged=" + filter_unflagged); Log.i("Boundary filter seen=" + filter_seen + " unflagged=" + filter_unflagged);
SearchTerm searchUnseen = null; List<SearchTerm> and = new ArrayList<>();
if (filter_seen && state.ifolder.getPermanentFlags().contains(Flags.Flag.SEEN))
searchUnseen = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
SearchTerm searchFlagged = null; if (filter_seen &&
if (filter_unflagged && state.ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED)) state.ifolder.getPermanentFlags().contains(Flags.Flag.SEEN))
searchFlagged = new FlagTerm(new Flags(Flags.Flag.FLAGGED), true); and.add(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
if (searchUnseen != null && searchFlagged != null) if (filter_unflagged &&
state.imessages = state.ifolder.search(new AndTerm(searchUnseen, searchFlagged)); state.ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED))
else if (searchUnseen != null) and.add(new FlagTerm(new Flags(Flags.Flag.FLAGGED), true));
state.imessages = state.ifolder.search(searchUnseen);
else if (searchFlagged != null) if (and.size() == 0)
state.imessages = state.ifolder.search(searchFlagged);
else
state.imessages = state.ifolder.getMessages(); state.imessages = state.ifolder.getMessages();
else
state.imessages = state.ifolder.search(new AndTerm(and.toArray(new SearchTerm[0])));
} else { } else {
Object result = state.ifolder.doCommand(new IMAPFolder.ProtocolCommand() { Object result = state.ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override @Override
@ -380,7 +377,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
return imessages; return imessages;
} else { } else {
Log.i("Boundary search=" + criteria); Log.i("Boundary server search=" + criteria);
List<SearchTerm> or = new ArrayList<>(); List<SearchTerm> or = new ArrayList<>();
List<SearchTerm> and = new ArrayList<>(); List<SearchTerm> and = new ArrayList<>();
@ -415,9 +412,11 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
or.add(new BodyTerm(search)); or.add(new BodyTerm(search));
} }
if (criteria.with_unseen) if (criteria.with_unseen &&
state.ifolder.getPermanentFlags().contains(Flags.Flag.SEEN))
and.add(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); and.add(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
if (criteria.with_flagged) if (criteria.with_flagged &&
state.ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED))
and.add(new FlagTerm(new Flags(Flags.Flag.FLAGGED), true)); and.add(new FlagTerm(new Flags(Flags.Flag.FLAGGED), true));
SearchTerm term = null; SearchTerm term = null;
@ -581,6 +580,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
Message[] imessages = null; Message[] imessages = null;
void reset() { void reset() {
Log.i("Boundary reset");
destroyed = false; destroyed = false;
error = false; error = false;
index = 0; index = 0;

View file

@ -48,7 +48,25 @@ import java.util.concurrent.ExecutorService;
public class ViewModelMessages extends ViewModel { public class ViewModelMessages extends ViewModel {
private AdapterMessage.ViewType last = AdapterMessage.ViewType.UNIFIED; private AdapterMessage.ViewType last = AdapterMessage.ViewType.UNIFIED;
private Map<AdapterMessage.ViewType, Model> models = new HashMap<>(); private Map<AdapterMessage.ViewType, Model> models = new HashMap<AdapterMessage.ViewType, Model>() {
@Nullable
@Override
public Model put(AdapterMessage.ViewType key, Model value) {
Model existing = this.get(key);
if (existing != null && existing.boundary != null)
existing.boundary.destroy();
return super.put(key, value);
}
@Nullable
@Override
public Model remove(@Nullable Object key) {
Model existing = this.get(key);
if (existing != null && existing.boundary != null)
existing.boundary.destroy();
return super.remove(key);
}
};
private ExecutorService executor = Helper.getBackgroundExecutor(2, "model"); private ExecutorService executor = Helper.getBackgroundExecutor(2, "model");