mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-26 01:09:13 -05:00
synchronize around thumbnail cache to avoid loading images twice
This commit is contained in:
parent
1d2e2f71c2
commit
252d015b71
@ -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,10 +345,17 @@ 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)) {
|
||||
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);
|
||||
@ -357,7 +365,8 @@ public class FileBackend {
|
||||
}
|
||||
thumbnail = resize(fullsize, size);
|
||||
thumbnail = rotate(thumbnail, getRotation(file));
|
||||
this.mXmppConnectionService.getBitmapCache().put(message.getUuid(),thumbnail);
|
||||
this.mXmppConnectionService.getBitmapCache().put(uuid, thumbnail);
|
||||
}
|
||||
}
|
||||
return thumbnail;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user