Account for fetched to display messages

pull/147/head
M66B 6 years ago
parent c29adbd894
commit efaa964a85

@ -39,7 +39,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
interface IBoundaryCallbackMessages {
void onLoading();
void onLoaded();
void onLoaded(int fetched);
void onError(Throwable ex);
}
@ -78,19 +78,22 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
private void load() {
executor.submit(new Runnable() {
private int fetched;
@Override
public void run() {
if (model == null)
return;
try {
fetched = 0;
handler.post(new Runnable() {
@Override
public void run() {
intf.onLoading();
}
});
model.load();
fetched = model.load();
} catch (final Throwable ex) {
Log.e("Boundary", ex);
handler.post(new Runnable() {
@ -103,7 +106,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
handler.post(new Runnable() {
@Override
public void run() {
intf.onLoaded();
intf.onLoaded(fetched);
}
});
}

@ -1748,10 +1748,10 @@ public class FragmentMessages extends FragmentBase {
}
@Override
public void onLoaded() {
public void onLoaded(int fetched) {
RecyclerView.Adapter adapter = rvMessage.getAdapter();
int items = (adapter == null ? 0 : adapter.getItemCount());
tvNoEmail.setVisibility(items == 0 ? View.VISIBLE : View.GONE);
tvNoEmail.setVisibility(items + fetched == 0 ? View.VISIBLE : View.GONE);
pbWait.setVisibility(View.GONE);
}

@ -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() {

Loading…
Cancel
Save