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) {
        this.mContext = context;
        this.inflater = (LayoutInflater) context.getSystemService("layout_inflater");
    }

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

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

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

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

    public boolean isSelectable(int i) {
        try {
            return this.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 = this.inflater.inflate(R.layout.file_list_item, (ViewGroup) null);
        }
        ((TextView) view.findViewById(R.id.file_folder_name)).setText(this.mItems.get(i).getText());
        ((ImageView) view.findViewById(R.id.file_folder_icon)).setImageDrawable(this.mItems.get(i).getIcon());
        ImageView imageView = (ImageView) view.findViewById(R.id.browse_folder);
        if (this.mItems.get(i).ismIsFolder()) {
            imageView.setImageDrawable(this.mContext.getResources().getDrawable(R.C2136drawable.more));
        } else {
            imageView.setImageDrawable((Drawable) null);
        }
        return view;
    }
}
