package epson.print.imgsel;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import epson.print.R;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ImageFolderAdapter extends BaseAdapter {
    private List<FolderInfoAndThumbnail> mFolderList = new ArrayList();
    private LayoutInflater mLayoutInflater;
    private Resources mResources;

    public long getItemId(int i) {
        return 0;
    }

    public int getCount() {
        return this.mFolderList.size();
    }

    public Object getItem(int i) {
        return this.mFolderList.get(i);
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = this.mLayoutInflater.inflate(R.layout.listitem_image_folder, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.folderNameText);
        FolderInfoAndThumbnail folderInfoAndThumbnail = this.mFolderList.get(i);
        if (folderInfoAndThumbnail == null) {
            return view;
        }
        textView.setText(new File(folderInfoAndThumbnail.mImageFolderInfo.mCanonicalName).getName());
        ((TextView) view.findViewById(R.id.imageVolumeText)).setText(this.mResources.getString(R.string.memcard_file_num_format, new Object[]{Integer.valueOf(folderInfoAndThumbnail.mImageFolderInfo.getImageCount())}));
        ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
        if (folderInfoAndThumbnail.mBitmap != null) {
            imageView.setImageBitmap(folderInfoAndThumbnail.mBitmap);
        } else {
            imageView.setImageResource(R.drawable.ic_action_warning);
        }
        return view;
    }

    public ImageFolderAdapter(Context context) {
        this.mLayoutInflater = LayoutInflater.from(context);
        this.mResources = context.getResources();
    }

    public void addItem(ImageFolderInfo imageFolderInfo, Bitmap bitmap) {
        this.mFolderList.add(new FolderInfoAndThumbnail(imageFolderInfo, bitmap));
        notifyDataSetChanged();
    }

    public ImageFolderInfo getFolderInfo(int i) {
        return this.mFolderList.get(i).mImageFolderInfo;
    }

    public void releaseResource() {
        for (FolderInfoAndThumbnail next : this.mFolderList) {
            if (next.mBitmap != null) {
                next.mBitmap.recycle();
                next.mBitmap = null;
            }
        }
        this.mFolderList.clear();
    }

    static class FolderInfoAndThumbnail {
        public Bitmap mBitmap;
        public ImageFolderInfo mImageFolderInfo;

        public FolderInfoAndThumbnail(ImageFolderInfo imageFolderInfo, Bitmap bitmap) {
            this.mImageFolderInfo = imageFolderInfo;
            this.mBitmap = bitmap;
        }
    }
}
