package com.bytedance.android.livesdk.rank.impl;

import X.0Ul;
import X.0b0;
import X.0cm;
import X.1jk;
import X.2K7;
import X.3D7;
import X.7xM;
import X.C1046Fup;
import X.C1059Fv2;
import X.C1284Fyf;
import X.C1612G9l;
import X.C2082GRn;
import X.C2083GRo;
import X.C2120GSz;
import X.C2296GZt;
import X.C2307Ga4;
import X.C2918Gjv;
import X.C3123GnE;
import X.C3127GnI;
import X.C3151Gng;
import X.C3152Gnh;
import X.C3154Gnj;
import X.C3155Gnk;
import X.C3160Gnp;
import X.C3162Gnr;
import X.C3164Gnt;
import X.C3168Gnx;
import X.C3170Gnz;
import X.C3171Go0;
import X.C3174Go3;
import X.C3176Go5;
import X.C3177Go6;
import X.C3178Go7;
import X.C3179Go8;
import X.C3181GoA;
import X.C3183GoC;
import X.C3185GoE;
import X.C3212Gof;
import X.C3248GpF;
import X.C3491GtA;
import X.C3946H1f;
import X.GAD;
import X.GKY;
import X.GT1;
import X.H14;
import X.HEP;
import X.HFX;
import X.HI6;
import X.M12;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.bytedance.android.live.wallet.IWalletService;
import com.bytedance.android.livesdk.LiveDialogFragment;
import com.bytedance.android.livesdk.livesetting.rank.LiveFlareAudienceEnableSetting;
import com.bytedance.android.livesdk.model.BorderInfo;
import com.bytedance.android.livesdk.performance.LivePerformanceManager;
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.datachannel.DataChannelGlobal;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import kotlin.h.b.n;

public final class OnlineAudienceRankListDialog extends LiveDialogFragment implements GT1, C3212Gof {
    public static final C3177Go6 LIZIZ = new C3177Go6((byte) 0);
    public String LIZ;
    public boolean LIZJ;
    public View LIZLLL;
    public 1jk LJ;
    public C3164Gnt LJFF;
    public C1612G9l LJI;
    public C3168Gnx LJII;
    public 3D7 LJIIIIZZ;
    public C3154Gnj LJIIIZ;
    public C3946H1f LJIIJ;
    public C3171Go0 LJIIJJI;
    public final long LJIIZILJ;
    public final C2307Ga4 LJIJ;
    public ViewTreeObserver.OnDrawListener LJIJI;
    public HashMap LJIJJ;

    static {
        Covode.recordClassIndex(20370);
    }

    public final View LIZ(int i) {
        if (this.LJIJJ == null) {
            this.LJIJJ = new HashMap();
        }
        View view = (View) this.LJIJJ.get(Integer.valueOf(i));
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(i);
        this.LJIJJ.put(Integer.valueOf(i), findViewById);
        return findViewById;
    }

    public final void z_() {
        HashMap hashMap = this.LJIJJ;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public final C2307Ga4 b_() {
        return this.LJIJ;
    }

    public static boolean LJII() {
        try {
            return 2K7.LIZ.LIZJ();
        } catch (Exception unused) {
            return false;
        }
    }

    public final void LIZLLL() {
        3D7 r1 = this.LJIIIIZZ;
        if (r1 != null) {
            r1.setVisibility(0);
        }
    }

    public final void LJ() {
        C3168Gnx gnx = this.LJII;
        if (gnx != null) {
            gnx.setVisibility(0);
        }
    }

    public final void LJFF() {
        View view = this.LIZLLL;
        if (view == null) {
            n.LIZ("");
        }
        LIZ(view);
    }

    public final void LJI() {
        C1612G9l g9l = this.LJI;
        if (g9l != null) {
            g9l.setVisibility(8);
        }
    }

    public OnlineAudienceRankListDialog() {
        this.LJIIZILJ = new Date(System.currentTimeMillis()).getTime();
        this.LJIJ = C2307Ga4.PANEL_ONLINE_AUDIENCE_RANK;
        this.LJIJI = new C3183GoC(this);
    }

    public final void onDestroyView() {
        ViewTreeObserver viewTreeObserver;
        C3946H1f h1f = this.LJIIJ;
        if (!(h1f == null || (viewTreeObserver = h1f.getViewTreeObserver()) == null)) {
            viewTreeObserver.removeOnDrawListener(this.LJIJI);
        }
        super.onDestroyView();
        C3171Go0 go0 = this.LJIIJJI;
        if (go0 != null) {
            go0.LIZ();
        }
        z_();
    }

    public final void onStart() {
        super.onStart();
        DataChannel dataChannel = this.LJIILIIL;
        if (dataChannel != null) {
            dataChannel.LIZIZ(C1284Fyf.class, true);
        }
    }

    public final void onStop() {
        OnlineAudienceRankListDialog.super.onStop();
        DataChannel dataChannel = this.LJIILIIL;
        if (dataChannel != null) {
            dataChannel.LIZIZ(C1284Fyf.class, false);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:12:0x0033  */
    /* JADX WARNING: Removed duplicated region for block: B:15:0x0038  */
    /* JADX WARNING: Removed duplicated region for block: B:17:0x003e  */
    /* JADX WARNING: Removed duplicated region for block: B:9:0x002e  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final X.C1044Fun LIZ() {
        /*
            r4 = this;
            android.content.Context r0 = r4.getContext()
            int r3 = X.C0536Fjq.LIZ(r0)
            X.Fun r2 = new X.Fun
            r0 = 2131561735(0x7f0d0d07, float:1.8748879E38)
            r2.<init>(r0)
            com.bytedance.ies.sdk.datachannel.DataChannel r1 = r4.LJIILIIL
            if (r1 == 0) goto L_0x0044
            java.lang.Class<X.HFX> r0 = X.HFX.class
            java.lang.Object r0 = r1.LIZIZ(r0)
            java.lang.Boolean r0 = (java.lang.Boolean) r0
            if (r0 == 0) goto L_0x0044
            boolean r1 = r0.booleanValue()
            if (r1 == 0) goto L_0x0040
        L_0x0024:
            r0 = 80
        L_0x0026:
            r2.LJI = r0
            r0 = 0
            r2.LJFF = r0
            r0 = -1
            if (r1 == 0) goto L_0x003e
            r0 = -1
        L_0x002f:
            r2.LJII = r0
            if (r1 == 0) goto L_0x0034
            r3 = -1
        L_0x0034:
            r2.LJIIIIZZ = r3
            if (r1 == 0) goto L_0x003d
            r0 = 2131887282(0x7f1204b2, float:1.9409167E38)
            r2.LIZIZ = r0
        L_0x003d:
            return r2
        L_0x003e:
            r0 = r3
            goto L_0x002f
        L_0x0040:
            r0 = 8388629(0x800015, float:1.1754973E-38)
            goto L_0x0026
        L_0x0044:
            r1 = 1
            goto L_0x0024
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.android.livesdk.rank.impl.OnlineAudienceRankListDialog.LIZ():X.Fun");
    }

    public /* synthetic */ OnlineAudienceRankListDialog(byte b) {
        this();
    }

    private final void LIZ(View view) {
        C3946H1f h1f = this.LJIIJ;
        if (h1f != null) {
            h1f.setVisibility(8);
        }
        C3164Gnt gnt = this.LJFF;
        if (gnt != null) {
            gnt.setVisibility(8);
        }
        C3154Gnj gnj = this.LJIIIZ;
        if (gnj != null) {
            gnj.setVisibility(8);
        }
        C3168Gnx gnx = this.LJII;
        if (gnx != null) {
            gnx.setContainer(this);
            gnx.setVisibility(8);
        }
        C3164Gnt gnt2 = this.LJFF;
        if (gnt2 != null) {
            gnt2.getContext();
            if (LJII()) {
                C1612G9l g9l = (C1612G9l) view.findViewById(2131367435);
                g9l.setVisibility(0);
                this.LJI = g9l;
                C3171Go0 go0 = this.LJIIJJI;
                if (go0 != null) {
                    go0.LIZ(this.LJIILIIL);
                }
            } else {
                gnt2.setContainer(this);
                gnt2.setVisibility(0);
            }
        }
        ((ImageView) view.findViewById(2131369103)).setOnClickListener(new GAD(this));
    }

    public final void onDismiss(DialogInterface dialogInterface) {
        Object obj;
        String str;
        LivePerformanceManager.getInstance().onModuleStop("audience_list");
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("rank_position", "active_user_rank_detail");
        linkedHashMap.put("last_user_rank", String.valueOf(C3151Gng.LIZ));
        C3491GtA LIZ2 = C3491GtA.LJFF.LIZ("active_user_rank_swipe_to_end");
        LIZ2.LIZ();
        LIZ2.LIZ((Map<String, String>) linkedHashMap);
        LIZ2.LIZLLL();
        DataChannel dataChannel = this.LJIILIIL;
        long j = this.LJIIZILJ;
        LinkedHashMap linkedHashMap2 = new LinkedHashMap();
        linkedHashMap2.put("duration", String.valueOf(new Date(System.currentTimeMillis()).getTime() - j));
        linkedHashMap2.put("show_user_position", "top_active_user_rank");
        linkedHashMap2.put("rank_position", "active_user_rank_detail");
        if (dataChannel != null) {
            obj = dataChannel.LIZIZ(C1059Fv2.class);
        } else {
            obj = null;
        }
        if (n.LIZ(obj, true)) {
            str = "anchor";
        } else {
            str = "user";
        }
        linkedHashMap2.put("user_type", str);
        C3491GtA LIZ3 = C3491GtA.LJFF.LIZ("livesdk_active_user_rank_duration");
        LIZ3.LIZ(dataChannel);
        LIZ3.LIZ((Map<String, String>) linkedHashMap2);
        LIZ3.LIZLLL();
        long time = new Date(System.currentTimeMillis()).getTime() - this.LJIIZILJ;
        Room room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
        if (room != null) {
            long id = room.getId();
            long ownerUserId = room.getOwnerUserId();
            if (id > 0 && ownerUserId > 0) {
                LinkedHashMap linkedHashMap3 = new LinkedHashMap();
                linkedHashMap3.put("duration", String.valueOf(time));
                linkedHashMap3.put("room_id", String.valueOf(id));
                linkedHashMap3.put("anchor_id", String.valueOf(ownerUserId));
                C3491GtA LIZ4 = C3491GtA.LJFF.LIZ("anchor_active_user_rank_duration");
                LIZ4.LIZ();
                LIZ4.LIZ((Map<String, String>) linkedHashMap3);
                LIZ4.LIZLLL();
            }
        }
    }

    public final void onViewCreated(View view, Bundle bundle) {
        int i;
        String str;
        M12.LIZ(view);
        super.onViewCreated(view, bundle);
        try {
            if (this.LJIILIIL != null) {
                this.LIZLLL = view;
                C3185GoE goE = new C3185GoE();
                this.LJIIJJI = goE;
                goE.LIZ((C3212Gof) this);
                Bundle arguments = getArguments();
                boolean z = false;
                if (arguments != null) {
                    i = arguments.getInt("online_count");
                } else {
                    i = 0;
                }
                Bundle arguments2 = getArguments();
                if (arguments2 != null) {
                    z = arguments2.getBoolean("show_flare");
                }
                this.LIZJ = z;
                Bundle arguments3 = getArguments();
                if (arguments3 != null) {
                    str = arguments3.getString("task_id");
                } else {
                    str = null;
                }
                this.LIZ = str;
                View findViewById = view.findViewById(2131371474);
                if (findViewById != null) {
                    findViewById.setOnClickListener(new C3170Gnz(this));
                }
                1jk findViewById2 = view.findViewById(2131372248);
                findViewById2.setText(0b0.LIZ(2131689825, i));
                this.LJ = findViewById2;
                C3946H1f h1f = (C3946H1f) view.findViewById(2131362449);
                DataChannel dataChannel = this.LJIILIIL;
                C3151Gng.LIZ = -1;
                h1f.LIZ(new C3152Gnh(dataChannel));
                this.LJIIJ = h1f;
                this.LJIIIIZZ = view.findViewById(2131368016);
                this.LJIIIZ = (C3154Gnj) view.findViewById(2131370078);
                this.LJII = (C3168Gnx) view.findViewById(2131370116);
                this.LJFF = (C3164Gnt) view.findViewById(2131368032);
                LIZ(view);
                C3151Gng.LIZ(this.LJIILIIL, "active_user_rank_detail");
                return;
            }
            throw new IllegalArgumentException("Required value was null.".toString());
        } catch (IllegalArgumentException unused) {
        }
    }

    public final void LIZ(C3127GnI gnI, String str) {
        boolean z;
        M12.LIZ(gnI, str);
        try {
            if (this.LJIILIIL == null) {
                throw new IllegalStateException("Required value was null.".toString());
            } else if (this.LJIIL) {
                C3154Gnj gnj = this.LJIIIZ;
                if (gnj != null) {
                    gnj.setVisibility(0);
                }
                C3154Gnj gnj2 = this.LJIIIZ;
                if (gnj2 != null) {
                    gnj2.LJI = this.LJIILIIL;
                    gnj2.LJII = this;
                    gnj2.LJIIIIZZ = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
                    gnj2.LJIIIZ = gnI;
                    gnj2.LJIIJ = str;
                }
                C3154Gnj gnj3 = this.LJIIIZ;
                if (gnj3 != null) {
                    HI6.LIZ(gnj3.LIZJ, gnj3.LJIIIZ.LIZ.getAvatarThumb(), gnj3.LIZJ.getWidth(), gnj3.LIZJ.getHeight(), 2131234641);
                    BorderInfo LIZ2 = C2918Gjv.LIZ(gnj3.LJIIIZ.LIZ);
                    if (LIZ2 != null) {
                        HI6.LIZ(gnj3.findViewById(2131366298), LIZ2.LIZ);
                        C2918Gjv.LIZ(gnj3.LJIIIZ.LIZ, "active_user_rank_bottom_bar", false);
                    }
                    boolean z2 = true;
                    if (C3181GoA.LJI.LIZ(gnj3.LJI, 1) != 2) {
                        gnj3.LIZLLL.setVisibility(0);
                        gnj3.LIZLLL.setText(C2296GZt.LIZJ(gnj3.LJIIIZ.LIZJ).toUpperCase(Locale.US) + " " + gnj3.LJIIJ);
                    } else {
                        gnj3.LIZLLL.setVisibility(8);
                    }
                    String LIZ3 = 0Ul.LIZ(gnj3.LJIIIZ.LIZ);
                    1jk r1 = gnj3.LIZIZ;
                    if (TextUtils.isEmpty(LIZ3)) {
                        LIZ3 = "";
                    }
                    r1.setText(LIZ3);
                    int i = gnj3.LJIIIZ.LIZIZ;
                    if (i > 99 || gnj3.LJIIIZ.LIZJ <= 0) {
                        gnj3.LIZ.setText("-");
                    } else {
                        if (i == 1) {
                            gnj3.LIZ.setTextColor(gnj3.getResources().getColor(2131100599));
                        } else if (i == 2) {
                            gnj3.LIZ.setTextColor(gnj3.getResources().getColor(2131100600));
                        } else if (i != 3) {
                            gnj3.LIZ.setTextColor(gnj3.getResources().getColor(2131100598));
                        } else {
                            gnj3.LIZ.setTextColor(gnj3.getResources().getColor(2131100601));
                        }
                        gnj3.LIZ.setText(String.valueOf(i));
                    }
                    gnj3.LJ.setVisibility(0);
                    if (C3181GoA.LJI.LIZ(gnj3.LJI, 1) == 2) {
                        gnj3.LJ.setText(2131830187);
                    } else {
                        gnj3.LJ.setText(gnj3.LJIIIZ.LJ);
                    }
                    gnj3.LJFF.setVisibility(0);
                    if (gnj3.LJIIIIZZ.getRoomAuthStatus() == null || !gnj3.LJIIIIZZ.getRoomAuthStatus().isEnableGift()) {
                        z = false;
                    } else {
                        z = true;
                    }
                    if (0cm.LIZ(IWalletService.class).walletCenter().LIZIZ() <= 0) {
                        z2 = false;
                    }
                    C2083GRo LIZ4 = C2082GRn.LIZ(false, z2, z);
                    if (LIZ4 == C2083GRo.GREY) {
                        gnj3.LJFF.setAlpha(0.34f);
                    }
                    gnj3.LJFF.setOnClickListener(new C2120GSz(gnj3, LIZ4));
                }
            } else {
                throw new IllegalStateException("Check failed.".toString());
            }
        } catch (IllegalArgumentException unused) {
        }
    }

    public final void LIZ(List<C3127GnI> list, String str) {
        boolean z;
        Boolean bool;
        ViewTreeObserver viewTreeObserver;
        ViewTreeObserver viewTreeObserver2;
        M12.LIZ(list, str);
        try {
            if (!this.LJIIL) {
                throw new IllegalStateException("Check failed.".toString());
            } else if (getContext() != null) {
                H14 h14 = new H14();
                h14.LIZ(C3179Go8.class, new C3248GpF());
                h14.LIZ(C3174Go3.class, new C3162Gnr());
                h14.LIZ(C3178Go7.class, new C1046Fup(this.LJIILIIL, new GKY(this)));
                h14.LIZ(C3127GnI.class, new C3123GnE(this.LJIILIIL));
                h14.LIZ(C3176Go5.class, new C3155Gnk());
                7xM r3 = new 7xM();
                r3.add(new C3179Go8());
                if (this.LIZJ && LiveFlareAudienceEnableSetting.INSTANCE.enable()) {
                    r3.add(new C3178Go7());
                }
                r3.add(new C3174Go3(list.size(), str));
                r3.addAll(list);
                r3.add(new C3176Go5());
                h14.LIZ((List<?>) r3);
                C3946H1f h1f = this.LJIIJ;
                if (!(h1f == null || (viewTreeObserver2 = h1f.getViewTreeObserver()) == null)) {
                    viewTreeObserver2.removeOnDrawListener(this.LJIJI);
                }
                C3946H1f h1f2 = this.LJIIJ;
                if (!(h1f2 == null || (viewTreeObserver = h1f2.getViewTreeObserver()) == null)) {
                    viewTreeObserver.addOnDrawListener(this.LJIJI);
                }
                C3946H1f h1f3 = this.LJIIJ;
                if (h1f3 != null) {
                    getContext();
                    h1f3.setLayoutManager(new LinearLayoutManager());
                }
                C3946H1f h1f4 = this.LJIIJ;
                if (h1f4 != null) {
                    h1f4.setAdapter(h14);
                }
                C3946H1f h1f5 = this.LJIIJ;
                if (h1f5 != null) {
                    C3160Gnp gnp = C3160Gnp.AUDIENCE_RANK;
                    DataChannel dataChannel = this.LJIILIIL;
                    if (dataChannel == null || (bool = (Boolean) dataChannel.LIZIZ(HFX.class)) == null) {
                        z = true;
                    } else {
                        z = bool.booleanValue();
                    }
                    h1f5.LIZ(gnp, z);
                }
                C3946H1f h1f6 = this.LJIIJ;
                if (h1f6 != null) {
                    h1f6.setVisibility(0);
                }
                1jk r2 = this.LJ;
                if (r2 != null) {
                    r2.setText(0b0.LIZ(2131689825, list.size()));
                }
            } else {
                throw new IllegalStateException("Required value was null.".toString());
            }
        } catch (IllegalStateException unused) {
        }
    }
}
