package com.michaldabski.panoramio.utils;

import android.graphics.Bitmap;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

/**
 * Created by Michal on 08/08/2014.
 */
public class LruImageCache implements ImageLoader.ImageCache
{
    private final LruCache<String, Bitmap> bitmapLruCache = new LruCache<String, Bitmap>(20);

    @Override
    public Bitmap getBitmap(String url)
    {
        return bitmapLruCache.get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap)
    {
        bitmapLruCache.put(url, bitmap);
    }

    public void clear()
    {
        bitmapLruCache.evictAll();
    }

}

@@ -55,23 +55,85 @@
 oid.
-graphics.Bitmap
+annotation.TargetApi;%0Aimport android.graphics.Bitmap;%0Aimport android.os.Build
 ;%0Aim
@@ -279,16 +279,49 @@
 ageCache
+ extends LruCache%3CString, Bitmap%3E
  impleme
@@ -358,96 +358,79 @@
    p
-rivate final LruCache%3CString, Bitmap%3E bitmapLruCache = new LruCache%3CString, Bitmap%3E(20);
+ublic LruImageCache()%0A    %7B%0A        super(getOptimalCacheSize());%0A    %7D
 %0A%0A  
@@ -502,31 +502,16 @@
  return 
-bitmapLruCache.
 get(url)
@@ -600,31 +600,16 @@
         
-bitmapLruCache.
 put(url,
@@ -667,32 +667,464 @@
     
-bitmapLruCache.evictAll(
+evictAll();%0A    %7D%0A%0A    @TargetApi(Build.VERSION_CODES.KITKAT)%0A    @Override%0A    protected int sizeOf(String key, Bitmap value)%0A    %7B%0A        if (Build.VERSION.SDK_INT %3C Build.VERSION_CODES.KITKAT)%0A            return value.getByteCount();%0A        else%0A            return value.getAllocationByteCount();%0A    %7D%0A%0A    public static int getOptimalCacheSize()%0A    %7B%0A        long maxMemory = Runtime.getRuntime().maxMemory();%0A        return (int) (0.4f * maxMemory
 );%0A 

Refactor cache