package epson.print.rpcopy;

import android.content.Context;
import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
import epson.print.R;
import epson.print.CommonDefine;
import epson.print.rpcopy.ActivityBase;
import epson.print.rpcopy.Component.ecopycomponent.ECopyComponent;
import epson.print.rpcopy.Component.ecopycomponent.ECopyOptionItem;
import java.util.Iterator;

public class CopyProcess implements ECopyComponent.ICopyStatusListener {
    ActivityBase activityBase;
    ECopyComponent.ICopyCancelRequest cancelRequest;
    ECopyComponent copyComponent;
    boolean disconnectWifi;
    String jobToken;
    ActivityBase.errorDialog printererror;
    ActivityBase.WheelDialog wheel;

    public CopyProcess(ActivityBase activityBase2) {
        this(activityBase2, (String) null);
    }

    public CopyProcess(ActivityBase activityBase2, String str) {
        this.copyComponent = ECopyComponent.sharedComponent();
        this.disconnectWifi = false;
        this.activityBase = activityBase2;
        this.jobToken = str;
        ActivityBase activityBase3 = this.activityBase;
        activityBase3.getClass();
        this.wheel = new ActivityBase.WheelDialog(this.activityBase);
    }

    public void startCopy(Context context) {
        String str = this.jobToken;
        this.cancelRequest = str == null ? this.copyComponent.startCopy(this, context) : this.copyComponent.recoverCopy(str, this);
    }

    public void onStarted(ECopyComponent.ICopyStatusListener.CopyTaskType copyTaskType) {
        this.wheel.show(this.activityBase.getString(R.string.CopyTaskProgressCopying), new ActivityBase.CancelRequestCallback() {
            public void onCancelRequest() {
                CopyProcess.this.cancelRequest.cancel();
            }
        });
    }

    public void onProcessed(ECopyComponent.ICopyStatusListener.CopyTaskType copyTaskType, int i, int i2, ECopyComponent.ICopyStatusListener.CopyTaskProgress copyTaskProgress, final ECopyComponent.ICopyResumeRequest iCopyResumeRequest) {
        ActivityBase.errorDialog errordialog = this.printererror;
        if (errordialog != null) {
            errordialog.Cancel();
        }
        if (copyTaskProgress.equals(ECopyComponent.ICopyStatusListener.CopyTaskProgress.Copying) || copyTaskProgress.equals(ECopyComponent.ICopyStatusListener.CopyTaskProgress.Processing)) {
            ActivityBase.WheelDialog wheelDialog = this.wheel;
            wheelDialog.setText(this.activityBase.getString(R.string.CopyTaskProgressCopying) + " " + i2 + CommonDefine.SLASH + i);
        } else {
            this.wheel.setText("");
        }
        switch (copyTaskProgress) {
            case Stopped:
                ActivityBase activityBase2 = this.activityBase;
                activityBase2.getClass();
                this.printererror = new ActivityBase.errorDialog(this.activityBase);
                ECopyComponent.ICopyResumeRequest.StopReason stopReason = iCopyResumeRequest.getStopReason();
                if (stopReason.equals(ECopyComponent.ICopyResumeRequest.StopReason.PrinterMediaEmptyError)) {
                    Iterator<ECopyOptionItem> it = this.copyComponent.getCopyOptionItems().iterator();
                    while (it.hasNext()) {
                        ECopyOptionItem next = it.next();
                        if (next.getKey().equals(ECopyOptionItem.ECopyOptionItemKey.PrintMediaSource) && next.getSelectedChoice().equals(ECopyOptionItem.ECopyOptionItemChoice.PrintMediaSource_Manual)) {
                            stopReason = ECopyComponent.ICopyResumeRequest.StopReason.ManualfeedGuide;
                        }
                    }
                }
                String[] reasonText = this.printererror.getReasonText(stopReason);
                this.printererror.showErrorDialog(reasonText[0], reasonText[1], iCopyResumeRequest.isPossibleClearError() ? ActivityBase.DialogButtons.ClearErrorCancel : ActivityBase.DialogButtons.Cancel, new ActivityBase.IClose() {
                    public void onClose(ActivityBase.ClickButton clickButton) {
                        iCopyResumeRequest.resume(clickButton == ActivityBase.ClickButton.ClearError ? ECopyComponent.ICopyResumeRequest.ResumeState.ClearError : ECopyComponent.ICopyResumeRequest.ResumeState.Cancel);
                    }
                });
                return;
            case Waiting2ndPage:
                this.activityBase.showNextPageDialog(new ActivityBase.INextPageClose() {
                    public void onClose(ECopyComponent.ICopyResumeRequest.ResumeState resumeState) {
                        iCopyResumeRequest.resume(resumeState);
                    }
                });
                return;
            case Canceling:
                this.wheel.hideCancelButton();
                return;
            default:
                return;
        }
    }

    public void onFinished(ECopyComponent.ICopyStatusListener.CopyTaskType copyTaskType, ECopyComponent.ICopyStatusListener.CopyTaskResult copyTaskResult) {
        this.wheel.dismiss();
        switch (copyTaskResult) {
            case Succeed:
                Iterator<ECopyOptionItem> it = this.copyComponent.getCopyOptionItems().iterator();
                while (it.hasNext()) {
                    ECopyOptionItem next = it.next();
                    if (next.getKey().equals(ECopyOptionItem.ECopyOptionItemKey.Copies)) {
                        next.selectValue(next.getDefaultValue());
                        this.copyComponent.setCopyOptionItem(next);
                    }
                }
                break;
            case Busy:
            case ErrorCommunication:
            case RemoveAdfPaper:
            case ErrorOther:
                ActivityBase activityBase2 = this.activityBase;
                activityBase2.getClass();
                this.printererror = new ActivityBase.errorDialog(this.activityBase);
                String[] reasonText = this.printererror.getReasonText(copyTaskResult);
                this.printererror.showErrorDialog(reasonText[0], reasonText[1], ActivityBase.DialogButtons.Ok, new ActivityBase.IClose() {
                    public void onClose(ActivityBase.ClickButton clickButton) {
                    }
                });
                break;
        }
        if (this.disconnectWifi) {
            WiFiDirectManager.disconnect(this.activityBase, WiFiDirectManager.DEVICE_TYPE_PRINTER, ActivityBase.printerIp);
        }
    }

    public boolean isProccessing() {
        return this.wheel.isShowing();
    }

    public void setDisconnectWifi(boolean z) {
        this.disconnectWifi = z;
    }
}
