package com.bytedance.android.livesdk.qa;

import X.0Aq;
import X.0Ay;
import X.0BC;
import X.0CH;
import X.7he;
import X.7vl;
import X.C1064Fv7;
import X.C1485G4o;
import X.C1490G4t;
import X.C2495Gd6;
import X.C3491GtA;
import X.C4345HGo;
import X.C4453HKs;
import X.Crj;
import X.G5Q;
import X.G6F;
import X.G6G;
import X.G6H;
import X.G6I;
import X.G78;
import X.G7I;
import X.G7Q;
import X.G7T;
import X.G7W;
import X.G7X;
import X.G8S;
import X.M12;
import android.view.View;
import androidx.lifecycle.LiveData;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.android.livesdk.livesetting.broadcast.QAQuickEntranceSetting;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.ss.ugc.live.sdk.message.interfaces.IMessageManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;
import kotlin.h.b.n;

public final class QASuggestedFragment extends BaseQATabFragment {
    public static final G7W LJI = new G7W((byte) 0);
    public G7X LJFF;
    public final Crj LJII = 7vl.LIZ(new G7I(this));
    public final String LJIIIIZZ = "suggested";
    public boolean LJIIIZ;
    public final Crj LJIIJ = 7he.LIZ(new G7T(this));
    public HashMap LJIIJJI;

    static {
        Covode.recordClassIndex(20100);
    }

    private final SuggestedQuestionViewModel LIZJ() {
        return (SuggestedQuestionViewModel) this.LJII.getValue();
    }

    private final G8S LIZLLL() {
        return (G8S) this.LJIIJ.getValue();
    }

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

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

    public final void onDestroy() {
        DataChannel dataChannel;
        IMessageManager iMessageManager;
        super.onDestroy();
        if (this.LJFF != null && (dataChannel = this.LIZ) != null && (iMessageManager = (IMessageManager) dataChannel.LIZIZ(C4345HGo.class)) != null) {
            int intType = C4453HKs.QUESTION_DELETE_MESSAGE.getIntType();
            G7X g7x = this.LJFF;
            if (g7x == null) {
                n.LIZ("");
            }
            iMessageManager.addMessageListener(intType, g7x);
        }
    }

    public final void onDestroyView() {
        G8S LIZLLL = LIZLLL();
        LIZLLL.LIZ().removeCallbacksAndMessages((Object) null);
        RecyclerView recyclerView = LIZLLL.LIZIZ;
        if (recyclerView != null) {
            recyclerView.LIZIZ(LIZLLL);
            recyclerView.LIZIZ(LIZLLL);
        }
        LIZLLL.LIZIZ().clear();
        super.onDestroyView();
        LIZIZ();
    }

    private final void LJ() {
        String str;
        String str2;
        if (this.LIZIZ) {
            ArrayList<G6F> arrayList = new ArrayList<>();
            arrayList.addAll(C1485G4o.LIZJ);
            int i = 0;
            for (G6F g6f : arrayList) {
                if (!(g6f == null || g6f.LIZ == null || !g6f.LIZ.LIZIZ())) {
                    i++;
                }
            }
            int LIZ = C1485G4o.LJ.LIZ();
            C3491GtA LIZ2 = C3491GtA.LJFF.LIZ("livesdk_anchor_qa_list_show");
            LIZ2.LIZ(this.LIZ);
            LIZ2.LIZ("show_answered_question_cnt", i);
            LIZ2.LIZ("show_not_answered_question_cnt", LIZ);
            LIZ2.LIZ("show_question_cnt", i + LIZ);
            if (LIZ()) {
                str = this.LIZLLL;
            } else {
                str = this.LJ;
            }
            LIZ2.LIZ("qa_list_enter_from", str);
            LIZ2.LIZ("sub_list", this.LJIIIIZZ);
            if (C1485G4o.LIZ) {
                str2 = "1";
            } else {
                str2 = "0";
            }
            LIZ2.LIZ("is_qa_list_end", str2);
            LIZ2.LIZLLL();
            LIZ(false);
        }
    }

    public final void onVisible() {
        Room room;
        if (!this.LJIIIZ) {
            this.LJIIIZ = true;
            DataChannel dataChannel = this.LIZ;
            if (!(dataChannel == null || (room = (Room) dataChannel.LIZIZ(C1064Fv7.class)) == null)) {
                G7X g7x = new G7X(dataChannel, room, this.LJIIIIZZ);
                g7x.LIZ(LIZJ());
                this.LJFF = g7x;
                dataChannel.LIZ((0CH) this, C1490G4t.class, new G6H(this));
                dataChannel.LIZ((0CH) this, C2495Gd6.class, new G6I(this));
                if (G5Q.LIZJ(dataChannel) || QAQuickEntranceSetting.INSTANCE.enable()) {
                    LIZJ().LIZ(room, this.LIZJ, dataChannel, false);
                } else {
                    LIZJ().LIZ(room, this.LIZJ, dataChannel, G5Q.LJIIIZ(dataChannel));
                }
                SuggestedQuestionViewModel LIZJ = LIZJ();
                if (LIZJ.LJIIIIZZ == null) {
                    0Aq<Long, G6F> r1 = LIZJ.LJIIJ;
                    if (r1 == null) {
                        n.LIZ("");
                    }
                    LIZJ.LJIIIIZZ = new 0Ay(r1, LIZJ.LJIIJJI).LIZ();
                }
                LiveData<0BC<G6F>> liveData = LIZJ.LJIIIIZZ;
                Objects.requireNonNull(liveData, "null cannot be cast to non-null type androidx.lifecycle.LiveData<androidx.paging.PagedList<com.bytedance.android.livesdk.qa.QuestionEx>>");
                liveData.observe(this, new G78(this));
                RecyclerView LIZ = LIZ(2131369211);
                G7X g7x2 = this.LJFF;
                if (g7x2 == null) {
                    n.LIZ("");
                }
                LIZ.setAdapter(g7x2);
                LIZ.getContext();
                LIZ.setLayoutManager(new LinearLayoutManager());
                G8S LIZLLL = LIZLLL();
                G6G g6g = new G6G(this, dataChannel);
                M12.LIZ(g6g);
                LIZLLL.LIZ = g6g;
                RecyclerView recyclerView = LIZLLL.LIZIZ;
                if (recyclerView != null) {
                    recyclerView.LIZ(LIZLLL);
                    recyclerView.LIZ(LIZLLL);
                }
                IMessageManager iMessageManager = (IMessageManager) dataChannel.LIZIZ(C4345HGo.class);
                if (iMessageManager != null) {
                    int intType = C4453HKs.QUESTION_DELETE_MESSAGE.getIntType();
                    G7X g7x3 = this.LJFF;
                    if (g7x3 == null) {
                        n.LIZ("");
                    }
                    iMessageManager.addMessageListener(intType, g7x3);
                }
            }
            LIZJ().LIZJ.observe(this, new G7Q(this));
        }
        LJ();
    }

    public static final /* synthetic */ G7X LIZ(QASuggestedFragment qASuggestedFragment) {
        G7X g7x = qASuggestedFragment.LJFF;
        if (g7x == null) {
            n.LIZ("");
        }
        return g7x;
    }
}
