package com.bytedance.ies.bullet.service.popup;

import X.0HH;
import X.1hK;
import X.2FV;
import X.2He;
import X.2Pr;
import X.2fU;
import X.2te;
import X.2th;
import X.7Ks;
import X.7he;
import X.7s1;
import X.8jA;
import X.C0672KCx;
import X.C0984KOx;
import X.C1017KQe;
import X.C1091KTa;
import X.C1112KTv;
import X.C1268KZv;
import X.C1421KcO;
import X.C1422KcP;
import X.C1424KcR;
import X.C1431KcY;
import X.C1565Kei;
import X.C1566Kej;
import X.C1599KfG;
import X.C1603KfK;
import X.C1616KfX;
import X.C1622Kfd;
import X.C1633Kfo;
import X.C1765Khw;
import X.C1926KkX;
import X.C2424KsZ;
import X.C2425Ksa;
import X.C2519Ku6;
import X.C2525KuC;
import X.C2727KxS;
import X.C2728KxT;
import X.C2729KxU;
import X.C2730KxV;
import X.C2731KxW;
import X.C2732KxX;
import X.C2735Kxa;
import X.C2736Kxb;
import X.C2737Kxc;
import X.C2740Kxf;
import X.C2741Kxg;
import X.C2744Kxj;
import X.C2793KyW;
import X.C2796KyZ;
import X.C2801Kye;
import X.C2807Kyk;
import X.C2811Kyo;
import X.C2812Kyp;
import X.C4097LeS;
import X.C4105Lea;
import X.C4939Ls2;
import X.Crj;
import X.HcU;
import X.JJj;
import X.JKB;
import X.JKQ;
import X.KQA;
import X.KT7;
import X.KTX;
import X.KU7;
import X.KVN;
import X.KVQ;
import X.M12;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.Dialog;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import androidx.appcompat.app.AppCompatDialogFragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import kotlin.h.b.n;

public final class BulletPopUpFragment extends AppCompatDialogFragment implements C1017KQe, C1422KcP, KTX {
    public static final List<BulletPopUpFragment> LJIJJ = new ArrayList();
    public static final List<BulletPopUpFragment> LJIJJLI = new ArrayList();
    public static final C1633Kfo LJIL = new C1633Kfo((byte) 0);
    public KT7 LIZ;
    public C1599KfG LIZIZ;
    public C2811Kyo LIZJ;
    public C0984KOx LIZLLL;
    public C2744Kxj LJ;
    public C4939Ls2<2Pr> LJFF;
    public View LJI;
    public boolean LJII = true;
    public boolean LJIIIIZZ;
    public String LJIIIZ;
    public Boolean LJIIJ;
    public Boolean LJIIJJI;
    public C2730KxV LJIIL = C2730KxV.UNKNOWN;
    public Activity LJIILIIL;
    public KQA LJIILJJIL;
    public C2727KxS LJIILL;
    public C2425Ksa LJIILLIIL;
    public String LJIIZILJ = "default_bid";
    public JKB LJIJ = JKB.NONE;
    public Throwable LJIJI;
    public final Crj LJJ = 7he.LIZ(new C2519Ku6(this));
    public C2801Kye LJJI = C2801Kye.NONE;
    public final Crj LJJIFFI = 7he.LIZ(new C2741Kxg(this));
    public final Crj LJJII = 7he.LIZ(new C1622Kfd(this));
    public final Crj LJJIII = 7he.LIZ(new C2740Kxf(this));
    public HashMap LJJIIJ;

    public final FrameLayout LJI() {
        return (FrameLayout) this.LJJ.getValue();
    }

    public final C2793KyW LJII() {
        return (C2793KyW) this.LJJIFFI.getValue();
    }

    public final C2812Kyp LJIIIZ() {
        return (C2812Kyp) this.LJJIII.getValue();
    }

    public final C1431KcY getLoggerWrapper() {
        return (C1431KcY) this.LJJII.getValue();
    }

    public final void LIZLLL() {
        dismissAllowingStateLoss();
    }

    private final void LJIIL() {
        C2744Kxj kxj = this.LJ;
        if (kxj != null) {
            kxj.LIZJ();
        }
    }

    public final String LIZ() {
        return this.LJIIZILJ;
    }

    public final String LJ() {
        return LJIIJ();
    }

    public final Uri LJFF() {
        C2727KxS kxS = this.LJIILL;
        if (kxS == null) {
            n.LIZ("");
        }
        return kxS.LJ;
    }

    public final C2727KxS LJIIIIZZ() {
        C2727KxS kxS = this.LJIILL;
        if (kxS == null) {
            n.LIZ("");
        }
        return kxS;
    }

    public final void dismiss() {
        LIZ((C4939Ls2<2Pr>) new HcU(this));
    }

    public final void dismissAllowingStateLoss() {
        C2730KxV kxV = C2730KxV.UNKNOWN;
        M12.LIZ((Object) kxV);
        if (kxV == C2730KxV.JSB) {
            this.LJIIL = kxV;
        }
        BulletPopUpFragment.super.dismissAllowingStateLoss();
    }

    public final /* synthetic */ void onDestroyView() {
        BulletPopUpFragment.super.onDestroyView();
        HashMap hashMap = this.LJJIIJ;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    static {
        Covode.recordClassIndex(28835);
    }

    public final String LJIIJ() {
        C0672KCx LIZ2;
        String str;
        C0984KOx kOx = this.LIZLLL;
        if (kOx == null || (LIZ2 = kOx.LIZ()) == null || (str = LIZ2.LIZ) == null) {
            return "";
        }
        return str;
    }

    public final void onPause() {
        C0984KOx kOx;
        BulletPopUpFragment.super.onPause();
        this.LJIIJJI = false;
        if (n.LIZ(this.LJIIJ, true) && (kOx = this.LIZLLL) != null) {
            kOx.LJIIJ();
        }
    }

    public final void onResume() {
        C0984KOx kOx;
        BulletPopUpFragment.super.onResume();
        this.LJIIJJI = true;
        if (n.LIZ(this.LJIIJ, true) && (kOx = this.LIZLLL) != null) {
            kOx.LJIIIZ();
        }
    }

    public final void onStop() {
        BulletPopUpFragment.super.onStop();
        try {
            Dialog dialog = getDialog();
            dialog.show();
            2fU.LIZ.LIZ(dialog);
            2te.constructor-impl(2Pr.LIZ);
        } catch (Throwable th) {
            2te.constructor-impl(2th.LIZ(th));
        }
    }

    public final String LIZIZ() {
        String string;
        KVQ LIZ2 = KVN.LIZIZ.LIZ();
        C2727KxS kxS = this.LJIILL;
        if (kxS == null) {
            n.LIZ("");
        }
        C1112KTv<String, Object> LIZ3 = LIZ2.LIZ(kxS.LIZ);
        if (LIZ3 == null || (string = LIZ3.getString("__x_param_channel")) == null) {
            return "";
        }
        return string;
    }

    public final String LIZJ() {
        String string;
        KVQ LIZ2 = KVN.LIZIZ.LIZ();
        C2727KxS kxS = this.LJIILL;
        if (kxS == null) {
            n.LIZ("");
        }
        C1112KTv<String, Object> LIZ3 = LIZ2.LIZ(kxS.LIZ);
        if (LIZ3 == null || (string = LIZ3.getString("__x_param_bundle")) == null) {
            return "";
        }
        return string;
    }

    public final void onDestroy() {
        BulletPopUpFragment.super.onDestroy();
        if (this.LJIILIIL != null && this.LJIILL != null) {
            C0984KOx kOx = this.LIZLLL;
            if (kOx != null) {
                kOx.onEvent(new C2729KxU(this));
            }
            C2425Ksa ksa = this.LJIILLIIL;
            if (ksa != null) {
                ksa.LIZIZ(this);
            }
            new Handler().postDelayed(new C2737Kxc(this), 100);
            M12.LIZ((Object) this);
            List<BulletPopUpFragment> list = LJIJJ;
            list.remove(this);
            BulletPopUpFragment bulletPopUpFragment = (BulletPopUpFragment) C4105Lea.LJIIJ(list);
            if (bulletPopUpFragment != null) {
                C2727KxS kxS = bulletPopUpFragment.LJIILL;
                if (kxS == null) {
                    n.LIZ("");
                }
                if (kxS.LIZLLL == 3) {
                    bulletPopUpFragment.LJIIL();
                }
            }
            LJIJJLI.add(this);
            C2727KxS kxS2 = this.LJIILL;
            if (kxS2 == null) {
                n.LIZ("");
            }
            if (kxS2.LIZLLL == 1) {
                C1633Kfo kfo = LJIL;
                C2727KxS kxS3 = this.LJIILL;
                if (kxS3 == null) {
                    n.LIZ("");
                }
                BulletPopUpFragment LIZ2 = kfo.LIZ(kxS3.LJIILLIIL);
                if (LIZ2 != null) {
                    LIZ2.LJIIL();
                }
            }
        }
    }

    public final C1599KfG LJIIJJI() {
        Activity activity = this.LJIILIIL;
        if (activity == null) {
            n.LIZ("");
        }
        C1599KfG kfG = new C1599KfG(activity, (AttributeSet) null, 6, (byte) 0);
        this.LIZ = kfG.getProviderFactory();
        KQA kqa = this.LJIILJJIL;
        if (kqa == null) {
            n.LIZ("");
        }
        kfG.LIZIZ(kqa);
        C2727KxS kxS = this.LJIILL;
        if (kxS == null) {
            n.LIZ("");
        }
        Bundle bundle = kxS.LJFF;
        if (bundle == null) {
            bundle = new Bundle();
        }
        C2727KxS kxS2 = this.LJIILL;
        if (kxS2 == null) {
            n.LIZ("");
        }
        Uri uri = kxS2.LJ;
        JJj jJj = JJj.LIZ;
        Context context = kfG.getContext();
        n.LIZ(context, "");
        jJj.LIZ(context);
        C1091KTa kTa = (C1091KTa) KVN.LIZIZ.LIZ().LIZ(this.LJIIZILJ, C1091KTa.class);
        if (kTa != null) {
            Activity activity2 = this.LJIILIIL;
            if (activity2 == null) {
                n.LIZ("");
            }
            C1616KfX LIZ2 = kTa.LIZ(activity2);
            if (LIZ2 != null) {
                View view = LIZ2.getView();
                FrameLayout.LayoutParams LIZLLL2 = kTa.LIZLLL();
                if (LIZLLL2 != null) {
                    kfG.LIZ(view, LIZLLL2);
                } else {
                    kfG.LIZ(view, 17, 0, 0, 0, 0);
                }
            }
            Activity activity3 = this.LJIILIIL;
            if (activity3 == null) {
                n.LIZ("");
            }
            C1926KkX LIZIZ2 = kTa.LIZIZ(activity3);
            if (LIZIZ2 != null) {
                new C2525KuC(kTa, this, kfG);
                new C1765Khw(kTa, this, kfG);
                View LIZ3 = LIZIZ2.LIZ();
                FrameLayout.LayoutParams LJ2 = kTa.LJ();
                if (LJ2 != null) {
                    kfG.LIZIZ(LIZ3, LJ2);
                } else {
                    kfG.LIZIZ(LIZ3, new FrameLayout.LayoutParams(-1, -1));
                }
            }
        }
        C2727KxS kxS3 = this.LJIILL;
        if (kxS3 == null) {
            n.LIZ("");
        }
        M12.LIZ((Object) kxS3);
        if (kxS3.LJI <= 0 && kxS3.LJII <= 0) {
            C2727KxS kxS4 = this.LJIILL;
            if (kxS4 == null) {
                n.LIZ("");
            }
            Integer num = kxS4.LJIJ;
            if (num != null) {
                bundle.putInt("lynxview_width", num.intValue());
            }
            C2727KxS kxS5 = this.LJIILL;
            if (kxS5 == null) {
                n.LIZ("");
            }
            Integer num2 = kxS5.LJIJI;
            if (num2 != null) {
                bundle.putInt("lynxview_height", num2.intValue());
            }
        }
        try {
            C2727KxS kxS6 = this.LJIILL;
            if (kxS6 == null) {
                n.LIZ("");
            }
            Bundle bundle2 = kxS6.LJIIZILJ;
            if (bundle2 != null) {
                bundle.putAll(bundle2);
            }
        } catch (Exception e) {
            0HH.LIZ(e);
        }
        C2424KsZ ksZ = new C2424KsZ(this);
        KT7 kt7 = new KT7();
        kt7.LIZ(KU7.class, new C1565Kei(this));
        kt7.LIZ(C1268KZv.class, new C1566Kej(this));
        kfG.LIZ(uri, bundle, kt7, (C1603KfK) ksZ);
        return kfG;
    }

    private final Animator.AnimatorListener LIZIZ(C4939Ls2<2Pr> ls2) {
        return new C2728KxT(this, ls2);
    }

    public final void LIZ(C2801Kye kye) {
        M12.LIZ((Object) kye);
        this.LJJI = kye;
    }

    public final void onDismiss(DialogInterface dialogInterface) {
        if (this.LJIIL == C2730KxV.UNKNOWN) {
            this.LJIIL = C2730KxV.TAP_MASK;
        }
        BulletPopUpFragment.super.onDismiss(dialogInterface);
    }

    /* JADX WARNING: type inference failed for: r2v0, types: [X.KxW, android.app.Dialog] */
    public final Dialog onCreateDialog(Bundle bundle) {
        Context context = getContext();
        if (context == null) {
            n.LIZ();
        }
        n.LIZ(context, "");
        ? kxW = new C2731KxW(this, context);
        1hK activity = getActivity();
        if (activity != null) {
            kxW.setOwnerActivity(activity);
        }
        return kxW;
    }

    public final void LIZ(C4939Ls2<2Pr> ls2) {
        Animator animator;
        String str;
        try {
            if (this.LJI == null || this.LJJI == C2801Kye.NONE || this.LJIJ == JKB.DONE) {
                ls2.invoke();
            } else if (this.LJIJI != null) {
                StringBuilder sb = new StringBuilder("reAnimEnd with msg:");
                Throwable th = this.LJIJI;
                if (th != null) {
                    str = th.getMessage();
                } else {
                    str = null;
                }
                sb.append(str);
                C1421KcO.LIZ(this, sb.toString(), (C1424KcR) null, "popup", 2);
                ls2.invoke();
            } else if (this.LJIJ != JKB.DOING) {
                this.LJIJ = JKB.DOING;
                C2736Kxb kxb = new C2736Kxb(this, ls2);
                int i = C2807Kyk.LIZ[this.LJJI.ordinal()];
                if (i == 1) {
                    View view = this.LJI;
                    if (view == null) {
                        n.LIZ();
                    }
                    view.animate().translationX((float) LJI().getWidth()).setDuration(300).setListener(LIZIZ(kxb)).start();
                } else if (i == 2) {
                    AnimatorSet animatorSet = new AnimatorSet();
                    animatorSet.addListener(LIZIZ(kxb));
                    animatorSet.setDuration(300);
                    animatorSet.setInterpolator(new 7Ks((byte) 0));
                    Animator[] animatorArr = new Animator[1];
                    View view2 = this.LJI;
                    float[] fArr = new float[2];
                    if (view2 == null) {
                        n.LIZ();
                    }
                    fArr[0] = view2.getTranslationY();
                    fArr[1] = (float) LJI().getHeight();
                    ObjectAnimator ofFloat = ObjectAnimator.ofFloat(view2, "translationY", fArr);
                    n.LIZ(ofFloat, "");
                    animatorArr[0] = ofFloat;
                    List LIZJ2 = C4097LeS.LIZJ(animatorArr);
                    if (LJII() != null) {
                        C2793KyW LJII2 = LJII();
                        if (LJII2 == null) {
                            n.LIZ();
                        }
                        LIZJ2.add(LJII2.LIZJ());
                    }
                    animatorSet.playTogether(LIZJ2);
                    animatorSet.start();
                } else if (i != 3) {
                    kxb.invoke();
                } else {
                    C2793KyW LJII3 = LJII();
                    if (LJII3 != null) {
                        animator = LJII3.LIZJ();
                    } else {
                        animator = null;
                    }
                    if (LJII() == null || animator == null) {
                        kxb.invoke();
                        return;
                    }
                    animator.setDuration(300);
                    animator.addListener(LIZIZ(kxb));
                    animator.start();
                }
            }
        } catch (Exception e) {
            C1421KcO.LIZ(this, "dismiss failed with: " + e.getMessage(), (C1424KcR) null, "popup", 2);
        }
    }

    public final void printReject(Throwable th, String str) {
        M12.LIZ((Object) th, (Object) str);
        C1421KcO.LIZ(this, th, str);
    }

    public final void LIZ(View view, C0984KOx kOx) {
        if (view != null) {
            view.post(new C2735Kxa(this, kOx));
        }
    }

    public static Object LIZ(Context context, String str) {
        Object obj;
        MethodCollector.i(910);
        if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) {
            if (!2FV.LIZIZ && "connectivity".equals(str)) {
                try {
                    new 7s1().LIZ();
                    2FV.LIZIZ = true;
                    obj = context.getSystemService(str);
                } catch (Throwable unused) {
                }
            }
            obj = context.getSystemService(str);
        } else if (2FV.LIZ) {
            synchronized (ClipboardManager.class) {
                try {
                    obj = context.getSystemService(str);
                    if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
                        Field declaredField = ClipboardManager.class.getDeclaredField("mHandler");
                        declaredField.setAccessible(true);
                        declaredField.set(obj, new 2He((Handler) declaredField.get(obj)));
                    }
                } catch (Exception e) {
                    8jA.LIZ(e, "ClipboardManager Handler Reflect Fail");
                } catch (Throwable th) {
                    MethodCollector.o(910);
                    throw th;
                }
                2FV.LIZ = false;
            }
        } else {
            obj = context.getSystemService(str);
        }
        MethodCollector.o(910);
        return obj;
    }

    public final void onViewCreated(View view, Bundle bundle) {
        C2744Kxj kxj;
        Dialog dialog;
        Window window;
        M12.LIZ((Object) view);
        BulletPopUpFragment.super.onViewCreated(view, bundle);
        if (this.LJIILIIL == null || this.LJIILL == null) {
            C1421KcO.LIZ(this, "act and config is not init, dismiss dialog fragment", (C1424KcR) null, "popup", 2);
            dismissAllowingStateLoss();
            return;
        }
        C2727KxS kxS = this.LJIILL;
        if (kxS == null) {
            n.LIZ("");
        }
        this.LJII = kxS.LJJIFFI;
        view.post(new C2796KyZ(this, view));
        C2727KxS kxS2 = this.LJIILL;
        if (kxS2 == null) {
            n.LIZ("");
        }
        view.setBackgroundColor(Color.parseColor(kxS2.LJIIIZ));
        C2793KyW LJII2 = LJII();
        if (LJII2 != null) {
            LJII2.LIZ();
        }
        C2727KxS kxS3 = this.LJIILL;
        if (kxS3 == null) {
            n.LIZ("");
        }
        if (!(!kxS3.LJIILL || (dialog = getDialog()) == null || (window = dialog.getWindow()) == null)) {
            JKQ jkq = JKQ.LIZ;
            n.LIZ(window, "");
            Context context = window.getContext();
            n.LIZ(context, "");
            jkq.LIZ(window, context, new C2732KxX(window, this));
        }
        C2727KxS kxS4 = this.LJIILL;
        if (kxS4 == null) {
            n.LIZ("");
        }
        int i = kxS4.LIZLLL;
        if (i == 0) {
            C1633Kfo kfo = LJIL;
            C2727KxS kxS5 = this.LJIILL;
            if (kxS5 == null) {
                n.LIZ("");
            }
            BulletPopUpFragment LIZ2 = kfo.LIZ(kxS5.LJIILLIIL);
            if (LIZ2 != null && (kxj = LIZ2.LJ) != null) {
                kxj.LIZLLL();
            }
        } else if (i == 3) {
            C1633Kfo kfo2 = LJIL;
            C2727KxS kxS6 = this.LJIILL;
            if (kxS6 == null) {
                n.LIZ("");
            }
            BulletPopUpFragment LIZ3 = kfo2.LIZ(kxS6.LJIILLIIL);
            if (LIZ3 != null) {
                LIZ3.LJFF = null;
                C2744Kxj kxj2 = LIZ3.LJ;
                if (kxj2 != null) {
                    kxj2.LJ();
                }
            }
        }
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ((Object) layoutInflater);
        return LJI();
    }

    public final void printLog(String str, C1424KcR kcR, String str2) {
        M12.LIZ(str, kcR, str2);
        C1421KcO.LIZ(this, str, kcR, str2);
    }
}
