package epson.scan.lib;

import android.content.Context;


import epson.common.Constants;
import epson.common.Utils;
import epson.print.CommonDefine;

public class ScanInfoStorage {
    private static final String PREFS_KEY_ESC_I_VERSION = "esc/i-version";
    private static ScanInfoStorage sScanInfoStorage;

    public static ScanInfoStorage getInstance() {
        if (sScanInfoStorage == null) {
            sScanInfoStorage = new ScanInfoStorage();
        }
        return sScanInfoStorage;
    }

    @VisibleForTesting
    protected static void setInstance(ScanInfoStorage scanInfoStorage) {
        sScanInfoStorage = scanInfoStorage;
    }

    static void saveSettings(Context context, ScannerInfo scannerInfo) {
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_SOURCE, scannerInfo.getSourceValue());
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_CHOSEN_SIZE, scannerInfo.getSizeValue());
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_COLOR, scannerInfo.getColorValue());
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_RESOLUTION, scannerInfo.getResolutionValue());
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_2SIDED, scannerInfo.getTwoSidedScanningValue());
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_DENSITY, scannerInfo.getDensityValue());
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_DENSITY_STATUS, scannerInfo.isDensityStatus());
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_GAMMA, scannerInfo.getGammaValue());
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_ROTATE, scannerInfo.isAdfDuplexRotaitonYes());
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_ADF_PAPER_GUIDE, scannerInfo.getAdfPaperGuide());
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, CommonDefine.RE_SEARCH, true);
    }

    static void saveSelectedScannerSupportedOptions(Context context, int[] iArr) {
        Utils.savePref(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_VERSION, iArr[0]);
        Utils.savePref(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_BASIC_RESOLUTION, iArr[1]);
        Utils.savePref(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_WIDTH, iArr[2]);
        Utils.savePref(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_HEIGHT, iArr[3]);
        Utils.savePref(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_ADF_WIDTH, iArr[4]);
        Utils.savePref(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_ADF_HEIGHT, iArr[5]);
        Utils.savePref(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_SUPPORTED_ADF_DUPLEX, iArr[6]);
    }

    public static void saveScannerConnectivityInfo(Context context, String str, String str2, String str3, int i) {
        getInstance().saveScannerConnectivityInfoNonStatic(context, str, str2, str3, i);
    }

    protected void saveScannerConnectivityInfoNonStatic(Context context, String str, String str2, String str3, int i) {
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_MODEL, str);
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_IP, str2);
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_ID, str3);
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_LOCATION, i);
    }

    public void loadScannerConnectivityInfo(Context context, ScannerInfo scannerInfo) {
        scannerInfo.setScannerId(Utils.getPrefString(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_ID));
        scannerInfo.setModelName(Utils.getPrefString(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_MODEL));
        scannerInfo.setIp(Utils.getPrefString(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_IP));
        scannerInfo.setLocation(Utils.getPrefInt(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_LOCATION));
    }

    public void loadScanSetting(Context context, ScannerInfo scannerInfo) {
        scannerInfo.setSupportedAdfDuplex(Utils.getPrefInt(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_SUPPORTED_ADF_DUPLEX));
        scannerInfo.setTwoSidedScanningValue(Utils.getPrefInt(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_2SIDED));
        scannerInfo.setDensityValue(Utils.getPrefInt(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_DENSITY));
        scannerInfo.setDensityStatus(Utils.getPrefBoolean(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_DENSITY_STATUS));
        scannerInfo.setGammaValue(Utils.getPrefInt(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_GAMMA));
        scannerInfo.setAdfDuplexRotaitonYes(Utils.getPrefBoolean(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_ROTATE));
        scannerInfo.setAdfPaperGuide(Utils.getPrefInt(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_ADF_PAPER_GUIDE));
    }

    public void loadSupportedValue(Context context, ScannerInfo scannerInfo) {
        scannerInfo.setSupportedBasicResolution(Utils.getPrefInt(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_BASIC_RESOLUTION));
        scannerInfo.setSupportedBasicWidth(Utils.getPrefInt(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_WIDTH));
        scannerInfo.setSupportedBasicHeight(Utils.getPrefInt(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_HEIGHT));
        scannerInfo.setSupportedAdfWidth(Utils.getPrefInt(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_ADF_WIDTH));
        scannerInfo.setSupportedAdfHeight(Utils.getPrefInt(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_ADF_HEIGHT));
    }

    public void loadSupportedAdfSize(Context context, ScannerInfo scannerInfo) {
        scannerInfo.setSupportedAdfWidth(Utils.getPrefInt(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_ADF_WIDTH));
        scannerInfo.setSupportedAdfHeight(Utils.getPrefInt(context, Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_OPTIONS_ADF_HEIGHT));
    }

    public void loadColorValue(Context context, ScannerInfo scannerInfo) {
        scannerInfo.setColorValue(Utils.getPrefInt(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_COLOR));
    }

    public void loadResolution(Context context, ScannerInfo scannerInfo) {
        scannerInfo.setResolutionValue(Utils.getPrefInt(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_RESOLUTION));
    }

    public void loadReadUnitValue(Context context, ScannerInfo scannerInfo) {
        scannerInfo.setSourceValue(Utils.getPrefInt(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_SOURCE));
    }

    public int getScanSourceUnit(Context context, int i) {
        return context.getSharedPreferences(Constants.SCAN_REFS_USED_SCANNER_PATH, 0).getInt(Constants.SCAN_REFS_SETTINGS_SOURCE, i);
    }

    public int getScanSourceUnit(Context context) {
        return getScanSourceUnit(context, 1);
    }

    public int getTwoSideValue(Context context) {
        return Utils.getPrefInt(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_2SIDED);
    }

    public void saveEscIVersionNonStatic(Context context, int i) {
        Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, PREFS_KEY_ESC_I_VERSION, i);
    }

    public int loadEscIVersionNonStatic(Context context) {
        return context.getSharedPreferences(Constants.SCAN_REFS_USED_SCANNER_PATH, 0).getInt(PREFS_KEY_ESC_I_VERSION, 1);
    }

    public static void saveEscIVersion(Context context, int i) {
        getInstance().saveEscIVersionNonStatic(context, i);
    }

    public static int loadEscIVersion(Context context) {
        return getInstance().loadEscIVersionNonStatic(context);
    }
}
