package ff;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.d1;
import androidx.fragment.app.e0;
import androidx.recyclerview.widget.q1;
import com.google.android.gms.measurement.internal.u1;
import ie.h0;
import java.util.ArrayList;
import java.util.List;
import kotlinx.coroutines.y;
import mf.q;
import org.drive_hunter.R;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import p000if.g;
import pe.n;
import xyz.netfly.viewmodel.HomeViewModel;
import xyz.stream.api.entity.CategoryEntity;
import xyz.stream.utils.event.CheckEvent;
import xyz.stream.utils.event.ParentalLockEvent;
import xyz.stream.utils.event.RemainingDayEvent;
import xyz.stream.utils.event.UpdateProgressEvent;
import xyz.stream.view.BaseFragment;
import xyz.stream.view.UiUtils;
import xyz.stream.view.listener.OnFragmentScrollListener;
import xyz.stream.view.listener.OnFragmentSendDataListener;

/* JADX INFO: loaded from: classes3.dex */
public class f extends BaseFragment<HomeViewModel, h0> implements OnFragmentScrollListener {
    public static final /* synthetic */ int I0 = 0;
    public int E0 = 0;
    public int F0 = 0;
    public final ArrayList G0 = new ArrayList();
    public c H0;

    /* JADX WARN: Removed duplicated region for block: B:69:0x0153  */
    /* JADX WARN: Removed duplicated region for block: B:72:0x0185  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x0195  */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void J(int i10) {
        BaseFragment bVar;
        OnFragmentSendDataListener onFragmentSendDataListener;
        String tag;
        ((h0) this.binding).f26947l.setVisibility(8);
        this.F0 = 0;
        d1 childFragmentManager = getChildFragmentManager();
        childFragmentManager.getClass();
        androidx.fragment.app.a aVar = new androidx.fragment.app.a(childFragmentManager);
        int iIntValue = ((CategoryEntity) this.G0.get(i10)).getSourceType().intValue();
        if (iIntValue == 2 || iIntValue == 3) {
            ((h0) this.binding).f26937b.setPadding(0, 0, 0, 0);
        } else {
            ((h0) this.binding).f26937b.setPadding(0, 140, 0, 0);
        }
        Object objG = u1.g("fragment", iIntValue);
        BaseFragment baseFragment = (BaseFragment) childFragmentManager.findFragmentByTag("fragment" + iIntValue);
        List<e0> listD = childFragmentManager.f2368c.d();
        if (!listD.isEmpty()) {
            for (e0 e0Var : listD) {
                if (e0Var != null && e0Var.isAdded() && ((tag = e0Var.getTag()) == null || !tag.equals(objG))) {
                    if (e0Var.isVisible() && (e0Var instanceof BaseFragment)) {
                        ((BaseFragment) e0Var).scrollToTop();
                    }
                    aVar.k(e0Var);
                }
            }
        }
        d1 d1Var = aVar.f2310r;
        int i11 = R.color.kid_top;
        int i12 = R.drawable.shadow_kid;
        if (baseFragment != null) {
            aVar.l(baseFragment);
            if (childFragmentManager.I()) {
                aVar.i(true);
            } else {
                if (aVar.f2569i) {
                    throw new IllegalStateException("This transaction is already being added to the back stack");
                }
                aVar.f2570j = false;
                d1Var.y(aVar, false);
            }
            baseFragment.refreshData();
            baseFragment.scrollToTop();
            if (iIntValue != 5) {
                i11 = R.color.bg_color;
                i12 = i11;
            }
            OnFragmentSendDataListener onFragmentSendDataListener2 = this.onFragmentSendDataListener;
            if (onFragmentSendDataListener2 != null) {
                onFragmentSendDataListener2.onBgChange(i12);
            }
            ((h0) this.binding).f26947l.setBackgroundResource(i11);
            this.E0 = i10;
            this.H0.setSelectedPosition(i10);
            return;
        }
        if (iIntValue == 1) {
            bVar = new jf.f();
            bVar.setOnFragmentScrollListener(this);
        } else if (iIntValue == 3) {
            bVar = new kf.d();
            bVar.setOnFragmentScrollListener(this);
        } else if (iIntValue == 6) {
            bVar = new g();
            bVar.setOnFragmentScrollListener(this);
        } else if (iIntValue == 11) {
            bVar = new q();
            bVar.setOnFragmentScrollListener(this);
        } else if (iIntValue == 2) {
            bVar = new kf.b();
            bVar.setOnFragmentScrollListener(this);
        } else {
            if (iIntValue == 5) {
                bVar = new hf.c();
                bVar.setOnFragmentScrollListener(this);
                onFragmentSendDataListener = this.onFragmentSendDataListener;
                if (onFragmentSendDataListener != null) {
                    onFragmentSendDataListener.onBgChange(i12);
                }
                ((h0) this.binding).f26947l.setBackgroundResource(i11);
                this.E0 = i10;
                this.H0.setSelectedPosition(i10);
                aVar.add(((h0) this.binding).f26937b.getId(), bVar, "fragment" + iIntValue);
                if (!childFragmentManager.I()) {
                    aVar.i(true);
                    return;
                } else {
                    if (aVar.f2569i) {
                        throw new IllegalStateException("This transaction is already being added to the back stack");
                    }
                    aVar.f2570j = false;
                    d1Var.y(aVar, false);
                    return;
                }
            }
            if (iIntValue != 9) {
                return;
            }
            bVar = new gf.b();
            bVar.setOnFragmentScrollListener(this);
        }
        i11 = R.color.bg_color;
        i12 = i11;
        onFragmentSendDataListener = this.onFragmentSendDataListener;
        if (onFragmentSendDataListener != null) {
        }
        ((h0) this.binding).f26947l.setBackgroundResource(i11);
        this.E0 = i10;
        this.H0.setSelectedPosition(i10);
        aVar.add(((h0) this.binding).f26937b.getId(), bVar, "fragment" + iIntValue);
        if (!childFragmentManager.I()) {
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void focus() {
        try {
            int iIntValue = ((CategoryEntity) this.G0.get(this.E0)).getSourceType().intValue();
            BaseFragment baseFragment = (BaseFragment) getChildFragmentManager().findFragmentByTag("fragment" + iIntValue);
            if (baseFragment == null) {
                return;
            }
            baseFragment.focus();
        } catch (Exception unused) {
        }
    }

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

    @Override // xyz.stream.view.BaseFragment
    public final void initData() {
        VB vb2 = this.binding;
        if (vb2 == 0) {
            return;
        }
        ((h0) vb2).f26938c.setVisibility(8);
        ((h0) this.binding).f26940e.setVisibility(8);
        ((h0) this.binding).f26943h.setVisibility(8);
        ArrayList arrayList = this.G0;
        if (arrayList.isEmpty()) {
            if (this.H0 == null) {
                initView();
                initListener();
            }
            arrayList.clear();
            arrayList.add(new CategoryEntity(getString(R.string.for_you), 1));
            arrayList.add(new CategoryEntity(getString(R.string.live_tv), 6));
            arrayList.add(new CategoryEntity(getString(R.string.sports), 11));
            arrayList.add(new CategoryEntity(getString(R.string.series), 3));
            arrayList.add(new CategoryEntity(getString(R.string.search_movie), 2));
            arrayList.add(new CategoryEntity(getString(R.string.kids), 5));
            if (xyz.stream.utils.e.d().f36116e) {
                arrayList.add(new CategoryEntity(getString(R.string.only_18), 9));
            }
            this.H0.notifyDataSetChanged();
            t4.d dVarG = t4.f.x(arrayList).e(new xyz.netfly.mobile.player.c(getArguments() != null ? getArguments().getInt("categoryType", 1) : 1, 9)).g();
            int i10 = 0;
            Object obj = (CategoryEntity) arrayList.get(0);
            Object obj2 = dVarG.f32947a;
            if (obj2 != null) {
                obj = obj2;
            }
            int iIndexOf = arrayList.indexOf(obj);
            this.E0 = iIndexOf;
            this.H0.setSelectedPosition(iIndexOf);
            J(this.E0);
            ((h0) this.binding).f26942g.post(new e(this, i10));
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initListener() {
        this.H0.setOnItemListener(new n(this, 4));
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initView() {
        fe.d.b().j(this);
        y.S("HomePage");
        this.H0 = new c(requireActivity(), this.G0);
        ((h0) this.binding).f26942g.setSpacingWithMargins(0, UiUtils.dp2px(20.0f));
        ((h0) this.binding).f26942g.setAdapter(this.H0);
    }

    @Override // xyz.stream.view.listener.OnFragmentScrollListener
    public final void onCategoryFocus() {
        View viewFindViewByPosition;
        q1 layoutManager = ((h0) this.binding).f26942g.getLayoutManager();
        if (layoutManager == null || (viewFindViewByPosition = layoutManager.findViewByPosition(this.E0)) == null) {
            return;
        }
        viewFindViewByPosition.requestFocus();
    }

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

    @Override // xyz.stream.view.listener.OnFragmentScrollListener
    public final void onHideTopView() {
        ((h0) this.binding).f26947l.setVisibility(8);
        this.F0 = 0;
    }

    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void onMessageEvent(CheckEvent checkEvent) {
        xyz.stream.utils.e0.m().p(requireActivity());
    }

    @Override // xyz.stream.view.listener.OnFragmentScrollListener
    public final void onViewScroll(int i10) {
        int i11 = this.F0 + i10;
        this.F0 = i11;
        if (i11 > UiUtils.dp2px(200.0f) && ((h0) this.binding).f26947l.getVisibility() == 8) {
            ((h0) this.binding).f26947l.setVisibility(0);
        } else {
            if (this.F0 >= UiUtils.dp2px(50.0f) || ((h0) this.binding).f26947l.getVisibility() != 0) {
                return;
            }
            ((h0) this.binding).f26947l.setVisibility(8);
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final boolean scrollToTop() {
        ArrayList arrayList = this.G0;
        if (arrayList.isEmpty()) {
            return false;
        }
        int iIntValue = ((CategoryEntity) arrayList.get(this.E0)).getSourceType().intValue();
        BaseFragment baseFragment = (BaseFragment) getChildFragmentManager().findFragmentByTag("fragment" + iIntValue);
        if (this.F0 <= 0 || baseFragment == null) {
            return false;
        }
        baseFragment.scrollToTop();
        ((h0) this.binding).f26947l.setVisibility(8);
        this.F0 = 0;
        ((h0) this.binding).f26942g.setSelection(this.E0);
        return true;
    }

    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void onMessageEvent(RemainingDayEvent remainingDayEvent) {
        fe.d.b().k(remainingDayEvent);
        h0 h0Var = (h0) this.binding;
        xyz.stream.utils.e0.t(h0Var.f26939d, h0Var.f26944i, h0Var.f26945j, remainingDayEvent.remainingText);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    @SuppressLint({"SetTextI18n"})
    public void onMessageEvent(UpdateProgressEvent updateProgressEvent) {
        VB vb2 = this.binding;
        if (vb2 == 0) {
            return;
        }
        if (!updateProgressEvent.finish) {
            ((h0) vb2).f26938c.setVisibility(0);
            ((h0) this.binding).f26940e.setVisibility(0);
            ((h0) this.binding).f26943h.setVisibility(0);
            ((h0) this.binding).f26946k.setText(getString(R.string.updating) + " " + updateProgressEvent.completeCount + "/" + updateProgressEvent.totalCount);
            ((h0) this.binding).f26941f.setProgress(updateProgressEvent.progress);
            return;
        }
        ((h0) vb2).f26940e.setVisibility(8);
        ((h0) this.binding).f26943h.setVisibility(8);
        ((h0) this.binding).f26938c.setVisibility(8);
        this.F0 = 0;
        ((h0) this.binding).f26947l.setVisibility(8);
    }

    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ParentalLockEvent parentalLockEvent) {
        boolean z10 = xyz.stream.utils.e.d().f36116e;
        ArrayList arrayList = this.G0;
        int i10 = 1;
        if (z10) {
            arrayList.add(new CategoryEntity(getString(R.string.only_18), 9));
            this.H0.notifyItemInserted(arrayList.size() - 1);
            return;
        }
        int i11 = 0;
        while (true) {
            if (i11 >= arrayList.size()) {
                i11 = -1;
                break;
            } else if (((CategoryEntity) arrayList.get(i11)).getSourceType().intValue() == 9) {
                break;
            } else {
                i11++;
            }
        }
        if (i11 != -1) {
            arrayList.remove(i11);
            this.H0.notifyItemRemoved(i11);
            if (this.E0 == i11) {
                this.E0 = 0;
                J(0);
                ((h0) this.binding).f26942g.post(new e(this, i10));
            }
        }
    }
}
