Search in sources :

Example 1 with GlideUrl

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);
    }
}
Also used : InputStream(java.io.InputStream) GlideUrl(com.bumptech.glide.load.model.GlideUrl) Nullable(android.support.annotation.Nullable)

Example 2 with GlideUrl

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);
}
Also used : ModelLoader(com.bumptech.glide.load.model.ModelLoader) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GlideUrl(com.bumptech.glide.load.model.GlideUrl) Test(org.junit.Test)

Example 3 with GlideUrl

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));
}
Also used : GlideUrl(com.bumptech.glide.load.model.GlideUrl) Uri(android.net.Uri) Test(org.junit.Test)

Example 4 with GlideUrl

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));
}
Also used : GlideUrl(com.bumptech.glide.load.model.GlideUrl) Uri(android.net.Uri) Test(org.junit.Test)

Example 5 with GlideUrl

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);
}
Also used : ModelLoader(com.bumptech.glide.load.model.ModelLoader) GlideUrl(com.bumptech.glide.load.model.GlideUrl) Test(org.junit.Test)

Aggregations

GlideUrl (com.bumptech.glide.load.model.GlideUrl)8 Test (org.junit.Test)5 Uri (android.net.Uri)3 ModelLoader (com.bumptech.glide.load.model.ModelLoader)2 InputStream (java.io.InputStream)2 Nullable (android.support.annotation.Nullable)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 HttpUrlFetcher (com.bumptech.glide.load.data.HttpUrlFetcher)1 VideoLoadMvpView (com.yiw.circledemo.widgets.videolist.model.VideoLoadMvpView)1 VideoLoadTarget (com.yiw.circledemo.widgets.videolist.target.VideoLoadTarget)1 VideoProgressTarget (com.yiw.circledemo.widgets.videolist.target.VideoProgressTarget)1 TextureVideoView (com.yiw.circledemo.widgets.videolist.widget.TextureVideoView)1 File (java.io.File)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1