diff options
author | Christian S <christian@pix-art.de> | 2016-04-30 21:10:24 +0200 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2016-04-30 21:10:24 +0200 |
commit | ab37336d1edc446f17d7a7aaeb653efb170283d9 (patch) | |
tree | 609ca7afbc7bd0c4af0344af310fa0bd352bd4ae /src/main/java/eu/siacs/conversations/persistance/FileBackend.java | |
parent | fe60bd582aee184b49d1af14357cb88ad2637c3e (diff) | |
parent | 936006173ce11111f10c0bddd66d28c439ca584e (diff) |
Merge remote-tracking branch 'refs/remotes/siacs/master' into development
Diffstat (limited to 'src/main/java/eu/siacs/conversations/persistance/FileBackend.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 306092141..c63ce870f 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -20,6 +20,7 @@ import android.system.StructStat; import android.util.Base64; import android.util.Base64OutputStream; import android.util.Log; +import android.util.LruCache; import android.webkit.MimeTypeMap; import java.io.ByteArrayOutputStream; @@ -344,20 +345,28 @@ public class FileBackend { } } - public Bitmap getThumbnail(Message message, int size, boolean cacheOnly) - throws FileNotFoundException { - Bitmap thumbnail = mXmppConnectionService.getBitmapCache().get(message.getUuid()); + public Bitmap getThumbnail(Message message, int size, boolean cacheOnly) throws FileNotFoundException { + final String uuid = message.getUuid(); + final LruCache<String,Bitmap> cache = mXmppConnectionService.getBitmapCache(); + Log.d(Config.LOGTAG,"get thumbnail for "+uuid+" cacheOnly="+Boolean.toString(cacheOnly)); + Bitmap thumbnail = cache.get(uuid); if ((thumbnail == null) && (!cacheOnly)) { - File file = getFile(message); - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inSampleSize = calcSampleSize(file, size); - Bitmap fullsize = BitmapFactory.decodeFile(file.getAbsolutePath(),options); - if (fullsize == null) { - throw new FileNotFoundException(); + synchronized (cache) { + thumbnail = cache.get(uuid); + if (thumbnail != null) { + return thumbnail; + } + File file = getFile(message); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inSampleSize = calcSampleSize(file, size); + Bitmap fullsize = BitmapFactory.decodeFile(file.getAbsolutePath(), options); + if (fullsize == null) { + throw new FileNotFoundException(); + } + thumbnail = resize(fullsize, size); + thumbnail = rotate(thumbnail, getRotation(file)); + this.mXmppConnectionService.getBitmapCache().put(uuid, thumbnail); } - thumbnail = resize(fullsize, size); - thumbnail = rotate(thumbnail, getRotation(file)); - this.mXmppConnectionService.getBitmapCache().put(message.getUuid(),thumbnail); } return thumbnail; } |