package kf;

import android.view.View;
import android.widget.ImageView;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.e0;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.t;
import ie.i5;
import java.util.ArrayList;
import java.util.List;
import org.drive_hunter.R;
import xyz.netfly.ui.main.adapter.k;
import xyz.netfly.ui.main.adapter.l;
import xyz.netfly.ui.main.adapter.p;
import xyz.stream.api.entity.PageInfo;
import xyz.stream.api.entity.TagsEntity;
import xyz.stream.api.entity.VideoEntity;
import xyz.stream.api.entity.VideoInfoEntity;
import xyz.stream.api.q;
import xyz.stream.api.viewmodel.VideoActionViewModel;
import xyz.stream.utils.f0;
import xyz.stream.view.CustomImageView;
import xyz.stream.view.SingleTypeAdapter;
import xyz.stream.view.SpacesItemHorDecoration;
import xyz.stream.view.SpacesItemVerDecoration;
import xyz.stream.view.UiUtils;
import xyz.stream.view.listener.OnFragmentScrollListener;
import xyz.stream.view.listener.OnFragmentSendDataListener;
import xyz.stream.view.refresh.layout.AutoRefreshLayout;

/* JADX INFO: loaded from: classes3.dex */
public final class i {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public i5 f29158a;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public p f29161d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final e0 f29162e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f29163f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public OnFragmentScrollListener f29164g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public VideoActionViewModel f29165h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public VideoInfoEntity f29166i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public RecyclerView f29167j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public AutoRefreshLayout f29168k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public ArrayList f29169l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public k f29170m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public SingleTypeAdapter f29171n;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public View f29174q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public OnFragmentSendDataListener f29175r;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ArrayList f29159b = new ArrayList();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ArrayList f29160c = new ArrayList();

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final ArrayList f29172o = new ArrayList();

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final ArrayList f29173p = new ArrayList();

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public int f29176s = -1;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public PageInfo f29177t = PageInfo.init(3);

    public i(e0 e0Var) {
        this.f29162e = e0Var;
    }

    public final void a() {
        this.f29160c.clear();
        this.f29166i = null;
        this.f29174q = null;
        this.f29159b.clear();
        this.f29169l.clear();
        i5 i5Var = this.f29158a;
        if (i5Var != null) {
            i5Var.f27023n.setVisibility(0);
            this.f29158a.f27019j.setVisibility(0);
            this.f29158a.f27018i.setVisibility(8);
            this.f29158a.f27012c.setVisibility(8);
            this.f29158a.f27032w.setText("");
        }
    }

    public final void b() {
        ArrayList arrayListM = f0.o().m(Integer.class, "sp_dislike_list");
        if (arrayListM.isEmpty()) {
            return;
        }
        ArrayList arrayList = this.f29160c;
        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.f29159b.remove(size);
                p pVar = this.f29161d;
                if (pVar != null) {
                    pVar.notifyItemRemoved(size);
                    this.f29161d.notifyItemRangeChanged(size, arrayList.size() - size);
                }
            }
        }
        k kVar = this.f29170m;
        if (kVar != null) {
            kVar.e(arrayListM);
        }
    }

    public final void c(VideoActionViewModel videoActionViewModel, int i10, AutoRefreshLayout autoRefreshLayout, RecyclerView recyclerView, OnFragmentScrollListener onFragmentScrollListener, OnFragmentSendDataListener onFragmentSendDataListener) {
        this.f29165h = videoActionViewModel;
        this.f29163f = i10;
        this.f29167j = recyclerView;
        this.f29168k = autoRefreshLayout;
        this.f29164g = onFragmentScrollListener;
        this.f29175r = onFragmentSendDataListener;
        e0 e0Var = this.f29162e;
        View view = null;
        if (e0Var.isAdded()) {
            this.f29169l = new ArrayList();
            this.f29177t = PageInfo.init(3);
            int i11 = 0;
            this.f29168k.setEnableHeaderTranslationContent(false);
            this.f29168k.setHeaderInsetStartPx(80);
            this.f29158a = i5.inflate(e0Var.getLayoutInflater(), null, false);
            e0Var.requireActivity();
            this.f29167j.setLayoutManager(new LinearLayoutManager());
            this.f29167j.addItemDecoration(new SpacesItemVerDecoration(UiUtils.dp2px(15.0f)));
            k kVar = new k(e0Var.requireActivity(), this.f29169l);
            this.f29170m = kVar;
            this.f29167j.setAdapter(kVar);
            k kVar2 = this.f29170m;
            kVar2.f35573d = this.f29158a.f27010a;
            kVar2.notifyItemInserted(0);
            if (e0Var.isAdded()) {
                this.f29158a.f27022m.setAnimation(null);
                int i12 = 1;
                this.f29158a.f27022m.setSelectedItemAtCentered(true);
                this.f29158a.f27022m.addItemDecoration(new SpacesItemHorDecoration(UiUtils.dp2px(10.0f), 0, 0));
                FragmentActivity fragmentActivityRequireActivity = e0Var.requireActivity();
                ArrayList arrayList = this.f29160c;
                p pVar = new p(fragmentActivityRequireActivity, arrayList, UiUtils.dp2px(340.0f));
                this.f29161d = pVar;
                this.f29158a.f27022m.setAdapter(pVar);
                e0Var.requireActivity();
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(0, false);
                this.f29158a.f27021l.addItemDecoration(new SpacesItemHorDecoration(UiUtils.dp2px(10.0f), 0, 0));
                this.f29158a.f27021l.setLayoutManager(linearLayoutManager);
                arrayList.clear();
                for (int i13 = 0; i13 < 10; i13++) {
                    arrayList.add(null);
                }
                this.f29161d.notifyDataSetChanged();
                this.f29161d.f35595f = new h(this, i11);
                SpacesItemHorDecoration spacesItemHorDecoration = new SpacesItemHorDecoration(UiUtils.dp2px(10.0f), 0, 0);
                this.f29158a.f27020k.setSelectedItemAtCentered(true);
                this.f29158a.f27020k.addItemDecoration(spacesItemHorDecoration);
                if (this.f29163f == 2) {
                    a aVar = new a(this.f29173p, e0Var.requireActivity());
                    this.f29171n = aVar;
                    this.f29158a.f27020k.setAdapter(aVar);
                } else {
                    c cVar = new c(this.f29172o, e0Var.requireActivity());
                    this.f29171n = cVar;
                    this.f29158a.f27020k.setAdapter(cVar);
                }
                this.f29171n.setOnItemListener(new h(this, i12));
            }
        }
        this.f29168k.setOnRefreshListener(new f(this));
        this.f29168k.setOnLoadMoreListener(new f(this));
        this.f29170m.f35572c = new f(this);
        this.f29167j.addOnScrollListener(new t(this, 5));
        this.f29170m.f35575f = new f(this);
        RecyclerView recyclerView2 = this.f29167j;
        if (recyclerView2 != null && (recyclerView2.getParent() instanceof View)) {
            view = (View) this.f29167j.getParent();
        }
        if (view != null) {
            view.addOnLayoutChangeListener(new com.google.android.material.navigation.c(this, 2));
        }
    }

    public final void d() {
        e0 e0Var = this.f29162e;
        if (e0Var.isAdded()) {
            this.f29177t = PageInfo.init(3);
            this.f29174q = null;
            this.f29168k.resetNoMoreData();
            this.f29165h.getTrendingNow(this.f29163f);
            this.f29165h.liveTrendingNow.c(e0Var.getViewLifecycleOwner(), new g(this, 0));
        }
    }

    public final void e() {
        if (this.f29177t.getPage() == 1) {
            this.f29170m.c(false);
        }
        this.f29165h.getCollectionVideoList(this.f29163f, this.f29177t.getPage(), this.f29177t.getPageSize());
        this.f29165h.liveCollectionList.c(this.f29162e.getViewLifecycleOwner(), new g(this, 3));
    }

    public final void f() {
        if (this.f29158a == null) {
            return;
        }
        ArrayList arrayList = this.f29159b;
        if (arrayList.isEmpty()) {
            return;
        }
        this.f29174q = null;
        this.f29158a.f27022m.scrollToPosition(0);
        g((VideoInfoEntity) arrayList.get(0));
        this.f29167j.scrollToPosition(0);
    }

    public final void g(VideoInfoEntity videoInfoEntity) {
        VideoInfoEntity videoInfoEntity2 = this.f29166i;
        if (videoInfoEntity2 == null || !videoInfoEntity2.getId().equals(videoInfoEntity.getId())) {
            this.f29158a.f27023n.setVisibility(8);
            this.f29158a.f27019j.setVisibility(8);
            this.f29158a.f27018i.setVisibility(0);
            this.f29158a.f27012c.setVisibility(0);
            this.f29158a.f27032w.setText(R.string.trending_now);
            this.f29166i = videoInfoEntity;
            CustomImageView customImageView = this.f29158a.f27012c;
            q qVarG = q.g();
            String backdropPath = videoInfoEntity.getBackdropPath();
            qVarG.getClass();
            customImageView.load(CustomImageView.Request.image(q.f(backdropPath)).size(1562, 880));
            xyz.stream.utils.e.d().getClass();
            if (xyz.stream.utils.e.e().contains("ar")) {
                this.f29158a.f27012c.getImageView().setScaleX(-1.0f);
                UiUtils.setViewRtl(this.f29158a.f27012c);
            }
            List<TagsEntity> tags = videoInfoEntity.getTags();
            e0 e0Var = this.f29162e;
            if (tags == null || videoInfoEntity.getTags().isEmpty()) {
                this.f29158a.f27021l.setVisibility(8);
            } else {
                this.f29158a.f27021l.setVisibility(0);
                ArrayList arrayList = new ArrayList();
                for (TagsEntity tagsEntity : videoInfoEntity.getTags()) {
                    if (tagsEntity != null) {
                        arrayList.add(tagsEntity.getTitle());
                    }
                }
                this.f29158a.f27021l.setAdapter(new l(arrayList.subList(0, Math.min(videoInfoEntity.getTags().size(), 4)), e0Var.requireActivity()));
            }
            this.f29158a.f27014e.setBackgroundResource(R.mipmap.subtitle_grey);
            this.f29158a.f27011b.setBackgroundResource(R.mipmap.audio_grey);
            this.f29158a.f27026q.setText((videoInfoEntity.getDescription() == null || videoInfoEntity.getDescription().isEmpty()) ? e0Var.getString(R.string.default_description) : videoInfoEntity.getDescription());
            UiUtils.setReleaseDate(this.f29158a.f27029t, videoInfoEntity.getReleaseDate());
            UiUtils.setCertificate(this.f29158a.f27025p, videoInfoEntity.getCertificate(), videoInfoEntity.getSourceType().intValue());
            FragmentActivity fragmentActivityRequireActivity = e0Var.requireActivity();
            i5 i5Var = this.f29158a;
            UiUtils.setSubtitle(fragmentActivityRequireActivity, i5Var.f27030u, i5Var.f27014e, videoInfoEntity.getSubtitles());
            FragmentActivity fragmentActivityRequireActivity2 = e0Var.requireActivity();
            i5 i5Var2 = this.f29158a;
            UiUtils.setAudio(fragmentActivityRequireActivity2, i5Var2.f27024o, i5Var2.f27011b, videoInfoEntity.getAudios());
            this.f29158a.f27027r.setText(kotlinx.coroutines.flow.h.l(videoInfoEntity.getRuntime()));
            this.f29158a.f27028s.setText(videoInfoEntity.getVoteAverage());
            if (videoInfoEntity.getLogo() == null || videoInfoEntity.getLogo().isEmpty()) {
                this.f29158a.f27013d.setVisibility(8);
                this.f29158a.f27031v.setText(videoInfoEntity.getTitle());
                this.f29158a.f27031v.setVisibility(0);
                return;
            }
            this.f29158a.f27013d.setVisibility(0);
            CustomImageView customImageView2 = this.f29158a.f27013d;
            q qVarG2 = q.g();
            String logo = videoInfoEntity.getLogo().startsWith("/") ? "https://image.tmdb.org/t/p/w500" + videoInfoEntity.getLogo() : videoInfoEntity.getLogo();
            qVarG2.getClass();
            customImageView2.load(CustomImageView.Request.image(q.f(logo)).showDefaultImage(false).scaleType(ImageView.ScaleType.FIT_START).onImageLoadListener(new androidx.media3.exoplayer.analytics.g(this, videoInfoEntity, 28)));
            this.f29158a.f27031v.setVisibility(8);
        }
    }
}
