package epson.scan.activity;

import android.content.Context;
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.Iterator;
import java.util.LinkedHashMap;

import epson.print.R;

public class ScanSettingsDetailAdapter extends BaseAdapter {
    private LinkedHashMap<String, Integer> lhmListSettingsSupport;
    private LayoutInflater mInflater;
    private int selectedValue;

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

    public ScanSettingsDetailAdapter(Context context, LinkedHashMap<String, Integer> linkedHashMap, int i) {
        mInflater = LayoutInflater.from(context);
        lhmListSettingsSupport = linkedHashMap;
        selectedValue = i;
    }

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

    public Object getItem(int i) {
        return lhmListSettingsSupport.get(Integer.valueOf(i));
    }

    public void setSelected(int i) {
        selectedValue = i;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        DetailSettingHolder detailSettingHolder;
        if (view == null) {
            view = mInflater.inflate(R.layout.scan_settings_item, (ViewGroup) null);
            detailSettingHolder = new DetailSettingHolder();
            detailSettingHolder.text = (TextView) view.findViewById(R.id.tvSettingName);
            detailSettingHolder.img = (ImageView) view.findViewById(R.id.ivSettingSelected);
            detailSettingHolder.img.setBackgroundResource(R.drawable.selected);
            view.setTag(detailSettingHolder);
        } else {
            detailSettingHolder = (DetailSettingHolder) view.getTag();
        }
        Iterator<String> it = lhmListSettingsSupport.keySet().iterator();
        int i2 = 0;
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            String next = it.next();
            if (i2 == i) {
                int intValue = lhmListSettingsSupport.get(next).intValue();
                detailSettingHolder.text.setText(next);
                if (intValue == selectedValue) {
                    detailSettingHolder.img.setVisibility(View.VISIBLE);
                } else {
                    detailSettingHolder.img.setVisibility(4);
                }
                detailSettingHolder.value = intValue;
            } else {
                i2++;
            }
        }
        return view;
    }

    static class DetailSettingHolder {
        ImageView img;
        TextView text;
        int value;

        DetailSettingHolder() {
        }
    }
}
