package epson.scan.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import epson.common.Constants;
import epson.common.CustomListRow;
import epson.common.CustomListRowAdapter;
import epson.common.CustomListRowImpl;
import epson.print.ActivityIACommon;
import epson.print.R;
import epson.print.Util.EPLog;

public class ScanSettingsAdvanceDetailActivity extends ActivityIACommon {
    private static final String SCAN_SETTINGS_LAST_VALUE = "SCAN_SETTINGS_LAST_VALUE";
    private List<CustomListRow> items;
    private int lastAdfRotate;
    private int lastValue;
    private LinkedHashMap<String, Integer> lhmListOptionValue;
    private ListView listSelect;
    private ListView listSelect2;
    private AdapterView.OnItemClickListener mListOptionClick = new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            if (view.getTag() instanceof ScanSettingsDetailAdapter.DetailSettingHolder) {
                ScanSettingsDetailAdapter.DetailSettingHolder detailSettingHolder = (ScanSettingsDetailAdapter.DetailSettingHolder) view.getTag();
                Intent intent = ScanSettingsAdvanceDetailActivity.this.getIntent();
                int access$000 = ScanSettingsAdvanceDetailActivity.this.screenId;
                if (access$000 == R.string.str_settings_2sided_title) {
                    int unused = ScanSettingsAdvanceDetailActivity.this.lastValue = detailSettingHolder.value;
                    String unused2 = ScanSettingsAdvanceDetailActivity.this.strSelText = detailSettingHolder.text.getText().toString();
                    ScanSettingsAdvanceDetailActivity.this.ssdAdapter.setSelected(ScanSettingsAdvanceDetailActivity.this.lastValue);
                    ScanSettingsAdvanceDetailActivity.this.ssdAdapter.notifyDataSetChanged();
                    if (ScanSettingsAdvanceDetailActivity.this.lastValue == 1) {
                        ScanSettingsAdvanceDetailActivity.this.listSelect2.setVisibility(View.VISIBLE);
                    } else {
                        ScanSettingsAdvanceDetailActivity.this.listSelect2.setVisibility(View.GONE);
                    }
                } else if (access$000 == R.string.str_settings_gamma_title) {
                    intent.putExtra(Constants.SCAN_REFS_SETTINGS_GAMMA, detailSettingHolder.value);
                    intent.putExtra(Constants.SCAN_REFS_SETTINGS_GAMMA_NAME, detailSettingHolder.text.getText().toString());
                    ScanSettingsAdvanceDetailActivity.this.setResult(-1, intent);
                    ScanSettingsAdvanceDetailActivity.this.finish();
                }
            }
        }
    };
    private AdapterView.OnItemClickListener mListOptionClick2 = new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            EPLog.i("mListOptionClick2", "[position]" + i);
            EPLog.i("mListOptionClick2", "[id]" + j);
            int unused = ScanSettingsAdvanceDetailActivity.this.lastAdfRotate = i;
            switch (i) {
                case 0:
                    ScanSettingsAdvanceDetailActivity.mlAdapter.setList(0, CustomListRowImpl.create().addText("").prefixImage(Integer.valueOf(R.drawable.scan_counter_direction)).suffixImage(Integer.valueOf(R.drawable.selected)));
                    ScanSettingsAdvanceDetailActivity.mlAdapter.setList(1, CustomListRowImpl.create().addText("").prefixImage(Integer.valueOf(R.drawable.scan_same_direction)));
                    break;
                case 1:
                    ScanSettingsAdvanceDetailActivity.mlAdapter.setList(0, CustomListRowImpl.create().addText("").prefixImage(Integer.valueOf(R.drawable.scan_counter_direction)));
                    ScanSettingsAdvanceDetailActivity.mlAdapter.setList(1, CustomListRowImpl.create().addText("").prefixImage(Integer.valueOf(R.drawable.scan_same_direction)).suffixImage(Integer.valueOf(R.drawable.selected)));
                    break;
            }
            ScanSettingsAdvanceDetailActivity.mlAdapter.notifyDataSetChanged();
        }
    };
    private CustomListRowAdapter mlAdapter;
    private int screenId;
    private String screenTitle;
    private ScanSettingsDetailAdapter ssdAdapter;
    private String strSelText;
    private int supportedAdfDuplex;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.scan_settings_detail_2);
        Bundle extras = getIntent().getExtras();
        screenId = extras.getInt(Constants.SCAN_SETTINGS_DETAIL_TITLE);
        lastValue = extras.getInt(SCAN_SETTINGS_LAST_VALUE);
        supportedAdfDuplex = extras.getInt(Constants.SCAN_REFS_OPTIONS_SUPPORTED_ADF_DUPLEX);
        lastAdfRotate = extras.getInt(Constants.SCAN_REFS_SETTINGS_ROTATE);
        listSelect = (ListView) findViewById(R.id.lvScannerSettingOptions);
        listSelect2 = (ListView) findViewById(R.id.lvScannerSettingOptions2);
        getListCorespondenceOptions(this.screenId);
        setListCorespondenceOptions(this.screenId);
        setActionBar(getTitle().toString(), true);
    }

    private void getListCorespondenceOptions(int i) {
        items = new ArrayList();
        lhmListOptionValue = new LinkedHashMap<>();
        if (i == R.string.str_settings_2sided_title) {
            screenTitle = getString(R.string.str_settings_2sided_title);
            if (this.supportedAdfDuplex == 1) {
                lhmListOptionValue.put(getString(R.string.str_yes), 1);
            }
            lhmListOptionValue.put(getString(R.string.str_no), 0);
            switch (this.lastAdfRotate) {
                case 0:
                    items.add(CustomListRowImpl.create().addText(" ").prefixImage(Integer.valueOf(R.drawable.scan_counter_direction)).suffixImage(Integer.valueOf(R.drawable.selected)));
                    items.add(CustomListRowImpl.create().addText("").prefixImage(Integer.valueOf(R.drawable.scan_same_direction)));
                    return;
                case 1:
                    items.add(CustomListRowImpl.create().addText(" ").prefixImage(Integer.valueOf(R.drawable.scan_counter_direction)));
                    items.add(CustomListRowImpl.create().addText("").prefixImage(Integer.valueOf(R.drawable.scan_same_direction)).suffixImage(Integer.valueOf(R.drawable.selected)));
                    return;
                default:
                    return;
            }
        } else if (i == R.string.str_settings_gamma_title) {
            screenTitle = getString(R.string.str_settings_gamma_title);
            lhmListOptionValue.put(getString(R.string.str_settings_gamma_10), 0);
            lhmListOptionValue.put(getString(R.string.str_settings_gamma_18), 1);
        }
    }

    private void setListCorespondenceOptions(int i) {
        setTitle(this.screenTitle);
        if (i == R.string.str_settings_2sided_title) {
            mlAdapter = new CustomListRowAdapter(this, R.layout.com_customline_row, items);
            listSelect2.setAdapter(mlAdapter);
            listSelect2.setOnItemClickListener(mListOptionClick2);
            if (this.lastValue == 1) {
                listSelect2.setVisibility(View.VISIBLE);
            } else {
                listSelect2.setVisibility(View.GONE);
            }
        }
        ssdAdapter = new ScanSettingsDetailAdapter(getBaseContext(), lhmListOptionValue, lastValue);
        listSelect.setAdapter(this.ssdAdapter);
        listSelect.setOnItemClickListener(mListOptionClick);
    }

    public void onBackPressed() {
        Intent intent = getIntent();
        int i = screenId;
        if (i == R.string.str_settings_2sided_title) {
            if (this.lastValue == 1) {
                strSelText = getString(R.string.str_yes);
            } else {
                strSelText = getString(R.string.str_no);
            }
            intent.putExtra(Constants.SCAN_REFS_SETTINGS_2SIDED, lastValue);
            intent.putExtra(Constants.SCAN_REFS_SETTINGS_2SIDED_NAME, strSelText);
            intent.putExtra(Constants.SCAN_REFS_SETTINGS_ROTATE, lastAdfRotate);
            setResult(-1, intent);
        } else if (i == R.string.str_settings_gamma_title) {
            setResult(0, intent);
        }
        finish();
        super.onBackPressed();
    }
}
