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

import X.070;
import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0CM;
import X.0Gf;
import X.0Gp;
import X.0HH;
import X.1hK;
import X.2GD;
import X.2Pr;
import X.33g;
import X.4PU;
import X.BOz;
import X.C0131MIu;
import X.C5303OQg;
import X.C5397OTw;
import X.C5413OUm;
import X.C5415OUo;
import X.C5438OVl;
import X.C5459OWg;
import X.C5530OYz;
import X.OUD;
import X.OUV;
import X.OUW;
import X.OVT;
import X.OWI;
import X.Pvw;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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.arch.widgets.base.WidgetManager;
import com.ss.android.ugc.aweme.base.fragment.AmeBaseFragment;
import com.ss.android.ugc.aweme.choosemusic.api.ChooseMusicApi;
import com.ss.android.ugc.aweme.choosemusic.model.ChooseMusicWithSceneViewModel;
import com.ss.android.ugc.aweme.choosemusic.viewholder.recycler.MusicRecyclerViewPoolViewModel;
import com.ss.android.ugc.aweme.music.model.Music;
import com.ss.android.ugc.aweme.out.AVExternalServiceImpl;
import com.ss.android.ugc.aweme.performance.OpenMusicPanelPerformanceMonitor;
import com.ss.android.ugc.aweme.performance.PerformanceMonitor;
import com.ss.android.ugc.aweme.views.WrapLinearLayoutManager;
import java.util.List;

public abstract class BaseDiscoverMusicFragment extends AmeBaseFragment implements 0CM<33g>, 4PU, BOz {
    public RecyclerView LIZ;
    public C5303OQg LIZIZ;
    public DataCenter LIZJ;
    public WidgetManager LIZLLL;
    public C5459OWg LJ;
    public C5415OUo LJIIIZ;
    public C5530OYz LJIIJ;
    public C5397OTw<OVT> LJIIJJI;
    public OUD LJIIL;
    public long LJIILIIL;
    public long LJIILJJIL;
    public int LJIILL;
    public int LJIIZILJ;
    public int LJIJ;

    static {
        Covode.recordClassIndex(56113);
    }

    public abstract void LIZ(33g r1);

    public abstract void LIZIZ();

    public abstract void LIZJ();

    public final View LJIIJJI() {
        return this.LIZ;
    }

    public final /* synthetic */ 2Pr LJFF() {
        LJ();
        return 2Pr.LIZ;
    }

    /* renamed from: bc_ */
    public final void LJ() {
        C5459OWg oWg;
        0Gp<OUW> musicCollectionFeed;
        int i = this.LJIIZILJ - 2;
        if (i < 0) {
            i = 0;
        }
        OUD oud = this.LJIIL;
        int i2 = this.LJIJ;
        if (!oud.LIZLLL) {
            oud.LIZLLL = true;
            Pvw LIZ2 = Pvw.LIZ();
            Integer valueOf = Integer.valueOf(i);
            if (ChooseMusicApi.LIZ()) {
                musicCollectionFeed = ChooseMusicApi.LIZ.commerceMusicCollectionFeed(valueOf, 10);
            } else {
                musicCollectionFeed = ChooseMusicApi.LIZ.musicCollectionFeed(valueOf, 10, i2);
            }
            musicCollectionFeed.LIZ(new OUV(oud, LIZ2), 0Gp.LIZIZ, (0Gf) null);
        }
        if (aq_() && (oWg = this.LJ) != null) {
            oWg.showLoadMoreLoading();
        }
    }

    public final void LIZ(int i) {
        C5459OWg oWg = this.LJ;
        if (oWg != null) {
            oWg.LIZJ(i);
        }
    }

    public void setUserVisibleHint(boolean z) {
        C5459OWg oWg;
        BaseDiscoverMusicFragment.super.setUserVisibleHint(z);
        if (this.LIZ != null && z && (oWg = this.LJ) != null) {
            oWg.LIZ(true);
        }
    }

    public void onCreate(Bundle bundle) {
        int i;
        int i2;
        BaseDiscoverMusicFragment.super.onCreate(bundle);
        if (getArguments() != null) {
            i = getArguments().getInt("com.ss.android.ugc.aweme.intent.extra.EXTRA_MUSIC_TYPE");
        } else {
            i = 1;
        }
        this.LJIILL = i;
        if (getArguments() != null) {
            i2 = getArguments().getInt("sound_page_scene");
        } else {
            i2 = 0;
        }
        this.LJIJ = i2;
        if (getArguments() == null) {
            this.LJIILIIL = 0;
            this.LJIILJJIL = 0;
            return;
        }
        this.LJIILIIL = getArguments().getLong("max_video_duration", 0);
        this.LJIILJJIL = getArguments().getLong("shoot_video_length", 0);
    }

    public /* synthetic */ void onChanged(Object obj) {
        List list;
        Integer num;
        33g r11 = (33g) obj;
        if (r11 != null) {
            String str = r11.LIZ;
            str.hashCode();
            switch (str.hashCode()) {
                case -1635157503:
                    if (str.equals("music_collect_status")) {
                        LIZ(r11);
                        return;
                    }
                    return;
                case 3322014:
                    if (str.equals("list") && (list = (List) this.LIZJ.LIZ("list")) != null && list.size() > 0) {
                        AVExternalServiceImpl.LIZ().provideAVPerformance().end((PerformanceMonitor) OpenMusicPanelPerformanceMonitor.LIZ, "set_music_data");
                        int itemCount = this.LJ.getItemCount();
                        this.LJIIZILJ = list.size();
                        boolean booleanValue = ((Boolean) this.LIZJ.LIZIZ("is_busi_sticker", false)).booleanValue();
                        if ("challenge".equals(this.LIZJ.LIZIZ("shoot_way", (Object) null))) {
                            if (this.LIZJ.LIZ("data_challenge") != null) {
                                this.LJ.LIZLLL(5);
                            } else {
                                List list2 = (List) this.LIZJ.LIZIZ("data_sticker", (Object) null);
                                if (list2 != null && list2.size() > 0) {
                                    this.LJ.LIZLLL(4);
                                }
                            }
                        } else if (booleanValue) {
                            LIZJ();
                        } else {
                            List list3 = (List) this.LIZJ.LIZIZ("data_sticker", (Object) null);
                            boolean isAutomaticMusicDeteriorationExperimentEnabled = AVExternalServiceImpl.LIZ().configService().avsettingsConfig().isAutomaticMusicDeteriorationExperimentEnabled();
                            if (list3 != null && list3.size() > 0 && !isAutomaticMusicDeteriorationExperimentEnabled) {
                                this.LJ.LIZLLL(4);
                            } else if (this.LIZJ.LIZ("data_challenge") != null) {
                                this.LJ.LIZLLL(5);
                            }
                        }
                        this.LJ.LJI = ((Boolean) this.LIZJ.LIZIZ("show_music_radio", false)).booleanValue();
                        this.LJ.LJFF = this.LJIIZILJ;
                        int itemCount2 = this.LJ.getItemCount() - itemCount;
                        if (itemCount2 <= 0) {
                            this.LJ.notifyDataSetChanged();
                        } else if (TextUtils.equals(Build.MODEL, "Redmi 6A") || TextUtils.equals(Build.MODEL, "Redmi 6")) {
                            this.LJ.notifyDataSetChanged();
                        } else {
                            this.LJ.notifyItemRangeInserted(itemCount, itemCount2);
                        }
                        if (this.LIZJ.LIZ("collection_feed_has_more") == null) {
                            return;
                        }
                        if (((Integer) this.LIZJ.LIZ("collection_feed_has_more")).intValue() == 1) {
                            this.LJ.resetLoadMoreState();
                            return;
                        } else {
                            LIZIZ();
                            return;
                        }
                    } else {
                        return;
                    }
                case 510590654:
                    if (str.equals("should_load_more_pick")) {
                        this.LJIIL.LIZ(true, (String) null, (Music) null, false, this.LJIJ);
                        return;
                    }
                    return;
                case 1110903186:
                    if (str.equals("collection_feed_status") && (num = (Integer) this.LIZJ.LIZ("collection_feed_status")) != null && num.intValue() == 1) {
                        LIZIZ();
                        return;
                    }
                    return;
                default:
                    return;
            }
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View LIZ2;
        if (C0131MIu.LIZ()) {
            LIZ2 = 0HH.LIZ(layoutInflater, 2131559731, viewGroup, false);
        } else {
            LIZ2 = 0HH.LIZ(layoutInflater, 2131559744, viewGroup, false);
        }
        this.LIZ = LIZ2.findViewById(2131367126);
        this.LIZIZ = (C5303OQg) LIZ2.findViewById(2131370625);
        C5459OWg oWg = new C5459OWg(this, this.LIZLLL, this.LIZJ, this.LJIIIZ, this.LJIIJ, this.LJIIJJI, this.LJIILL, this.LJIJ);
        this.LJ = oWg;
        oWg.setLoadMoreListener(this);
        this.LJ.setLoaddingTextColor(070.LIZJ(getContext(), 2131099758));
        this.LJ.LJII = this.LJIILIIL;
        this.LJ.LJIIIIZZ = this.LJIILJJIL;
        this.LIZ.setOverScrollMode(2);
        RecyclerView recyclerView = this.LIZ;
        getContext();
        recyclerView.setLayoutManager(new WrapLinearLayoutManager());
        this.LIZ.setRecycledViewPool(MusicRecyclerViewPoolViewModel.LIZ.LIZ(viewGroup.getContext()));
        this.LIZ.setAdapter(this.LJ);
        1hK requireActivity = requireActivity();
        0Bx LIZ3 = 0By.LIZ(requireActivity, (0Bv) null);
        if (2GD.LIZ) {
            0Bs.LIZ(LIZ3, requireActivity);
        }
        ChooseMusicWithSceneViewModel LIZ4 = LIZ3.LIZ(ChooseMusicWithSceneViewModel.class);
        if (LIZ4.LIZ) {
            LIZ4.LIZLLL().observe(this, new C5413OUm(this));
        } else {
            new OWI(new C5438OVl(this), 5).LIZ(this.LIZ);
        }
        DataCenter dataCenter = this.LIZJ;
        dataCenter.LIZ("list", this, C0131MIu.LIZ());
        dataCenter.LIZ("should_load_more_pick", this);
        dataCenter.LIZ("music_collect_status", this);
        dataCenter.LIZ("collection_feed_status", this);
        return LIZ2;
    }
}
