All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.squareup.picasso.TargetRequest Maven / Gradle / Ivy

There is a newer version: 2.71828
Show newest version
package com.squareup.picasso;

import android.net.Uri;
import java.lang.ref.WeakReference;
import java.util.List;

final class TargetRequest extends Request {

  private final WeakReference weakTarget;
  private final Target strongTarget;

  TargetRequest(Picasso picasso, Uri uri, int resourceId, Target target, boolean strong,
      PicassoBitmapOptions bitmapOptions, List transformations, boolean skipCache) {
    super(picasso, uri, resourceId, null, bitmapOptions, transformations, skipCache, false, 0,
        null);
    this.weakTarget = strong ? null : new WeakReference(target);
    this.strongTarget = strong ? target : null;
  }

  @Override Target getTarget() {
    return strongTarget != null ? strongTarget : weakTarget.get();
  }

  @Override void complete() {
    if (result == null) {
      throw new AssertionError(
          String.format("Attempted to complete request with no result!\n%s", this));
    }
    Target target = getTarget();
    if (target != null) {
      target.onSuccess(result);
      if (result.isRecycled()) {
        throw new IllegalStateException("Target callback must not recycle bitmap!");
      }
    }
  }

  @Override void error() {
    Target target = getTarget();
    if (target == null) {
      return;
    }
    target.onError();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy