package com.ss.android.ugc.aweme.feed.adapter;

import X.0CM;
import X.0QK;
import X.2GO;
import X.2UX;
import X.2cN;
import X.2dc;
import X.2nK;
import X.33g;
import X.3F7;
import X.3P1;
import X.4aP;
import X.C5233Etp;
import X.CuD;
import X.Cz0;
import X.CzM;
import X.FGN;
import X.GIv;
import X.GS2;
import X.GS7;
import X.Gsf;
import X.H2E;
import X.HDG;
import X.HIf;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.DecelerateInterpolator;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.android.livesdkapi.depend.model.live.SlimRoom;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.arch.widgets.base.DataCenter;
import com.ss.android.ugc.aweme.feed.feedwidget.FeedLiveWindowWidget;
import com.ss.android.ugc.aweme.feed.model.live.StreamUrlStruct;
import com.ss.android.ugc.aweme.follow.presenter.RoomStruct;
import com.ss.android.ugc.aweme.live.LiveOuterService;
import com.ss.android.ugc.aweme.profile.model.User;
import java.util.HashSet;
import java.util.Set;

public class FollowLiveVideoViewHolder extends FullFeedVideoViewHolder implements 2GO {
    public RoomStruct LIZLLL;
    public boolean LJ;
    public boolean LJFF;
    public View LJI;
    public View LJII;
    public boolean LJIIIIZZ;
    public Room LJIIIZ;
    public HDG LJIIJ = LiveOuterService.LJJI().LIZ((H2E) new H2E() {
        static {
            Covode.recordClassIndex(76437);
        }

        public final void LIZ(TextureView textureView, int i, int i2) {
        }

        public final void LIZ(String str) {
        }

        public final void LIZIZ() {
        }

        public final void LIZIZ(String str) {
        }

        public final void LIZJ(String str) {
        }

        public final void LIZLLL(String str) {
        }

        public final void LIZ() {
            int i;
            FollowLiveVideoViewHolder followLiveVideoViewHolder = FollowLiveVideoViewHolder.this;
            if (!followLiveVideoViewHolder.LJIIIIZZ) {
                followLiveVideoViewHolder.LJIIIIZZ = true;
                if (followLiveVideoViewHolder.LIZLLL != null) {
                    2UX r3 = new 2UX();
                    r3.LIZ("enter_from_merge", "homepage_follow");
                    r3.LIZ("action_type", "click");
                    r3.LIZ("anchor_id", followLiveVideoViewHolder.LIZLLL.ownerUserId);
                    r3.LIZ("room_id", followLiveVideoViewHolder.LIZLLL.id);
                    RoomStruct roomStruct = followLiveVideoViewHolder.LIZLLL;
                    if (roomStruct.owner != null) {
                        i = roomStruct.owner.getFollowStatus();
                        if (!(i == 0 || i == 1 || i == 2)) {
                            i = roomStruct.owner.getFollowerStatus() == 0 ? 0 : 3;
                        }
                    } else {
                        i = -1;
                    }
                    r3.LIZ("follow_status", i);
                    r3.LIZ("enter_method", "live_window");
                    if (followLiveVideoViewHolder.LJIIL != null) {
                        r3.LIZ("request_id", followLiveVideoViewHolder.LJIIL.getRequestId());
                        r3.LIZ("order", followLiveVideoViewHolder.LJIIL.getAwemePosition());
                    }
                    2nK.LIZ("livesdk_live_show", r3.LIZ);
                }
                followLiveVideoViewHolder.LIZ(followLiveVideoViewHolder.LJI, followLiveVideoViewHolder.LJII);
            }
        }

        public final void LIZ(HIf hIf, Object obj) {
            int i = 7.LIZ[hIf.ordinal()];
            if (i == 1 || i == 2) {
                FollowLiveVideoViewHolder.this.LJJIJL();
            }
        }
    });
    public int LJLJLLL = -1;
    public FeedLiveWindowWidget LJLL;
    public Animator LJLLI;
    public boolean LJLLILLLL;
    public boolean LJLLJ;
    public boolean LJLLL;
    public boolean LJLLLL;
    public 2cN LJLLLLLL;
    public Handler LJLZ = new Handler(Looper.getMainLooper()) {
        static {
            Covode.recordClassIndex(76436);
        }

        public final void handleMessage(Message message) {
            if (FollowLiveVideoViewHolder.this.LJFF && message.what == 100 && FollowLiveVideoViewHolder.this.LJ && FollowLiveVideoViewHolder.this.LJJIIZI()) {
                FollowLiveVideoViewHolder.this.LJJIJIL();
            }
        }
    };

    static {
        Covode.recordClassIndex(76435);
    }

    public final int LJIIJJI() {
        return 3;
    }

    private void LJLLLLLL() {
        this.LJLZ.removeMessages(100);
    }

    public final /* synthetic */ CuD aM_() {
        return aM_();
    }

    public final void cq_() {
        super.cq_();
        LJJIJIIJIL();
    }

    private void LJZI() {
        if (LJJIIZI()) {
            LJJIJL();
        }
    }

    private void LL() {
        Animator animator = this.LJLLI;
        if (animator != null) {
            animator.cancel();
            this.LJLLI = null;
        }
    }

    public final void LJII() {
        super.LJII();
        this.LJIIJ.LIZJ();
        this.LJLLILLLL = false;
    }

    public final void LJIILJJIL() {
        super.LJIILJJIL();
        this.LJIIJ.LJ();
        LJLLLLLL();
        LL();
    }

    public final boolean LJJIIZI() {
        RoomStruct roomStruct = this.LIZLLL;
        if (roomStruct == null || !roomStruct.isPullUrlValid()) {
            return false;
        }
        return true;
    }

    public final /* synthetic */ Long LJJIJLIJ() {
        return Long.valueOf(System.currentTimeMillis() - this.LJJLIIIJL);
    }

    private void LLF() {
        2cN r0 = this.LJLLLLLL;
        if (r0 != null) {
            if (!r0.isDisposed()) {
                this.LJLLLLLL.dispose();
            }
            this.LJLLLLLL = null;
        }
    }

    public final void LJI() {
        super.LJI();
        LJZI();
        if (this.LJIIIIZZ) {
            LJJIJIL();
        } else if (this.LJLLL) {
            LJZ();
        }
    }

    public final void LJJIJL() {
        3P1 LJ2 = LiveOuterService.LJJI().LJ();
        if (LJ2 != null) {
            LLF();
            this.LJLLLLLL = LJ2.LIZ(this.LIZLLL.id, new GS7() {
                static {
                    Covode.recordClassIndex(76439);
                }

                public final void LIZ(boolean z) {
                    boolean z2 = true;
                    if (z != FollowLiveVideoViewHolder.this.LJ) {
                        FollowLiveVideoViewHolder.this.LJ = z;
                        FollowLiveVideoViewHolder.this.LJLJJI().LIZ("live_has_end", (Object) Boolean.valueOf(!FollowLiveVideoViewHolder.this.LJ));
                        if (FollowLiveVideoViewHolder.this.LJFF) {
                            FollowLiveVideoViewHolder.this.LJJIJIIJIL();
                        }
                    }
                    if (!z) {
                        FollowLiveVideoViewHolder.this.LJIIJ.LIZ();
                        FollowLiveVideoViewHolder followLiveVideoViewHolder = FollowLiveVideoViewHolder.this;
                        if (!followLiveVideoViewHolder.LJFF || !FollowLiveVideoViewHolder.this.LJIIIIZZ) {
                            z2 = false;
                        }
                        followLiveVideoViewHolder.LJIIIZ(z2);
                    }
                }
            });
        }
    }

    public final CzM cr_() {
        if (this.LJLIIIL != null) {
            return this.LJLIIIL;
        }
        this.LJLIIIL = new Cz0(this.LJLJJLL, new FGN(this));
        return this.LJLIIIL;
    }

    private void LJZ() {
        long liveWindowShowTime = this.LJIIL.getLiveWindowShowTime() * 1000;
        if (liveWindowShowTime > 0) {
            if (liveWindowShowTime < 2000) {
                liveWindowShowTime = 2000;
            }
            Handler handler = this.LJLZ;
            handler.sendMessageDelayed(handler.obtainMessage(100), liveWindowShowTime);
        }
    }

    private void LJZL() {
        if (!this.LJIIIIZZ) {
            if (this.LJII.getVisibility() == 8) {
                this.LJII.setVisibility(0);
                this.LJII.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    static {
                        Covode.recordClassIndex(76438);
                    }

                    public final void onGlobalLayout() {
                        FollowLiveVideoViewHolder.this.LJII.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        View view = FollowLiveVideoViewHolder.this.LJII;
                        FollowLiveVideoViewHolder followLiveVideoViewHolder = FollowLiveVideoViewHolder.this;
                        view.setTranslationX(followLiveVideoViewHolder.LIZIZ(followLiveVideoViewHolder.LJII));
                    }
                });
                return;
            }
            this.LJII.setVisibility(0);
            View view = this.LJII;
            view.setTranslationX(LIZIZ(view));
        }
    }

    private boolean LLD() {
        Object LIZIZ;
        User author = this.LJIIL.getAuthor();
        if (author != null) {
            long j = author.roomId;
            if (j > 0 && (LIZIZ = LJLJJI().LIZIZ("key_open_live_aweme_list", null)) != null && (LIZIZ instanceof Set)) {
                return ((Set) LIZIZ).contains(Long.valueOf(j));
            }
        }
        return false;
    }

    public final void LIZJ() {
        super.LIZJ();
        this.LJ = false;
        this.LJIIIZ = null;
        this.LJLLLL = false;
        this.LJIIIIZZ = false;
        LL();
        LLF();
        if (this.LJII.getVisibility() == 0) {
            this.LJII.setVisibility(4);
            this.LJII.setTranslationX(0.0f);
        }
        if (this.LJI.getVisibility() != 0) {
            this.LJI.setVisibility(0);
            this.LJI.setTranslationX(0.0f);
        }
    }

    public final void LJIILL() {
        super.LJIILL();
        DataCenter LJLJJI = LJLJJI();
        LJLJJI.LIZ("dismiss_live_window", (0CM<33g>) this);
        LJLJJI.LIZ("live_window_clicked", (0CM<33g>) this);
        this.LJLL = new FeedLiveWindowWidget();
        0QK.LIZ(this.LJLIL, (View) null, 2131362882, 2131373030);
        this.LJLI.LIZIZ(2131366876, this.LJLL);
        this.LJII = this.LJLL.LIZ;
    }

    public final void LJJIJIIJIL() {
        this.LIZLLL = null;
        LJLZ();
        if (this.LJII.getVisibility() == 0) {
            this.LJII.setVisibility(4);
        }
        if (this.LJ) {
            this.LJLLJ = LLD();
        }
        LJZI();
    }

    public final void LJJIJIL() {
        if (this.LJ && this.LJFF && !this.LJLLJ && this.LJLL.LJ() != null && LJJIIZI() && !this.LJLLILLLL) {
            this.LJLLILLLL = true;
            LJZL();
            this.LJIIJ.LIZ(true, this.LIZLLL, this.LJLL.LJ());
        }
    }

    private void LJLZ() {
        boolean z;
        Room room = this.LJIIIZ;
        if (room != null) {
            this.LIZLLL = Gsf.LIZ(room);
        }
        if (this.LJIIL != null && this.LJIIL.getAuthor() != null) {
            String str = this.LJIIL.getAuthor().roomData;
            if (str != null) {
                SlimRoom slimRoom = (SlimRoom) 2dc.LIZ(str, SlimRoom.class);
                RoomStruct roomStruct = null;
                if (slimRoom != null) {
                    RoomStruct roomStruct2 = new RoomStruct();
                    roomStruct2.id = slimRoom.getId();
                    roomStruct2.ownerUserId = slimRoom.getOwnerUserId();
                    StreamUrlStruct LIZ = Gsf.LIZ(slimRoom.getStreamUrl(), slimRoom.getMultiStreamDefaultQualitySdkKey());
                    if (LIZ != null) {
                        roomStruct2.stream_url = LIZ;
                        roomStruct2.isThirdParty = slimRoom.isThirdParty;
                        roomStruct2.isScreenshot = slimRoom.isScreenshot;
                        if (slimRoom.getStreamType() == GIv.AUDIO) {
                            z = true;
                        } else {
                            z = false;
                        }
                        roomStruct2.liveTypeAudio = z;
                        roomStruct = roomStruct2;
                    }
                }
                this.LIZLLL = roomStruct;
            }
            if (this.LIZLLL == null) {
                long j = this.LJIIL.getAuthor().roomId;
                if (!this.LJLLLL && j > 0) {
                    this.LJLLLL = true;
                    LiveOuterService.LJJI().LJ().LIZ(j, new GS2() {
                        static {
                            Covode.recordClassIndex(76440);
                        }

                        public final void LIZ(Room room) {
                            FollowLiveVideoViewHolder.this.LJIIIZ = room;
                            FollowLiveVideoViewHolder.this.LIZLLL = Gsf.LIZ(room);
                            if (FollowLiveVideoViewHolder.this.LJFF) {
                                FollowLiveVideoViewHolder.this.LJJIJIIJIL();
                            }
                        }
                    });
                }
            }
        }
    }

    public /* synthetic */ void onChanged(Object obj) {
        onChanged((33g) obj);
    }

    private ObjectAnimator LJ(View view) {
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(view, "translationX", new float[]{LIZIZ(view), 0.0f});
        ofFloat.setDuration(300);
        return ofFloat;
    }

    private ObjectAnimator LJFF(View view) {
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(view, "translationX", new float[]{0.0f, LIZIZ(view)});
        ofFloat.setDuration(300);
        return ofFloat;
    }

    public final void LIZ(int i) {
        super.LIZ(i);
        this.LJLJLLL = i;
        this.LJFF = true;
        LJZI();
        if (!LJJIIZI() || this.LJLLJ) {
            LJIIIZ(false);
        } else {
            LJZ();
        }
    }

    public final void LIZLLL(boolean z) {
        super.LIZLLL(z);
        this.LJFF = false;
        this.LJIIJ.LIZ();
        LJIIIZ(false);
        this.LJLLILLLL = false;
        this.LJLLL = false;
        LJLLLLLL();
        LL();
    }

    public final void LJIIIZ(boolean z) {
        this.LJIIIIZZ = false;
        if (z) {
            LIZ(this.LJII, this.LJI);
            return;
        }
        this.LJII.setVisibility(8);
        this.LJI.setVisibility(0);
        this.LJI.setTranslationX(0.0f);
    }

    public FollowLiveVideoViewHolder(4aP r3) {
        super(r3);
        this.LJI = r3.LIZ.findViewById(2131362560);
    }

    public final float LIZIZ(View view) {
        if (view.getContext() != null && 3F7.LIZ(view.getContext())) {
            return (float) view.getContext().getResources().getDisplayMetrics().widthPixels;
        }
        float f = (float) (-view.getWidth());
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (!(layoutParams instanceof ViewGroup.MarginLayoutParams)) {
            return f;
        }
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
        return (f - ((float) marginLayoutParams.leftMargin)) - ((float) marginLayoutParams.rightMargin);
    }

    public final void LIZ(33g r5) {
        String aid;
        C5233Etp etp;
        super.onChanged(r5);
        if (r5 != null) {
            String str = r5.LIZ;
            str.hashCode();
            switch (str.hashCode()) {
                case -906007925:
                    if (str.equals("live_window_clicked")) {
                        this.LJIIJ.LIZ();
                        if (this.LJII.getVisibility() == 0) {
                            LJIIIZ(true);
                        }
                        if (this.LJIIL != null && (aid = this.LJIIL.getAid()) != null) {
                            this.LJLLJ = true;
                            Object LIZIZ = LJLJJI().LIZIZ("key_open_live_aweme_list", null);
                            if (LIZIZ == null) {
                                HashSet hashSet = new HashSet();
                                hashSet.add(aid);
                                LJLJJI().LIZ("key_open_live_aweme_list", (Object) hashSet);
                                return;
                            } else if (LIZIZ instanceof Set) {
                                ((Set) LIZIZ).add(aid);
                                return;
                            } else {
                                return;
                            }
                        } else {
                            return;
                        }
                    } else {
                        return;
                    }
                case -162745511:
                    if (str.equals("feed_internal_event") && (etp = (C5233Etp) r5.LIZ()) != null && etp.LIZ == 19) {
                        this.LJIIJ.LIZ();
                        LJIIIZ(false);
                        this.LJLLL = true;
                        return;
                    }
                    return;
                case 1471092846:
                    if (str.equals("dismiss_live_window")) {
                        LJIIIZ(true);
                        return;
                    }
                    return;
                default:
                    return;
            }
        }
    }

    public final void LIZ(final View view, final View view2) {
        LL();
        AnimatorSet animatorSet = new AnimatorSet();
        this.LJLLI = animatorSet;
        animatorSet.playTogether(new Animator[]{LJ(view2), LJFF(view)});
        animatorSet.setInterpolator(new DecelerateInterpolator());
        animatorSet.addListener(new AnimatorListenerAdapter() {
            static {
                Covode.recordClassIndex(76441);
            }

            public final void onAnimationCancel(Animator animator) {
                view.setVisibility(4);
            }

            public final void onAnimationEnd(Animator animator) {
                view.setVisibility(4);
            }

            public final void onAnimationStart(Animator animator) {
                view2.setVisibility(0);
            }
        });
        animatorSet.start();
    }
}
