package hf;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.fragment.app.FragmentActivity;
import androidx.media3.exoplayer.analytics.g;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.t;
import ie.l0;
import ie.x0;
import java.util.ArrayList;
import kotlinx.coroutines.flow.h;
import kotlinx.coroutines.y;
import org.drive_hunter.R;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import pe.n;
import xyz.netfly.ui.main.adapter.k;
import xyz.netfly.ui.main.adapter.p;
import xyz.stream.api.entity.PageInfo;
import xyz.stream.api.entity.VideoEntity;
import xyz.stream.api.entity.VideoInfoEntity;
import xyz.stream.api.q;
import xyz.stream.api.viewmodel.KidsViewModel;
import xyz.stream.utils.e;
import xyz.stream.utils.event.DislikeEvent;
import xyz.stream.utils.f0;
import xyz.stream.view.BaseFragment;
import xyz.stream.view.CustomImageView;
import xyz.stream.view.GridSpacingItemDecoration;
import xyz.stream.view.SpacesItemHorDecoration;
import xyz.stream.view.SpacesItemVerDecoration;
import xyz.stream.view.UiUtils;
import xyz.stream.view.tvrecyclerview.V7GridLayoutManager;

/* JADX INFO: loaded from: classes3.dex */
public class c extends BaseFragment<KidsViewModel, l0> {
    public static final /* synthetic */ int Q0 = 0;
    public k I0;
    public d J0;
    public p K0;
    public x0 M0;
    public View N0;
    public VideoInfoEntity O0;
    public final ArrayList E0 = new ArrayList();
    public final ArrayList F0 = new ArrayList();
    public PageInfo G0 = PageInfo.init(3);
    public final ArrayList H0 = new ArrayList();
    public final ArrayList L0 = new ArrayList();
    public int P0 = -1;

    public final void J() {
        if (this.G0.getPage() == 1) {
            k kVar = this.I0;
            if (kVar.f35579j) {
                kVar.c(false);
            }
        }
        ((KidsViewModel) this.viewModel).getKidsList(this.G0.getPage(), this.G0.getPageSize());
        ((KidsViewModel) this.viewModel).liveKidsList.c(getViewLifecycleOwner(), new b(this, 1));
    }

    public final void K(VideoInfoEntity videoInfoEntity) {
        String logo;
        VideoInfoEntity videoInfoEntity2 = this.O0;
        if (videoInfoEntity2 == null || !videoInfoEntity2.getId().equals(videoInfoEntity.getId())) {
            this.O0 = videoInfoEntity;
            this.M0.f27655m.setVisibility(8);
            this.M0.f27652j.setVisibility(8);
            this.M0.f27664v.setVisibility(8);
            this.M0.f27651i.setVisibility(0);
            this.M0.f27665w.setVisibility(0);
            e.d().getClass();
            if (e.e().contains("ar")) {
                this.M0.f27645c.getImageView().setScaleX(-1.0f);
                UiUtils.setViewRtl(this.M0.f27645c);
            }
            CustomImageView customImageView = this.M0.f27645c;
            q qVarG = q.g();
            String backdropPath = videoInfoEntity.getBackdropPath();
            qVarG.getClass();
            customImageView.load(CustomImageView.Request.image(q.f(backdropPath)).radius(UiUtils.dp2px(24.0f)).size(UiUtils.dp2px(896.0f), UiUtils.dp2px(504.0f)));
            this.M0.f27647e.setBackgroundResource(R.mipmap.subtitle_grey);
            this.M0.f27644b.setBackgroundResource(R.mipmap.audio_grey);
            this.M0.f27658p.setText((videoInfoEntity.getDescription() == null || videoInfoEntity.getDescription().isEmpty()) ? getString(R.string.default_description) : videoInfoEntity.getDescription());
            UiUtils.setReleaseDate(this.M0.f27661s, videoInfoEntity.getReleaseDate());
            UiUtils.setCertificate(this.M0.f27657o, videoInfoEntity.getCertificate(), videoInfoEntity.getSourceType().intValue());
            FragmentActivity fragmentActivityRequireActivity = requireActivity();
            x0 x0Var = this.M0;
            UiUtils.setSubtitle(fragmentActivityRequireActivity, x0Var.f27662t, x0Var.f27647e, videoInfoEntity.getSubtitles());
            FragmentActivity fragmentActivityRequireActivity2 = requireActivity();
            x0 x0Var2 = this.M0;
            UiUtils.setAudio(fragmentActivityRequireActivity2, x0Var2.f27656n, x0Var2.f27644b, videoInfoEntity.getAudios());
            this.M0.f27659q.setText(h.l(videoInfoEntity.getRuntime()));
            this.M0.f27660r.setText(videoInfoEntity.getVoteAverage());
            if (videoInfoEntity.getLogo() == null || videoInfoEntity.getLogo().isEmpty()) {
                this.M0.f27646d.setVisibility(8);
                this.M0.f27663u.setText(videoInfoEntity.getTitle());
                this.M0.f27663u.setVisibility(0);
                return;
            }
            this.M0.f27646d.setVisibility(0);
            CustomImageView customImageView2 = this.M0.f27646d;
            q qVarG2 = q.g();
            if (videoInfoEntity.getLogo().startsWith("/")) {
                logo = "https://image.tmdb.org/t/p/w500" + videoInfoEntity.getLogo();
            } else {
                logo = videoInfoEntity.getLogo();
            }
            qVarG2.getClass();
            customImageView2.load(CustomImageView.Request.image(q.f(logo)).showDefaultImage(false).scaleType(ImageView.ScaleType.FIT_START).onImageLoadListener(new g(this, videoInfoEntity, 27)));
            this.M0.f27663u.setVisibility(8);
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void clearData() {
        this.E0.clear();
        this.F0.clear();
        this.H0.clear();
        this.L0.clear();
        this.O0 = null;
        this.G0 = PageInfo.init(3);
        x0 x0Var = this.M0;
        if (x0Var != null) {
            x0Var.f27655m.setVisibility(0);
            this.M0.f27652j.setVisibility(0);
            this.M0.f27664v.setVisibility(0);
            this.M0.f27651i.setVisibility(8);
            this.M0.f27665w.setVisibility(8);
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void focus() {
        View childAt;
        View view = this.N0;
        if (view != null) {
            view.post(new xyz.netfly.ads.h(this, 26));
            return;
        }
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) this.M0.f27653k.getLayoutManager();
        if (linearLayoutManager == null || (childAt = linearLayoutManager.getChildAt(0)) == null) {
            return;
        }
        this.N0 = childAt;
        childAt.requestFocus();
    }

    @Override // xyz.stream.view.BaseFragment
    public final v3.a getViewBinding(LayoutInflater layoutInflater, ViewGroup viewGroup) {
        return l0.inflate(layoutInflater, viewGroup, false);
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initData() {
        if (isAdded()) {
            ((l0) this.binding).f27169b.resetNoMoreData();
            ((KidsViewModel) this.viewModel).getTopVideoList();
            ((KidsViewModel) this.viewModel).liveTopList.c(getViewLifecycleOwner(), new b(this, 0));
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initListener() {
        this.I0.f35572c = new a(this);
        ((l0) this.binding).f27170c.addOnScrollListener(new t(this, 3));
        this.J0.setOnItemListener(new n(this, 5));
        this.I0.f35575f = new a(this);
        ((l0) this.binding).f27168a.addOnLayoutChangeListener(new com.google.android.material.navigation.c(this, 1));
        ((l0) this.binding).f27169b.setOnRefreshListener(new a(this));
        ((l0) this.binding).f27169b.setOnLoadMoreListener(new a(this));
        this.K0.f35595f = new gf.e(this, 1);
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initView() {
        y.S("KidsPage");
        this.M0 = x0.inflate(getLayoutInflater(), null, false);
        fe.d.b().j(this);
        V7GridLayoutManager v7GridLayoutManager = new V7GridLayoutManager(getContext(), 4);
        this.M0.f27654l.addItemDecoration(new GridSpacingItemDecoration(4, UiUtils.dp2px(15.0f), true));
        this.M0.f27654l.setLayoutManager(v7GridLayoutManager);
        d dVar = new d(this.L0, requireActivity());
        this.J0 = dVar;
        this.M0.f27654l.setAdapter(dVar);
        requireActivity();
        ((l0) this.binding).f27170c.setLayoutManager(new LinearLayoutManager());
        ((l0) this.binding).f27170c.addItemDecoration(new SpacesItemVerDecoration(UiUtils.dp2px(15.0f)));
        k kVar = new k(requireActivity(), this.H0);
        this.I0 = kVar;
        ((l0) this.binding).f27170c.setAdapter(kVar);
        k kVar2 = this.I0;
        kVar2.f35573d = this.M0.f27643a;
        kVar2.notifyItemInserted(0);
        ArrayList arrayList = this.E0;
        arrayList.clear();
        for (int i10 = 0; i10 < 10; i10++) {
            arrayList.add(null);
        }
        this.M0.f27653k.addItemDecoration(new SpacesItemHorDecoration(UiUtils.dp2px(10.0f)));
        p pVar = new p(requireActivity(), arrayList, UiUtils.dp2px(340.0f));
        this.K0 = pVar;
        this.M0.f27653k.setAdapter(pVar);
    }

    @Override // androidx.fragment.app.e0
    public final void onDestroy() {
        super.onDestroy();
        fe.d.b().m(this);
    }

    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void onMessageEvent(DislikeEvent dislikeEvent) {
        ArrayList arrayListM = f0.o().m(Integer.class, "sp_dislike_list");
        if (arrayListM.isEmpty()) {
            return;
        }
        ArrayList arrayList = this.E0;
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            VideoEntity videoEntity = (VideoEntity) arrayList.get(size);
            if (videoEntity != null && arrayListM.contains(Integer.valueOf(videoEntity.getVideoId()))) {
                arrayList.remove(size);
                this.F0.remove(size);
                this.K0.notifyItemRemoved(size);
            }
        }
        k kVar = this.I0;
        if (kVar != null) {
            kVar.e(arrayListM);
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void refreshData() {
        super.refreshData();
        this.N0 = null;
        ((l0) this.binding).f27169b.autoRefresh();
    }

    @Override // xyz.stream.view.BaseFragment
    public final boolean scrollToTop() {
        VB vb2 = this.binding;
        if (vb2 == 0) {
            return false;
        }
        ((l0) vb2).f27170c.scrollToPosition(0);
        this.N0 = null;
        return true;
    }
}
