use of com.bumptech.glide.request.ResourceCallback in project glide by bumptech.
the class EngineJob method handleResultOnMainThread.
@Synthetic
void handleResultOnMainThread() {
stateVerifier.throwIfRecycled();
if (isCancelled) {
resource.recycle();
release(false);
return;
} else if (cbs.isEmpty()) {
throw new IllegalStateException("Received a resource without any callbacks to notify");
} else if (hasResource) {
throw new IllegalStateException("Already have resource");
}
engineResource = engineResourceFactory.build(resource, isCacheable);
hasResource = true;
// Hold on to resource for duration of request so we don't recycle it in the middle of
// notifying if it synchronously released by one of the callbacks.
engineResource.acquire();
listener.onEngineJobComplete(key, engineResource);
for (ResourceCallback cb : cbs) {
if (!isInIgnoredCallbacks(cb)) {
engineResource.acquire();
cb.onResourceReady(engineResource, dataSource);
}
}
// Our request is complete, so we can release the resource.
engineResource.release();
release(false);
}
use of com.bumptech.glide.request.ResourceCallback in project glide by bumptech.
the class EngineTest method testCallbackIsAddedToExistingRunnerWithExistingLoad.
@Test
public void testCallbackIsAddedToExistingRunnerWithExistingLoad() {
harness.doLoad();
ResourceCallback newCallback = mock(ResourceCallback.class);
harness.cb = newCallback;
harness.doLoad();
verify(harness.job).addCallback(eq(newCallback));
}
use of com.bumptech.glide.request.ResourceCallback in project glide by bumptech.
the class EngineJobTest method testRemovingCallbackDuringOnExceptionIsIgnoredIfCallbackHasAlreadyBeenCalled.
@Test
public void testRemovingCallbackDuringOnExceptionIsIgnoredIfCallbackHasAlreadyBeenCalled() {
harness = new EngineJobHarness();
final EngineJob<Object> job = harness.getJob();
final ResourceCallback cb = mock(ResourceCallback.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
job.removeCallback(cb);
return null;
}
}).when(cb).onLoadFailed(any(GlideException.class));
GlideException exception = new GlideException("test");
job.addCallback(cb);
job.start(harness.decodeJob);
job.onLoadFailed(exception);
verify(cb, times(1)).onLoadFailed(eq(exception));
}
use of com.bumptech.glide.request.ResourceCallback in project glide by bumptech.
the class EngineJobTest method testNotifiesNewCallbackOfResourceIfCallbackIsAddedDuringOnResourceReady.
@Test
public void testNotifiesNewCallbackOfResourceIfCallbackIsAddedDuringOnResourceReady() {
final EngineJob<Object> job = harness.getJob();
final ResourceCallback existingCallback = mock(ResourceCallback.class);
final ResourceCallback newCallback = mock(ResourceCallback.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
job.addCallback(newCallback);
return null;
}
}).when(existingCallback).onResourceReady(anyResource(), isADataSource());
job.addCallback(existingCallback);
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
verify(newCallback).onResourceReady(eq(harness.engineResource), eq(harness.dataSource));
}
use of com.bumptech.glide.request.ResourceCallback in project glide by bumptech.
the class EngineJobTest method testRemovingCallbackDuringOnResourceReadyPreventsResourceFromBeingAcquiredForCallback.
@Test
public void testRemovingCallbackDuringOnResourceReadyPreventsResourceFromBeingAcquiredForCallback() {
final EngineJob<Object> job = harness.getJob();
final ResourceCallback notYetCalled = mock(ResourceCallback.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
job.removeCallback(notYetCalled);
return null;
}
}).when(harness.cb).onResourceReady(anyResource(), isADataSource());
job.addCallback(notYetCalled);
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
// Once for notifying, once for called.
verify(harness.engineResource, times(2)).acquire();
}
Aggregations