/** * Computes a result, or throws an exception if unable to do so. * * @return computed result * @throws Exception if unable to compute a result */ @Override public String call() throws Exception { Ln.d("Resolving url: %s", mImageUrl); Image imageAlbum = ImageResolver.resolve(mImageUrl); if (imageAlbum instanceof ImgurAlbumType) { ImgurAlbumType imgurAlbumType = (ImgurAlbumType) imageAlbum; if (imgurAlbumType != null) { return mImgurImagePrefix + imgurAlbumType.getAlbum().getCover() + mImgurImageSuffix; } } return null; }
/** * @param imageUrl the result of {@link #call()} * @throws Exception, captured on passed to onException() if present. */ @Override protected void onSuccess(String imageUrl) throws Exception { if (mImageView != null) { ResolveAlbumCoverWorkerTask albumCoverResolverWorkerTask = getAlbumCoverResolverTask(mImageView); if (this == albumCoverResolverWorkerTask) { try { Picasso.with(mContext) .load(Uri.parse(imageUrl)) .placeholder(R.drawable.loading_spinner_48) .error(R.drawable.error_photo) .into(mImageView); } catch (Exception e) { Ln.e(e, "Failed to load image"); Picasso.with(mContext).load(R.drawable.error_photo).into(mImageView); } } } }