Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added target from cache #48

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private void fetchImage(final T model, int width, int height, final int loadCoun
public boolean onImageReady(Bitmap image) {
if (loadCount != currentCount || !canSetImage() || image == null) return false;

target.onImageReady(image);
target.onImageReady(image, loadedFromCache);
if (imageReadyCallback != null)
imageReadyCallback.onImageReady(model, target, loadedFromCache);
isImageSet = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ImageViewTarget(ImageView imageView) {
}

@Override
public void onImageReady(Bitmap bitmap) {
public void onImageReady(Bitmap bitmap, boolean fromCache) {
imageView.setImageBitmap(bitmap);
}

Expand Down
3 changes: 2 additions & 1 deletion library/src/com/bumptech/glide/presenter/target/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public interface SizeReadyCallback {

/**
* The method that will be called when the image load has finished
* @param fromCache True if the bitmap comes from a local cache (memory or disk).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually only true if the image comes from the in memory cache. Really it's an indication that onImageReady was called synchronously with the Glide.load call.

* @param bitmap The loaded image
*/
public void onImageReady(Bitmap bitmap);
public void onImageReady(Bitmap bitmap, boolean fromCache);

/**
* A method that can optionally be implemented to set any placeholder that might have been passed to Glide to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public LruBitmapPool(int maxSize) {

@Override
public synchronized boolean put(Bitmap bitmap) {
// BitmapFactory.decodeStream can sometimes return bitmaps with null configs, which can't generally be reused
if (bitmap.getConfig() == null)
return false;

final int size = getSize(bitmap);

pool.put(bitmap);
Expand Down Expand Up @@ -126,6 +130,10 @@ public int hashCode() {
}

public void put(Bitmap bitmap) {
// BitmapFactory.decodeStream can sometimes return bitmaps with null configs, which can't generally be reused
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only check this in the outer put method.

if (bitmap.getConfig() == null)
return;

final Key key = keyPool.get(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());

LinkedEntry entry = keyToEntry.get(key);
Expand Down