package epson.print;

import android.content.Context;
import android.graphics.drawable.Drawable;
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 java.util.ArrayList;
import java.util.List;

public class IconifiedTextListAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private Context mContext;
    private List<IconifiedText> mItems = new ArrayList();

    public boolean areAllItemsSelectable() {
        return false;
    }

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

    public IconifiedTextListAdapter(Context context) {
        mContext = context;
        inflater = (LayoutInflater) context.getSystemService("layout_inflater");
    }

    public void addItem(IconifiedText iconifiedText) {
        mItems.add(iconifiedText);
    }

    public void setListItems(List<IconifiedText> list) {
        mItems = list;
    }

    public int getCount() {
        return mItems.size();
    }

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

    public boolean isSelectable(int i) {
        try {
            return mItems.get(i).isSelectable();
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
            return super.areAllItemsEnabled();
        }
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.file_list_item, (ViewGroup) null);
        }
        ((TextView) view.findViewById(R.id.file_folder_name)).setText(mItems.get(i).getText());
        ((ImageView) view.findViewById(R.id.file_folder_icon)).setImageDrawable(mItems.get(i).getIcon());
        ImageView imageView = (ImageView) view.findViewById(R.id.browse_folder);
        if (mItems.get(i).ismIsFolder()) {
            imageView.setImageDrawable(mContext.getResources().getDrawable(R.C2136drawable.more));
        } else {
            imageView.setImageDrawable((Drawable) null);
        }
        return view;
    }
}
