package epson.print;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Parcel;
import android.os.Parcelable;


import epson.common.Constants;
import epson.provider.SharedPreferencesProvider;

public class MyPrinter implements Parcelable {
    public static final Creator<MyPrinter> CREATOR = new Creator<MyPrinter>() {
        public MyPrinter createFromParcel(Parcel parcel) {
            return new MyPrinter(parcel);
        }

        public MyPrinter[] newArray(int i) {
            return new MyPrinter[i];
        }
    };
    public static final int PRINTER_IP = 3;
    public static final int PRINTER_LOCAL = 1;
    public static final int PRINTER_REMOTE = 2;
    public static final int PRINTER_UNKNOWN = 0;
    public static final String PRINTER_USB = "USB";
    private String mCommonDeviceName;
    private String mEmailAddress;
    private String mIp;
    private int mLang;
    private int mLocation;
    private String mName;
    private String mPrinterId;
    private int mPrinterIndex;
    private String mScannerId;
    private String mSerialNo;

    public int describeContents() {
        return 0;
    }

    private MyPrinter() {
        this.mName = null;
        this.mIp = null;
        this.mPrinterId = null;
        this.mScannerId = null;
        this.mSerialNo = null;
        this.mEmailAddress = null;
        this.mLocation = 0;
        this.mLang = 1;
        this.mCommonDeviceName = null;
        this.mPrinterIndex = -1;
    }

    public MyPrinter(String str, String str2, String str3, String str4) {
        this.mName = null;
        this.mIp = null;
        this.mPrinterId = null;
        this.mScannerId = null;
        this.mSerialNo = null;
        this.mEmailAddress = null;
        this.mLocation = 0;
        this.mLang = 1;
        this.mCommonDeviceName = null;
        this.mPrinterIndex = -1;
        this.mName = str;
        this.mIp = str2;
        this.mPrinterId = str3;
        this.mSerialNo = str4;
        this.mLocation = 1;
    }

    public MyPrinter(String str, String str2, String str3, String str4, String str5) {
        this.mName = null;
        this.mIp = null;
        this.mPrinterId = null;
        this.mScannerId = null;
        this.mSerialNo = null;
        this.mEmailAddress = null;
        this.mLocation = 0;
        this.mLang = 1;
        this.mCommonDeviceName = null;
        this.mPrinterIndex = -1;
        this.mName = str;
        this.mIp = str2;
        this.mPrinterId = str3;
        this.mSerialNo = str4;
        this.mEmailAddress = str5;
        this.mLocation = 2;
    }

    public MyPrinter(String str, String str2, String str3, String str4, String str5, int i) {
        this.mName = null;
        this.mIp = null;
        this.mPrinterId = null;
        this.mScannerId = null;
        this.mSerialNo = null;
        this.mEmailAddress = null;
        this.mLocation = 0;
        this.mLang = 1;
        this.mCommonDeviceName = null;
        this.mPrinterIndex = -1;
        this.mName = str;
        this.mIp = str2;
        this.mPrinterId = str3;
        this.mSerialNo = str4;
        this.mEmailAddress = str5;
        this.mLocation = i;
    }

    public String getName() {
        return this.mName;
    }

    public String getIp() {
        return this.mIp;
    }

    public void setIp(String str) {
        this.mIp = str;
    }

    public String getPrinterId() {
        return this.mPrinterId;
    }

    public String getSerialNo() {
        return this.mSerialNo;
    }

    public String getEmailAddress() {
        return this.mEmailAddress;
    }

    public int getLocation() {
        return this.mLocation;
    }

    public void setLocation(int i) {
        this.mLocation = i;
    }

    public String getCommonDeviceName() {
        return this.mCommonDeviceName;
    }

    public void setCommonDeviceName(String str) {
        this.mCommonDeviceName = str;
    }

    public int getPrinterIndex() {
        return this.mPrinterIndex;
    }

    public void setPrinterIndex(int i) {
        this.mPrinterIndex = i;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:4:0x000a, code lost:
        r2 = new epson.print.EPPrinterManager(r2).loadRemotePrinterInfo(getEmailAddress());
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public String getRemotePrinterAccessKey(Context r2) {
        /*
            r1 = this;
            java.lang.String r0 = r1.mEmailAddress
            if (r0 == 0) goto L_0x001c
            int r0 = r0.length()
            if (r0 <= 0) goto L_0x001c
            epson.print.EPPrinterManager r0 = new epson.print.EPPrinterManager
            r0.<init>(r2)
            java.lang.String r2 = r1.getEmailAddress()
            epson.print.EPPrinterInfo r2 = r0.loadRemotePrinterInfo(r2)
            if (r2 == 0) goto L_0x001c
            java.lang.String r2 = r2.printerAccessKey
            return r2
        L_0x001c:
            java.lang.String r2 = ""
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.print.MyPrinter.getRemotePrinterAccessKey(android.content.Context):java.lang.String");
    }

    public String getUserDefName(Context context) {
        EPPrinterInfo loadRemotePrinterInfo;
        EPPrinterInfo loadIpPrinterInfo;
        EPPrinterManager ePPrinterManager = new EPPrinterManager(context);
        switch (this.mLocation) {
            case 2:
                if (!(getEmailAddress() == null || getEmailAddress().length() <= 0 || (loadRemotePrinterInfo = ePPrinterManager.loadRemotePrinterInfo(getEmailAddress())) == null || loadRemotePrinterInfo.userDefName == null || loadRemotePrinterInfo.userDefName.length() <= 0)) {
                    return loadRemotePrinterInfo.userDefName;
                }
            case 3:
                if (!(getPrinterId() == null || getPrinterId().length() <= 0 || (loadIpPrinterInfo = ePPrinterManager.loadIpPrinterInfo(getPrinterId())) == null || loadIpPrinterInfo.userDefName == null || loadIpPrinterInfo.userDefName.length() <= 0)) {
                    return loadIpPrinterInfo.userDefName;
                }
        }
        return this.mName;
    }

    public String getScannerId() {
        return this.mScannerId;
    }

    public void setScannerId(String str) {
        this.mScannerId = str;
    }

    public int getLang() {
        return this.mLang;
    }

    public void setLang(int i) {
        this.mLang = i;
    }

    private MyPrinter(Parcel parcel) {
        this.mName = null;
        this.mIp = null;
        this.mPrinterId = null;
        this.mScannerId = null;
        this.mSerialNo = null;
        this.mEmailAddress = null;
        this.mLocation = 0;
        this.mLang = 1;
        this.mCommonDeviceName = null;
        this.mPrinterIndex = -1;
        this.mName = parcel.readString();
        this.mIp = parcel.readString();
        this.mPrinterId = parcel.readString();
        this.mSerialNo = parcel.readString();
        this.mEmailAddress = parcel.readString();
        this.mLocation = parcel.readInt();
        this.mScannerId = parcel.readString();
        this.mLang = parcel.readInt();
        this.mPrinterIndex = parcel.readInt();
    }

    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(this.mName);
        parcel.writeString(this.mIp);
        parcel.writeString(this.mPrinterId);
        parcel.writeString(this.mSerialNo);
        parcel.writeString(this.mEmailAddress);
        parcel.writeInt(this.mLocation);
        parcel.writeString(this.mScannerId);
        parcel.writeInt(this.mLang);
        parcel.writeInt(this.mPrinterIndex);
    }

    public static MyPrinter getCurPrinter(Context context) {
        MyPrinter myPrinter = new MyPrinter();
        SharedPreferencesProvider.SharedPreferencesMulti instace = SharedPreferencesProvider.getInstace(context);
        myPrinter.mName = instace.getString(Constants.PRINTER_NAME, (String) null);
        myPrinter.mPrinterId = instace.getString(Constants.PRINTER_ID, (String) null);
        myPrinter.mIp = instace.getString(Constants.PRINTER_IP, (String) null);
        myPrinter.mSerialNo = instace.getString(Constants.PRINTER_SERIAL_NO, (String) null);
        myPrinter.mEmailAddress = instace.getString(Constants.PRINTER_EMAIL_ADDRESS, (String) null);
        myPrinter.mLocation = instace.getInt(Constants.PRINTER_LOCATION, 0);
        myPrinter.mLang = instace.getInt(Constants.LANG, 1);
        return myPrinter;
    }

    public void setCurPrinter(Context context) {
        SharedPreferences.Editor edit = context.getSharedPreferences("PrintSetting", 0).edit();
        edit.putString(Constants.PRINTER_NAME, getName());
        edit.putString(Constants.PRINTER_IP, getIp());
        edit.putString(Constants.PRINTER_ID, getPrinterId());
        edit.putString(Constants.PRINTER_SERIAL_NO, getSerialNo());
        edit.putString(Constants.PRINTER_EMAIL_ADDRESS, getEmailAddress());
        edit.putInt(Constants.PRINTER_LOCATION, getLocation());
        edit.putInt(Constants.LANG, getLang());
        edit.remove("PRINTER_ACCESS_KEY");
        edit.commit();
    }

    public static void clearCurPrinter(Context context) {
        SharedPreferences.Editor edit = context.getSharedPreferences("PrintSetting", 0).edit();
        edit.remove(Constants.PRINTER_NAME);
        edit.remove(Constants.PRINTER_IP);
        edit.remove(Constants.PRINTER_ID);
        edit.remove(Constants.PRINTER_SERIAL_NO);
        edit.remove(Constants.PRINTER_EMAIL_ADDRESS);
        edit.remove(Constants.PRINTER_LOCATION);
        edit.remove(Constants.LANG);
        edit.remove("PRINTER_ACCESS_KEY");
        edit.commit();
    }

    public static int getCurrectLocation(Context context) {
        return getCurPrinter(context).getLocation();
    }

    public static boolean isRemotePrinter(Context context) {
        return getCurrectLocation(context) == 2;
    }

    public static String getPrinterDeviceId(Context context, boolean z) {
        MyPrinter curPrinter = getCurPrinter(context);
        String name = curPrinter.getName();
        return (curPrinter.getLocation() != 2 || !z) ? name : getRemotePrinterDeviceIdFromServer(context, curPrinter.getEmailAddress());
    }

    /* JADX WARNING: Code restructure failed: missing block: B:3:0x0009, code lost:
        r7 = epson.print.ecclient.EpsonConnectAccess.getPrinterInfo(r7, r8, new epson.print.MyPrinter((java.lang.String) null, (java.lang.String) null, (java.lang.String) null, (java.lang.String) null, r8).getRemotePrinterAccessKey(r7));
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    static String getRemotePrinterDeviceIdFromServer(Context r7, String r8) {
        /*
            if (r8 == 0) goto L_0x0029
            int r0 = r8.length()
            if (r0 > 0) goto L_0x0009
            goto L_0x0029
        L_0x0009:
            epson.print.MyPrinter r0 = new epson.print.MyPrinter
            r2 = 0
            r3 = 0
            r4 = 0
            r5 = 0
            r1 = r0
            r6 = r8
            r1.<init>(r2, r3, r4, r5, r6)
            java.lang.String r0 = r0.getRemotePrinterAccessKey(r7)
            epson.print.ecclient.EpsonConnectAccess$RemotePrinterInfo r7 = epson.print.ecclient.EpsonConnectAccess.getPrinterInfo(r7, r8, r0)
            if (r7 == 0) goto L_0x0026
            java.lang.String r8 = r7.mDeviceId
            if (r8 != 0) goto L_0x0023
            goto L_0x0026
        L_0x0023:
            java.lang.String r7 = r7.mDeviceId
            return r7
        L_0x0026:
            java.lang.String r7 = ""
            return r7
        L_0x0029:
            java.lang.String r7 = ""
            return r7
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.print.MyPrinter.getRemotePrinterDeviceIdFromServer(android.content.Context, java.lang.String):java.lang.String");
    }

    public static boolean isPrinterRouteOtg(@NonNull Context context) {
        return PRINTER_USB.equals(getCurPrinter(context).getIp());
    }
}
