package K.K.㸾.ῲ.ῲ;

import ai.advance.liveness.lib.Detector;
import ai.advance.liveness.lib.LivenessView;
import ai.advance.liveness.lib.http.entity.ResultEntity;
import ai.advance.liveness.sdk.R$drawable;
import ai.advance.liveness.sdk.R$id;
import ai.advance.liveness.sdk.R$layout;
import ai.advance.liveness.sdk.R$raw;
import ai.advance.liveness.sdk.R$string;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import ῲ.ῲ.K.DialogInterfaceC1958;
import K.K.K.C2373;
import K.K.㸾.K.C2383;
import K.K.㸾.K.㳳.AbstractC2391;
import K.K.㸾.K.㳳.AbstractC2392;

/* renamed from: K.K.㸾.ῲ.ῲ.K  reason: contains not printable characters */
/* compiled from: LivenessFragment */
public class C2377 extends Fragment implements Detector.AbstractC0023, AbstractC2392 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public ImageView f8226;

    /* renamed from: ඓ  reason: contains not printable characters */
    public ImageView f8227;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public View f8228;

    /* renamed from: ῲ  reason: contains not printable characters */
    public SparseArray<AnimationDrawable> f8229;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public TextView f8230;

    /* renamed from: 㳳  reason: contains not printable characters */
    public ProgressDialog f8231;

    /* renamed from: 㴹  reason: contains not printable characters */
    public TextView f8232;

    /* renamed from: 㸾  reason: contains not printable characters */
    public LivenessView f8233;

    /* renamed from: 㿎  reason: contains not printable characters */
    public CheckBox f8234;

    /* renamed from: K.K.㸾.ῲ.ῲ.K$ʬ  reason: contains not printable characters */
    /* compiled from: LivenessFragment */
    public class DialogInterface$OnClickListenerC2378 implements DialogInterface.OnClickListener {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ String f8236;

        public DialogInterface$OnClickListenerC2378(String str) {
            this.f8236 = str;
        }

        public void onClick(DialogInterface dialogInterface, int i) {
            C2383.m6382(this.f8236);
            FragmentActivity activity = C2377.this.getActivity();
            dialogInterface.dismiss();
            if (activity != null) {
                activity.setResult(-1);
                activity.finish();
            }
        }
    }

    /* renamed from: K.K.㸾.ῲ.ῲ.K$ῲ  reason: contains not printable characters */
    /* compiled from: LivenessFragment */
    public class C2379 implements CompoundButton.OnCheckedChangeListener {
        public C2379() {
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            C2377.this.f8233.setSoundPlayEnable(z);
            if (z) {
                C2377.this.m6364();
            }
        }
    }

    /* renamed from: K.K.㸾.ῲ.ῲ.K$K  reason: contains not printable characters */
    /* compiled from: LivenessFragment */
    public class View$OnClickListenerC2380 implements View.OnClickListener {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ FragmentActivity f8238;

        public View$OnClickListenerC2380(C2377 k, FragmentActivity fragmentActivity) {
            this.f8238 = fragmentActivity;
        }

        public void onClick(View view) {
            this.f8238.onBackPressed();
        }
    }

    @Override // androidx.fragment.app.Fragment
    public void onActivityCreated(Bundle bundle) {
        super.onActivityCreated(bundle);
        m6374();
        this.f8229 = new SparseArray<>();
        this.f8233.m108(this);
    }

    @Override // androidx.fragment.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        return layoutInflater.inflate(R$layout.fragment_liveness, viewGroup, false);
    }

    @Override // androidx.fragment.app.Fragment
    public void onDetach() {
        m6372();
        super.onDetach();
    }

    @Override // K.K.㸾.K.㳳.AbstractC2392
    /* renamed from: ඓ  reason: contains not printable characters */
    public void m6362() {
        this.f8233.m107(new C2381());
    }

    /* renamed from: ᕣ  reason: contains not printable characters */
    public final void m6363() {
        Detector.DetectionType currentDetectionType = this.f8233.getCurrentDetectionType();
        if (currentDetectionType != null) {
            int i = 0;
            int ordinal = currentDetectionType.ordinal();
            if (ordinal == 1) {
                i = R$string.liveness_blink;
            } else if (ordinal == 2) {
                i = R$string.liveness_mouse;
            } else if (ordinal == 3) {
                i = R$string.liveness_pos_raw;
            }
            this.f8232.setText(i);
            AnimationDrawable r0 = m6367(currentDetectionType);
            this.f8227.setImageDrawable(r0);
            r0.start();
        }
    }

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final void m6364() {
        if (this.f8234.getVisibility() != 0) {
            this.f8234.setVisibility(0);
        }
        int i = -1;
        Detector.DetectionType currentDetectionType = this.f8233.getCurrentDetectionType();
        if (currentDetectionType != null) {
            int ordinal = currentDetectionType.ordinal();
            if (ordinal == 1) {
                i = R$raw.action_blink;
            } else if (ordinal == 2) {
                i = R$raw.action_open_mouth;
            } else if (ordinal == 3) {
                i = R$raw.action_turn_head;
            }
        }
        this.f8233.m104(i, true, 1500L);
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final void m6366(Detector.WarnCode warnCode) {
        if (!this.f8233.m113()) {
            this.f8232.setText(R$string.liveness_hold_phone_vertical);
        } else if (warnCode != null) {
            switch (warnCode.ordinal()) {
                case 0:
                    this.f8232.setText(R$string.liveness_no_people_face);
                    return;
                case 1:
                    this.f8232.setText(R$string.liveness_tip_move_furthre);
                    return;
                case 2:
                    this.f8232.setText(R$string.liveness_tip_move_closer);
                    return;
                case 3:
                    this.f8232.setText(R$string.liveness_move_face_center);
                    return;
                case 4:
                    this.f8232.setText(R$string.liveness_frontal);
                    return;
                case 5:
                case 9:
                    this.f8232.setText(R$string.liveness_still);
                    return;
                case 6:
                case 7:
                default:
                    return;
                case 8:
                    this.f8232.setText(R$string.liveness_face_occ);
                    return;
                case 10:
                    m6363();
                    return;
            }
        }
    }

    @Override // ai.advance.liveness.lib.Detector.AbstractC0023
    /* renamed from: K  reason: contains not printable characters */
    public void m6371(boolean z, String str, String str2) {
        ProgressDialog progressDialog = this.f8231;
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
        if (z) {
            m6366(null);
            return;
        }
        if ("NO_RESPONSE".equals(str)) {
            str2 = getString(R$string.liveness_failed_reason_auth_failed);
        }
        FragmentActivity activity = getActivity();
        if (activity != null) {
            new DialogInterfaceC1958.C1959(activity).setMessage(str2).setPositiveButton(R$string.liveness_perform, new DialogInterface$OnClickListenerC2378(str2)).create().show();
        }
    }

    /* renamed from: 㳳  reason: contains not printable characters */
    public void m6372() {
        ProgressDialog progressDialog = this.f8231;
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
        this.f8233.m93();
    }

    @Override // K.K.㸾.K.㳳.AbstractC2392
    /* renamed from: 㸾  reason: contains not printable characters */
    public void m6373() {
        m6364();
        m6363();
        this.f8230.setBackgroundResource(R$drawable.liveness_shape_right_timer);
    }

    /* renamed from: 㿎  reason: contains not printable characters */
    public void m6374() {
        FragmentActivity activity = getActivity();
        if (activity != null) {
            this.f8226 = (ImageView) activity.findViewById(R$id.mask_view);
            this.f8233 = (LivenessView) activity.findViewById(R$id.liveness_view);
            this.f8227 = (ImageView) activity.findViewById(R$id.tip_image_view);
            this.f8232 = (TextView) activity.findViewById(R$id.tip_text_view);
            this.f8230 = (TextView) activity.findViewById(R$id.timer_text_view_camera_activity);
            this.f8228 = activity.findViewById(R$id.progress_layout);
            this.f8234 = (CheckBox) activity.findViewById(R$id.voice_check_box);
            activity.findViewById(R$id.back_view_camera_activity).setOnClickListener(new View$OnClickListenerC2380(this, activity));
            this.f8234.setChecked(C2373.f8217);
            this.f8234.setOnCheckedChangeListener(new C2379());
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:13:0x0024  */
    /* JADX WARNING: Removed duplicated region for block: B:15:? A[RETURN, SYNTHETIC] */
    /* renamed from: K  reason: contains not printable characters */
    public AnimationDrawable m6367(Detector.DetectionType detectionType) {
        int i;
        AnimationDrawable animationDrawable;
        if (detectionType != null) {
            int ordinal = detectionType.ordinal();
            if (ordinal == 1) {
                i = R$drawable.anim_frame_blink;
            } else if (ordinal == 2) {
                i = R$drawable.anim_frame_open_mouse;
            } else if (ordinal == 3) {
                i = R$drawable.anim_frame_turn_head;
            }
            animationDrawable = this.f8229.get(i);
            if (animationDrawable == null) {
                return animationDrawable;
            }
            AnimationDrawable animationDrawable2 = (AnimationDrawable) getResources().getDrawable(i);
            this.f8229.put(i, animationDrawable2);
            return animationDrawable2;
        }
        i = -1;
        animationDrawable = this.f8229.get(i);
        if (animationDrawable == null) {
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static /* synthetic */ void m6361(C2377 k) {
        FragmentActivity activity = k.getActivity();
        if (activity != null) {
            activity.setResult(-1);
            activity.finish();
        }
    }

    /* renamed from: K.K.㸾.ῲ.ῲ.K$㸾  reason: contains not printable characters */
    /* compiled from: LivenessFragment */
    public class C2381 implements AbstractC2391 {
        public C2381() {
        }

        /* renamed from: K  reason: contains not printable characters */
        public void m6375() {
            C2377.this.f8228.setVisibility(0);
            C2377.this.f8230.setVisibility(8);
            C2377.this.f8233.setVisibility(8);
            C2377.this.f8234.setVisibility(8);
            C2377.this.f8227.setVisibility(8);
            C2377.this.f8232.setVisibility(8);
            C2377.this.f8226.setVisibility(8);
        }

        /* renamed from: K  reason: contains not printable characters */
        public void m6376(ResultEntity resultEntity) {
            if (!resultEntity.f8209 && "NO_RESPONSE".equals(resultEntity.f8212)) {
                C2383.m6382(C2377.this.getString(R$string.liveness_failed_reason_bad_network));
            }
            C2377.m6361(C2377.this);
        }
    }

    @Override // K.K.㸾.K.㳳.AbstractC2392
    /* renamed from: K  reason: contains not printable characters */
    public void m6370(Detector.WarnCode warnCode) {
        if (isAdded()) {
            m6366(warnCode);
        }
    }

    @Override // ai.advance.liveness.lib.Detector.AbstractC0023
    /* renamed from: ῲ  reason: contains not printable characters */
    public void m6365() {
        ProgressDialog progressDialog = this.f8231;
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
        this.f8231 = new ProgressDialog(getContext());
        this.f8231.setMessage(getString(R$string.liveness_auth_check));
        this.f8231.setCanceledOnTouchOutside(false);
        this.f8231.show();
    }

    @Override // K.K.㸾.K.㳳.AbstractC2392
    @SuppressLint({"SetTextI18n"})
    /* renamed from: K  reason: contains not printable characters */
    public void m6368(long j) {
        if (isAdded()) {
            int i = (int) (j / 1000);
            TextView textView = this.f8230;
            textView.setText(i + "s");
        }
    }

    @Override // K.K.㸾.K.㳳.AbstractC2392
    /* renamed from: K  reason: contains not printable characters */
    public void m6369(Detector.DetectionFailedType detectionFailedType, Detector.DetectionType detectionType) {
        String str;
        if (isAdded()) {
            int ordinal = detectionFailedType.ordinal();
            if (ordinal == 1) {
                this.f8232.setText(R$string.liveness_weak_light);
            } else if (ordinal != 2) {
                String str2 = null;
                int ordinal2 = detectionFailedType.ordinal();
                if (ordinal2 == 0) {
                    str2 = getString(R$string.liveness_failed_reason_timeout);
                } else if (ordinal2 == 3) {
                    int ordinal3 = detectionType.ordinal();
                    if (ordinal3 == 1 || ordinal3 == 2) {
                        str = getString(R$string.liveness_failed_reason_facemissing_blink_mouth);
                    } else if (ordinal3 == 3) {
                        str = getString(R$string.liveness_failed_reason_facemissing_pos_yaw);
                    }
                    str2 = str;
                } else if (ordinal2 == 4) {
                    str2 = getString(R$string.liveness_failed_reason_multipleface);
                } else if (ordinal2 == 5) {
                    str2 = getString(R$string.liveness_failed_reason_muchaction);
                }
                C2383.m6382(str2);
                FragmentActivity activity = getActivity();
                if (activity != null) {
                    activity.setResult(-1);
                    activity.finish();
                }
            } else {
                this.f8232.setText(R$string.liveness_too_light);
            }
        }
    }
}
