package cn.net.caoyao.cpzshandset.service.thread.impl.ythImage;

import java.util.List;

import android.graphics.Bitmap;
import android.os.Handler;
import cn.net.caoyao.cpzshandset.common.bitmap.MBitmapService;
import cn.net.caoyao.cpzshandset.common.config.RequestConstant;
import cn.net.caoyao.cpzshandset.common.config.TConfig;
import cn.net.caoyao.cpzshandset.common.util.LogUtil;
import cn.net.cpzslibs.prot.utils.StrUtils;

public class DownloadImageRunable implements Runnable{
	private List<String> currentImages;
	private List<String> beforeImages;
	private MBitmapService bitmapService;
	private Handler mHandler;
	public DownloadImageRunable(Handler mHandler,List<String> currentImages,List<String> beforeImages,MBitmapService bitmapService) {
		this.mHandler = mHandler;
		this.currentImages = currentImages;
		this.beforeImages = beforeImages;
		this.bitmapService = bitmapService;
	}

	@Override
	public void run() {
		if (beforeImages != null && currentImages != null) {
			for (String url : beforeImages) {
				if (!currentImages.contains(url)) {
					bitmapService.clearCache(url);
				}
			}
		}
		
		
		for (int i = 0; i < currentImages.size(); i++) {
			if (!StrUtils.isEmpty(currentImages.get(i))) {
				Bitmap b = bitmapService.justDownloadImage(currentImages.get(i));
				LogUtil.d(TConfig.Echo, "第 "+i + " 下载完成：" + b);
			}
		}
		mHandler.sendEmptyMessage(RequestConstant.DOWNLOAD_PRODUCT_IMAGE_SUCCESS);
	}

}
