package epson.scan.activity;

import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
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.C2135R;

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) {
        this.mLayoutInflater = LayoutInflater.from(context);
        this.mStringIdArray = iArr;
        this.mCurrentPosition = i;
        this.mLeftImageId = null;
    }

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

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

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

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

    public int getPosition() {
        return this.mCurrentPosition;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        int i2 = 0;
        if (view == null) {
            view = this.mLayoutInflater.inflate(C2135R.layout.i2_scan_setting_item, viewGroup, false);
        }
        if (this.mLeftImageId != null) {
            ImageView imageView = (ImageView) view.findViewById(C2135R.C2137id.leftImageView);
            imageView.setImageResource(this.mLeftImageId[i]);
            imageView.setVisibility(0);
        }
        if (this.mStringIdArray[0] != 0) {
            ((TextView) view.findViewById(C2135R.C2137id.tvSettingName)).setText(this.mStringIdArray[i]);
        }
        ImageView imageView2 = (ImageView) view.findViewById(C2135R.C2137id.ivSettingSelected);
        if (i != this.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) {
            this.mStringIdArray = iArr;
            this.mCurrentPosition = i;
        }

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