Example #1
0
  @Override
  public boolean startNext() {
    while (modelLoaders == null || !hasNextModelLoader()) {
      sourceIdIndex++;
      if (sourceIdIndex >= cacheKeys.size()) {
        return false;
      }

      Key sourceId = cacheKeys.get(sourceIdIndex);
      Key originalKey = new DataCacheKey(sourceId, helper.getSignature());
      cacheFile = helper.getDiskCache().get(originalKey);
      if (cacheFile != null) {
        this.sourceKey = sourceId;
        modelLoaders = helper.getModelLoaders(cacheFile);
        modelLoaderIndex = 0;
      }
    }

    loadData = null;
    boolean started = false;
    while (!started && hasNextModelLoader()) {
      ModelLoader<File, ?> modelLoader = modelLoaders.get(modelLoaderIndex++);
      loadData =
          modelLoader.buildLoadData(
              cacheFile, helper.getWidth(), helper.getHeight(), helper.getOptions());
      if (loadData != null && helper.hasLoadPath(loadData.fetcher.getDataClass())) {
        started = true;
        loadData.fetcher.loadData(helper.getPriority(), this);
      }
    }
    return started;
  }
Example #2
0
    public RequestHarness() {
      modelLoader = mock(ModelLoader.class);
      when(modelLoader.getResourceFetcher(any(Number.class), anyInt(), anyInt()))
          .thenReturn(mock(DataFetcher.class));
      when(loadProvider.getModelLoader()).thenReturn(modelLoader);
      when(loadProvider.getCacheDecoder()).thenReturn(cacheDecoder);
      when(loadProvider.getSourceDecoder()).thenReturn(sourceDecoder);
      when(loadProvider.getSourceEncoder()).thenReturn(sourceEncoder);
      when(loadProvider.getEncoder()).thenReturn(encoder);
      when(loadProvider.getTranscoder()).thenReturn(transcoder);
      when(requestCoordinator.canSetImage(any(Request.class))).thenReturn(true);
      when(requestCoordinator.canNotifyStatusChanged(any(Request.class))).thenReturn(true);

      when(resource.get()).thenReturn(result);
    }
  @Override
  public DataFetcher<InputStream> getResourceFetcher(T model, int width, int height) {
    GlideUrl result = null;
    if (modelCache != null) {
      result = modelCache.get(model, width, height);
    }

    if (result == null) {
      String stringURL = getUrl(model, width, height);
      if (TextUtils.isEmpty(stringURL)) {
        return null;
      }

      result = new GlideUrl(stringURL);

      if (modelCache != null) {
        modelCache.put(model, width, height, result);
      }
    }

    return concreteLoader.getResourceFetcher(result, width, height);
  }