package ff;

import android.os.Bundle;
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 ef.k;
import ie.i0;
import java.util.ArrayList;
import java.util.List;
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.ads.h;
import xyz.netfly.viewmodel.HomeViewModel;
import xyz.stream.api.entity.CategoryEntity;
import xyz.stream.utils.event.ParentalLockEvent;
import xyz.stream.view.BaseFragment;
import xyz.stream.view.SpacesItemHorDecoration;
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 d extends BaseFragment<HomeViewModel, i0> implements OnFragmentScrollListener {
    public static final /* synthetic */ int J0 = 0;
    public c H0;
    public int E0 = 0;
    public int F0 = 0;
    public final ArrayList G0 = new ArrayList();
    public boolean I0 = false;

    public final void J(int i10) {
        BaseFragment kVar;
        BaseFragment bVar;
        int i11;
        String tag;
        ((i0) this.binding).f26999g.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) {
            ((i0) this.binding).f26994b.setPadding(0, 0, 0, 0);
        } else {
            ((i0) this.binding).f26994b.setPadding(0, 150, 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);
                }
            }
        }
        if (iIntValue == 13 || iIntValue == 12) {
            ((i0) this.binding).f26998f.setVisibility(0);
        } else {
            ((i0) this.binding).f26998f.setVisibility(8);
        }
        this.I0 = false;
        ((i0) this.binding).f26998f.setText(R.string.edit);
        int i12 = R.color.bg_color;
        if (baseFragment != null) {
            aVar.l(baseFragment);
            if (childFragmentManager.I()) {
                aVar.i(true);
            } else {
                aVar.i(false);
            }
            if (this.E0 == i10) {
                baseFragment.refreshData();
            } else if (iIntValue == 13 || iIntValue == 12) {
                baseFragment.initData();
            } else {
                baseFragment.refreshData();
            }
            baseFragment.scrollToTop();
            if (iIntValue == 5) {
                i12 = R.drawable.shadow_kid;
                i11 = R.color.kid_top;
            } else {
                i11 = R.color.bg_color;
            }
            OnFragmentSendDataListener onFragmentSendDataListener = this.onFragmentSendDataListener;
            if (onFragmentSendDataListener != null) {
                onFragmentSendDataListener.onBgChange(i12);
            }
            ((i0) this.binding).f26999g.setBackgroundResource(i11);
            this.E0 = i10;
            this.H0.setSelectedPosition(i10);
            return;
        }
        if (iIntValue == 3) {
            bVar = new kf.d();
            bVar.setOnFragmentScrollListener(this);
        } else if (iIntValue == 2) {
            bVar = new kf.b();
            bVar.setOnFragmentScrollListener(this);
        } else {
            if (iIntValue == 12) {
                kVar = new cf.c();
                Bundle bundle = new Bundle();
                bundle.putInt("sourceType", getArguments() != null ? getArguments().getInt("categoryType", 0) : 0);
                kVar.setArguments(bundle);
                kVar.setOnFragmentScrollListener(this);
            } else {
                if (iIntValue != 13) {
                    return;
                }
                kVar = new k();
                Bundle bundle2 = new Bundle();
                bundle2.putInt("sourceType", getArguments() != null ? getArguments().getInt("categoryType", 0) : 0);
                kVar.setArguments(bundle2);
                kVar.setOnFragmentScrollListener(this);
            }
            bVar = kVar;
        }
        OnFragmentSendDataListener onFragmentSendDataListener2 = this.onFragmentSendDataListener;
        if (onFragmentSendDataListener2 != null) {
            onFragmentSendDataListener2.onBgChange(R.color.bg_color);
        }
        ((i0) this.binding).f26999g.setBackgroundResource(R.color.bg_color);
        this.E0 = i10;
        this.H0.setSelectedPosition(i10);
        aVar.add(((i0) this.binding).f26994b.getId(), bVar, "fragment" + iIntValue);
        if (childFragmentManager.I()) {
            aVar.i(true);
        } else {
            aVar.i(false);
        }
    }

    @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 i0.inflate(layoutInflater, viewGroup, false);
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initData() {
        VB vb2 = this.binding;
        if (vb2 == 0) {
            return;
        }
        ((i0) vb2).f26995c.setVisibility(8);
        ((i0) this.binding).f26997e.setVisibility(8);
        ArrayList arrayList = this.G0;
        if (arrayList.isEmpty()) {
            if (this.H0 == null) {
                initView();
                initListener();
            }
            arrayList.clear();
            int i10 = getArguments() != null ? getArguments().getInt("categoryType", 1) : 1;
            if (i10 == 2) {
                arrayList.add(new CategoryEntity(getString(R.string.search_movie), 2));
            } else if (i10 == 3) {
                arrayList.add(new CategoryEntity(getString(R.string.series), 3));
            }
            arrayList.add(new CategoryEntity(getString(R.string.my_list), 12));
            arrayList.add(new CategoryEntity(getString(R.string.history), 13));
            this.H0.notifyDataSetChanged();
            this.E0 = 0;
            this.H0.setSelectedPosition(0);
            J(this.E0);
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initListener() {
        this.H0.setOnItemListener(new n(this, 3));
        ((i0) this.binding).f26998f.setOnClickListener(new com.google.android.material.textfield.b(this, 20));
        ((i0) this.binding).f26998f.setOnKeyListener(new oe.d(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);
        ((i0) this.binding).f26996d.addItemDecoration(new SpacesItemHorDecoration(UiUtils.dp2px(10.0f)));
        ((i0) this.binding).f26996d.setAdapter(this.H0);
    }

    @Override // xyz.stream.view.listener.OnFragmentScrollListener
    public final void onCategoryFocus() {
        View viewFindViewByPosition;
        q1 layoutManager = ((i0) this.binding).f26996d.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() {
        ((i0) this.binding).f26999g.setVisibility(8);
        this.F0 = 0;
    }

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

    @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) && ((i0) this.binding).f26999g.getVisibility() == 8) {
            ((i0) this.binding).f26999g.setVisibility(0);
        } else {
            if (this.F0 >= UiUtils.dp2px(50.0f) || ((i0) this.binding).f26999g.getVisibility() != 0) {
                return;
            }
            ((i0) this.binding).f26999g.setVisibility(8);
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void refreshData() {
        super.refreshData();
        int iIntValue = ((CategoryEntity) this.G0.get(this.E0)).getSourceType().intValue();
        BaseFragment baseFragment = (BaseFragment) getChildFragmentManager().findFragmentByTag("fragment" + iIntValue);
        if (baseFragment != null) {
            baseFragment.refreshData();
        }
    }

    @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();
        ((i0) this.binding).f26999g.setVisibility(8);
        this.F0 = 0;
        ((i0) this.binding).f26996d.setSelection(this.E0);
        return true;
    }
}
