use of com.octo.android.robospice.request.listener.RequestProgress in project robospice by stephanenicolas.
the class SpiceRequest method setStatus.
/* package private */
void setStatus(final RequestStatus status) {
this.progress = new RequestProgress(status);
publishProgress();
}
use of com.octo.android.robospice.request.listener.RequestProgress in project robospice by stephanenicolas.
the class SpiceManagerTest method test_should_receive_request_progress_updates_in_right_order.
public void test_should_receive_request_progress_updates_in_right_order() throws InterruptedException {
// TDD test for issue 36
// given
spiceManager.start(getContext());
SpiceRequestStub<String> spiceRequestStub = new SpiceRequestSucceedingStub<String>(TEST_CLASS, TEST_RETURNED_DATA);
RequestListenerWithProgressHistoryStub<String> requestListenerStub = new RequestListenerWithProgressHistoryStub<String>();
// when
spiceManager.execute(spiceRequestStub, TEST_CACHE_KEY, TEST_DURATION, requestListenerStub);
requestListenerStub.awaitComplete(REQUEST_COMPLETION_TIME_OUT);
requestListenerStub.await(REQUEST_COMPLETION_TIME_OUT);
// test
assertTrue(requestListenerStub.isComplete());
final int expectedRequestProgressCount = 4;
synchronized (requestListenerStub.getRequestProgressesHistory()) {
for (RequestProgress requestProgress : requestListenerStub.getRequestProgressesHistory()) {
Ln.d("RequestProgress received : %s", requestProgress.getStatus());
}
}
int progressStatusIndex = 0;
assertEquals(RequestStatus.PENDING, requestListenerStub.getRequestProgressesHistory().get(progressStatusIndex++).getStatus());
assertEquals(RequestStatus.LOADING_FROM_NETWORK, requestListenerStub.getRequestProgressesHistory().get(progressStatusIndex++).getStatus());
assertEquals(RequestStatus.WRITING_TO_CACHE, requestListenerStub.getRequestProgressesHistory().get(progressStatusIndex++).getStatus());
assertEquals(RequestStatus.COMPLETE, requestListenerStub.getRequestProgressesHistory().get(progressStatusIndex++).getStatus());
assertEquals(expectedRequestProgressCount, requestListenerStub.getRequestProgressesHistory().size());
assertTrue(requestListenerStub.isSuccessful());
}
use of com.octo.android.robospice.request.listener.RequestProgress in project robospice by stephanenicolas.
the class RequestProgressManager method notifyListenersOfRequestProgress.
protected <T> void notifyListenersOfRequestProgress(final CachedSpiceRequest<?> request, final Set<RequestListener<?>> listeners, final RequestStatus status) {
notifyListenersOfRequestProgress(request, listeners, new RequestProgress(status));
checkAllRequestComplete();
}
use of com.octo.android.robospice.request.listener.RequestProgress in project robospice by stephanenicolas.
the class RequestProgressManager method createProgressListener.
public <T> RequestProgressListener createProgressListener(final CachedSpiceRequest<T> request) {
// add a progress listener to the request to be notified of
// progress during load data from network
final RequestProgressListener requestProgressListener = new RequestProgressListener() {
@Override
public void onRequestProgressUpdate(final RequestProgress progress) {
final Set<RequestListener<?>> listeners = mapRequestToRequestListener.get(request);
notifyListenersOfRequestProgress(request, listeners, progress);
}
};
return requestProgressListener;
}
Aggregations