Search in sources :

Example 1 with RequestProgress

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();
}
Also used : RequestProgress(com.octo.android.robospice.request.listener.RequestProgress)

Example 2 with RequestProgress

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());
}
Also used : RequestListenerWithProgressHistoryStub(com.octo.android.robospice.stub.RequestListenerWithProgressHistoryStub) RequestProgress(com.octo.android.robospice.request.listener.RequestProgress) SpiceRequestSucceedingStub(com.octo.android.robospice.stub.SpiceRequestSucceedingStub)

Example 3 with RequestProgress

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();
}
Also used : RequestProgress(com.octo.android.robospice.request.listener.RequestProgress)

Example 4 with RequestProgress

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;
}
Also used : RequestProgressListener(com.octo.android.robospice.request.listener.RequestProgressListener) RequestListener(com.octo.android.robospice.request.listener.RequestListener) RequestProgress(com.octo.android.robospice.request.listener.RequestProgress)

Aggregations

RequestProgress (com.octo.android.robospice.request.listener.RequestProgress)4 RequestListener (com.octo.android.robospice.request.listener.RequestListener)1 RequestProgressListener (com.octo.android.robospice.request.listener.RequestProgressListener)1 RequestListenerWithProgressHistoryStub (com.octo.android.robospice.stub.RequestListenerWithProgressHistoryStub)1 SpiceRequestSucceedingStub (com.octo.android.robospice.stub.SpiceRequestSucceedingStub)1