package ve;

import android.view.View;
import androidx.recyclerview.widget.q1;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import xyz.netfly.ui.live.tv.LiveActivity;
import xyz.stream.api.entity.LiveCategoryEntity;
import xyz.stream.api.entity.LiveChannelEntity;

/* JADX INFO: loaded from: classes3.dex */
public final /* synthetic */ class j implements androidx.lifecycle.x {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f33871a;

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

    public /* synthetic */ j(p pVar, int i10) {
        this.f33871a = i10;
        this.f33872b = pVar;
    }

    @Override // androidx.lifecycle.x
    public final void onChanged(Object obj) {
        int i10 = this.f33871a;
        final int i11 = 1;
        final int i12 = 0;
        final p pVar = this.f33872b;
        switch (i10) {
            case 0:
                xyz.stream.api.viewmodel.j jVar = (xyz.stream.api.viewmodel.j) obj;
                if (jVar == null) {
                    pVar.getClass();
                    break;
                } else {
                    int i13 = pVar.H;
                    if (i13 != Integer.MIN_VALUE) {
                        if (jVar.f35981a == pVar.J) {
                            boolean z10 = pVar.I;
                            pVar.H = Integer.MIN_VALUE;
                            pVar.I = false;
                            pVar.J = -1;
                            List list = jVar.f35982b;
                            if (list == null || list.isEmpty()) {
                                pVar.D = false;
                            } else {
                                ArrayList arrayList = pVar.f33891h;
                                ArrayList arrayList2 = pVar.f33897n;
                                ArrayList arrayList3 = pVar.f33896m;
                                if (i13 == -1) {
                                    Object obj2 = t4.f.x(arrayList).e(new te.l(1)).g().f32947a;
                                    if (obj2 == null) {
                                        obj2 = null;
                                    }
                                    LiveCategoryEntity liveCategoryEntity = (LiveCategoryEntity) obj2;
                                    if (liveCategoryEntity != null) {
                                        liveCategoryEntity.setProgramTotal(Integer.valueOf(pVar.f33904u.size()));
                                        pVar.f33893j.notifyItemChanged(arrayList.indexOf(liveCategoryEntity));
                                    }
                                    arrayList3.addAll(p.h(list, new int[0]));
                                    pVar.f33902s = 2;
                                } else if (i13 == -2) {
                                    arrayList3.addAll(p.h(list, new int[0]));
                                    pVar.f33902s = 1;
                                    Object obj3 = t4.f.x(arrayList).e(new te.l(2)).g().f32947a;
                                    if (obj3 == null) {
                                        obj3 = null;
                                    }
                                    LiveCategoryEntity liveCategoryEntity2 = (LiveCategoryEntity) obj3;
                                    if (liveCategoryEntity2 != null) {
                                        liveCategoryEntity2.setProgramTotal(Integer.valueOf(pVar.f33905v.size()));
                                        pVar.f33893j.notifyItemChanged(arrayList.indexOf(liveCategoryEntity2));
                                    }
                                    if (pVar.f33909z == null) {
                                        arrayList2.clear();
                                        arrayList2.addAll(arrayList3);
                                        LiveChannelEntity liveChannelEntity = (LiveChannelEntity) ((List) arrayList3.get(0)).get(0);
                                        pVar.f33909z = liveChannelEntity;
                                        xe.a aVar = pVar.f33908y;
                                        if (aVar != null) {
                                            ((LiveActivity) aVar).L(i13, liveChannelEntity);
                                        }
                                    }
                                } else {
                                    arrayList3.addAll(p.h(list, new int[0]));
                                    if (pVar.f33909z == null) {
                                        arrayList2.clear();
                                        arrayList2.addAll(arrayList3);
                                        pVar.f33902s = pVar.f33904u.isEmpty() ? 2 : 3;
                                        LiveChannelEntity liveChannelEntity2 = (LiveChannelEntity) list.get(0);
                                        pVar.f33909z = liveChannelEntity2;
                                        xe.a aVar2 = pVar.f33908y;
                                        if (aVar2 != null) {
                                            ((LiveActivity) aVar2).L(i13, liveChannelEntity2);
                                        }
                                    }
                                }
                                ArrayList arrayList4 = pVar.f33898o;
                                if (!z10) {
                                    pVar.f33894k = 0;
                                    arrayList4.addAll((Collection) arrayList3.get(0));
                                    pVar.f33895l.notifyDataSetChanged();
                                } else if (pVar.f33909z != null) {
                                    Object obj4 = t4.f.x(arrayList3).e(new h(pVar, 3)).g().f32947a;
                                    List list2 = (List) (obj4 != null ? obj4 : null);
                                    int iIndexOf = list2 != null ? arrayList3.indexOf(list2) : -1;
                                    arrayList4.clear();
                                    if (iIndexOf != -1) {
                                        arrayList4.addAll((Collection) arrayList3.get(iIndexOf));
                                        pVar.f33894k = iIndexOf;
                                    } else {
                                        arrayList4.addAll((Collection) arrayList3.get(0));
                                        pVar.f33894k = 0;
                                    }
                                    pVar.f33895l.notifyDataSetChanged();
                                }
                                if (arrayList2.isEmpty()) {
                                    arrayList2.addAll(arrayList3);
                                }
                                pVar.f33884a.post(new Runnable() { // from class: ve.k
                                    @Override // java.lang.Runnable
                                    public final void run() {
                                        int i14 = i12;
                                        p pVar2 = pVar;
                                        switch (i14) {
                                            case 0:
                                                pVar2.D = false;
                                                we.c cVar = pVar2.f33895l;
                                                LiveChannelEntity liveChannelEntity3 = pVar2.f33909z;
                                                cVar.f(liveChannelEntity3 != null ? liveChannelEntity3.getId().intValue() : -1);
                                                pVar2.d();
                                                if (pVar2.C) {
                                                    q1 layoutManager = pVar2.f33885b.getLayoutManager();
                                                    Objects.requireNonNull(layoutManager);
                                                    View viewFindViewByPosition = layoutManager.findViewByPosition(pVar2.f33902s);
                                                    if (viewFindViewByPosition != null) {
                                                        viewFindViewByPosition.requestFocus();
                                                    }
                                                    pVar2.C = false;
                                                }
                                                break;
                                            default:
                                                pVar2.d();
                                                break;
                                        }
                                    }
                                });
                            }
                            break;
                        }
                    }
                }
                break;
            default:
                List list3 = (List) obj;
                pVar.f33900q.f27076c.setVisibility(0);
                pVar.f33900q.f27080g.setVisibility(0);
                pVar.f33900q.f27079f.setVisibility(0);
                ArrayList arrayList5 = pVar.f33896m;
                arrayList5.clear();
                ArrayList arrayList6 = pVar.f33898o;
                arrayList6.clear();
                pVar.f33894k = 0;
                pVar.f33895l.notifyDataSetChanged();
                if (list3 == null || list3.isEmpty()) {
                    pVar.f33900q.f27079f.setText(String.valueOf(0));
                } else {
                    pVar.f33900q.f27079f.setText(String.valueOf(list3.size()));
                    arrayList5.addAll(p.h(list3, 8));
                    arrayList6.addAll((Collection) arrayList5.get(0));
                    pVar.f33895l.notifyDataSetChanged();
                    pVar.f33884a.post(new Runnable() { // from class: ve.k
                        @Override // java.lang.Runnable
                        public final void run() {
                            int i14 = i11;
                            p pVar2 = pVar;
                            switch (i14) {
                                case 0:
                                    pVar2.D = false;
                                    we.c cVar = pVar2.f33895l;
                                    LiveChannelEntity liveChannelEntity3 = pVar2.f33909z;
                                    cVar.f(liveChannelEntity3 != null ? liveChannelEntity3.getId().intValue() : -1);
                                    pVar2.d();
                                    if (pVar2.C) {
                                        q1 layoutManager = pVar2.f33885b.getLayoutManager();
                                        Objects.requireNonNull(layoutManager);
                                        View viewFindViewByPosition = layoutManager.findViewByPosition(pVar2.f33902s);
                                        if (viewFindViewByPosition != null) {
                                            viewFindViewByPosition.requestFocus();
                                        }
                                        pVar2.C = false;
                                    }
                                    break;
                                default:
                                    pVar2.d();
                                    break;
                            }
                        }
                    });
                }
                break;
        }
    }
}
