package com.ss.android.ugc.aweme.relation.base;

import X.0AA;
import X.0AP;
import X.2Pr;
import X.2te;
import X.2th;
import X.C0436Cwu;
import X.C1633Dcr;
import X.LsC;
import X.M12;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.fragment.app.DialogFragment;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.common.ui.BaseDialogFragment;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import kotlin.h.b.n;

public final class CustomDialogFragment extends BaseDialogFragment {
    public static final C1633Dcr LJII = new C1633Dcr((byte) 0);
    public View LIZ;
    public boolean LIZIZ;
    public C0436Cwu<Integer, Integer> LIZJ;
    public final List<LsC<Window, 2Pr>> LIZLLL = new ArrayList();
    public LsC<? super String, 2Pr> LJ;
    public DialogInterface.OnCancelListener LJFF;
    public String LJI = "default";
    public SparseArray LJIIIIZZ;

    static {
        Covode.recordClassIndex(102705);
    }

    public final Window LIZ() {
        Dialog dialog = getDialog();
        if (dialog != null) {
            return dialog.getWindow();
        }
        return null;
    }

    public final /* synthetic */ void onDestroyView() {
        CustomDialogFragment.super.onDestroyView();
        SparseArray sparseArray = this.LJIIIIZZ;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    public final void onStart() {
        TypedArray obtainStyledAttributes;
        CustomDialogFragment.super.onStart();
        Context context = getContext();
        if (context != null && (obtainStyledAttributes = context.obtainStyledAttributes((AttributeSet) null, new int[]{2130968736, 2130968737, 2130968738, 2130968739, 2130968740, 2130968741, 2130968742, 2130968743, 2130968744, 2130968745, 2130968746, 2130968747, 2130968748, 2130968749, 2130968750, 2130968751, 2130968752, 2130968753, 2130968754}, 2130968685, 0)) != null) {
            int resourceId = obtainStyledAttributes.getResourceId(0, 0);
            Dialog dialog = getDialog();
            n.LIZIZ(dialog, "");
            Window window = dialog.getWindow();
            if (window != null) {
                window.setWindowAnimations(resourceId);
            }
            obtainStyledAttributes.recycle();
        }
    }

    public final void onCancel(DialogInterface dialogInterface) {
        CustomDialogFragment.super.onCancel(dialogInterface);
        DialogInterface.OnCancelListener onCancelListener = this.LJFF;
        if (onCancelListener != null) {
            onCancelListener.onCancel(dialogInterface);
        }
    }

    public final void onDismiss(DialogInterface dialogInterface) {
        CustomDialogFragment.super.onDismiss(dialogInterface);
        LsC<? super String, 2Pr> lsC = this.LJ;
        if (lsC != null) {
            lsC.invoke(this.LJI);
        }
    }

    public final void LIZ(LsC<? super Window, 2Pr> lsC) {
        Window window;
        M12.LIZ(lsC);
        Dialog dialog = getDialog();
        if (dialog == null || (window = dialog.getWindow()) == null) {
            this.LIZLLL.add(lsC);
            return;
        }
        lsC.invoke(window);
        window.setAttributes(window.getAttributes());
    }

    public final void onCreate(Bundle bundle) {
        CustomDialogFragment.super.onCreate(bundle);
        if (bundle != null) {
            dismissAllowingStateLoss();
        }
        C0436Cwu<Integer, Integer> cwu = this.LIZJ;
        if (cwu != null) {
            setStyle(cwu.getFirst().intValue(), cwu.getSecond().intValue());
        }
    }

    public final void onViewCreated(View view, Bundle bundle) {
        M12.LIZ(view);
        CustomDialogFragment.super.onViewCreated(view, bundle);
        Window LIZ2 = LIZ();
        if (LIZ2 != null) {
            Iterator<T> it = this.LIZLLL.iterator();
            while (it.hasNext()) {
                ((LsC) it.next()).invoke(LIZ2);
            }
            this.LIZLLL.clear();
            LIZ2.setAttributes(LIZ2.getAttributes());
        }
    }

    public final void show(0AA r6, String str) {
        if (r6 != null) {
            try {
                Field declaredField = DialogFragment.class.getDeclaredField("mDismissed");
                n.LIZIZ(declaredField, "");
                declaredField.setAccessible(true);
                declaredField.set(this, false);
                Field declaredField2 = DialogFragment.class.getDeclaredField("mShownByMe");
                n.LIZIZ(declaredField2, "");
                declaredField2.setAccessible(true);
                declaredField2.set(this, true);
                2te.constructor-impl(2Pr.LIZ);
            } catch (Throwable th) {
                2te.constructor-impl(2th.LIZ(th));
            }
            0AP LIZ2 = r6.LIZ();
            n.LIZIZ(LIZ2, "");
            if (isAdded()) {
                LIZ2.LIZJ(this);
            } else {
                LIZ2.LIZ(this, str);
            }
            LIZ2.LIZJ();
        }
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        View view = this.LIZ;
        if (view != null) {
            return view;
        }
        throw new IllegalArgumentException("Required value was null.".toString());
    }
}
