package com.bytedance.android.live.slot;

import X.2cN;
import X.6Is;
import X.AnonymousClass0CB;
import X.AnonymousClass0CH;
import X.AnonymousClass0CM;
import X.AnonymousClass14N;
import X.AnonymousClass14P;
import X.C11100cm;
import X.C265614c;
import X.C266114h;
import X.C266214i;
import X.C266514l;
import X.C266914p;
import X.C267014q;
import X.C31351Mn;
import X.FvK;
import X.Fvh;
import X.Gc2;
import X.Gc3;
import X.HFY;
import android.os.Bundle;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import com.bytedance.android.live.slot.IFrameSlot;
import com.bytedance.android.livesdkapi.host.IHostAction;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.ies.sdk.widgets.LiveRecyclableWidget;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class FrameL2SlotWidget extends LiveRecyclableWidget implements AnonymousClass14N, Gc3, WeakHandler.IHandler, 6Is {
    public FrameSlotController LIZ;
    public IFrameSlot LIZIZ;
    public IFrameSlot.SlotViewModel LIZJ;
    public View LIZLLL;
    public boolean LJ;
    public 2cN LJFF;
    public boolean LJI;
    public long LJII;

    static {
        Covode.recordClassIndex(10559);
    }

    public final void LIZ(AnonymousClass14P r1) {
    }

    public final void LIZ(Throwable th) {
        Gc2.LIZ(this, th);
    }

    public int getLayoutId() {
        return 0;
    }

    public void handleMsg(Message message) {
    }

    public void onStateChanged(AnonymousClass0CH r1, AnonymousClass0CB r2) {
        FrameL2SlotWidget.super.onStateChanged(r1, r2);
    }

    public final String LJIIL() {
        return getClass().getName();
    }

    /* JADX WARNING: type inference failed for: r0v8, types: [com.bytedance.android.live.slot.FrameSlotController, X.0CG] */
    public void onUnload() {
        IFrameSlot.SlotViewModel slotViewModel = this.LIZJ;
        if (slotViewModel != null) {
            slotViewModel.LIZ((AnonymousClass0CH) this);
        }
        2cN r0 = this.LJFF;
        if (r0 != null) {
            r0.dispose();
        }
        if (this.dataChannel != null) {
            this.dataChannel.LIZIZ(FvK.class, 0);
            this.dataChannel.LIZIZ(Fvh.class, false);
        }
        this.LJ = false;
        if (this.LIZ != null) {
            getLifecycle().LIZIZ(this.LIZ);
            this.LIZ.onDestroy();
        }
        if (this.dataChannel != null) {
            this.dataChannel.LIZIZ(FvK.class, 0);
            this.dataChannel.LIZIZ(Fvh.class, false);
            this.dataChannel.LIZIZ(this);
        }
    }

    public void onInit(Object[] objArr) {
        hide();
    }

    public void onLoad(Object[] objArr) {
        if (this.dataChannel.LIZIZ(HFY.class) != null) {
            this.LJII = SystemClock.uptimeMillis();
            C31351Mn.LIZ.post(new C266914p(this), this);
        }
    }

    /* JADX WARNING: type inference failed for: r3v0, types: [com.bytedance.android.live.slot.FrameL2SlotWidget, X.0CH] */
    public final void LIZ(C266114h r4, IFrameSlot.SlotViewModel slotViewModel) {
        final C265614c r2 = r4.LIZIZ;
        this.LIZIZ = (IFrameSlot) r2.LJIIIZ();
        this.LIZJ = slotViewModel;
        slotViewModel.LIZ.observe(this, new AnonymousClass0CM<Pair<Boolean, String>>() {
            static {
                Covode.recordClassIndex(10561);
            }

            public final /* synthetic */ void onChanged(Object obj) {
                MethodCollector.i(292);
                Pair pair = (Pair) obj;
                if (FrameL2SlotWidget.this.getView() == null || pair == null) {
                    MethodCollector.o(292);
                    return;
                }
                if (Boolean.TRUE.equals(pair.first)) {
                    if ((FrameL2SlotWidget.this.getView() instanceof ViewGroup) && (!FrameL2SlotWidget.this.isShowing() || ((ViewGroup) Objects.requireNonNull(FrameL2SlotWidget.this.getView())).getChildCount() <= 0)) {
                        ((ViewGroup) FrameL2SlotWidget.this.getView()).removeAllViews();
                        FrameL2SlotWidget frameL2SlotWidget = FrameL2SlotWidget.this;
                        frameL2SlotWidget.LIZLLL = frameL2SlotWidget.LIZIZ.LIZ(FrameL2SlotWidget.this.getContext());
                        if (FrameL2SlotWidget.this.LIZLLL != null) {
                            ((ViewGroup) FrameL2SlotWidget.this.getView()).addView(FrameL2SlotWidget.this.LIZLLL);
                            if (!FrameL2SlotWidget.this.LJ) {
                                r2.LIZ("during_live");
                                FrameL2SlotWidget.this.show();
                                HashMap hashMap = new HashMap();
                                if (!FrameL2SlotWidget.this.LJI) {
                                    C266214i.LIZ.LIZ(hashMap, FrameL2SlotWidget.this.LIZ.LJII, FrameL2SlotWidget.this.LJII);
                                    C266514l.LIZ.LIZ(r2, (Map<String, String>) hashMap);
                                }
                                FrameL2SlotWidget.this.LJI = true;
                                C266514l.LIZ.LIZ("FrameL2SlotWidget", r2, "slot visible change, visible: true", (Object) hashMap);
                                if (FrameL2SlotWidget.this.dataChannel != null) {
                                    FrameL2SlotWidget.this.dataChannel.LIZIZ(Fvh.class, true);
                                }
                                Animation LIZ2 = FrameL2SlotWidget.this.LIZIZ.LIZ();
                                if (LIZ2 != null) {
                                    FrameL2SlotWidget.this.LIZLLL.startAnimation(LIZ2);
                                    C266514l.LIZ.LIZ("FrameL2SlotWidget", r2, "slot start in anim");
                                }
                                if (!FrameL2SlotWidget.this.LIZLLL.hasOnClickListeners()) {
                                    FrameL2SlotWidget.this.LIZLLL.setOnClickListener(new View.OnClickListener() {
                                        static {
                                            Covode.recordClassIndex(10562);
                                        }

                                        public final void onClick(View view) {
                                            if (!TextUtils.isEmpty((CharSequence) null)) {
                                                C11100cm.LIZ(IHostAction.class).openLiveBrowser((String) null, new Bundle(), FrameL2SlotWidget.this.getContext());
                                            }
                                        }
                                    });
                                }
                                FrameL2SlotWidget.this.LIZLLL.post(new Runnable() {
                                    static {
                                        Covode.recordClassIndex(10563);
                                    }

                                    public final void run() {
                                        if (FrameL2SlotWidget.this.dataChannel != null) {
                                            FrameL2SlotWidget.this.dataChannel.LIZIZ(FvK.class, Integer.valueOf(FrameL2SlotWidget.this.LIZLLL.getHeight()));
                                        }
                                    }
                                });
                                MethodCollector.o(292);
                                return;
                            }
                        }
                    }
                } else if (FrameL2SlotWidget.this.LIZLLL != null && FrameL2SlotWidget.this.isShowing()) {
                    Animation LIZIZ2 = FrameL2SlotWidget.this.LIZIZ.LIZIZ();
                    if (LIZIZ2 == null || "visibility_reason_conflict".equals(pair.second) || "visibility_reason_dispose".equals(pair.second)) {
                        if (FrameL2SlotWidget.this.getView() instanceof ViewGroup) {
                            ((ViewGroup) FrameL2SlotWidget.this.getView()).removeAllViews();
                            FrameL2SlotWidget.this.hide();
                            C266514l.LIZ.LIZ("FrameL2SlotWidget", r2, "slot visible change, visible: false");
                        }
                        if (FrameL2SlotWidget.this.dataChannel != null) {
                            FrameL2SlotWidget.this.dataChannel.LIZIZ(FvK.class, 0);
                            FrameL2SlotWidget.this.dataChannel.LIZIZ(Fvh.class, false);
                            MethodCollector.o(292);
                            return;
                        }
                    } else {
                        LIZIZ2.setAnimationListener(new Animation.AnimationListener() {
                            static {
                                Covode.recordClassIndex(10564);
                            }

                            public final void onAnimationRepeat(Animation animation) {
                            }

                            public final void onAnimationStart(Animation animation) {
                            }

                            public final void onAnimationEnd(Animation animation) {
                                View view = FrameL2SlotWidget.this.getView();
                                if (view != null) {
                                    view.post(new C267014q(this, view, r2));
                                }
                                if (FrameL2SlotWidget.this.dataChannel != null) {
                                    FrameL2SlotWidget.this.dataChannel.LIZIZ(FvK.class, 0);
                                    FrameL2SlotWidget.this.dataChannel.LIZIZ(Fvh.class, false);
                                }
                            }
                        });
                        FrameL2SlotWidget.this.LIZLLL.startAnimation(LIZIZ2);
                        C266514l.LIZ.LIZ("FrameL2SlotWidget", r2, "slot start end anim");
                    }
                }
                MethodCollector.o(292);
            }
        });
    }
}
