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

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

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

Loading…
Cancel
Save