package com.epson.cameracopy.p006ui;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.p000v4.app.DialogFragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.epson.cameracopy.printlayout.DocumentSizeInfo;
import com.epson.cameracopy.printlayout.RegistedDocumentSizeList;
import epson.print.ActivityIACommon;

import java.util.Locale;

/* renamed from: com.epson.cameracopy.ui.DocumentSizeSettingActivity */
public class DocumentSizeSettingActivity extends ActivityIACommon implements View.OnClickListener {
    private int ID_DIALOG_DELETE = 1;
    private int ID_DIALOG_RESET = 2;
    private Button mAdd;
    private Button mClear;
    private Button mDelete;
    private Button mEdit;
    private ListView mListView;
    private Button mSelect;
    SelectListAdapter mSelectListAdapter;
    private int mSelectPos;

    public void doNegativeClick(int i) {
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_document_size_setting);
        setActionBar((int) R.string.document_size_title, true);
        mListView = (ListView) findViewById(R.id.docsize_list);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                DocumentSizeSettingActivity documentSizeSettingActivity = DocumentSizeSettingActivity.this;
                documentSizeSettingActivity.onSelectDocsizeList(documentSizeSettingActivity.mSelectListAdapter.getItem(i), view, i);
            }
        });
        mSelectListAdapter = new SelectListAdapter();
        mListView.setAdapter(mSelectListAdapter);
        mSelect = (Button) findViewById(R.id.select_button);
        mSelect.setOnClickListener(this);
        mEdit = (Button) findViewById(R.id.edit_button);
        mEdit.setOnClickListener(this);
        mDelete = (Button) findViewById(R.id.delete_button);
        mDelete.setOnClickListener(this);
        mAdd = (Button) findViewById(R.id.add_button);
        mAdd.setOnClickListener(this);
        mClear = (Button) findViewById(R.id.clear_button);
        mClear.setOnClickListener(this);
    }

    protected void onStart() {
        super.onStart();
        mSelectListAdapter.reload();
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.add_button /*2131230807*/:
                addNewDocumentSize();
                break;
            case R.id.clear_button /*2131230914*/:
                resetDocumentSizeList();
                break;
            case R.id.delete_button /*2131230979*/:
                deleteDocumentSize();
                break;
            case R.id.edit_button /*2131231009*/:
                editDocumentSize(mSelectPos);
                break;
            case R.id.select_button /*2131231472*/:
                selectDocumentSize(mSelectPos);
                break;
        }
        findViewById(R.id.document_size_menu).setVisibility(4);
    }

    public void onSelectDocsizeList(Object obj, View view, int i) {
        mSelectPos = i;
        if (findViewById(R.id.document_size_menu).getVisibility() != 0) {
            DocumentSizeInfo documentSizeInfo = (DocumentSizeInfo) obj;
            ((TextView) findViewById(R.id.menu_text)).setText(documentSizeInfo.getDocSizeName(this));
            boolean z = true;
            mEdit.setEnabled(documentSizeInfo.getPaperId() == -2);
            if (documentSizeInfo.getPaperId() == -1) {
                z = false;
            }
            mDelete.setEnabled(z);
            findViewById(R.id.document_size_menu).setVisibility(0);
            return;
        }
        findViewById(R.id.document_size_menu).setVisibility(4);
    }

    private void addNewDocumentSize() {
        DocumentSizeInfo documentSizeInfo = new DocumentSizeInfo();
        String country = Locale.getDefault().getCountry();
        if (country.equals(Locale.US.getCountry()) || country.equals(Locale.CANADA.getCountry())) {
            documentSizeInfo.setDocSizeName(getString(R.string.new_document_size));
            documentSizeInfo.setScaleId(2);
            documentSizeInfo.setWidth(8.5d);
            documentSizeInfo.setHeight(11.0d);
            documentSizeInfo.setPaperId(-2);
            documentSizeInfo.setDocSizeNameId(0);
        } else {
            documentSizeInfo.setDocSizeName(getString(R.string.new_document_size));
            documentSizeInfo.setScaleId(1);
            documentSizeInfo.setWidth(210.0d);
            documentSizeInfo.setHeight(297.0d);
            documentSizeInfo.setPaperId(-2);
            documentSizeInfo.setDocSizeNameId(0);
        }
        Intent intent = new Intent(this, DocumentSizeEditActivity.class);
        intent.putExtra("DocumentSize", documentSizeInfo);
        intent.putExtra("DocumentSizePos", -1);
        startActivity(intent);
    }

    private void selectDocumentSize(int i) {
        mSelectListAdapter.select(i);
        finish();
    }

    private void editDocumentSize(int i) {
        Intent intent = new Intent(this, DocumentSizeEditActivity.class);
        intent.putExtra("DocumentSize", (DocumentSizeInfo) mSelectListAdapter.getItem(i));
        intent.putExtra("DocumentSizePos", i);
        startActivity(intent);
    }

    private void deleteDocumentSize() {
        Bundle bundle = new Bundle();
        bundle.putString("message", getString(R.string.delete_documentsize_message));
        bundle.putInt("id", ID_DIALOG_DELETE);
        NotifyDialogFragment notifyDialogFragment = new NotifyDialogFragment();
        notifyDialogFragment.setArguments(bundle);
        notifyDialogFragment.show(getSupportFragmentManager(), "notify-dialog");
    }

    private void resetDocumentSizeList() {
        Bundle bundle = new Bundle();
        bundle.putString("message", getString(R.string.reset_documentsize_message));
        bundle.putInt("id", ID_DIALOG_RESET);
        NotifyDialogFragment notifyDialogFragment = new NotifyDialogFragment();
        notifyDialogFragment.setArguments(bundle);
        notifyDialogFragment.show(getSupportFragmentManager(), "notify-dialog");
    }

    /* renamed from: com.epson.cameracopy.ui.DocumentSizeSettingActivity$SelectListAdapter */
    class SelectListAdapter extends BaseAdapter {
        RegistedDocumentSizeList mRegistedDocumentSizeList;

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

        public SelectListAdapter() {
            reload();
        }

        public void reload() {
            mRegistedDocumentSizeList = RegistedDocumentSizeList.getInstance(DocumentSizeSettingActivity.this);
            notifyDataSetChanged();
        }

        public void select(int i) {
            mRegistedDocumentSizeList.select(i);
            notifyDataSetChanged();
        }

        public int getCount() {
            RegistedDocumentSizeList registedDocumentSizeList = mRegistedDocumentSizeList;
            if (registedDocumentSizeList == null) {
                return 0;
            }
            return registedDocumentSizeList.size();
        }

        public Object getItem(int i) {
            RegistedDocumentSizeList registedDocumentSizeList = mRegistedDocumentSizeList;
            if (registedDocumentSizeList == null) {
                return null;
            }
            return registedDocumentSizeList.getItem(i);
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            if (view == null) {
                view = DocumentSizeSettingActivity.this.getLayoutInflater().inflate(R.layout.select_list_row, viewGroup, false);
            }
            RegistedDocumentSizeList registedDocumentSizeList = mRegistedDocumentSizeList;
            if (registedDocumentSizeList == null) {
                return view;
            }
            DocumentSizeInfo item = registedDocumentSizeList.getItem(i);
            ((TextView) view.findViewById(R.id.docsize_name)).setText(item.getDocSizeName(DocumentSizeSettingActivity.this));
            ImageView imageView = (ImageView) view.findViewById(R.id.current_docsize_image);
            if (mRegistedDocumentSizeList.isSelected(item)) {
                imageView.setVisibility(0);
            } else {
                imageView.setVisibility(4);
            }
            return view;
        }

        public void delete(DocumentSizeInfo documentSizeInfo, int i) {
            mRegistedDocumentSizeList.delete(documentSizeInfo, i);
            notifyDataSetChanged();
        }

        public void reset() {
            mRegistedDocumentSizeList.reset();
            notifyDataSetChanged();
        }
    }

    /* renamed from: com.epson.cameracopy.ui.DocumentSizeSettingActivity$NotifyDialogFragment */
    public static class NotifyDialogFragment extends DialogFragment {
        public Dialog onCreateDialog(Bundle bundle) {
            super.onCreateDialog(bundle);
            String string = getArguments().getString("message");
            final int i = getArguments().getInt("id");
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage(string);
            builder.setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    ((DocumentSizeSettingActivity) NotifyDialogFragment.this.getActivity()).doPositiveClick(i);
                }
            });
            builder.setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    ((DocumentSizeSettingActivity) NotifyDialogFragment.this.getActivity()).doNegativeClick(i);
                }
            });
            AlertDialog create = builder.create();
            create.setCanceledOnTouchOutside(false);
            return create;
        }
    }

    public void doPositiveClick(int i) {
        if (i == ID_DIALOG_RESET) {
            mSelectListAdapter.reset();
        } else if (i == ID_DIALOG_DELETE) {
            mSelectListAdapter.delete((DocumentSizeInfo) mSelectListAdapter.getItem(mSelectPos), mSelectPos);
            mSelectPos--;
        }
    }
}
