// Path: src/com/andrewshu/android/reddit/common/util/StringUtils.java
// public class StringUtils {
// 
// 	public static boolean isEmpty(CharSequence s) {
// 		return s == null || "".equals(s);
// 	}
// 
// 	public static boolean listContainsIgnoreCase(ArrayList<String> list, String str){
// 		for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
// 			String string = (String) iterator.next();
// 			
// 			if(string.equalsIgnoreCase(str))
// 				return true;
// 		}
// 		return false;
// 	}
// 
// }
// 
// Path: src/com/andrewshu/android/reddit/threads/ShowThumbnailsTask.java
// public static class ThumbnailLoadAction {
//    	public ThingInfo thingInfo;
//    	public ImageView imageView;  // prefer imageView; if it's null, use threadIndex
//    	public int threadIndex;
//    	public ThumbnailLoadAction(ThingInfo thingInfo, ImageView imageView, int threadIndex) {
//    		this.thingInfo = thingInfo;
//    		this.imageView = imageView;
//    		this.threadIndex = threadIndex;
//    	}
//    }


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.net.MalformedURLException;
import java.util.HashMap;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import android.app.ListActivity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import com.andrewshu.android.reddit.R;
import com.andrewshu.android.reddit.common.util.StringUtils;
import com.andrewshu.android.reddit.things.ThingInfo;
import com.andrewshu.android.reddit.threads.ShowThumbnailsTask.ThumbnailLoadAction;
	private static final String TAG = "ShowThumbnailsTask";

	public ShowThumbnailsTask(ListActivity activity, HttpClient client, Integer defaultThumbnailResource) {
		this.mActivity = activity;
		this.mClient = client;
		this.mDefaultThumbnailResource = defaultThumbnailResource;
	}
	
	public static class ThumbnailLoadAction {
    	public ThingInfo thingInfo;
    	public ImageView imageView;  // prefer imageView; if it's null, use threadIndex
    	public int threadIndex;
    	public ThumbnailLoadAction(ThingInfo thingInfo, ImageView imageView, int threadIndex) {
    		this.thingInfo = thingInfo;
    		this.imageView = imageView;
    		this.threadIndex = threadIndex;
    	}
    }
	
	@Override
	protected Void doInBackground(ThumbnailLoadAction... thumbnailLoadActions) {
		for (ThumbnailLoadAction thumbnailLoadAction : thumbnailLoadActions) {
			loadThumbnail(thumbnailLoadAction.thingInfo);
			publishProgress(thumbnailLoadAction);
		}
		return null;
	}
	
	// TODO use external storage cache if present
	private void loadThumbnail(ThingInfo thingInfo) {
// Path: src/com/andrewshu/android/reddit/common/util/StringUtils.java
// public class StringUtils {
// 
// 	public static boolean isEmpty(CharSequence s) {
// 		return s == null || "".equals(s);
// 	}
// 
// 	public static boolean listContainsIgnoreCase(ArrayList<String> list, String str){
// 		for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
// 			String string = (String) iterator.next();
// 			
// 			if(string.equalsIgnoreCase(str))
// 				return true;
// 		}
// 		return false;
// 	}
// 
// }
// 
// Path: src/com/andrewshu/android/reddit/threads/ShowThumbnailsTask.java
// public static class ThumbnailLoadAction {
//    	public ThingInfo thingInfo;
//    	public ImageView imageView;  // prefer imageView; if it's null, use threadIndex
//    	public int threadIndex;
//    	public ThumbnailLoadAction(ThingInfo thingInfo, ImageView imageView, int threadIndex) {
//    		this.thingInfo = thingInfo;
//    		this.imageView = imageView;
//    		this.threadIndex = threadIndex;
//    	}
//    }


// Path: src/com/andrewshu/android/reddit/threads/ShowThumbnailsTask.java
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.net.MalformedURLException;
import java.util.HashMap;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import android.app.ListActivity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import com.andrewshu.android.reddit.R;
import com.andrewshu.android.reddit.common.util.StringUtils;
import com.andrewshu.android.reddit.things.ThingInfo;
import com.andrewshu.android.reddit.threads.ShowThumbnailsTask.ThumbnailLoadAction;

	private static final String TAG = "ShowThumbnailsTask";

	public ShowThumbnailsTask(ListActivity activity, HttpClient client, Integer defaultThumbnailResource) {
		this.mActivity = activity;
		this.mClient = client;
		this.mDefaultThumbnailResource = defaultThumbnailResource;
	}
	
	public static class ThumbnailLoadAction {
    	public ThingInfo thingInfo;
    	public ImageView imageView;  // prefer imageView; if it's null, use threadIndex
    	public int threadIndex;
    	public ThumbnailLoadAction(ThingInfo thingInfo, ImageView imageView, int threadIndex) {
    		this.thingInfo = thingInfo;
    		this.imageView = imageView;
    		this.threadIndex = threadIndex;
    	}
    }
	
	@Override
	protected Void doInBackground(ThumbnailLoadAction... thumbnailLoadActions) {
		for (ThumbnailLoadAction thumbnailLoadAction : thumbnailLoadActions) {
			loadThumbnail(thumbnailLoadAction.thingInfo);
			publishProgress(thumbnailLoadAction);
		}
		return null;
	}
	
	// TODO use external storage cache if present
	private void loadThumbnail(ThingInfo thingInfo) {
		if ("default".equals(thingInfo.getThumbnail()) || "self".equals(thingInfo.getThumbnail()) || StringUtils.isEmpty(thingInfo.getThumbnail())) {