package epson.scan.activity;

import android.content.Context;
import android.support.annotation.DrawableRes;


import android.support.annotation.StringRes;
import android.support.annotation.UiThread;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
import epson.print.R;

public class ModeListAdapter extends BaseAdapter {
    private int mCurrentPosition;
    private LayoutInflater mLayoutInflater;
    @DrawableRes
    private int[] mLeftImageId;
    private int[] mStringIdArray;

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

    public ModeListAdapter(@NonNull Context context, @StringRes int[] iArr, int i) {
        mLayoutInflater = LayoutInflater.from(context);
        mStringIdArray = iArr;
        mCurrentPosition = i;
        mLeftImageId = null;
    }

    public ModeListAdapter(@NonNull Context context, @Nullable @StringRes int[] iArr, @DrawableRes int[] iArr2, int i) {
        mLayoutInflater = LayoutInflater.from(context);
        mStringIdArray = iArr == null ? new int[iArr2.length] : iArr;
        mCurrentPosition = i;
        mLeftImageId = iArr2;
    }

    public int getCount() {
        return mStringIdArray.length;
    }

    public Object getItem(int i) {
        return 0;
    }

    @UiThread
    public void setPosition(int i) {
        mCurrentPosition = i;
        int i2 = mCurrentPosition;
        if (i2 < 0) {
            mCurrentPosition = 0;
        } else if (i2 >= getCount()) {
            mCurrentPosition = getCount() - 1;
        }
        notifyDataSetChanged();
    }

    public int getPosition() {
        return mCurrentPosition;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        int i2 = 0;
        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.i2_scan_setting_item, viewGroup, false);
        }
        if (mLeftImageId != null) {
            ImageView imageView = (ImageView) view.findViewById(R.id.leftImageView);
            imageView.setImageResource(mLeftImageId[i]);
            imageView.setVisibility(0);
        }
        if (mStringIdArray[0] != 0) {
            ((TextView) view.findViewById(R.id.tvSettingName)).setText(mStringIdArray[i]);
        }
        ImageView imageView2 = (ImageView) view.findViewById(R.id.ivSettingSelected);
        if (i != mCurrentPosition) {
            i2 = 8;
        }
        imageView2.setVisibility(i2);
        return view;
    }

    public static class Builder implements LocalListAdapterBuilder {
        private int mCurrentPosition;
        private int[] mStringIdArray;

        public Builder(int[] iArr, int i) {
            mStringIdArray = iArr;
            mCurrentPosition = i;
        }

        public ListAdapter build(Context context) {
            return new ModeListAdapter(context, mStringIdArray, mCurrentPosition);
        }
    }
}
