package p000if;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.lifecycle.x;
import androidx.recyclerview.widget.t;
import com.google.android.gms.measurement.internal.u1;
import com.google.android.material.textfield.b;
import ie.b0;
import ie.m0;
import java.util.ArrayList;
import java.util.List;
import kotlinx.coroutines.y;
import oe.d;
import org.drive_hunter.R;
import v3.a;
import xyz.stream.api.entity.LiveChannelEntity;
import xyz.stream.api.entity.TagLiveEntity;
import xyz.stream.api.viewmodel.LiveViewModel;
import xyz.stream.api.viewmodel.j;
import xyz.stream.utils.e;
import xyz.stream.view.BaseFragment;
import xyz.stream.view.SpacesItemVerDecoration;
import xyz.stream.view.UiUtils;

/* JADX INFO: loaded from: classes3.dex */
public class g extends BaseFragment<LiveViewModel, m0> {
    public static final /* synthetic */ int O0 = 0;
    public k E0;
    public View G0;
    public b0 N0;
    public final ArrayList F0 = new ArrayList();
    public boolean H0 = false;
    public boolean I0 = false;
    public boolean J0 = false;
    public boolean K0 = false;
    public int L0 = 0;
    public int M0 = -1;

    public final int J(int i10) {
        int i11 = 0;
        while (true) {
            ArrayList arrayList = this.F0;
            if (i11 >= arrayList.size()) {
                return -1;
            }
            if (((TagLiveEntity) arrayList.get(i11)).getTagId() == i10) {
                return i11;
            }
            i11++;
        }
    }

    public final void K() {
        ((m0) this.binding).f27198c.setVisibility(this.F0.isEmpty() ? 0 : 8);
    }

    public final void L(TagLiveEntity tagLiveEntity, int i10) {
        int iJ = J(tagLiveEntity.getTagId());
        ArrayList arrayList = this.F0;
        if (iJ >= 0) {
            arrayList.set(iJ, tagLiveEntity);
            this.E0.notifyItemChanged(iJ);
            return;
        }
        int iMin = Math.min(Math.max(i10, 0), arrayList.size());
        arrayList.add(iMin, tagLiveEntity);
        this.E0.notifyItemInserted(iMin);
        int i11 = iMin + 1;
        int itemCount = this.E0.getItemCount();
        if (i11 < 0 || i11 >= itemCount) {
            return;
        }
        this.E0.notifyItemRangeChanged(i11, itemCount - i11);
    }

    @Override // xyz.stream.view.BaseFragment
    public final void clearData() {
        this.F0.clear();
        this.H0 = false;
        this.K0 = false;
        this.L0 = 0;
        this.M0 = -1;
    }

    @Override // xyz.stream.view.BaseFragment
    public final void focus() {
        View viewD;
        super.focus();
        if (this.G0 == null && (viewD = u1.d(((m0) this.binding).f27199d, 0)) != null) {
            this.G0 = viewD;
        }
        View view = this.G0;
        if (view != null) {
            view.post(new e(this, 0));
        }
    }

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

    @Override // xyz.stream.view.BaseFragment
    public final void initData() {
        final int i10 = 1;
        final int i11 = 0;
        if (!this.I0) {
            this.I0 = true;
            ((LiveViewModel) this.viewModel).liveAllChannel.c(getViewLifecycleOwner(), new x(this) { // from class: if.f

                /* JADX INFO: renamed from: b, reason: collision with root package name */
                public final /* synthetic */ g f27818b;

                {
                    this.f27818b = this;
                }

                @Override // androidx.lifecycle.x
                public final void onChanged(Object obj) {
                    int i12 = i11;
                    g gVar = this.f27818b;
                    switch (i12) {
                        case 0:
                            List list = (List) obj;
                            if (gVar.K0) {
                                gVar.K0 = false;
                                gVar.H0 = true;
                                ArrayList arrayList = gVar.F0;
                                arrayList.clear();
                                if (list != null && !list.isEmpty()) {
                                    arrayList.addAll(list);
                                }
                                k kVar = gVar.E0;
                                kVar.f27833d = false;
                                kVar.notifyDataSetChanged();
                                if (!gVar.J0 && list != null && !list.isEmpty()) {
                                    k kVar2 = gVar.E0;
                                    ConstraintLayout constraintLayout = gVar.N0.f26667a;
                                    View view = kVar2.f27832c;
                                    boolean z10 = view != null;
                                    int itemCount = view == null ? -1 : kVar2.getItemCount() - 1;
                                    kVar2.f27832c = constraintLayout;
                                    if (!z10 && constraintLayout != null) {
                                        kVar2.notifyItemInserted(constraintLayout == null ? -1 : kVar2.getItemCount() - 1);
                                    } else if (z10 && constraintLayout != null) {
                                        kVar2.notifyItemChanged(constraintLayout == null ? -1 : kVar2.getItemCount() - 1);
                                    } else if (z10) {
                                        kVar2.notifyItemRemoved(itemCount);
                                    }
                                    gVar.J0 = true;
                                }
                                gVar.L0 = 1;
                                gVar.M0 = ((LiveViewModel) gVar.viewModel).getLiveChannel(-1);
                                break;
                            }
                            break;
                        default:
                            j jVar = (j) obj;
                            if (jVar == null) {
                                int i13 = g.O0;
                                gVar.getClass();
                                break;
                            } else if (jVar.f35981a == gVar.M0) {
                                gVar.M0 = -1;
                                int i14 = gVar.L0;
                                ArrayList arrayList2 = gVar.F0;
                                if (i14 == 1) {
                                    gVar.L0 = 0;
                                    List<LiveChannelEntity> list2 = jVar.f35982b;
                                    if (list2 == null || list2.isEmpty()) {
                                        int iJ = gVar.J(-1);
                                        if (iJ >= 0) {
                                            arrayList2.remove(iJ);
                                            gVar.E0.notifyItemRemoved(iJ);
                                            int itemCount2 = gVar.E0.getItemCount();
                                            if (iJ >= 0 && iJ < itemCount2) {
                                                gVar.E0.notifyItemRangeChanged(iJ, itemCount2 - iJ);
                                            }
                                        }
                                        gVar.K();
                                    } else {
                                        TagLiveEntity tagLiveEntity = new TagLiveEntity();
                                        tagLiveEntity.setTagId(-1);
                                        tagLiveEntity.setTagTitle(gVar.getString(R.string.favorite));
                                        tagLiveEntity.setVideoList(list2);
                                        gVar.L(tagLiveEntity, 1);
                                        gVar.K();
                                    }
                                    gVar.L0 = 2;
                                    gVar.M0 = ((LiveViewModel) gVar.viewModel).getLiveChannel(-2);
                                } else if (i14 == 2) {
                                    gVar.L0 = 0;
                                    List listN = re.a.u().n();
                                    if (listN == null || listN.isEmpty()) {
                                        int iJ2 = gVar.J(-2);
                                        if (iJ2 >= 0) {
                                            arrayList2.remove(iJ2);
                                            gVar.E0.notifyItemRemoved(iJ2);
                                            int itemCount3 = gVar.E0.getItemCount();
                                            if (iJ2 >= 0 && iJ2 < itemCount3) {
                                                gVar.E0.notifyItemRangeChanged(iJ2, itemCount3 - iJ2);
                                            }
                                        }
                                        gVar.K();
                                    } else {
                                        TagLiveEntity tagLiveEntity2 = new TagLiveEntity();
                                        tagLiveEntity2.setTagId(-2);
                                        tagLiveEntity2.setTagTitle(gVar.getString(R.string.recent));
                                        tagLiveEntity2.setVideoList(listN);
                                        gVar.L(tagLiveEntity2, gVar.J(-1) >= 0 ? 2 : 1);
                                        gVar.K();
                                    }
                                }
                                break;
                            }
                            break;
                    }
                }
            });
            ((LiveViewModel) this.viewModel).liveChannel.c(getViewLifecycleOwner(), new x(this) { // from class: if.f

                /* JADX INFO: renamed from: b, reason: collision with root package name */
                public final /* synthetic */ g f27818b;

                {
                    this.f27818b = this;
                }

                @Override // androidx.lifecycle.x
                public final void onChanged(Object obj) {
                    int i12 = i10;
                    g gVar = this.f27818b;
                    switch (i12) {
                        case 0:
                            List list = (List) obj;
                            if (gVar.K0) {
                                gVar.K0 = false;
                                gVar.H0 = true;
                                ArrayList arrayList = gVar.F0;
                                arrayList.clear();
                                if (list != null && !list.isEmpty()) {
                                    arrayList.addAll(list);
                                }
                                k kVar = gVar.E0;
                                kVar.f27833d = false;
                                kVar.notifyDataSetChanged();
                                if (!gVar.J0 && list != null && !list.isEmpty()) {
                                    k kVar2 = gVar.E0;
                                    ConstraintLayout constraintLayout = gVar.N0.f26667a;
                                    View view = kVar2.f27832c;
                                    boolean z10 = view != null;
                                    int itemCount = view == null ? -1 : kVar2.getItemCount() - 1;
                                    kVar2.f27832c = constraintLayout;
                                    if (!z10 && constraintLayout != null) {
                                        kVar2.notifyItemInserted(constraintLayout == null ? -1 : kVar2.getItemCount() - 1);
                                    } else if (z10 && constraintLayout != null) {
                                        kVar2.notifyItemChanged(constraintLayout == null ? -1 : kVar2.getItemCount() - 1);
                                    } else if (z10) {
                                        kVar2.notifyItemRemoved(itemCount);
                                    }
                                    gVar.J0 = true;
                                }
                                gVar.L0 = 1;
                                gVar.M0 = ((LiveViewModel) gVar.viewModel).getLiveChannel(-1);
                                break;
                            }
                            break;
                        default:
                            j jVar = (j) obj;
                            if (jVar == null) {
                                int i13 = g.O0;
                                gVar.getClass();
                                break;
                            } else if (jVar.f35981a == gVar.M0) {
                                gVar.M0 = -1;
                                int i14 = gVar.L0;
                                ArrayList arrayList2 = gVar.F0;
                                if (i14 == 1) {
                                    gVar.L0 = 0;
                                    List<LiveChannelEntity> list2 = jVar.f35982b;
                                    if (list2 == null || list2.isEmpty()) {
                                        int iJ = gVar.J(-1);
                                        if (iJ >= 0) {
                                            arrayList2.remove(iJ);
                                            gVar.E0.notifyItemRemoved(iJ);
                                            int itemCount2 = gVar.E0.getItemCount();
                                            if (iJ >= 0 && iJ < itemCount2) {
                                                gVar.E0.notifyItemRangeChanged(iJ, itemCount2 - iJ);
                                            }
                                        }
                                        gVar.K();
                                    } else {
                                        TagLiveEntity tagLiveEntity = new TagLiveEntity();
                                        tagLiveEntity.setTagId(-1);
                                        tagLiveEntity.setTagTitle(gVar.getString(R.string.favorite));
                                        tagLiveEntity.setVideoList(list2);
                                        gVar.L(tagLiveEntity, 1);
                                        gVar.K();
                                    }
                                    gVar.L0 = 2;
                                    gVar.M0 = ((LiveViewModel) gVar.viewModel).getLiveChannel(-2);
                                } else if (i14 == 2) {
                                    gVar.L0 = 0;
                                    List listN = re.a.u().n();
                                    if (listN == null || listN.isEmpty()) {
                                        int iJ2 = gVar.J(-2);
                                        if (iJ2 >= 0) {
                                            arrayList2.remove(iJ2);
                                            gVar.E0.notifyItemRemoved(iJ2);
                                            int itemCount3 = gVar.E0.getItemCount();
                                            if (iJ2 >= 0 && iJ2 < itemCount3) {
                                                gVar.E0.notifyItemRangeChanged(iJ2, itemCount3 - iJ2);
                                            }
                                        }
                                        gVar.K();
                                    } else {
                                        TagLiveEntity tagLiveEntity2 = new TagLiveEntity();
                                        tagLiveEntity2.setTagId(-2);
                                        tagLiveEntity2.setTagTitle(gVar.getString(R.string.recent));
                                        tagLiveEntity2.setVideoList(listN);
                                        gVar.L(tagLiveEntity2, gVar.J(-1) >= 0 ? 2 : 1);
                                        gVar.K();
                                    }
                                }
                                break;
                            }
                            break;
                    }
                }
            });
        }
        ((m0) this.binding).f27198c.setVisibility(8);
        this.K0 = true;
        if (!this.H0) {
            ArrayList arrayList = this.F0;
            arrayList.clear();
            for (int i12 = 0; i12 < 3; i12++) {
                TagLiveEntity tagLiveEntity = new TagLiveEntity();
                tagLiveEntity.setVideoList(new ArrayList());
                for (int i13 = 0; i13 < 7; i13++) {
                    tagLiveEntity.getVideoList().add(null);
                }
                arrayList.add(tagLiveEntity);
            }
            k kVar = this.E0;
            if (kVar != null) {
                kVar.f27833d = true;
                kVar.notifyDataSetChanged();
                this.E0.notifyDataSetChanged();
            }
        }
        ((LiveViewModel) this.viewModel).getPropertiesChannels();
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initListener() {
        this.N0.f26668b.setOnClickListener(new b(this, 22));
        this.N0.f26668b.setOnKeyListener(new d(this, 5));
        ((m0) this.binding).f27199d.addOnScrollListener(new t(this, 4));
        this.E0.f27834e = new com.google.gson.internal.a(this, 22);
    }

    @Override // xyz.stream.view.BaseFragment
    public final void initView() {
        y.S("LivePage");
        UiUtils.setSvgPicture(((m0) this.binding).f27197b, R.drawable.cloud_no_content, Integer.valueOf(R.color.main_color));
        ((m0) this.binding).f27199d.setSelectedItemAtCentered(true);
        ((m0) this.binding).f27199d.setAnimation(null);
        this.N0 = b0.inflate(getLayoutInflater(), null, false);
        ((m0) this.binding).f27199d.addItemDecoration(new SpacesItemVerDecoration(UiUtils.dp2px(15.0f), 0, 0));
        k kVar = new k(requireActivity(), this.F0);
        this.E0 = kVar;
        ((m0) this.binding).f27199d.setAdapter(kVar);
        if (e.d().f36119h) {
            UiUtils.setUnFocusable(this.N0.f26668b);
            this.N0.f26668b.setBackgroundResource(R.drawable.shape_login_select);
            this.N0.f26668b.setTextColor(getResources().getColor(R.color.main_text));
        }
    }

    @Override // xyz.stream.view.BaseFragment, androidx.fragment.app.e0
    public final void onResume() {
        super.onResume();
        if (this.H0) {
            this.L0 = 1;
            this.M0 = ((LiveViewModel) this.viewModel).getLiveChannel(-1);
        }
    }

    @Override // xyz.stream.view.BaseFragment
    public final void refreshData() {
        super.refreshData();
        initData();
    }

    @Override // xyz.stream.view.BaseFragment
    public final boolean scrollToTop() {
        if (!isAdded()) {
            return true;
        }
        VB vb2 = this.binding;
        if (vb2 == 0) {
            return false;
        }
        ((m0) vb2).f27199d.scrollToPosition(0);
        this.G0 = null;
        return true;
    }
}
