Retry browsing

pull/177/head
M66B 5 years ago
parent 38e81a3c3c
commit 305b205a98

@ -139,7 +139,19 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} }
}); });
if (server) if (server)
fetched = load_server(state); try {
fetched = load_server(state);
} catch (Throwable ex) {
if (state.error || ex instanceof IllegalArgumentException)
throw ex;
Log.w("Boundary", ex);
close();
state.reset();
// Retry
fetched = load_server(state);
}
else else
fetched = load_device(state); fetched = load_device(state);
} catch (final Throwable ex) { } catch (final Throwable ex) {
@ -552,7 +564,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
return found; return found;
} }
void close() { void destroy() {
final State state = this.state; final State state = this.state;
this.state = new State(); this.state = new State();
state.destroyed = true; state.destroyed = true;
@ -560,23 +572,27 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
Log.i("Boundary close"); close();
try {
if (state.ifolder != null)
state.ifolder.close();
} catch (Throwable ex) {
Log.e("Boundary", ex);
}
try {
if (state.iservice != null)
state.iservice.close();
} catch (Throwable ex) {
Log.e("Boundary", ex);
}
} }
}); });
} }
void close() {
Log.i("Boundary close");
try {
if (state.ifolder != null)
state.ifolder.close();
} catch (Throwable ex) {
Log.e("Boundary", ex);
}
try {
if (state.iservice != null)
state.iservice.close();
} catch (Throwable ex) {
Log.e("Boundary", ex);
}
}
private class State { private class State {
boolean destroyed = false; boolean destroyed = false;
boolean error = false; boolean error = false;
@ -588,5 +604,17 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
EmailService iservice = null; EmailService iservice = null;
IMAPFolder ifolder = null; IMAPFolder ifolder = null;
Message[] imessages = null; Message[] imessages = null;
void reset() {
destroyed = false;
error = false;
index = 0;
offset = 0;
ids = null;
matches = null;
iservice = null;
ifolder = null;
imessages = null;
}
} }
} }

@ -417,7 +417,7 @@ public class ViewModelMessages extends ViewModel {
owner.getLifecycle().addObserver(new LifecycleObserver() { owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() { public void onDestroyed() {
boundary.close(); boundary.destroy();
} }
}); });
} }

Loading…
Cancel
Save