package com.bytedance.android.livesdk.interaction.custompoll;

import X.0CB;
import X.0CH;
import X.0Ul;
import X.0Ur;
import X.0Zm;
import X.0Zo;
import X.0Zp;
import X.0b0;
import X.0cm;
import X.0hP;
import X.1hK;
import X.2Pr;
import X.2us;
import X.47t;
import X.6Is;
import X.7he;
import X.C1064Fv7;
import X.C1190Fx9;
import X.C1393G1a;
import X.C1430G2l;
import X.C1434G2p;
import X.C1856GIv;
import X.C2182GVj;
import X.C2189GVq;
import X.C2199GWa;
import X.C2201GWc;
import X.C2675Gg0;
import X.C3491GtA;
import X.C4167H9s;
import X.C4366HHj;
import X.C6455Hzs;
import X.Crj;
import X.Crx;
import X.GW6;
import X.GWA;
import X.GWB;
import X.GWD;
import X.GWF;
import X.GWG;
import X.GWJ;
import X.GWK;
import X.GWN;
import X.GWO;
import X.GWP;
import X.GWQ;
import X.GWR;
import X.GWS;
import X.GWY;
import X.LsC;
import X.M12;
import X.Tib;
import android.animation.ValueAnimator;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.view.View;
import android.widget.TextView;
import com.bytedance.android.live.base.model.user.User;
import com.bytedance.android.live.function.IRoomFunctionService;
import com.bytedance.android.livesdk.model.UserAttr;
import com.bytedance.android.livesdk.model.message.PollMessage;
import com.bytedance.android.livesdk.model.message.PollStartContent;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.bytedance.ies.sdk.widgets.LiveRecyclableWidget;
import com.bytedance.ies.sdk.widgets.WidgetExtendsKt;
import java.util.ArrayList;
import java.util.List;
import kotlin.h.b.n;

public final class CustomPollCardWidget extends LiveRecyclableWidget implements 6Is {
    public static final C2201GWc LJFF = new C2201GWc((byte) 0);
    public final List<View> LIZ = new ArrayList();
    public final Handler LIZIZ = new Handler(Looper.getMainLooper());
    public final Runnable LIZJ = new GWK(this);
    public boolean LIZLLL;
    public String LJ = "timeout";
    public boolean LJI;
    public final Crj LJII = 7he.LIZ(new GWY(this));
    public final Crj LJIIIIZZ = 7he.LIZ(new GWQ(this));
    public final Crj LJIIIZ = 7he.LIZ(new GWP(this));
    public final Crj LJIIJ = 7he.LIZ(new GWS(this));
    public final Crj LJIIJJI = 7he.LIZ(new GWR(this));
    public final Crj LJIIL = 7he.LIZ(new GWO(this));
    public final Crj LJIILIIL = 7he.LIZ(new GWN(this));
    public 0Zo LJIILJJIL;
    public long LJIILL;
    public boolean LJIILLIIL;
    public final C2189GVq LJIIZILJ = new C2189GVq(this);
    public final ValueAnimator LJIJ;
    public final Crj LJIJI;

    static {
        Covode.recordClassIndex(17016);
    }

    private final C4167H9s LJ() {
        return (C4167H9s) this.LJII.getValue();
    }

    private final TextView LJFF() {
        return (TextView) this.LJIIIIZZ.getValue();
    }

    private final TextView LJI() {
        return (TextView) this.LJIIJ.getValue();
    }

    private final View LJII() {
        return (View) this.LJIIJJI.getValue();
    }

    private final View LJIIIIZZ() {
        return (View) this.LJIIL.getValue();
    }

    private final ValueAnimator LJIIIZ() {
        return (ValueAnimator) this.LJIJI.getValue();
    }

    public final TextView LIZ() {
        return (TextView) this.LJIIIZ.getValue();
    }

    public final View LIZIZ() {
        return (View) this.LJIILIIL.getValue();
    }

    public final int getLayoutId() {
        return 2131562170;
    }

    public final void onInit(Object[] objArr) {
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public final boolean isShowing() {
        return this.LIZLLL;
    }

    public final void LIZJ() {
        String str;
        if (C1430G2l.LIZJ(this.dataChannel)) {
            str = "anchor_click";
        } else if (LIZ(this.dataChannel)) {
            str = "moderator_close";
        } else {
            str = "audience_click";
        }
        this.LJ = str;
        hide();
    }

    public final void LIZLLL() {
        Context context;
        1hK LIZ2;
        Context context2 = this.context;
        if (context2 != null && C1430G2l.LIZ(context2) != null && (context = this.context) != null && (LIZ2 = C1430G2l.LIZ(context)) != null) {
            0hP.LIZ(0cm.LIZ(IRoomFunctionService.class), "poll_card", LIZ2, this.dataChannel);
        }
    }

    public final void onUnload() {
        Room room = (Room) this.dataChannel.LIZIZ(C1064Fv7.class);
        if (room != null) {
            C2182GVj.LJIIJJI.LIZIZ(room.getId(), (0Zm) this.LJIIZILJ);
        }
        this.LJ = "leave_room";
        hide();
        DataChannel dataChannel = this.dataChannel;
        if (dataChannel != null) {
            dataChannel.LIZIZ(C1190Fx9.class, false);
        }
        this.LIZIZ.removeCallbacksAndMessages((Object) null);
    }

    public CustomPollCardWidget() {
        ValueAnimator ofFloat = ValueAnimator.ofFloat(new float[]{0.0f, 1.0f});
        ofFloat.addUpdateListener(new Crx(this));
        this.LJIJ = ofFloat;
        this.LJIJI = 7he.LIZ(new GWD(this));
    }

    public final void hide() {
        String str;
        User user;
        String str2;
        Long l;
        String str3;
        Long l2;
        PollStartContent pollStartContent;
        Room room;
        C1856GIv streamType;
        PollStartContent pollStartContent2;
        if (this.LIZLLL) {
            0Zo r11 = this.LJIILJJIL;
            Boolean bool = null;
            if (r11 != null) {
                0Zp r7 = 0Zp.LIZ;
                DataChannel dataChannel = this.dataChannel;
                long uptimeMillis = SystemClock.uptimeMillis() - this.LJIILL;
                String str4 = this.LJ;
                M12.LIZ(r11, str4);
                if (C1430G2l.LJFF(dataChannel) || C1430G2l.LIZJ(dataChannel)) {
                    str = "livesdk_anchor_custom_poll_card_duration";
                } else {
                    str = "livesdk_poll_card_duration";
                }
                PollMessage pollMessage = r11.LJFF;
                if (pollMessage == null || (pollStartContent2 = pollMessage.LIZJ) == null) {
                    user = null;
                } else {
                    user = pollStartContent2.LJ;
                }
                String LIZ2 = r7.LIZ(user);
                C3491GtA LIZ3 = C3491GtA.LJFF.LIZ(str);
                LIZ3.LIZ(dataChannel);
                if (dataChannel == null || (room = (Room) dataChannel.LIZIZ(C1064Fv7.class)) == null || (streamType = room.getStreamType()) == null) {
                    str2 = null;
                } else {
                    str2 = C1393G1a.LIZ(streamType);
                }
                LIZ3.LIZ("live_type", str2);
                PollMessage pollMessage2 = r11.LJFF;
                if (pollMessage2 != null) {
                    l = Long.valueOf(pollMessage2.LIZIZ);
                } else {
                    l = null;
                }
                LIZ3.LIZ("poll_id", (Number) l);
                PollMessage pollMessage3 = r11.LJFF;
                if (pollMessage3 == null || (pollStartContent = pollMessage3.LIZJ) == null) {
                    str3 = null;
                } else {
                    str3 = pollStartContent.LIZLLL;
                }
                LIZ3.LIZ("poll_title", str3);
                LIZ3.LIZ("poll_sponsor", LIZ2);
                if (C1430G2l.LJFF(dataChannel)) {
                    User LIZ4 = 0Ur.LIZ.LIZ();
                    if (LIZ4 != null) {
                        l2 = Long.valueOf(LIZ4.getId());
                    } else {
                        l2 = null;
                    }
                    LIZ3.LIZ("moderator_id", (Number) l2);
                    LIZ3.LIZ("user_type", "moderator");
                } else if (C1430G2l.LIZJ(dataChannel)) {
                    LIZ3.LIZ("user_type", "anchor");
                }
                LIZ3.LIZ("duration", uptimeMillis);
                LIZ3.LIZ("end_type", str4);
                LIZ3.LIZLLL();
            }
            this.LJ = "others";
            this.LJIILJJIL = null;
            this.LIZLLL = false;
            this.LJIILL = 0;
            DataChannel dataChannel2 = this.dataChannel;
            if (dataChannel2 != null) {
                dataChannel2.LIZIZ(C1190Fx9.class, false);
            }
            this.LIZIZ.removeCallbacks(this.LIZJ);
            if (isViewValid()) {
                LJIIIZ().setFloatValues(new float[]{1.0f, 0.0f});
                LJIIIZ().start();
                ValueAnimator valueAnimator = this.LJIJ;
                n.LIZIZ(valueAnimator, "");
                valueAnimator.setStartDelay(0);
                this.LJIJ.setFloatValues(new float[]{1.0f, 0.0f});
                ValueAnimator valueAnimator2 = this.LJIJ;
                n.LIZIZ(valueAnimator2, "");
                valueAnimator2.setDuration(40);
                this.LJIJ.start();
                C4167H9s LJ2 = LJ();
                if (LJ2.LIZJ) {
                    LJ2.LIZJ = false;
                    LJ2.LIZIZ(0);
                    LJ2.LIZ(0);
                }
                DataChannel dataChannel3 = this.dataChannel;
                if (dataChannel3 != null) {
                    bool = Boolean.valueOf(C1430G2l.LIZJ(dataChannel3));
                }
                if (C1430G2l.LIZIZ(bool)) {
                    LIZIZ().postDelayed(new GWG(this), 100);
                }
                LIZIZ().postDelayed(new C2199GWa(this), 180);
            }
        }
    }

    public final void show() {
        String str;
        User user;
        String str2;
        Long l;
        String str3;
        PollStartContent pollStartContent;
        PollStartContent pollStartContent2;
        Room room;
        C1856GIv streamType;
        PollStartContent pollStartContent3;
        if (!this.LJI && !this.LIZLLL) {
            super.show();
            this.LIZLLL = true;
            if (C1430G2l.LIZJ(this.dataChannel) || LIZ(this.dataChannel)) {
                C1430G2l.LIZ(LJII());
            } else {
                C1430G2l.LIZIZ(LJII());
            }
            this.LJIILL = SystemClock.uptimeMillis();
            0Zo r3 = this.LJIILJJIL;
            if (r3 != null) {
                0Zp r2 = 0Zp.LIZ;
                DataChannel dataChannel = this.dataChannel;
                M12.LIZ(r3);
                if (C1430G2l.LJFF(dataChannel) || C1430G2l.LIZJ(dataChannel)) {
                    str = "livesdk_anchor_custom_poll_card_show";
                } else {
                    str = "livesdk_poll_card_show";
                }
                PollMessage pollMessage = r3.LJFF;
                Long l2 = null;
                if (pollMessage == null || (pollStartContent3 = pollMessage.LIZJ) == null) {
                    user = null;
                } else {
                    user = pollStartContent3.LJ;
                }
                String LIZ2 = r2.LIZ(user);
                C3491GtA LIZ3 = C3491GtA.LJFF.LIZ(str);
                LIZ3.LIZ(dataChannel);
                if (dataChannel == null || (room = (Room) dataChannel.LIZIZ(C1064Fv7.class)) == null || (streamType = room.getStreamType()) == null) {
                    str2 = null;
                } else {
                    str2 = C1393G1a.LIZ(streamType);
                }
                LIZ3.LIZIZ(str2);
                PollMessage pollMessage2 = r3.LJFF;
                if (pollMessage2 != null) {
                    l = Long.valueOf(pollMessage2.LIZIZ);
                } else {
                    l = null;
                }
                LIZ3.LIZ("poll_id", (Number) l);
                PollMessage pollMessage3 = r3.LJFF;
                if (pollMessage3 == null || (pollStartContent2 = pollMessage3.LIZJ) == null) {
                    str3 = null;
                } else {
                    str3 = pollStartContent2.LIZLLL;
                }
                LIZ3.LIZ("poll_title", str3);
                LIZ3.LIZ("poll_sponsor", LIZ2);
                if (C1430G2l.LJFF(dataChannel)) {
                    User LIZ4 = 0Ur.LIZ.LIZ();
                    if (LIZ4 != null) {
                        l2 = Long.valueOf(LIZ4.getId());
                    }
                    LIZ3.LIZ("moderator_id", (Number) l2);
                    LIZ3.LIZ("user_type", "moderator");
                } else if (C1430G2l.LIZJ(dataChannel)) {
                    LIZ3.LIZ("user_type", "anchor");
                }
                if (r3.LIZIZ > 0) {
                    PollMessage pollMessage4 = r3.LJFF;
                    if (!(pollMessage4 == null || (pollStartContent = pollMessage4.LIZJ) == null)) {
                        LIZ3.LIZ("time_remain", Math.max(0, pollStartContent.LIZIZ - (System.currentTimeMillis() + 47t.LIZ)));
                    }
                } else {
                    LIZ3.LIZ("time_remain", r3.LIZIZ);
                }
                LIZ3.LIZLLL();
            }
            this.dataChannel.LIZIZ(C1190Fx9.class, true);
            LJIIIZ().setFloatValues(new float[]{0.0f, 1.0f});
            LJIIIZ().start();
            this.LJIJ.setFloatValues(new float[]{0.0f, 1.0f});
            ValueAnimator valueAnimator = this.LJIJ;
            n.LIZIZ(valueAnimator, "");
            valueAnimator.setStartDelay(100);
            ValueAnimator valueAnimator2 = this.LJIJ;
            n.LIZIZ(valueAnimator2, "");
            valueAnimator2.setDuration(80);
            this.LJIJ.start();
            C4167H9s LJ2 = LJ();
            if (!LJ2.LIZJ) {
                LJ2.LIZJ = true;
                LJ2.requestLayout();
            }
        }
    }

    public final void LIZ(boolean z) {
        this.LJI = z;
        if (!z) {
            super.show();
        } else {
            super.hide();
        }
    }

    public final boolean LIZ(DataChannel dataChannel) {
        Boolean bool;
        UserAttr userAttr;
        User user;
        UserAttr userAttr2;
        if (dataChannel != null && (user = (User) dataChannel.LIZIZ(C1434G2p.class)) != null && (userAttr2 = user.getUserAttr()) != null) {
            return userAttr2.LIZIZ;
        }
        User LIZ2 = 0Ur.LIZ.LIZ();
        if (LIZ2 == null || (userAttr = LIZ2.getUserAttr()) == null) {
            bool = null;
        } else {
            bool = Boolean.valueOf(userAttr.LIZIZ);
        }
        return C1430G2l.LIZ(bool);
    }

    public final void LIZ(0Zo r11) {
        boolean z;
        Boolean bool;
        PollStartContent pollStartContent;
        PollStartContent pollStartContent2;
        PollStartContent pollStartContent3;
        User user;
        UserAttr userAttr;
        M12.LIZ(r11);
        if (C1430G2l.LIZJ(this.dataChannel) || LIZ(this.dataChannel)) {
            z = true;
        } else {
            z = false;
        }
        this.LJIILLIIL = z;
        this.LJIILJJIL = r11;
        if (r11.LIZIZ >= 0) {
            C1430G2l.LIZIZ((View) LIZ());
            if (r11.LIZIZ / 1000 >= 3600) {
                LIZ().setText(47t.LIZ((int) (r11.LIZIZ / 1000), ":"));
            } else {
                LIZ().setText(47t.LIZ(r11.LIZIZ / 1000));
            }
        } else {
            C1430G2l.LIZ((View) LIZ());
        }
        if (!this.LJIILLIIL) {
            C1430G2l.LIZIZ(LJII());
        } else {
            C1430G2l.LIZ(LJII());
        }
        PollMessage pollMessage = r11.LJFF;
        User user2 = null;
        if (pollMessage == null || (pollStartContent3 = pollMessage.LIZJ) == null || (user = pollStartContent3.LJ) == null || (userAttr = user.getUserAttr()) == null) {
            bool = null;
        } else {
            bool = Boolean.valueOf(userAttr.LIZIZ);
        }
        if (!C1430G2l.LIZ(bool)) {
            LJFF().setText(0b0.LIZ(2131828499));
        } else if (C1430G2l.LIZJ(this.dataChannel) || LIZ(this.dataChannel)) {
            TextView LJFF2 = LJFF();
            Object[] objArr = new Object[1];
            PollMessage pollMessage2 = r11.LJFF;
            if (!(pollMessage2 == null || (pollStartContent2 = pollMessage2.LIZJ) == null)) {
                user2 = pollStartContent2.LJ;
            }
            objArr[0] = 0Ul.LIZ(user2);
            LJFF2.setText(0b0.LIZ(2131828505, objArr));
        } else {
            LJFF().setText(0b0.LIZ(2131828504));
        }
        LJI().setText("");
        PollMessage pollMessage3 = r11.LJFF;
        if (pollMessage3 != null && (pollStartContent = pollMessage3.LIZJ) != null) {
            LJI().setText(pollStartContent.LIZLLL);
        }
    }

    public final void onLoad(Object[] objArr) {
        List<View> list = this.LIZ;
        TextView LJFF2 = LJFF();
        LJFF2.setAlpha(0.0f);
        list.add(LJFF2);
        List<View> list2 = this.LIZ;
        TextView LJI2 = LJI();
        LJI2.setAlpha(0.0f);
        list2.add(LJI2);
        List<View> list3 = this.LIZ;
        View findViewById = findViewById(2131363887);
        findViewById.setAlpha(0.0f);
        n.LIZIZ(findViewById, "");
        list3.add(findViewById);
        List<View> list4 = this.LIZ;
        TextView LIZ2 = LIZ();
        LIZ2.setAlpha(0.0f);
        list4.add(LIZ2);
        List<View> list5 = this.LIZ;
        View LJII2 = LJII();
        LJII2.setAlpha(0.0f);
        list5.add(LJII2);
        List<View> list6 = this.LIZ;
        View LJIIIIZZ2 = LJIIIIZZ();
        LJIIIIZZ2.setAlpha(0.0f);
        list6.add(LJIIIIZZ2);
        C1430G2l.LIZ(LJII(), 500, (LsC<? super View, 2Pr>) new GWA(this));
        View view = getView();
        if (view != null) {
            C1430G2l.LIZ(view, 500, (LsC<? super View, 2Pr>) new GWB(this));
        }
        C1430G2l.LIZ(LJIIIIZZ(), 500, (LsC<? super View, 2Pr>) new GWF(this));
        Room room = (Room) this.dataChannel.LIZIZ(C1064Fv7.class);
        if (room != null) {
            long id = room.getId();
            0Zo r5 = C2182GVj.LJIIJ.get(id);
            C2182GVj.LJIIJ.remove(id);
            if (r5 != null) {
                2us r4 = new 2us();
                r4.element = 0;
                this.dataChannel.LIZIZ((0CH) this, C1434G2p.class, new GW6(r4, r5, room, this));
            }
            C2182GVj.LJIIJJI.LIZ(room.getId(), (0Zm) this.LJIIZILJ);
        }
        ((C4366HHj) C2675Gg0.LIZ().LIZ(Tib.class).LIZ(new C6455Hzs()).LIZ(WidgetExtendsKt.autoDispose(this))).LIZ(new GWJ(this));
    }
}
