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

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.7s1;
import X.8jA;
import X.C1017KQe;
import X.C1421KcO;
import X.C1422KcP;
import X.C1424KcR;
import X.C2425Ksa;
import X.C2727KxS;
import X.C2744Kxj;
import X.C2745Kxk;
import X.C2746Kxl;
import X.C2747Kxm;
import X.C2748Kxn;
import X.C2749Kxo;
import X.C2750Kxp;
import X.C2751Kxq;
import X.C2793KyW;
import X.C2795KyY;
import X.C2799Kyc;
import X.C2801Kye;
import X.C2806Kyj;
import X.C2811Kyo;
import X.C2812Kyp;
import X.C3931Lbm;
import X.C4097LeS;
import X.C4105Lea;
import X.C4939Ls2;
import X.Crj;
import X.HcT;
import X.JKB;
import X.JKQ;
import X.KTX;
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.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
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 java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import kotlin.h.b.n;
import org.json.JSONObject;

public abstract class BasePopUpFragment extends AppCompatDialogFragment implements C1017KQe, C1422KcP, KTX {
    public static final List<BasePopUpFragment> LJIIL = new ArrayList();
    public static final List<BasePopUpFragment> LJIILIIL = new ArrayList();
    public static final C2749Kxo LJIILJJIL = new C2749Kxo((byte) 0);
    public C2799Kyc LIZ;
    public C2811Kyo LIZIZ;
    public C2744Kxj LIZJ;
    public C4939Ls2<2Pr> LIZLLL;
    public View LJ;
    public boolean LJFF;
    public C2748Kxn LJI;
    public Activity LJII;
    public C2727KxS LJIIIIZZ;
    public C3931Lbm LJIIIZ;
    public JKB LJIIJ;
    public Throwable LJIIJJI;
    public final Crj LJIILL;
    public C2801Kye LJIILLIIL;
    public final Crj LJIIZILJ;
    public C2425Ksa LJIJ;
    public Boolean LJIJI;
    public Boolean LJIJJ;
    public final Crj LJIJJLI;
    public HashMap LJIL;

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

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

    public final C2812Kyp LJIIIIZZ() {
        return (C2812Kyp) this.LJIJJLI.getValue();
    }

    public abstract String LJIIIZ();

    public abstract View LJIIJ();

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

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

    public final void dismissAllowingStateLoss() {
        C2748Kxn kxn = C2748Kxn.UNKNOWN;
        M12.LIZ((Object) kxn);
        if (kxn == C2748Kxn.JSB) {
            this.LJI = kxn;
        }
        BasePopUpFragment.super.dismissAllowingStateLoss();
    }

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

    public void onResume() {
        BasePopUpFragment.super.onResume();
        this.LJIJJ = true;
        n.LIZ(this.LJIJI, true);
    }

    static {
        Covode.recordClassIndex(28818);
    }

    public void onPause() {
        BasePopUpFragment.super.onPause();
        this.LJIJJ = false;
        n.LIZ(this.LJIJI, true);
    }

    public void onStop() {
        BasePopUpFragment.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 void onDestroy() {
        BasePopUpFragment.super.onDestroy();
        if (this.LJII != null && this.LJIIIIZZ != null) {
            JSONObject jSONObject = new JSONObject();
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("containerID", LJIIIZ());
            jSONObject.put("data", jSONObject2);
            jSONObject.put("eventName", "onClosePanel");
            new Handler().postDelayed(new C2751Kxq(this), 100);
            M12.LIZ((Object) this);
            List<BasePopUpFragment> list = LJIIL;
            list.remove(this);
            BasePopUpFragment basePopUpFragment = (BasePopUpFragment) C4105Lea.LJIIJ(list);
            if (basePopUpFragment != null) {
                C2727KxS kxS = basePopUpFragment.LJIIIIZZ;
                if (kxS == null) {
                    n.LIZ("");
                }
                if (kxS.LIZLLL == 3) {
                    basePopUpFragment.LJIIJJI();
                }
            }
            LJIILIIL.add(this);
            C2727KxS kxS2 = this.LJIIIIZZ;
            if (kxS2 == null) {
                n.LIZ("");
            }
            if (kxS2.LIZLLL == 1) {
                C2749Kxo kxo = LJIILJJIL;
                C2727KxS kxS3 = this.LJIIIIZZ;
                if (kxS3 == null) {
                    n.LIZ("");
                }
                BasePopUpFragment LIZ2 = kxo.LIZ(kxS3.LJIILLIIL);
                if (LIZ2 != null) {
                    LIZ2.LJIIJJI();
                }
            }
        }
    }

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

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

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

    public void onDismiss(DialogInterface dialogInterface) {
        if (this.LJI == C2748Kxn.UNKNOWN) {
            this.LJI = C2748Kxn.TAP_MASK;
        }
        C2425Ksa ksa = this.LJIJ;
        if (ksa != null) {
            ksa.LIZIZ(this);
        }
        BasePopUpFragment.super.onDismiss(dialogInterface);
    }

    public final void LIZ(C4939Ls2<2Pr> ls2) {
        Animator animator;
        String str;
        try {
            if (this.LJ == null || this.LJIILLIIL == C2801Kye.NONE || this.LJIIJ == JKB.DONE) {
                ls2.invoke();
            } else if (this.LJIIJJI != null) {
                StringBuilder sb = new StringBuilder("reAnimEnd with msg:");
                Throwable th = this.LJIIJJI;
                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.LJIIJ != JKB.DOING) {
                this.LJIIJ = JKB.DOING;
                C2750Kxp kxp = new C2750Kxp(this, ls2);
                int i = C2806Kyj.LIZ[this.LJIILLIIL.ordinal()];
                if (i == 1) {
                    View view = this.LJ;
                    if (view == null) {
                        n.LIZ();
                    }
                    view.animate().translationX((float) LJI().getWidth()).setDuration(300).setListener(LIZIZ(kxp)).start();
                } else if (i == 2) {
                    AnimatorSet animatorSet = new AnimatorSet();
                    animatorSet.addListener(LIZIZ(kxp));
                    animatorSet.setDuration(300);
                    animatorSet.setInterpolator(new 7Ks((byte) 0));
                    Animator[] animatorArr = new Animator[1];
                    View view2 = this.LJ;
                    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) {
                    kxp.invoke();
                } else {
                    C2793KyW LJII3 = LJII();
                    if (LJII3 != null) {
                        animator = LJII3.LIZJ();
                    } else {
                        animator = null;
                    }
                    if (LJII() == null || animator == null) {
                        kxp.invoke();
                        return;
                    }
                    animator.setDuration(300);
                    animator.addListener(LIZIZ(kxp));
                    animator.start();
                }
            }
        } catch (Exception e) {
            C1421KcO.LIZ(this, "dismiss failed with: " + e.getMessage(), (C1424KcR) null, "popup", 2);
        }
    }

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

    public void onViewCreated(View view, Bundle bundle) {
        C2744Kxj kxj;
        Dialog dialog;
        Window window;
        M12.LIZ((Object) view);
        BasePopUpFragment.super.onViewCreated(view, bundle);
        if (this.LJII == null || this.LJIIIIZZ == null) {
            C1421KcO.LIZ(this, "act and config is not init, dismiss dialog fragment", (C1424KcR) null, "popup", 2);
            dismissAllowingStateLoss();
            return;
        }
        C2727KxS kxS = this.LJIIIIZZ;
        if (kxS == null) {
            n.LIZ("");
        }
        this.LJFF = kxS.LJJIFFI;
        view.post(new C2795KyY(this, view));
        C2727KxS kxS2 = this.LJIIIIZZ;
        if (kxS2 == null) {
            n.LIZ("");
        }
        view.setBackgroundColor(Color.parseColor(kxS2.LJIIIZ));
        C2793KyW LJII2 = LJII();
        if (LJII2 != null) {
            LJII2.LIZ();
        }
        C2727KxS kxS3 = this.LJIIIIZZ;
        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 C2747Kxm(window, this));
        }
        C2727KxS kxS4 = this.LJIIIIZZ;
        if (kxS4 == null) {
            n.LIZ("");
        }
        int i = kxS4.LIZLLL;
        if (i == 0) {
            C2749Kxo kxo = LJIILJJIL;
            C2727KxS kxS5 = this.LJIIIIZZ;
            if (kxS5 == null) {
                n.LIZ("");
            }
            BasePopUpFragment LIZ2 = kxo.LIZ(kxS5.LJIILLIIL);
            if (!(LIZ2 == null || (kxj = LIZ2.LIZJ) == null)) {
                kxj.LIZLLL();
            }
        } else if (i == 3) {
            C2749Kxo kxo2 = LJIILJJIL;
            C2727KxS kxS6 = this.LJIIIIZZ;
            if (kxS6 == null) {
                n.LIZ("");
            }
            BasePopUpFragment LIZ3 = kxo2.LIZ(kxS6.LJIILLIIL);
            if (LIZ3 != null) {
                LIZ3.LIZLLL = null;
                C2744Kxj kxj2 = LIZ3.LIZJ;
                if (kxj2 != null) {
                    kxj2.LJ();
                }
            }
        }
        C2425Ksa ksa = this.LJIJ;
        if (ksa != null) {
            ksa.LIZ(this);
        }
    }

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