Account for fetched to display messages

This commit is contained in:
M66B
2019-01-27 08:15:25 +00:00
parent c29adbd894
commit efaa964a85
3 changed files with 25 additions and 19 deletions

View File

@@ -83,13 +83,14 @@ public class ViewModelBrowse extends ViewModel {
currentState.error = false;
}
void load() throws MessagingException, IOException {
int load() throws MessagingException, IOException {
final State state = currentState;
if (state == null || state.error)
return;
return 0;
DB db = DB.getInstance(state.context);
int local = 0;
if (state.search != null)
try {
db.beginTransaction();
@@ -99,8 +100,7 @@ public class ViewModelBrowse extends ViewModel {
Log.i("Messages=" + state.messages.size());
}
int matched = 0;
for (int i = state.local; i < state.messages.size() && matched < state.pageSize; i++) {
for (int i = state.local; i < state.messages.size() && local < state.pageSize; i++) {
state.local = i + 1;
boolean match = false;
@@ -128,24 +128,26 @@ public class ViewModelBrowse extends ViewModel {
if (!match && message.content)
match = body.toLowerCase().contains(find);
if (match)
if (match) {
local++;
db.message().setMessageFound(message.account, message.thread);
}
}
db.setTransactionSuccessful();
if (++matched >= state.pageSize)
return;
if (local == state.pageSize)
return local;
} finally {
db.endTransaction();
}
if (state.fid == null)
return;
return local;
final EntityFolder folder = db.folder().getBrowsableFolder(state.fid, state.search != null);
if (folder == null)
return;
return local;
if (state.imessages == null) {
EntityAccount account = db.account().getAccount(folder.account);
@@ -261,12 +263,12 @@ public class ViewModelBrowse extends ViewModel {
}
}
int count = 0;
while (state.index >= 0 && count < state.pageSize && currentState != null) {
int remote = 0;
while (state.index >= 0 && remote < state.pageSize && currentState != null) {
Log.i("Boundary index=" + state.index);
int from = Math.max(0, state.index - (state.pageSize - count) + 1);
int from = Math.max(0, state.index - (state.pageSize - remote) + 1);
Message[] isub = Arrays.copyOfRange(state.imessages, from, state.index + 1);
state.index -= (state.pageSize - count);
state.index -= (state.pageSize - remote);
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
@@ -291,7 +293,7 @@ public class ViewModelBrowse extends ViewModel {
folder, state.ifolder, (IMAPMessage) isub[j],
true,
new ArrayList<EntityRule>());
count++;
remote++;
}
db.message().setMessageFound(message.account, message.thread);
} catch (MessageRemovedException ex) {
@@ -319,6 +321,7 @@ public class ViewModelBrowse extends ViewModel {
}
Log.i("Boundary done");
return local + remote;
}
void clear() {