package com.bytedance.android.livesdk.broadcast.preview.virtual;

import X.0AP;
import X.0HH;
import X.0VN;
import X.0Xb;
import X.0b0;
import X.0fq;
import X.0yx;
import X.1B5;
import X.1B6;
import X.1Mr;
import X.1c5;
import X.1hK;
import X.2cN;
import X.86a;
import X.C1313Fz8;
import X.C1743GEm;
import X.C1762GFf;
import X.C1773GFq;
import X.C1781GFy;
import X.C1864GJd;
import X.C1867GJg;
import X.C1884GJx;
import X.C1941GMc;
import X.C1948GMj;
import X.C1952GMn;
import X.C1966GNb;
import X.C2290GZn;
import X.C3270Gpb;
import X.C4281HEc;
import X.C4409HJa;
import X.C6455Hzs;
import X.GFP;
import X.GFT;
import X.GGT;
import X.GI0;
import X.GKL;
import X.GN3;
import X.GNB;
import X.GNG;
import X.GNH;
import X.GNI;
import X.GNN;
import X.GNO;
import X.GNP;
import X.GNQ;
import X.GNW;
import X.GSF;
import X.GSG;
import X.HEZ;
import X.Mk2;
import X.Mk3;
import X.PgU;
import X.T94;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.bytedance.android.livesdk.broadcast.preview.virtual.LiveSettingApi;
import com.bytedance.android.livesdk.livesetting.effect.LiveNewEffectPanelSetting;
import com.bytedance.android.livesdk.ui.BaseFragment;
import com.bytedance.android.livesdkapi.depend.model.LiveEffect;
import com.bytedance.bpea.basics.Cert;
import com.bytedance.bpea.basics.PrivacyCert$Builder;
import com.bytedance.bpea.store.policy.PrivacyPolicyStore;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannelGlobal;

public class StartLivePreviewFragment extends BaseFragment implements GFP {
    public static int PREVIEW_HEIGHT = 1280;
    public static int PREVIEW_WIDTH = 720;
    public AnimationSet l2RAnimationSet;
    public C1743GEm listener = new C1743GEm() {
        static {
            Covode.recordClassIndex(12228);
        }

        public final int LIZ(String str, String str2) {
            return 0;
        }

        public final void LIZ(GKL gkl) {
        }

        public final void LIZ(LiveEffect liveEffect, String str) {
        }

        public final void LIZ(Cert cert) {
        }

        public final void LIZ(String str) {
        }

        public final void LIZIZ() {
        }

        public final void LIZIZ(LiveEffect liveEffect, String str) {
        }

        public final void LIZIZ(Cert cert) {
        }

        public final void LIZIZ(String str) {
        }

        public final void LIZLLL(float f) {
        }

        public final void LIZ() {
            StartLivePreviewFragment.this.getActivity().finish();
        }

        public final int LIZIZ(String[] strArr) {
            if (StartLivePreviewFragment.this.mStickerEffect == null) {
                return 0;
            }
            StartLivePreviewFragment.this.mStickerEffect.LIZIZ(strArr);
            return 0;
        }

        public final void LIZJ(float f) {
            if (StartLivePreviewFragment.this.mLiveBeautyHelper != null) {
                StartLivePreviewFragment.this.mLiveBeautyHelper.LIZJ(f);
            }
        }

        public final int LIZ(String[] strArr) {
            if (StartLivePreviewFragment.this.mStickerEffect == null) {
                return 0;
            }
            StartLivePreviewFragment.this.mStickerEffect.LIZ(strArr);
            return 0;
        }

        public final void LIZIZ(float f) {
            if (StartLivePreviewFragment.this.mLiveBeautyHelper != null) {
                StartLivePreviewFragment.this.mLiveBeautyHelper.LIZIZ(f);
            }
        }

        public final void LIZ(float f) {
            if (StartLivePreviewFragment.this.mLiveBeautyHelper != null) {
                StartLivePreviewFragment.this.mLiveBeautyHelper.LIZ(f);
            }
        }

        public final void LIZ(int i) {
            boolean z;
            if (StartLivePreviewFragment.this.mLiveBeautyHelper != null && StartLivePreviewFragment.this.mLiveFilterHelper != null) {
                int LJ = StartLivePreviewFragment.this.mLiveFilterHelper.LJ();
                StartLivePreviewFragment.this.mLiveFilterHelper.LIZ(i);
                StartLivePreviewFragment startLivePreviewFragment = StartLivePreviewFragment.this;
                if (i < LJ) {
                    z = true;
                } else {
                    z = false;
                }
                startLivePreviewFragment.showFilterName(z);
            }
        }

        public final int LIZJ(String[] strArr, String[] strArr2) {
            if (StartLivePreviewFragment.this.mStickerEffect == null) {
                return 0;
            }
            StartLivePreviewFragment.this.mStickerEffect.LIZIZ(strArr, strArr2);
            return 0;
        }

        public final int LIZIZ(String[] strArr, String[] strArr2) {
            if (StartLivePreviewFragment.this.mStickerEffect == null) {
                return 0;
            }
            StartLivePreviewFragment.this.mStickerEffect.LIZ(strArr, strArr2, true, false, false);
            return 0;
        }

        public final int LIZLLL(String[] strArr, String[] strArr2) {
            if (StartLivePreviewFragment.this.mStickerEffect == null) {
                return 0;
            }
            StartLivePreviewFragment.this.mStickerEffect.LIZIZ(strArr, strArr2, true, false, false);
            return 0;
        }

        public final int LIZ(String[] strArr, String[] strArr2) {
            if (StartLivePreviewFragment.this.mStickerEffect == null) {
                return 0;
            }
            StartLivePreviewFragment.this.mStickerEffect.LIZ(strArr, strArr2);
            return 0;
        }

        public final void LIZ(int i, Cert cert) {
            if (i != StartLivePreviewFragment.this.mCameraType) {
                StartLivePreviewFragment.this.mCameraType = i;
                if (StartLivePreviewFragment.this.mCameraCapture != null) {
                    StartLivePreviewFragment.this.mCameraCapture.LIZIZ(cert);
                }
            }
        }

        public final int LIZ(String str, String str2, float f) {
            if (StartLivePreviewFragment.this.mStickerEffect == null) {
                return 0;
            }
            StartLivePreviewFragment.this.mStickerEffect.LIZ(str, str2, f);
            return 0;
        }

        public final int LIZ(String str, String str2, int[] iArr) {
            if (StartLivePreviewFragment.this.mStickerEffect == null) {
                return 0;
            }
            StartLivePreviewFragment.this.mStickerEffect.LIZ(str, str2, iArr);
            return 0;
        }
    };
    public C1864GJd mCameraCapture;
    public int mCameraType = 1;
    public View mFilterLayout;
    public TextView mFilterText;
    public C2290GZn mGestureDetectLayout;
    public GestureDetector mGestureDetector;
    public View.OnTouchListener mGestureTouchListener = new View.OnTouchListener() {
        static {
            Covode.recordClassIndex(12229);
        }

        public final boolean onTouch(View view, MotionEvent motionEvent) {
            StartLivePreviewFragment.this.mGestureDetector.onTouchEvent(motionEvent);
            return false;
        }
    };
    public boolean mInitializedEffect;
    public C1941GMc mLiveBeautyHelper;
    public 1Mr mLiveFilterHelper;
    public 0VN mLiveStream;
    public View mLoadingView;
    public int mScreenWidth;
    public boolean mShowStartLiveFragment;
    public T94 mStartLiveFragment;
    public C1952GMn mStickerEffect;
    public 2cN mSubscribe;
    public SurfaceView mSurfaceView;
    public AnimationSet r2LAnimationSet;

    public static StartLivePreviewFragment newInstance() {
        return new StartLivePreviewFragment();
    }

    static {
        Covode.recordClassIndex(12225);
    }

    private void initGestureDetector() {
        this.mGestureDetector = new GestureDetector(getActivity(), new C1867GJg(this, (byte) 0));
        this.mGestureDetectLayout.LIZ(this.mGestureTouchListener);
    }

    private void initLiveFragment() {
        T94 createStartLiveFragment = GI0.LJIIJJI().createStartLiveFragment((C1762GFf) null);
        this.mStartLiveFragment = createStartLiveFragment;
        createStartLiveFragment.LIZ(this.listener);
        0AP LIZ = getActivity().getSupportFragmentManager().LIZ();
        LIZ.LIZIZ(2131363702, this.mStartLiveFragment.LJJJJLI());
        LIZ.LJ();
        GI0.LJIIJJI().startLiveManager().LIZ(this);
        if (this.mShowStartLiveFragment) {
            this.mStartLiveFragment.LJJJJJL();
        }
    }

    public void initEffect() {
        if (!this.mInitializedEffect) {
            this.mInitializedEffect = true;
            1Mr LJFF = C1773GFq.LJFF();
            this.mLiveFilterHelper = LJFF;
            LJFF.LIZ(this.mCameraCapture, GSF.LIZ((Fragment) this));
            this.mLiveBeautyHelper = new C1884GJx(C1773GFq.LIZLLL());
            C1952GMn gMn = new C1952GMn();
            this.mStickerEffect = gMn;
            C1864GJd gJd = this.mCameraCapture;
            if (gJd != null) {
                gJd.LIZ((0fq) gMn);
            }
            this.mStickerEffect.LIZ(LiveNewEffectPanelSetting.INSTANCE.useNewPanel() ? 1 : 0);
        }
    }

    public void onPause() {
        T94 t94 = this.mStartLiveFragment;
        if (t94 != null) {
            t94.LJJJJL();
        }
        0VN r4 = this.mLiveStream;
        if (r4 != null) {
            PrivacyCert$Builder with = PrivacyCert$Builder.with("bpea-389");
            with.usage("");
            with.tag("[offline test only] fragment onPause");
            with.policies(PrivacyPolicyStore.getVideoPrivacyPolicy(), PrivacyPolicyStore.getAudioPrivacyPolicy());
            r4.LIZIZ(with.build());
        }
        super.onPause();
    }

    public void onResume() {
        super.onResume();
        0VN r5 = this.mLiveStream;
        if (r5 != null) {
            PrivacyCert$Builder with = PrivacyCert$Builder.with("bpea-368");
            with.usage("");
            with.tag("[Offline test only] Switch to foreground");
            with.policies(PrivacyPolicyStore.getVideoPrivacyPolicy(), PrivacyPolicyStore.getAudioPrivacyPolicy());
            r5.LIZ(with.build());
        }
        T94 t94 = this.mStartLiveFragment;
        if (t94 == null) {
            this.mShowStartLiveFragment = true;
        } else {
            t94.LJJJJJL();
        }
    }

    private void initView() {
        this.mScreenWidth = 0b0.LIZJ();
        this.mFilterLayout = getView().findViewById(2131364876);
        this.mGestureDetectLayout = (C2290GZn) getView().findViewById(2131368358);
        this.mSurfaceView = (SurfaceView) getView().findViewById(2131370883);
        this.mFilterText = (TextView) getView().findViewById(2131364878);
        View findViewById = getView().findViewById(2131367399);
        this.mLoadingView = findViewById;
        findViewById.setVisibility(0);
        ((LiveSettingApi.WebcastAPI) 0yx.LIZ().LIZ(LiveSettingApi.WebcastAPI.class)).getLivePodCast().LIZ(new C6455Hzs()).LIZ(new GNO(this), new GNP(this));
    }

    public void onDestroy() {
        C1864GJd gJd = this.mCameraCapture;
        if (gJd != null) {
            PrivacyCert$Builder with = PrivacyCert$Builder.with("bpea-432");
            with.usage("");
            with.tag("stop video/audio capture when live ends");
            with.policies(PrivacyPolicyStore.getVideoPrivacyPolicy());
            gJd.LIZ((Cert) with.build());
            this.mCameraCapture = null;
        }
        2cN r0 = this.mSubscribe;
        if (r0 != null && !r0.isDisposed()) {
            this.mSubscribe.dispose();
        }
        0VN r3 = this.mLiveStream;
        if (r3 != null) {
            PrivacyCert$Builder with2 = PrivacyCert$Builder.with("bpea-489");
            with2.usage("");
            with2.tag("release when live ends");
            with2.policies(PrivacyPolicyStore.getVideoPrivacyPolicy(), PrivacyPolicyStore.getAudioPrivacyPolicy());
            r3.LIZJ(with2.build());
            this.mLiveStream = null;
        }
        GI0.LJIIJJI().startLiveManager().LIZIZ(this);
        super.onDestroy();
    }

    private void initCameraCapture() {
        int i;
        if (((Integer) C1781GFy.LJII.LIZIZ()).intValue() == 0) {
            i = 2;
        } else {
            i = 1;
        }
        this.mCameraType = i;
        1hK activity = getActivity();
        if (activity != null) {
            Intent intent = activity.getIntent();
            if (intent == null || !86a.LIZ(INVOKEVIRTUAL_com_bytedance_android_livesdk_broadcast_preview_virtual_StartLivePreviewFragment_com_ss_android_ugc_aweme_lancet_IntentLancet_getStringExtra(intent, "orientation"), "landscape")) {
                PREVIEW_WIDTH = 720;
                PREVIEW_HEIGHT = 1280;
            } else {
                PREVIEW_WIDTH = 1280;
                PREVIEW_HEIGHT = 720;
            }
        }
        0Xb r2 = new 0Xb(getContext());
        r2.LJIJJLI = GI0.LJII().getProjectKey();
        r2.LJJIIZ = new C1948GMj();
        r2.LJIJI = new GNN();
        r2.LJJIIZI = new C1966GNb();
        r2.LJIILLIIL = i;
        r2.LJJIJIIJI = GSG.INST.getModelFilePath();
        r2.LJJIJIIJIL = GSG.INST.getResourceFinder(getContext());
        r2.LIZ(PREVIEW_WIDTH, PREVIEW_HEIGHT);
        r2.LJIIZILJ = 5;
        this.mLiveStream = new C4409HJa(r2.LIZ());
        GN3 gn3 = new GN3(this.mSurfaceView, this.mLiveStream, true);
        this.mCameraCapture = gn3;
        gn3.LIZ((GNW) new GNW() {
            static {
                Covode.recordClassIndex(12226);
            }

            public final void LIZ(int i, int i2) {
            }

            public final void LIZ() {
                if (!StartLivePreviewFragment.this.mInitializedEffect) {
                    StartLivePreviewFragment.this.mSubscribe = PgU.LIZIZ(1).LIZ(Mk2.LIZ(Mk3.LIZ)).LIZ(new GNI(this), GNQ.LIZ);
                }
            }
        });
    }

    public void onStartLive() {
        C1864GJd gJd = this.mCameraCapture;
        if (gJd != null) {
            PrivacyCert$Builder with = PrivacyCert$Builder.with("bpea-431");
            with.usage("");
            with.tag("stop video/audio capture when live ends");
            with.policies(PrivacyPolicyStore.getVideoPrivacyPolicy());
            gJd.LIZ((Cert) with.build());
            this.mCameraCapture = null;
        }
        1Mr r0 = this.mLiveFilterHelper;
        if (r0 != null) {
            r0.LIZ();
        }
        0VN r3 = this.mLiveStream;
        if (r3 != null) {
            PrivacyCert$Builder with2 = PrivacyCert$Builder.with("bpea-390");
            with2.usage("");
            with2.tag("[offline test only] fragment onPause");
            with2.policies(PrivacyPolicyStore.getVideoPrivacyPolicy(), PrivacyPolicyStore.getAudioPrivacyPolicy());
            r3.LIZIZ(with2.build());
            0VN r32 = this.mLiveStream;
            PrivacyCert$Builder with3 = PrivacyCert$Builder.with("bpea-490");
            with3.usage("");
            with3.tag("release when live ends");
            with3.policies(PrivacyPolicyStore.getVideoPrivacyPolicy(), PrivacyPolicyStore.getAudioPrivacyPolicy());
            r32.LIZJ(with3.build());
            this.mLiveStream = null;
        }
        getActivity().finish();
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        C3270Gpb.LJIIJ = true;
    }

    public final /* synthetic */ void lambda$initView$1$StartLivePreviewFragment(Throwable th) {
        C1313Fz8.LIZ(0b0.LJ(), "fetch live permission fail, please retry", 0);
        this.mLoadingView.setVisibility(8);
    }

    public final /* synthetic */ void lambda$initView$0$StartLivePreviewFragment(1c5 r8) {
        GNG gng = ((GNB) r8.data).LIZIZ;
        if (gng != null) {
            DataChannelGlobal.LIZLLL.LIZ(HEZ.class, new GGT(gng.LIZ, gng.LIZJ, gng.LIZIZ, gng.LIZLLL));
        }
        GNH gnh = ((GNB) r8.data).LIZJ;
        if (gnh != null) {
            DataChannelGlobal.LIZLLL.LIZ(C4281HEc.class, new GFT(gnh.LIZJ, gnh.LIZIZ, gnh.LIZ));
        }
        initLiveFragment();
        this.mLoadingView.setVisibility(8);
    }

    public void showFilterName(boolean z) {
        String str;
        1Mr r0 = this.mLiveFilterHelper;
        if (r0 != null) {
            str = r0.LIZIZ();
        } else {
            str = "";
        }
        if (!TextUtils.isEmpty(str)) {
            this.mFilterText.setText(str);
            if (z) {
                if (this.l2RAnimationSet == null) {
                    this.l2RAnimationSet = generateAnimationSet(true);
                } else {
                    this.mFilterLayout.clearAnimation();
                }
                this.mFilterLayout.startAnimation(this.l2RAnimationSet);
                return;
            }
            if (this.r2LAnimationSet == null) {
                this.r2LAnimationSet = generateAnimationSet(false);
            } else {
                this.mFilterLayout.clearAnimation();
            }
            this.mFilterLayout.startAnimation(this.r2LAnimationSet);
        }
    }

    private AnimationSet generateAnimationSet(boolean z) {
        float f;
        float f2;
        float f3;
        float f4;
        float f5;
        int width = (this.mScreenWidth - this.mFilterText.getWidth()) / 2;
        AnimationSet animationSet = new AnimationSet(false);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
        alphaAnimation.setInterpolator(new 1B6());
        alphaAnimation.setDuration(300);
        if (z) {
            f = (float) (-width);
        } else {
            f = (float) width;
        }
        float f6 = -50.0f;
        if (z) {
            f2 = -50.0f;
        } else {
            f2 = 50.0f;
        }
        TranslateAnimation translateAnimation = new TranslateAnimation(f, f2, 0.0f, 0.0f);
        translateAnimation.setInterpolator(new 1B6());
        translateAnimation.setDuration(300);
        if (z) {
            f3 = -50.0f;
            f4 = 50.0f;
        } else {
            f3 = 50.0f;
            f4 = -50.0f;
        }
        TranslateAnimation translateAnimation2 = new TranslateAnimation(f3, f4, 0.0f, 0.0f);
        translateAnimation2.setInterpolator(new LinearInterpolator());
        translateAnimation2.setStartOffset(300);
        translateAnimation2.setDuration(200);
        AlphaAnimation alphaAnimation2 = new AlphaAnimation(1.0f, 0.0f);
        alphaAnimation2.setStartOffset(500);
        alphaAnimation2.setInterpolator(new 1B5());
        alphaAnimation2.setDuration(300);
        if (z) {
            f6 = 50.0f;
            f5 = (float) width;
        } else {
            f5 = (float) (-width);
        }
        TranslateAnimation translateAnimation3 = new TranslateAnimation(f6, f5, 0.0f, 0.0f);
        translateAnimation3.setStartOffset(500);
        translateAnimation3.setInterpolator(new 1B5());
        translateAnimation3.setDuration(300);
        animationSet.addAnimation(alphaAnimation);
        animationSet.addAnimation(translateAnimation);
        animationSet.addAnimation(translateAnimation2);
        animationSet.addAnimation(alphaAnimation2);
        animationSet.addAnimation(translateAnimation3);
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            static {
                Covode.recordClassIndex(12227);
            }

            public final void onAnimationRepeat(Animation animation) {
            }

            public final void onAnimationEnd(Animation animation) {
                StartLivePreviewFragment.this.mFilterLayout.setVisibility(4);
            }

            public final void onAnimationStart(Animation animation) {
                StartLivePreviewFragment.this.mFilterLayout.setVisibility(0);
            }
        });
        return animationSet;
    }

    public static String INVOKEVIRTUAL_com_bytedance_android_livesdk_broadcast_preview_virtual_StartLivePreviewFragment_com_ss_android_ugc_aweme_lancet_IntentLancet_getStringExtra(Intent intent, String str) {
        try {
            return intent.getStringExtra(str);
        } catch (Exception unused) {
            return null;
        }
    }

    public void onViewCreated(View view, Bundle bundle) {
        Intent intent;
        super.onViewCreated(view, bundle);
        1hK activity = getActivity();
        if (!(activity == null || (intent = activity.getIntent()) == null || !86a.LIZ(INVOKEVIRTUAL_com_bytedance_android_livesdk_broadcast_preview_virtual_StartLivePreviewFragment_com_ss_android_ugc_aweme_lancet_IntentLancet_getStringExtra(intent, "orientation"), "landscape"))) {
            activity.setRequestedOrientation(0);
        }
        initView();
        initCameraCapture();
        initGestureDetector();
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        return 0HH.LIZ(layoutInflater, 2131561522, viewGroup, false);
    }
}
