Example #1
0
  @Override
  public void onBindViewHolder(GiphyViewHolder holder, int position) {
    GiphyImage image = images.get(position);

    holder.modelReady = false;
    holder.image = image;
    holder.thumbnail.setAspectRatio(image.getGifAspectRatio());
    holder.gifProgress.setVisibility(View.GONE);

    DrawableRequestBuilder<String> thumbnailRequest = Glide.with(context).load(image.getStillUrl());

    if (Util.isLowMemory(context)) {
      Glide.with(context)
          .load(image.getStillUrl())
          .placeholder(
              new ColorDrawable(
                  Util.getRandomElement(MaterialColor.values()).toConversationColor(context)))
          .diskCacheStrategy(DiskCacheStrategy.ALL)
          .into(holder.thumbnail);

      holder.setModelReady();
    } else {
      Glide.with(context)
          .load(image.getGifUrl())
          .thumbnail(thumbnailRequest)
          .placeholder(
              new ColorDrawable(
                  Util.getRandomElement(MaterialColor.values()).toConversationColor(context)))
          .diskCacheStrategy(DiskCacheStrategy.ALL)
          .listener(holder)
          .into(holder.thumbnail);
    }
  }
Example #2
0
    public File getFile(boolean forMms) throws ExecutionException, InterruptedException {
      synchronized (this) {
        while (!modelReady) {
          Util.wait(this, 0);
        }
      }

      return Glide.with(context)
          .load(forMms ? image.getGifMmsUrl() : image.getGifUrl())
          .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
          .get();
    }
Example #3
0
    @Override
    public boolean onException(
        Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
      Log.w(TAG, e);

      synchronized (this) {
        if (image.getGifUrl().equals(model)) {
          this.modelReady = true;
          notifyAll();
        }
      }

      return false;
    }
Example #4
0
    @Override
    public boolean onResourceReady(
        GlideDrawable resource,
        String model,
        Target<GlideDrawable> target,
        boolean isFromMemoryCache,
        boolean isFirstResource) {
      synchronized (this) {
        if (image.getGifUrl().equals(model)) {
          this.modelReady = true;
          notifyAll();
        }
      }

      return false;
    }