package com.michaldabski.utils;

import java.io.File;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.LruCache;

import com.michaldabski.fileexplorer.R;

public class FileIconResolver extends LruCache<String, Bitmap>
{	
	final Context context;
	Bitmap nullIcon=null;
	
	public FileIconResolver(Context context)
	{
		super(50);
		this.context = context;
	}
	
	public Bitmap getNullIcon()
	{
		if (nullIcon == null)
			nullIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_file);
		return nullIcon;
	}
	
	public Bitmap getFileIcon(File file)
	{
		String mimeType = FileUtils.getFileMimeType(file);
		if (mimeType == null) return getNullIcon();
		
		Bitmap bitmap = super.get(mimeType);
		if (bitmap == null)
			bitmap = FileUtils.createFileIcon(file, context, false);
		put(mimeType, bitmap);
		return bitmap;
	}
}

@@ -289,16 +289,71 @@
 map%3E%0A%7B%09%0A
+%09public static final int CACHE_SIZE = 5 * 1024 * 1024;%0A
 %09final C
@@ -450,10 +450,18 @@
 per(
-50
+CACHE_SIZE
 );%0A%09
@@ -486,24 +486,122 @@
 ntext;%0A%09%7D%0A%09%0A
+%09@Override%0A%09protected int sizeOf(String key, Bitmap value)%0A%09%7B%0A%09%09return value.getByteCount();%0A%09%7D%0A%09%0A
 %09public Bitm

Define cache size for file icons in megabytes