mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-31 19:04:52 +01:00
Prevent images from being loaded multiple times
(copied from AntennaPodSP)
This commit is contained in:
parent
dfa10a5989
commit
b9ab10253a
@ -1,14 +1,8 @@
|
||||
package de.danoeh.antennapod.asynctask;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
@ -17,7 +11,14 @@ import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.PodcastApp;
|
||||
import de.danoeh.antennapod.R;
|
||||
|
||||
/** Caches and loads FeedImage bitmaps in the background */
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
/**
|
||||
* Caches and loads FeedImage bitmaps in the background
|
||||
*/
|
||||
public class ImageLoader {
|
||||
private static final String TAG = "ImageLoader";
|
||||
private static ImageLoader singleton;
|
||||
@ -104,10 +105,12 @@ public class ImageLoader {
|
||||
ImageView target, int length) {
|
||||
final int defaultCoverResource = getDefaultCoverResource(target
|
||||
.getContext());
|
||||
|
||||
if (source != null && source.getImageLoaderCacheKey() != null) {
|
||||
target.setTag(R.id.imageloader_key, source.getImageLoaderCacheKey());
|
||||
CachedBitmap cBitmap = getBitmapFromCoverCache(source.getImageLoaderCacheKey());
|
||||
final String cacheKey;
|
||||
if (source != null && (cacheKey = source.getImageLoaderCacheKey()) != null) {
|
||||
final Object currentTag = target.getTag(R.id.imageloader_key);
|
||||
if (currentTag == null || !cacheKey.equals(currentTag)) {
|
||||
target.setTag(R.id.imageloader_key, cacheKey);
|
||||
CachedBitmap cBitmap = getBitmapFromCoverCache(cacheKey);
|
||||
if (cBitmap != null && cBitmap.getLength() >= length) {
|
||||
target.setImageBitmap(cBitmap.getBitmap());
|
||||
} else {
|
||||
@ -116,6 +119,7 @@ public class ImageLoader {
|
||||
handler, target, source, length, IMAGE_TYPE_COVER);
|
||||
executor.submit(worker);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
target.setImageResource(defaultCoverResource);
|
||||
}
|
||||
@ -142,10 +146,12 @@ public class ImageLoader {
|
||||
ImageView target, int length) {
|
||||
final int defaultCoverResource = getDefaultCoverResource(target
|
||||
.getContext());
|
||||
|
||||
if (source != null && source.getImageLoaderCacheKey() != null) {
|
||||
target.setTag(R.id.imageloader_key, source.getImageLoaderCacheKey());
|
||||
CachedBitmap cBitmap = getBitmapFromThumbnailCache(source.getImageLoaderCacheKey());
|
||||
final String cacheKey;
|
||||
if (source != null && (cacheKey = source.getImageLoaderCacheKey()) != null) {
|
||||
final Object currentTag = target.getTag(R.id.imageloader_key);
|
||||
if (currentTag == null || !cacheKey.equals(currentTag)) {
|
||||
target.setTag(R.id.imageloader_key, cacheKey);
|
||||
CachedBitmap cBitmap = getBitmapFromThumbnailCache(cacheKey);
|
||||
if (cBitmap != null && cBitmap.getLength() >= length) {
|
||||
target.setImageBitmap(cBitmap.getBitmap());
|
||||
} else {
|
||||
@ -154,6 +160,7 @@ public class ImageLoader {
|
||||
handler, target, source, length, IMAGE_TYPE_THUMBNAIL);
|
||||
executor.submit(worker);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
target.setImageResource(defaultCoverResource);
|
||||
}
|
||||
@ -216,8 +223,9 @@ public class ImageLoader {
|
||||
* reset the existing one, depending on their implementation of
|
||||
* openInputStream. If a new InputStream is returned, the one given as a
|
||||
* parameter MUST be closed.
|
||||
*
|
||||
* @param input The input stream that was returned by openImageInputStream()
|
||||
* */
|
||||
*/
|
||||
public InputStream reopenImageInputStream(InputStream input);
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user