package com.ss.android.ugc.aweme.kids.choosemusic.fragment;

import X.0Gf;
import X.0Gp;
import X.2GO;
import X.33g;
import X.4PU;
import X.878;
import X.B9I;
import X.BOz;
import X.C5344ORv;
import X.C5418OUr;
import X.C5419OUs;
import X.C5420OUt;
import X.C5424OUx;
import X.C5431OVe;
import X.ISm;
import X.OSO;
import X.OSY;
import X.OUY;
import X.OV8;
import X.OVA;
import X.OVG;
import X.OVR;
import X.OVU;
import X.OW0;
import X.OWT;
import X.Rc9;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.arch.widgets.base.DataCenter;
import com.ss.android.ugc.aweme.kids.choosemusic.api.ChooseMusicApi;
import com.ss.android.ugc.aweme.music.model.Music;
import com.ss.android.ugc.aweme.shortvideo.model.MusicModel;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.greenrobot.eventbus.ThreadMode;

public class CollectMusicFragment extends BaseMusicListFragment implements 4PU, BOz, OVR<Music>, 2GO {
    public OVG LJIIJJI;
    public OSY LJIIL;

    static {
        Covode.recordClassIndex(89288);
    }

    public final String LIZIZ() {
        return "user_collected_music_list";
    }

    public final /* bridge */ /* synthetic */ void LIZIZ(Object obj) {
    }

    public final String LIZJ() {
        return "refresh_status_user_collected_music";
    }

    public final String LIZLLL() {
        return "loadmore_status_user_collected_music";
    }

    public final boolean LJFF() {
        return false;
    }

    public final int LJIIJ() {
        return 1;
    }

    public final String LJIIL() {
        return null;
    }

    public final void LJIILL() {
    }

    public Map<Integer, Object> getSubscriberEventTypes() {
        Map<Integer, Object> subscriberEventTypes = super.getSubscriberEventTypes();
        subscriberEventTypes.put(396, new Rc9(CollectMusicFragment.class, "onEvent", C5431OVe.class, ThreadMode.POSTING, 0, false));
        return subscriberEventTypes;
    }

    public final void LIZ() {
        super.LIZ();
        this.LIZLLL.LIZIZ();
    }

    public final View LJIIJJI() {
        if (this.LJIIIZ == null) {
            return null;
        }
        return ((C5419OUs) this.LJIIIZ).LIZIZ;
    }

    /* renamed from: LJIILIIL */
    public final OWT LJIIIZ() {
        if (this.LJIIIZ != null) {
            return this.LJIIIZ.LIZLLL();
        }
        return null;
    }

    public final void LJIILJJIL() {
        if (this.LIZLLL != null) {
            this.LIZLLL.LIZIZ();
        }
    }

    public final DataCenter LJ() {
        this.LJ = super.LJ();
        DataCenter dataCenter = this.LJ;
        dataCenter.LIZ("music_collect_status", this);
        dataCenter.LIZ("music_index", this);
        return this.LJ;
    }

    /* renamed from: bc_ */
    public final void LJIILLIIL() {
        if (this.LIZLLL != null && this.LJ != null) {
            OV8 ov8 = (OV8) this.LJ.LIZ("user_collected_music_list");
            if ((this.LJIIIZ instanceof C5419OUs) && ((C5419OUs) this.LJIIIZ).LJIIIIZZ) {
                if (this.LJIIIZ != null) {
                    this.LJIIIZ.LIZ();
                }
                C5418OUr oUr = this.LIZLLL;
                int intValue = ((Integer) ov8.LIZ("list_cursor")).intValue();
                if (!oUr.LJFF) {
                    oUr.LJFF = true;
                    ChooseMusicApi.LIZ(intValue).LIZ(new OUY(oUr), 0Gp.LIZIZ, (0Gf) null);
                }
            }
        }
    }

    @ISm
    public void onEvent(C5431OVe oVe) {
        if (this.LJ != null && oVe != null) {
            this.LJ.LIZ("music_collect_status", new OVU(0, oVe.LIZ, -1, -1, oVe.LIZIZ));
        }
    }

    public final OVA LIZIZ(View view) {
        View view2 = view;
        C5424OUx oUx = new C5424OUx(getContext(), view2, this, this, this, this.LJIIJ);
        oUx.LIZ((OVG) new OVG() {
            static {
                Covode.recordClassIndex(89289);
            }

            public final void LIZ(C5344ORv oRv) {
                if (CollectMusicFragment.this.LJIIJJI != null) {
                    CollectMusicFragment.this.LJIIJJI.LIZ(oRv);
                }
            }

            public final void LIZIZ(MusicModel musicModel) {
                if (CollectMusicFragment.this.LJIIJJI != null) {
                    CollectMusicFragment.this.LJIIJJI.LIZIZ(musicModel);
                }
            }

            public final void LIZ(MusicModel musicModel) {
                if (CollectMusicFragment.this.LJIIJJI != null) {
                    CollectMusicFragment.this.LJIIJJI.LIZ(musicModel);
                }
            }

            public final void LIZ(MusicModel musicModel, OSY osy) {
                if (CollectMusicFragment.this.LJIIJJI != null) {
                    CollectMusicFragment.this.LJIIJJI.LIZ(musicModel, osy);
                }
                if (((Integer) CollectMusicFragment.this.LJ.LIZIZ("music_position", -1)).intValue() == -2) {
                    CollectMusicFragment.this.LJ.LIZ("music_position", -1);
                    CollectMusicFragment.this.LJ.LIZ("music_index", -1);
                }
            }
        });
        OSY osy = new OSY("change_music_page", "favorite_song", "", OSO.LIZ);
        this.LJIIL = osy;
        oUx.LIZ(osy);
        oUx.LIZ(false);
        oUx.LIZ(new OW0(this));
        return oUx;
    }

    public void setUserVisibleHint(boolean z) {
        RecyclerView LJIIJJI2;
        MusicModel musicModel;
        CollectMusicFragment.super.setUserVisibleHint(z);
        if (z && (LJIIJJI() instanceof RecyclerView) && (LJIIJJI2 = LJIIJJI()) != null) {
            LinearLayoutManager layoutManager = LJIIJJI2.getLayoutManager();
            int LJIIL2 = layoutManager.LJIIL();
            B9I LIZLLL = this.LJIIIZ.LIZLLL();
            if (LIZLLL != null) {
                List data = LIZLLL.getData();
                if (!878.LIZ(data)) {
                    for (int LJIIJ = layoutManager.LJIIJ(); LJIIJ < LJIIL2; LJIIJ++) {
                        if (LJIIJ >= 0 && LJIIJ < data.size() && (musicModel = (MusicModel) data.get(LJIIJ)) != null) {
                            OSY osy = this.LJIIL;
                            String musicId = musicModel.getMusicId();
                            musicModel.getMatchedPGCSoundInfo();
                            OSO.LIZ(osy, musicId, LJIIJ, true);
                        }
                    }
                }
            }
        }
        if (this.LJIIIZ instanceof C5424OUx) {
            ((C5420OUt) this.LJIIIZ).LIZ(z);
        }
    }

    public final void LIZ(33g r7) {
        super.onChanged(r7);
        if (aq_()) {
            String str = r7.LIZ;
            str.hashCode();
            if (str.equals("music_collect_status")) {
                OVU ovu = (OVU) r7.LIZ();
                if (ovu.LIZ == 0 && ovu.LIZLLL == 1) {
                    MusicModel musicModel = ovu.LJ;
                    if (this.LJIIIZ != null && this.LJIIIZ.LIZLLL() != null) {
                        List data = this.LJIIIZ.LIZLLL().getData();
                        if (data == null) {
                            data = new ArrayList();
                        }
                        int i = 0;
                        while (i < data.size()) {
                            if (!musicModel.getMusicId().equals(((MusicModel) data.get(i)).getMusicId())) {
                                i++;
                            } else {
                                return;
                            }
                        }
                        if (data.size() == 0) {
                            data.add(musicModel);
                            this.LJIIIZ.LIZ(data, false);
                            return;
                        }
                        data.add(0, musicModel);
                        this.LJIIIZ.LIZLLL().notifyItemInserted(0);
                        if ((this.LJIIIZ instanceof C5419OUs) && ((C5419OUs) this.LJIIIZ).LIZIZ != null) {
                            ((C5419OUs) this.LJIIIZ).LIZIZ.LIZIZ(0);
                        }
                    }
                }
            } else if (str.equals("music_index") && ((Integer) this.LJ.LIZIZ("music_position", -1)).intValue() == -2) {
                LJIIIZ().LIZ();
            }
        }
    }
}
