Search in sources :

Example 6 with Key

use of com.bumptech.glide.load.Key in project glide by bumptech.

the class MultiModelLoader method buildLoadData.

@Override
public LoadData<Data> buildLoadData(Model model, int width, int height, Options options) {
    Key sourceKey = null;
    int size = modelLoaders.size();
    List<DataFetcher<Data>> fetchers = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        ModelLoader<Model, Data> modelLoader = modelLoaders.get(i);
        if (modelLoader.handles(model)) {
            LoadData<Data> loadData = modelLoader.buildLoadData(model, width, height, options);
            if (loadData != null) {
                sourceKey = loadData.sourceKey;
                fetchers.add(loadData.fetcher);
            }
        }
    }
    return !fetchers.isEmpty() ? new LoadData<>(sourceKey, new MultiFetcher<>(fetchers, exceptionListPool)) : null;
}
Also used : ArrayList(java.util.ArrayList) DataFetcher(com.bumptech.glide.load.data.DataFetcher) Key(com.bumptech.glide.load.Key)

Example 7 with Key

use of com.bumptech.glide.load.Key in project glide by bumptech.

the class EngineKeyTest method testDiffersIfSignatureDiffers.

@Test
public void testDiffersIfSignatureDiffers() throws UnsupportedEncodingException, NoSuchAlgorithmException {
    EngineKey first = harness.build();
    Key signature = mock(Key.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            MessageDigest digest = (MessageDigest) invocationOnMock.getArguments()[0];
            digest.update("signature".getBytes("UTF-8"));
            return null;
        }
    }).when(signature).updateDiskCacheKey(any(MessageDigest.class));
    harness.signature = signature;
    EngineKey second = harness.build();
    KeyAssertions.assertDifferent(first, second, false);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) MessageDigest(java.security.MessageDigest) Key(com.bumptech.glide.load.Key) Test(org.junit.Test)

Example 8 with Key

use of com.bumptech.glide.load.Key in project glide by bumptech.

the class RecyclerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ListViewHolder viewHolder, int position) {
    MediaStoreData current = data.get(position);
    Key signature = new MediaStoreSignature(current.mimeType, current.dateModified, current.orientation);
    requestBuilder.clone().apply(signatureOf(signature)).load(current.uri).into(viewHolder.image);
}
Also used : MediaStoreSignature(com.bumptech.glide.signature.MediaStoreSignature) Key(com.bumptech.glide.load.Key)

Aggregations

Key (com.bumptech.glide.load.Key)8 Test (org.junit.Test)3 File (java.io.File)2 DataFetcher (com.bumptech.glide.load.data.DataFetcher)1 MediaStoreSignature (com.bumptech.glide.signature.MediaStoreSignature)1 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1