use of com.bumptech.glide.load.model.GlideUrl in project glide by bumptech.
the class BaseGlideUrlLoader method buildLoadData.
@Override
@Nullable
public LoadData<InputStream> buildLoadData(Model model, int width, int height, Options options) {
GlideUrl result = null;
if (modelCache != null) {
result = modelCache.get(model, width, height);
}
if (result == null) {
String stringURL = getUrl(model, width, height, options);
if (TextUtils.isEmpty(stringURL)) {
return null;
}
result = new GlideUrl(stringURL, getHeaders(model, width, height, options));
if (modelCache != null) {
modelCache.put(model, width, height, result);
}
}
// TODO: this is expensive and slow to calculate every time, we should either cache these, or
// try to come up with a way to avoid finding them when not necessary.
List<String> alternateUrls = getAlternateUrls(model, width, height, options);
LoadData<InputStream> concreteLoaderData = concreteLoader.buildLoadData(result, width, height, options);
if (alternateUrls.isEmpty()) {
return concreteLoaderData;
} else {
return new LoadData<>(concreteLoaderData.sourceKey, getAlternateKeys(alternateUrls), concreteLoaderData.fetcher);
}
}
use of com.bumptech.glide.load.model.GlideUrl in project glide by bumptech.
the class BaseGlideUrlLoaderTest method testBuildsNewUrlIfNotPresentInCache.
@Test
public void testBuildsNewUrlIfNotPresentInCache() {
int width = 10;
int height = 11;
urlLoader.resultUrl = "fakeUrl";
when(wrapped.buildLoadData(any(GlideUrl.class), eq(width), eq(height), eq(options))).thenAnswer(new Answer<ModelLoader.LoadData<InputStream>>() {
@Override
public ModelLoader.LoadData<InputStream> answer(InvocationOnMock invocationOnMock) throws Throwable {
GlideUrl glideUrl = (GlideUrl) invocationOnMock.getArguments()[0];
assertEquals(urlLoader.resultUrl, glideUrl.toStringUrl());
return new ModelLoader.LoadData<>(mock(Key.class), fetcher);
}
});
assertEquals(fetcher, urlLoader.buildLoadData(new GlideUrl(urlLoader.resultUrl), width, height, options).fetcher);
}
use of com.bumptech.glide.load.model.GlideUrl in project glide by bumptech.
the class HttpUriLoaderTest method testHandlesHttpsUris.
@Test
public void testHandlesHttpsUris() throws MalformedURLException {
Uri httpsUri = Uri.parse("https://www.google.com");
loader.buildLoadData(httpsUri, IMAGE_SIDE, IMAGE_SIDE, OPTIONS);
assertTrue(loader.handles(httpsUri));
verify(urlLoader).buildLoadData(eq(new GlideUrl(httpsUri.toString())), eq(IMAGE_SIDE), eq(IMAGE_SIDE), eq(OPTIONS));
}
use of com.bumptech.glide.load.model.GlideUrl in project glide by bumptech.
the class HttpUriLoaderTest method testHandlesHttpUris.
@Test
public void testHandlesHttpUris() throws MalformedURLException {
Uri httpUri = Uri.parse("http://www.google.com");
loader.buildLoadData(httpUri, IMAGE_SIDE, IMAGE_SIDE, OPTIONS);
assertTrue(loader.handles(httpUri));
verify(urlLoader).buildLoadData(eq(new GlideUrl(httpUri.toString())), eq(IMAGE_SIDE), eq(IMAGE_SIDE), eq(OPTIONS));
}
use of com.bumptech.glide.load.model.GlideUrl in project glide by bumptech.
the class BaseGlideUrlLoaderTest method testReturnsUrlFromCacheIfPresent.
@Test
public void testReturnsUrlFromCacheIfPresent() {
Object model = new Object();
int width = 100;
int height = 200;
GlideUrl expectedUrl = mock(GlideUrl.class);
when(modelCache.get(eq(model), eq(width), eq(height))).thenReturn(expectedUrl);
when(wrapped.buildLoadData(eq(expectedUrl), eq(width), eq(height), eq(options))).thenReturn(new ModelLoader.LoadData<>(mock(Key.class), fetcher));
assertEquals(fetcher, urlLoader.buildLoadData(model, width, height, options).fetcher);
}
Aggregations