package epson.scan.activity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import epson.print.R;
import java.util.ArrayList;

public class ScanContinueParam {
    public static final int SCAN_ADF_MAX_PAGES_LIMIT = 50;
    public static final int SCAN_CONTINUE_MAX_PAGES_LIMIT = 300;
    private static boolean mIsContinueScanning;
    private static boolean mIsNeedShowErrorLimit;
    private static int mScannedFileCount;

    public interface ScanContinueDialogButtonClick {
        void onRequestScanAction();
    }

    public static void showScanErrorLimit(Context context) {
        if (mIsNeedShowErrorLimit) {
            ScanContinueDialogButtonClick scanContinueDialogButtonClick = (ScanContinueDialogButtonClick) context;
            AlertDialog.Builder message = new AlertDialog.Builder(context).setMessage(R.string.scan_alert_upper_limit_message);
            message.setPositiveButton(R.string.str_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            AlertDialog create = message.create();
            create.setCancelable(false);
            create.show();
        }
    }

    public static void judgeScanContinue(Context context, ArrayList<String> arrayList) {
        final ScanContinueDialogButtonClick scanContinueDialogButtonClick = (ScanContinueDialogButtonClick) context;
        if (!arrayList.isEmpty()) {
            View inflate = LayoutInflater.from(context).inflate(R.layout.dialog_scan_continue_confirmation, (ViewGroup) null);
            AlertDialog.Builder view = new AlertDialog.Builder(context).setView(inflate);
            TextView textView = (TextView) inflate.findViewById(R.id.scanContinue_title_tv);
            TextView textView2 = (TextView) inflate.findViewById(R.id.scanContinue_msg_tv);
            if (!isReachMaximumScan()) {
                textView.setVisibility(0);
                textView.setText(R.string.scan_dialog_title);
                textView2.setText(R.string.scan_dialog_message);
                view.setPositiveButton(R.string.scan_dialog_button_continue, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        ScanContinueParam.setContinueScanningFlag(true);
                        scanContinueDialogButtonClick.onRequestScanAction();
                    }
                });
            } else {
                textView.setVisibility(8);
                textView2.setText(R.string.scan_alert_and_scan_message);
            }
            view.setNeutralButton(R.string.scan_dialog_button_cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            }).setNegativeButton(R.string.scan_dialog_button_overwrite, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    ScanContinueParam.setContinueScanningFlag(false);
                    scanContinueDialogButtonClick.onRequestScanAction();
                }
            });
            AlertDialog create = view.create();
            create.setCanceledOnTouchOutside(false);
            create.setOnShowListener($$Lambda$ScanContinueParam$O5_W7A8WVuIPQG0HgQ75RE2hUc.INSTANCE);
            create.show();
            return;
        }
        setContinueScanningFlag(false);
        scanContinueDialogButtonClick.onRequestScanAction();
    }

    static /* synthetic */ void lambda$judgeScanContinue$0(DialogInterface dialogInterface) {
        AlertDialog alertDialog = (AlertDialog) dialogInterface;
        alertDialog.getButton(-1).setAllCaps(false);
        alertDialog.getButton(-2).setAllCaps(false);
        alertDialog.getButton(-3).setAllCaps(false);
    }

    public static void setContinueScanningFlag(boolean z) {
        mIsContinueScanning = z;
    }

    public static boolean isContinueScanning() {
        return mIsContinueScanning;
    }

    public static void resetParameter() {
        mIsContinueScanning = false;
        mScannedFileCount = 0;
    }

    public static void setScannedFileCount(int i) {
        mScannedFileCount = i;
    }

    public static int getAvailableScanPageCount() {
        int i = 300 - mScannedFileCount;
        if (i <= 0) {
            i = 1;
        }
        if (!mIsContinueScanning) {
            i = 50;
        }
        setIsNeedShowErrorLimitFlag(i);
        if (i >= 50) {
            return 50;
        }
        return i;
    }

    public static void setIsNeedShowErrorLimitFlag(int i) {
        mIsNeedShowErrorLimit = i < 50;
    }

    public static boolean isReachMaximumScan() {
        return mScannedFileCount >= 300;
    }
}
