|
|
|
@ -119,20 +119,20 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
|
@Override
|
|
|
|
|
public void onZeroItemsLoaded() {
|
|
|
|
|
Log.i("Boundary zero loaded");
|
|
|
|
|
queue_load(state, null);
|
|
|
|
|
queue_load(state, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemAtEndLoaded(@NonNull final TupleMessageEx itemAtEnd) {
|
|
|
|
|
Long id = (itemAtEnd == null ? null : itemAtEnd.id); // fall-safe
|
|
|
|
|
Log.i("Boundary at end=" + itemAtEnd.id +
|
|
|
|
|
" received=" + new Date(itemAtEnd.received));
|
|
|
|
|
|
|
|
|
|
if (state.end != null && state.end.equals(id)) {
|
|
|
|
|
Log.i("Boundary at same end=" + id);
|
|
|
|
|
if (state.end != null && state.end.equals(itemAtEnd.id)) {
|
|
|
|
|
Log.i("Boundary at same end=" + itemAtEnd.id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.i("Boundary at end=" + id);
|
|
|
|
|
queue_load(state, id);
|
|
|
|
|
queue_load(state, itemAtEnd.id, itemAtEnd.received);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void retry() {
|
|
|
|
@ -142,10 +142,10 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
|
close(state, true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
queue_load(state, null);
|
|
|
|
|
queue_load(state, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void queue_load(final State state, Long end) {
|
|
|
|
|
private void queue_load(final State state, Long end, Long after) {
|
|
|
|
|
state.end = end;
|
|
|
|
|
|
|
|
|
|
executor.submit(new Runnable() {
|
|
|
|
@ -179,7 +179,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
|
});
|
|
|
|
|
if (server)
|
|
|
|
|
try {
|
|
|
|
|
found = load_server(state);
|
|
|
|
|
found = load_server(state, after);
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
if (state.error || ex instanceof IllegalArgumentException)
|
|
|
|
|
throw ex;
|
|
|
|
@ -188,7 +188,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
|
close(state, true);
|
|
|
|
|
|
|
|
|
|
// Retry
|
|
|
|
|
found = load_server(state);
|
|
|
|
|
found = load_server(state, after);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
found = load_device(state);
|
|
|
|
@ -340,7 +340,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int load_server(final State state) throws MessagingException, IOException {
|
|
|
|
|
private int load_server(final State state, Long after) throws MessagingException, IOException {
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
@ -488,12 +488,22 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
|
List<EntityRule> rules = db.rule().getEnabledRules(browsable.id);
|
|
|
|
|
|
|
|
|
|
int found = 0;
|
|
|
|
|
while (state.index >= 0 && found < pageSize && !state.destroyed) {
|
|
|
|
|
Log.i("Boundary server index=" + state.index);
|
|
|
|
|
int from = Math.max(0, state.index - (pageSize - found) + 1);
|
|
|
|
|
Long last = null;
|
|
|
|
|
while (state.index >= 0 && !state.destroyed &&
|
|
|
|
|
(found < pageSize ||
|
|
|
|
|
(after != null && last != null && after < last))) {
|
|
|
|
|
Log.i("Boundary server index=" + state.index +
|
|
|
|
|
" found=" + found + "/" + pageSize +
|
|
|
|
|
" after=" + new Date(after == null ? 0 : after) +
|
|
|
|
|
"/" + new Date(last == null ? 0 : last));
|
|
|
|
|
int count = (pageSize - found);
|
|
|
|
|
if (count <= 0)
|
|
|
|
|
count = pageSize;
|
|
|
|
|
int from = Math.max(0, state.index - count + 1);
|
|
|
|
|
Log.i("Boundary " + from + "..." + state.index + " count=" + (state.index - from + 1));
|
|
|
|
|
Message[] isub = Arrays.copyOfRange(state.imessages, from, state.index + 1);
|
|
|
|
|
Arrays.fill(state.imessages, from, state.index + 1, null);
|
|
|
|
|
state.index -= (pageSize - found);
|
|
|
|
|
state.index -= count;
|
|
|
|
|
|
|
|
|
|
FetchProfile fp0 = new FetchProfile();
|
|
|
|
|
fp0.add(UIDFolder.FetchProfileItem.UID);
|
|
|
|
@ -532,7 +542,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core.State astate = new Core.State(ConnectionHelper.getNetworkState(context));
|
|
|
|
|
for (int j = isub.length - 1; j >= 0 && found < pageSize && !state.destroyed && astate.isRecoverable(); j--)
|
|
|
|
|
for (int j = isub.length - 1; j >= 0 && !state.destroyed && astate.isRecoverable(); j--)
|
|
|
|
|
try {
|
|
|
|
|
long uid = state.ifolder.getUID(isub[j]);
|
|
|
|
|
Log.i("Boundary server sync uid=" + uid);
|
|
|
|
@ -543,10 +553,16 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
|
(IMAPStore) state.iservice.getStore(), state.ifolder, (MimeMessage) isub[j],
|
|
|
|
|
true, true,
|
|
|
|
|
rules, astate, null);
|
|
|
|
|
found++;
|
|
|
|
|
}
|
|
|
|
|
if (message != null && criteria != null /* browsed */)
|
|
|
|
|
if (message != null) {
|
|
|
|
|
found++;
|
|
|
|
|
last = message.received;
|
|
|
|
|
if (criteria != null /* browsed */)
|
|
|
|
|
db.message().setMessageFound(message.id);
|
|
|
|
|
Log.i("Boundary server synced id=" + message.id +
|
|
|
|
|
" received=" + new Date(message.received) +
|
|
|
|
|
" found=" + found);
|
|
|
|
|
}
|
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
|
|
Log.w(browsable.name + " boundary server", ex);
|
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
|
@ -571,7 +587,13 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
|
close(state, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.i("Boundary server done memory=" + Log.getFreeMemMb());
|
|
|
|
|
Log.i("Boundary server done" +
|
|
|
|
|
" index=" + state.index +
|
|
|
|
|
" found=" + found + "/" + pageSize +
|
|
|
|
|
" after=" + new Date(after == null ? 0 : after) +
|
|
|
|
|
"/" + new Date(last == null ? 0 : last) +
|
|
|
|
|
" memory=" + Log.getFreeMemMb());
|
|
|
|
|
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|