package xyz.netfly.ui.main.sport;

import android.view.KeyEvent;
import android.view.View;
import ie.p;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mf.d;
import mf.e;
import mf.f;
import mf.i;
import mf.j;
import v3.a;
import xyz.netfly.viewmodel.SportsViewModel;
import xyz.stream.api.entity.LeagueEntity;
import xyz.stream.api.entity.MatchEntity;
import xyz.stream.view.BaseActivity;
import xyz.stream.view.SpacesItemVerDecoration;
import xyz.stream.view.UiUtils;

/* JADX INFO: loaded from: classes3.dex */
public class MatchActivity extends BaseActivity<SportsViewModel, p> {
    public static final /* synthetic */ int Q = 0;

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

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

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public String f35620c = "";

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

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

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

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

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

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public Map f35630m = new HashMap();

    public final void K() {
        if (this.f35630m.isEmpty()) {
            return;
        }
        this.f35625h = -1;
        ArrayList arrayList = this.f35628k;
        arrayList.clear();
        ((p) this.binding).f27321k.setVisibility(8);
        int i10 = this.f35624g;
        if (i10 == -1) {
            return;
        }
        int iIntValue = ((LeagueEntity) this.f35626i.get(i10)).getId().intValue();
        ArrayList arrayList2 = new ArrayList();
        if (iIntValue == 0) {
            int i11 = this.f35623f;
            if (i11 == -1) {
                return;
            }
            String str = (String) this.f35621d.get(i11);
            if (this.f35630m.get(str) != null) {
                List list = (List) this.f35630m.get(str);
                if (list == null) {
                    ((p) this.binding).f27321k.setVisibility(0);
                    return;
                }
                arrayList2.addAll(list);
            }
        } else {
            for (String str2 : this.f35630m.keySet()) {
                List<MatchEntity> list2 = (List) this.f35630m.get(str2);
                if (list2 != null) {
                    ArrayList arrayList3 = new ArrayList();
                    for (MatchEntity matchEntity : list2) {
                        if (matchEntity.getLeagueId().intValue() == iIntValue) {
                            arrayList3.add(matchEntity);
                        }
                    }
                    if (!arrayList3.isEmpty()) {
                        MatchEntity matchEntity2 = new MatchEntity();
                        matchEntity2.setTime(str2);
                        matchEntity2.setLeagueId(-1);
                        arrayList2.add(matchEntity2);
                        arrayList2.addAll(arrayList3);
                    }
                }
            }
        }
        if (arrayList2.isEmpty()) {
            ((p) this.binding).f27321k.setVisibility(0);
            this.f35629l.notifyDataSetChanged();
        } else {
            arrayList.addAll(arrayList2);
            this.f35629l.notifyDataSetChanged();
            ((p) this.binding).f27320j.post(new e(this, 0));
        }
    }

    @Override // xyz.stream.view.BaseActivity
    public final a getViewBinding() {
        return p.inflate(getLayoutInflater(), null, false);
    }

    @Override // xyz.stream.view.BaseActivity
    public final void initData() {
        super.initData();
        ((SportsViewModel) this.viewModel).getLeagueList();
        ((SportsViewModel) this.viewModel).liveLeagueList.c(this, new d(this, 0));
        UiUtils.showProgressDialog(this);
        ((SportsViewModel) this.viewModel).getMatchList(this.f35620c);
        ((SportsViewModel) this.viewModel).liveMatchList.c(this, new d(this, 1));
    }

    @Override // xyz.stream.view.BaseActivity
    public final void initListener() {
        super.initListener();
        this.f35629l.f30688c = new f(this, 0);
        this.f35627j.setOnItemListener(new f(this, 1));
        this.f35622e.setOnItemListener(new f(this, 2));
    }

    @Override // xyz.stream.view.BaseActivity
    public final void initView() {
        this.f35619b = getIntent().getIntExtra("leagueId", -1);
        String stringExtra = getIntent().getStringExtra("sportType");
        this.f35620c = stringExtra;
        if (stringExtra == null) {
            this.f35620c = "";
        }
        ((p) this.binding).f27318h.addItemDecoration(new SpacesItemVerDecoration(UiUtils.dp2px(17.0f)));
        j jVar = new j(1, this, this.f35621d);
        this.f35622e = jVar;
        ((p) this.binding).f27318h.setAdapter(jVar);
        j jVar2 = new j(0, this, this.f35626i);
        this.f35627j = jVar2;
        ((p) this.binding).f27319i.setAdapter(jVar2);
        ((p) this.binding).f27320j.addItemDecoration(new SpacesItemVerDecoration(UiUtils.dp2px(5.0f)));
        i iVar = new i(this.f35628k, this);
        this.f35629l = iVar;
        ((p) this.binding).f27320j.setAdapter(iVar);
    }

    @Override // androidx.appcompat.app.AppCompatActivity, android.app.Activity, android.view.KeyEvent.Callback
    public final boolean onKeyDown(int i10, KeyEvent keyEvent) {
        View viewFindViewByPosition;
        if (i10 != 4 || keyEvent.getAction() != 0) {
            return super.onKeyDown(i10, keyEvent);
        }
        if (xyz.stream.utils.e.d().f36119h) {
            finish();
            return true;
        }
        if (((p) this.binding).f27319i.getLayoutManager() == null || (viewFindViewByPosition = ((p) this.binding).f27319i.getLayoutManager().findViewByPosition(this.f35624g)) == null || viewFindViewByPosition.hasFocus()) {
            finish();
            return true;
        }
        viewFindViewByPosition.requestFocus();
        return true;
    }
}
