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

import X.0CH;
import X.0Gf;
import X.0Gp;
import X.2GO;
import X.33g;
import X.4PU;
import X.7eA;
import X.7eB;
import X.878;
import X.B9I;
import X.BOz;
import X.BPr;
import X.C5345ORw;
import X.C5403OUc;
import X.C5405OUe;
import X.C5410OUj;
import X.C5415OUo;
import X.C5440OVn;
import X.ISm;
import X.OSU;
import X.OSW;
import X.OSX;
import X.OUD;
import X.OUP;
import X.OV8;
import X.OVA;
import X.OVP;
import X.OVS;
import X.OWQ;
import X.OZ6;
import X.Rc9;
import android.util.Pair;
import android.view.View;
import androidx.fragment.app.Fragment;
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.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 OVP<Music>, 4PU, BOz, 2GO {
    public C5415OUo LJIIZILJ;
    public OSX LJIJ;

    static {
        Covode.recordClassIndex(56126);
    }

    public final void LIZ(OVS ovs) {
    }

    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 LJIILJJIL() {
        return 1;
    }

    public final String LJIILL() {
        return null;
    }

    public final int LJIILLIIL() {
        return 2131559745;
    }

    public final void LJIJI() {
    }

    public final void LJIL() {
    }

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

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

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

    /* renamed from: LJIJ */
    public final OWQ LJIIL() {
        if (this.LJIIJJI != null) {
            return this.LJIIJJI.LIZLLL();
        }
        return null;
    }

    public final void LJIJJLI() {
        if (this.LJIIIZ != null) {
            this.LJIIIZ.LIZIZ(this.LJIIL);
        }
    }

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

    /* renamed from: bc_ */
    public final void LJJ() {
        if (this.LJIIIZ != null && this.LJIIJ != null) {
            OV8 ov8 = (OV8) this.LJIIJ.LIZ("user_collected_music_list");
            if ((this.LJIIJJI instanceof C5403OUc) && ((C5403OUc) this.LJIIJJI).LJIIIZ) {
                if (this.LJIIJJI != null) {
                    this.LJIIJJI.LIZ();
                }
                if (ov8 != null) {
                    OUD oud = this.LJIIIZ;
                    int intValue = ((Integer) ov8.LIZ("list_cursor")).intValue();
                    int i = this.LJIIL;
                    if (!oud.LJFF) {
                        oud.LJFF = true;
                        ChooseMusicApi.LIZ(intValue, 20, i).LIZ(new OUP(oud), 0Gp.LIZIZ, (0Gf) null);
                    }
                }
            }
        }
    }

    @ISm
    public void onEvent(BPr bPr) {
        if (this.LJIIJ != null && bPr != null) {
            this.LJIIJ.LIZ("music_collect_status", new OVS(0, bPr.LIZ, -1, -1, bPr.LIZIZ));
        }
    }

    private void LJ(MusicModel musicModel) {
        if (this.LJIIJJI != null && this.LJIIJJI.LIZLLL() != null && this.LJIIJJI.LIZLLL().getData() != null) {
            List data = this.LJIIJJI.LIZLLL().getData();
            for (int i = 0; i < data.size(); i++) {
                MusicModel musicModel2 = (MusicModel) data.get(i);
                if (musicModel.getMusicId().equals(musicModel2.getMusicId())) {
                    this.LJIIZILJ.LIZJ(musicModel2);
                    data.remove(i);
                    this.LJIIJJI.LIZLLL().notifyItemRemoved(i);
                    if (data.size() == 0) {
                        this.LJIIJJI.LIZJ();
                        return;
                    }
                    return;
                }
            }
        }
    }

    public final OVA LIZIZ(View view) {
        View view2 = view;
        C5410OUj oUj = new C5410OUj(getContext(), view2, this, this, this, this.LJIILL);
        oUj.LIZ((Fragment) this);
        oUj.LIZ((Pair<Long, Long>) new Pair(Long.valueOf(this.LJIILIIL), Long.valueOf(this.LJIILJJIL)));
        oUj.LIZ((C5415OUo) new C5415OUo() {
            static {
                Covode.recordClassIndex(56127);
            }

            public final void LIZJ(MusicModel musicModel) {
            }

            public final int LJI() {
                return CollectMusicFragment.this.LJIIZILJ.LJI();
            }

            public final int LJII() {
                return CollectMusicFragment.this.LJIIZILJ.LJII();
            }

            public final void LIZ(7eA r2) {
                if (CollectMusicFragment.this.LJIIZILJ != null) {
                    CollectMusicFragment.this.LJIIZILJ.LIZ(r2);
                }
            }

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

            public final void LIZ(C5345ORw oRw) {
                if (CollectMusicFragment.this.LJIIZILJ != null) {
                    CollectMusicFragment.this.LJIIZILJ.LIZ(oRw);
                }
            }

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

            public final void LIZ(int i, 7eB r3) {
                CollectMusicFragment.this.LJIIZILJ.LIZ(i, r3);
            }

            public final void LIZ(MusicModel musicModel, OSX osx) {
                if (CollectMusicFragment.this.LJIIZILJ != null) {
                    CollectMusicFragment.this.LJIIZILJ.LIZ(musicModel, osx);
                }
                if (((Integer) CollectMusicFragment.this.LJIIJ.LIZIZ("music_position", -1)).intValue() == -2) {
                    CollectMusicFragment.this.LJIIJ.LIZ("music_position", -1);
                    CollectMusicFragment.this.LJIIJ.LIZ("music_index", -1);
                }
            }
        });
        OSX osx = new OSX("change_music_page", "favorite_song", "", OSU.LIZ);
        this.LJIJ = osx;
        oUj.LIZ(osx);
        oUj.LIZ(false);
        oUj.LIZ(new C5440OVn(this));
        return oUj;
    }

    public void setUserVisibleHint(boolean z) {
        RecyclerView LJIIJJI;
        MusicModel musicModel;
        OSX osx;
        boolean z2;
        CollectMusicFragment.super.setUserVisibleHint(z);
        if (z && (LJIIJJI() instanceof RecyclerView) && (LJIIJJI = LJIIJJI()) != null) {
            LinearLayoutManager layoutManager = LJIIJJI.getLayoutManager();
            int LJIIL = layoutManager.LJIIL();
            B9I LIZLLL = this.LJIIJJI.LIZLLL();
            if (LIZLLL != null) {
                List data = LIZLLL.getData();
                if (!878.LIZ(data)) {
                    for (int LJIIJ = layoutManager.LJIIJ(); LJIIJ < LJIIL; LJIIJ++) {
                        if (LJIIJ >= 0 && LJIIJ < data.size() && (musicModel = (MusicModel) data.get(LJIIJ)) != null && (osx = this.LJIJ) != null) {
                            osx.LJIIIIZZ = musicModel.getLogPb();
                            OZ6 oz6 = new OZ6(LJIIJJI, musicModel, LJIIJ, (byte) 0);
                            OSX osx2 = this.LJIJ;
                            if (musicModel.getMatchedPGCSoundInfo() != null) {
                                z2 = true;
                            } else {
                                z2 = false;
                            }
                            OSU.LIZ((OSW) oz6, (0CH) this, osx2, musicModel, LJIIJ, true, z2);
                        }
                    }
                }
            }
        }
        if (this.LJIIJJI instanceof C5410OUj) {
            ((C5405OUe) this.LJIIJJI).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")) {
                OVS ovs = (OVS) r7.LIZ();
                if (ovs.LIZ != 0) {
                    return;
                }
                if (ovs.LIZLLL == 1) {
                    MusicModel musicModel = ovs.LJ;
                    if (this.LJIIJJI != null && this.LJIIJJI.LIZLLL() != null) {
                        List data = this.LJIIJJI.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.LJIIJJI.LIZ(data, false);
                            return;
                        }
                        data.add(0, musicModel);
                        this.LJIIJJI.LIZLLL().notifyItemInserted(0);
                        if ((this.LJIIJJI instanceof C5403OUc) && ((C5403OUc) this.LJIIJJI).LIZIZ != null) {
                            ((C5403OUc) this.LJIIJJI).LIZIZ.LIZIZ(0);
                            return;
                        }
                        return;
                    }
                    return;
                }
                LJ(ovs.LJ);
            } else if (str.equals("music_index") && ((Integer) this.LJIIJ.LIZIZ("music_position", -1)).intValue() == -2) {
                LJIIL().LIZ();
            }
        }
    }
}
