Use attachment cache on layout passes
Avoid trying to load the preview bitmap if the attachment
is already cached.
b/17365401
Change-Id: Ie3a24f25749cca8da402894ac57dd1181a510b6a
diff --git a/src/com/android/mail/ui/AttachmentTile.java b/src/com/android/mail/ui/AttachmentTile.java
index 3fc8dc5..da1a4b9 100644
--- a/src/com/android/mail/ui/AttachmentTile.java
+++ b/src/com/android/mail/ui/AttachmentTile.java
@@ -94,7 +94,7 @@
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
- ThumbnailLoadTask.setupThumbnailPreview(this, mAttachment, null);
+ ThumbnailLoadTask.setupThumbnailPreview(mAttachmentPreviewCache, this, mAttachment, null);
}
public Attachment getAttachment() {
@@ -136,7 +136,8 @@
updateSubtitleText();
}
- ThumbnailLoadTask.setupThumbnailPreview(this, attachment, prevAttachment);
+ ThumbnailLoadTask.setupThumbnailPreview(mAttachmentPreviewCache, this, attachment,
+ prevAttachment);
}
private void updateSubtitleText() {
@@ -153,7 +154,7 @@
@Override
public void setThumbnailToDefault() {
- Bitmap cachedPreview = mAttachmentPreviewCache.get(mAttachment);
+ final Bitmap cachedPreview = mAttachmentPreviewCache.get(mAttachment);
if (cachedPreview != null) {
setThumbnail(cachedPreview);
return;
diff --git a/src/com/android/mail/ui/ThumbnailLoadTask.java b/src/com/android/mail/ui/ThumbnailLoadTask.java
index bfe6ae9..3709eee 100644
--- a/src/com/android/mail/ui/ThumbnailLoadTask.java
+++ b/src/com/android/mail/ui/ThumbnailLoadTask.java
@@ -48,8 +48,17 @@
private final int mWidth;
private final int mHeight;
- public static void setupThumbnailPreview(final AttachmentBitmapHolder holder,
- final Attachment attachment, final Attachment prevAttachment) {
+ public static void setupThumbnailPreview(AttachmentTile.AttachmentPreviewCache cache,
+ AttachmentBitmapHolder holder, Attachment attachment, Attachment prevAttachment) {
+ // Check cache first
+ if (cache != null) {
+ final Bitmap cached = cache.get(attachment);
+ if (cached != null) {
+ holder.setThumbnail(cached);
+ return;
+ }
+ }
+
final int width = holder.getThumbnailWidth();
final int height = holder.getThumbnailHeight();
if (attachment == null || width == 0 || height == 0