package com.bytedance.android.livesdk.drawerfeed;

import X.091;
import X.094;
import X.0AP;
import X.0UK;
import X.0bM;
import X.0cm;
import X.0hS;
import X.5Fn;
import X.86a;
import X.C1044Fun;
import X.C1344Fzd;
import X.C1612G9l;
import X.C2675Gg0;
import X.C3491GtA;
import X.C3499GtI;
import X.C3800Gy9;
import X.C3849Gyw;
import X.C3850Gyx;
import X.C5112HeD;
import X.Mjy;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.fragment.app.Fragment;
import com.bytedance.android.feed.api.ILiveFeedApiService;
import com.bytedance.android.livesdk.LiveDialogFragment;
import com.bytedance.covode.number.Covode;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LiveDrawerDialog extends LiveDialogFragment {
    public 094 LIZ;
    public Fragment LIZIZ;
    public C1612G9l LIZJ;
    public Bundle LIZLLL;
    public String LJ;
    public long LJFF;
    public List<091> LJI;
    public final Mjy LJII = new Mjy();
    public boolean LJIIIIZZ = false;
    public 091 LJIIIZ = new 091() {
        static {
            Covode.recordClassIndex(15834);
        }

        public final void LIZ(float f) {
        }

        public final void LIZIZ() {
            0UK.LJII.LJ = 0UK.LJIIIZ;
            C1344Fzd.LIZ().LIZJ();
            if (LiveDrawerDialog.this.getUserVisibleHint()) {
                LiveDrawerDialog.this.LIZLLL();
            }
            LiveDrawerDialog.this.dismissAllowingStateLoss();
        }

        public final void LIZ() {
            String str;
            C1344Fzd.LIZ().LIZIZ();
            if (LiveDrawerDialog.this.getUserVisibleHint()) {
                LiveDrawerDialog liveDrawerDialog = LiveDrawerDialog.this;
                if (!86a.LIZ(liveDrawerDialog.LJ)) {
                    str = liveDrawerDialog.LJ;
                } else {
                    str = "button";
                }
                HashMap hashMap = new HashMap();
                liveDrawerDialog.LJFF = SystemClock.elapsedRealtime();
                hashMap.put("request_page", C3499GtI.LIZ().LJ());
                C3491GtA LIZ2 = C3491GtA.LJFF.LIZ("livesdk_more_anchor_show");
                LIZ2.LIZ((Map<String, String>) hashMap);
                LIZ2.LIZLLL(str);
                LIZ2.LIZ(liveDrawerDialog.LJIILIIL);
                LIZ2.LIZLLL();
            }
        }

        public final void LIZ(int i) {
            if (i == 0 && LiveDrawerDialog.this.LIZ != null && !LiveDrawerDialog.this.LIZ.LIZJ(8388613)) {
                LiveDrawerDialog.this.LIZ.LIZIZ(true);
                LiveDrawerDialog.this.dismissAllowingStateLoss();
            }
        }
    };

    static {
        Covode.recordClassIndex(15831);
    }

    public final C1044Fun LIZ() {
        C1044Fun fun = new C1044Fun(2131559555);
        fun.LIZ = 0;
        fun.LIZIZ = 2131887121;
        return fun;
    }

    public final boolean LJIIIIZZ() {
        094 r0 = this.LIZ;
        if (r0 == null || !r0.isAttachedToWindow() || !this.LIZ.LIZJ(8388613)) {
            return false;
        }
        this.LIZ.LIZIZ(true);
        return true;
    }

    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        if (window != null) {
            window.addFlags(Integer.MIN_VALUE);
            window.setNavigationBarColor(-16777216);
            window.setLayout(-1, -1);
            if (getActivity() != null && 0bM.LIZ(getActivity())) {
                window.clearFlags(1024);
            }
        }
    }

    public final void LIZLLL() {
        String str;
        if (!86a.LIZ(this.LJ)) {
            str = this.LJ;
        } else {
            str = "button";
        }
        HashMap hashMap = new HashMap();
        hashMap.put("duration", String.valueOf(SystemClock.elapsedRealtime() - this.LJFF));
        hashMap.put("request_page", C3499GtI.LIZ().LJ());
        if (!86a.LIZ(C3499GtI.LIZ().LJ())) {
            hashMap.put("enter_live_method", C3499GtI.LIZ().LJ());
        }
        C3491GtA LIZ2 = C3491GtA.LJFF.LIZ("livesdk_more_anchor_duration");
        LIZ2.LIZ((Map<String, String>) hashMap);
        LIZ2.LIZLLL(str);
        LIZ2.LIZ(this.LJIILIIL);
        LIZ2.LIZLLL();
    }

    public void onDismiss(DialogInterface dialogInterface) {
        super.onDismiss(dialogInterface);
        this.LJII.LIZ();
    }

    public final /* synthetic */ boolean LIZ(int i, KeyEvent keyEvent) {
        boolean z;
        if (4 == i) {
            if (keyEvent.getAction() == 0) {
                this.LJIIIIZZ = true;
                return false;
            }
        } else if (4 != i) {
            return false;
        }
        if (1 != keyEvent.getAction()) {
            return false;
        }
        if (this.LJIIIIZZ) {
            z = LJIIIIZZ();
        } else {
            z = false;
        }
        this.LJIIIIZZ = false;
        return z;
    }

    public void onViewCreated(final View view, Bundle bundle) {
        super.onViewCreated(view, bundle);
        this.LJII.LIZ(C2675Gg0.LIZ().LIZ(0hS.class).LIZLLL(new C3850Gyx(this)));
        094 findViewById = view.findViewById(2131364260);
        this.LIZ = findViewById;
        findViewById.LIZ(this.LJIIIZ);
        if (5Fn.LIZIZ(this.LJI)) {
            for (091 LIZ2 : this.LJI) {
                this.LIZ.LIZ(LIZ2);
            }
        }
        ViewGroup viewGroup = (ViewGroup) view.findViewById(2131368345);
        int LIZ3 = (int) (((float) C5112HeD.LIZ(getContext())) - C5112HeD.LIZIZ(getContext(), 50.0f));
        if (LIZ3 > 0) {
            ViewGroup.LayoutParams layoutParams = viewGroup.getLayoutParams();
            layoutParams.width = LIZ3;
            viewGroup.setLayoutParams(layoutParams);
            this.LIZ.post(new Runnable() {
                static {
                    Covode.recordClassIndex(15832);
                }

                public final void run() {
                    if (LiveDrawerDialog.this.isVisible()) {
                        if (LiveDrawerDialog.this.LIZ != null) {
                            LiveDrawerDialog.this.LIZ.LIZ(true);
                        }
                        if (LiveDrawerDialog.this.LIZIZ == null) {
                            LiveDrawerDialog.this.LIZJ = (C1612G9l) view.findViewById(2131364168);
                            LiveDrawerDialog.this.LIZJ.setVisibility(0);
                            LiveDrawerDialog.this.LIZIZ = 0cm.LIZ(ILiveFeedApiService.class).createDrawerFeedFragment(new C3800Gy9() {
                                static {
                                    Covode.recordClassIndex(15833);
                                }

                                public final void LIZIZ() {
                                    LiveDrawerDialog.this.LIZLLL();
                                    LiveDrawerDialog.this.dismiss();
                                }

                                public final void LIZJ() {
                                    LiveDrawerDialog liveDrawerDialog = LiveDrawerDialog.this;
                                    if (liveDrawerDialog.LIZJ != null) {
                                        liveDrawerDialog.LIZJ.setVisibility(8);
                                    }
                                }

                                public final void LIZ() {
                                    LiveDrawerDialog liveDrawerDialog = LiveDrawerDialog.this;
                                    if (liveDrawerDialog.LIZ != null && liveDrawerDialog.LIZ.isAttachedToWindow()) {
                                        liveDrawerDialog.LIZ.requestDisallowInterceptTouchEvent(true);
                                    }
                                }
                            });
                            if (LiveDrawerDialog.this.LIZIZ != null) {
                                LiveDrawerDialog.this.LIZIZ.setArguments(LiveDrawerDialog.this.LIZLLL);
                            }
                        }
                        if (LiveDrawerDialog.this.LIZIZ != null && !LiveDrawerDialog.this.LIZIZ.isAdded()) {
                            0AP LIZ2 = LiveDrawerDialog.this.getChildFragmentManager().LIZ();
                            LIZ2.LIZ(2131368344, LiveDrawerDialog.this.LIZIZ);
                            LIZ2.LIZJ();
                        }
                    }
                }
            });
            getDialog().setOnKeyListener(new C3849Gyw(this));
        }
    }

    public static LiveDrawerDialog LIZ(List<091> list, Bundle bundle, String str) {
        LiveDrawerDialog liveDrawerDialog = new LiveDrawerDialog();
        liveDrawerDialog.LJI = list;
        liveDrawerDialog.LIZLLL = bundle;
        liveDrawerDialog.LJ = str;
        return liveDrawerDialog;
    }
}
