package mf;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.t;
import ie.t0;
import ie.y0;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import kotlinx.coroutines.y;
import org.drive_hunter.R;
import xyz.netfly.viewmodel.SportsViewModel;
import xyz.stream.api.entity.LeagueEntity;
import xyz.stream.api.entity.MatchEntity;
import xyz.stream.api.entity.PageInfo;
import xyz.stream.api.entity.VideoCollectionEntity;
import xyz.stream.view.BaseFragment;
import xyz.stream.view.SpacesItemHorDecoration;
import xyz.stream.view.SpacesItemVerDecoration;
import xyz.stream.view.UiUtils;

/* JADX INFO: loaded from: classes3.dex */
public class q extends BaseFragment<SportsViewModel, t0> {
    public static final /* synthetic */ int T0 = 0;
    public xyz.netfly.ui.main.adapter.k G0;
    public xyz.netfly.ui.main.adapter.k I0;
    public View K0;
    public y0 L0;
    public k N0;
    public l P0;
    public androidx.activity.result.d S0;
    public PageInfo E0 = PageInfo.init(3);
    public final ArrayList F0 = new ArrayList();
    public final ArrayList H0 = new ArrayList();
    public final LinkedHashMap J0 = new LinkedHashMap();
    public final ArrayList M0 = new ArrayList();
    public final ArrayList O0 = new ArrayList();
    public String Q0 = "";
    public boolean R0 = false;

    public final void J(String str) {
        List<LeagueEntity> list = ((SportsViewModel) this.viewModel).collectionLeagueMap.get(str);
        ArrayList arrayList = this.M0;
        arrayList.clear();
        if (list != null) {
            arrayList.addAll(list);
        }
        this.N0.notifyDataSetChanged();
    }

    public final void K() {
        if (this.E0.getPage() == 1) {
            this.G0.c(false);
        }
        ((SportsViewModel) this.viewModel).getCollectionList(this.E0.getPage(), this.E0.getPageSize());
        ((SportsViewModel) this.viewModel).liveCollectionList.c(this, new n(this, 1));
    }

    public final void L(String str) {
        String sportType;
        ArrayList arrayList = this.H0;
        arrayList.clear();
        this.I0.d(false);
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        String strTrim = str == null ? "" : str.trim();
        if (!strTrim.isEmpty()) {
            for (Map.Entry entry : this.J0.entrySet()) {
                List<MatchEntity> list = (List) entry.getValue();
                if (list != null && !list.isEmpty()) {
                    ArrayList arrayList2 = new ArrayList();
                    for (MatchEntity matchEntity : list) {
                        if (strTrim.equals((matchEntity == null || (sportType = matchEntity.getSportType()) == null) ? "" : sportType.trim())) {
                            arrayList2.add(matchEntity);
                        }
                    }
                    if (!arrayList2.isEmpty()) {
                        linkedHashMap.put((String) entry.getKey(), arrayList2);
                    }
                }
            }
        }
        if (!linkedHashMap.isEmpty()) {
            for (String str2 : linkedHashMap.keySet()) {
                VideoCollectionEntity videoCollectionEntity = new VideoCollectionEntity();
                if (str2.equals("2")) {
                    videoCollectionEntity.setTitle(requireActivity().getString(R.string.sports_on_now));
                } else if (str2.equals("1")) {
                    videoCollectionEntity.setTitle(requireActivity().getString(R.string.upcoming_events));
                }
                List<MatchEntity> list2 = (List) linkedHashMap.get(str2);
                if (list2 != null && !list2.isEmpty()) {
                    videoCollectionEntity.setMatches(list2);
                    arrayList.add(videoCollectionEntity);
                }
            }
        }
        if (arrayList.isEmpty()) {
            this.L0.f27728c.setVisibility(8);
        } else {
            this.L0.f27728c.setVisibility(0);
            Collections.sort(arrayList, new com.google.android.material.button.c(requireActivity().getString(R.string.sports_on_now), 3));
        }
        this.I0.notifyDataSetChanged();
    }

    @Override // xyz.stream.view.BaseFragment
    public final void clearData() {
        this.F0.clear();
        this.E0 = PageInfo.init(3);
    }

    @Override // xyz.stream.view.BaseFragment
    public final void focus() {
        View childAt;
        View childAt2;
        if (xyz.stream.utils.e.d().f36119h) {
            return;
        }
        View view = this.K0;
        if (view != null) {
            view.post(new o(this, 0));
            return;
        }
        if (this.H0.isEmpty()) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) this.L0.f27727b.getLayoutManager();
            if (linearLayoutManager == null || (childAt = linearLayoutManager.getChildAt(0)) == null) {
                return;
            }
            childAt.requestFocus();
            return;
        }
        LinearLayoutManager linearLayoutManager2 = (LinearLayoutManager) this.L0.f27728c.getLayoutManager();
        if (linearLayoutManager2 == null || (childAt2 = linearLayoutManager2.getChildAt(0)) == null) {
            return;
        }
        this.K0 = childAt2;
        childAt2.requestFocus();
    }

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

    @Override // xyz.stream.view.BaseFragment
    public final void initData() {
        super.initData();
        if (isAdded()) {
            clearData();
            xyz.netfly.ui.main.adapter.k kVar = this.G0;
            if (kVar != null) {
                kVar.notifyDataSetChanged();
            }
            this.E0 = PageInfo.init(3);
            ((t0) this.binding).f27489b.resetNoMoreData();
            if (!this.R0) {
                ArrayList arrayList = this.F0;
                arrayList.clear();
                for (int i10 = 0; i10 < 3; i10++) {
                    VideoCollectionEntity videoCollectionEntity = new VideoCollectionEntity();
                    videoCollectionEntity.setVideoList(new ArrayList());
                    for (int i11 = 0; i11 < 7; i11++) {
                        videoCollectionEntity.getVideoList().add(null);
                    }
                    arrayList.add(videoCollectionEntity);
                }
                xyz.netfly.ui.main.adapter.k kVar2 = this.G0;
                if (kVar2 != null) {
                    kVar2.d(true);
                }
                ArrayList arrayList2 = this.H0;
                arrayList2.clear();
                VideoCollectionEntity videoCollectionEntity2 = new VideoCollectionEntity();
                videoCollectionEntity2.setMatches(new ArrayList());
                for (int i12 = 0; i12 < 7; i12++) {
                    videoCollectionEntity2.getMatches().add(null);
                }
                arrayList2.add(videoCollectionEntity2);
                xyz.netfly.ui.main.adapter.k kVar3 = this.I0;
                if (kVar3 != null) {
                    kVar3.d(true);
                }
                ArrayList arrayList3 = this.M0;
                arrayList3.clear();
                this.L0.f27730e.setVisibility(8);
                this.L0.f27729d.setVisibility(0);
                for (int i13 = 0; i13 < 7; i13++) {
                    arrayList3.add(null);
                }
                k kVar4 = this.N0;
                if (kVar4 != null) {
                    kVar4.notifyDataSetChanged();
                }
            }
            ((SportsViewModel) this.viewModel).getLeagueList();
            ((SportsViewModel) this.viewModel).liveLeagueList.c(this, new n(this, 0));
            K();
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initListener() {
        super.initListener();
        ((t0) this.binding).f27491d.addOnScrollListener(new t(this, 6));
        ((t0) this.binding).f27489b.setOnRefreshListener(new m(this, 3));
        ((t0) this.binding).f27489b.setOnLoadMoreListener(new m(this, 4));
        xyz.netfly.ui.main.adapter.k kVar = this.G0;
        kVar.f35572c = new m(this, 5);
        kVar.f35575f = new m(this, 6);
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initView() {
        y.S("SportsPage");
        ((t0) this.binding).f27491d.setAnimation(null);
        ((t0) this.binding).f27491d.setLayoutManager(new LinearLayoutManager());
        ((t0) this.binding).f27491d.addItemDecoration(new SpacesItemVerDecoration(UiUtils.dp2px(15.0f), 0, 0));
        xyz.netfly.ui.main.adapter.k kVar = new xyz.netfly.ui.main.adapter.k(this.F0, requireActivity(), false);
        this.G0 = kVar;
        ((t0) this.binding).f27491d.setAdapter(kVar);
        y0 y0VarInflate = y0.inflate(getLayoutInflater(), null, false);
        this.L0 = y0VarInflate;
        xyz.netfly.ui.main.adapter.k kVar2 = this.G0;
        kVar2.f35573d = y0VarInflate.f27726a;
        kVar2.notifyItemInserted(0);
        this.L0.f27728c.setAnimation(null);
        xyz.netfly.ui.main.adapter.k kVar3 = new xyz.netfly.ui.main.adapter.k(this.H0, requireActivity(), false);
        this.I0 = kVar3;
        this.L0.f27728c.setAdapter(kVar3);
        k kVar4 = new k(1, requireActivity(), this.M0);
        this.N0 = kVar4;
        this.L0.f27727b.setAdapter(kVar4);
        this.P0 = new l(this.O0, requireActivity());
        ((t0) this.binding).f27490c.addItemDecoration(new SpacesItemHorDecoration(UiUtils.dp2px(10.0f)));
        ((t0) this.binding).f27490c.setAnimation(null);
        ((t0) this.binding).f27490c.setAdapter(this.P0);
        xyz.netfly.ui.main.adapter.k kVar5 = this.I0;
        kVar5.f35572c = new m(this, 0);
        kVar5.f35575f = new m(this, 1);
        kVar5.f35576g = new m(this, 2);
        this.N0.setOnItemListener(new pe.n(this, 6));
        this.L0.f27731f.setOnFocusChangeListener(new com.google.android.material.textfield.c(this, 5));
        this.L0.f27731f.setOnKeyListener(new oe.d(this, 7));
        this.L0.f27731f.setOnClickListener(new com.google.android.material.textfield.b(this, 25));
        this.P0.setOnItemListener(new oe.g(this, 8));
        if (xyz.stream.utils.e.d().f36119h) {
            UiUtils.setUnFocusable(this.L0.f27731f);
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void onInit() {
        super.onInit();
        this.S0 = registerForActivityResult(new b.c(), new m(this, 7));
    }

    @Override // xyz.stream.view.BaseFragment, androidx.fragment.app.e0
    public final void onResume() {
        super.onResume();
    }

    @Override // xyz.stream.view.BaseFragment
    public final void refreshData() {
        super.refreshData();
        this.K0 = null;
        ((t0) this.binding).f27489b.autoRefresh();
    }

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