package s9;

import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.search.SearchBar;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import org.drive_hunter.R;
import ve.e0;
import xyz.netfly.ui.live.tv.LiveActivity;
import xyz.stream.api.entity.LiveCategoryEntity;
import xyz.stream.api.entity.LiveChannelEntity;
import xyz.stream.view.UiUtils;

/* JADX INFO: loaded from: classes2.dex */
public final /* synthetic */ class c implements Runnable {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ Object f32677c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ Object f32678d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ Object f32679e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ Object f32680f;

    public /* synthetic */ c(Object obj, Object obj2, Object obj3, Object obj4, boolean z10, int i10) {
        this.f32675a = i10;
        this.f32677c = obj;
        this.f32678d = obj2;
        this.f32679e = obj3;
        this.f32680f = obj4;
        this.f32676b = z10;
    }

    @Override // java.lang.Runnable
    public final void run() {
        int i10 = this.f32675a;
        Object obj = this.f32680f;
        Object obj2 = this.f32679e;
        Object obj3 = this.f32678d;
        Object obj4 = this.f32677c;
        switch (i10) {
            case 0:
                f.a((f) obj4, (SearchBar) obj3, (View) obj2, (AppBarLayout) obj, this.f32676b);
                break;
            default:
                final e0 e0Var = (e0) obj4;
                final List list = (List) obj;
                final boolean z10 = this.f32676b;
                e0Var.getClass();
                final List list2 = (List) ((CompletableFuture) obj3).exceptionally((Function) new pe.l(2)).join();
                final List list3 = (List) ((CompletableFuture) obj2).exceptionally((Function) new pe.l(3)).join();
                final AppCompatActivity appCompatActivity = (AppCompatActivity) e0Var.f33846f.get();
                if (appCompatActivity != null) {
                    appCompatActivity.runOnUiThread(new Runnable() { // from class: ve.d0
                        @Override // java.lang.Runnable
                        public final void run() {
                            e0 e0Var2 = e0Var;
                            AppCompatActivity appCompatActivity2 = appCompatActivity;
                            List list4 = list2;
                            List list5 = list3;
                            List<LiveCategoryEntity> list6 = list;
                            boolean z11 = z10;
                            e0Var2.getClass();
                            UiUtils.dismissProgressDialog();
                            ArrayList arrayList = new ArrayList();
                            int i11 = 0;
                            arrayList.add(0, new LiveCategoryEntity(-3, appCompatActivity2.getString(R.string.search), -1));
                            arrayList.add(1, new LiveCategoryEntity(-2, appCompatActivity2.getString(R.string.recent), Integer.valueOf(list4.size())));
                            if (!list5.isEmpty()) {
                                arrayList.add(2, new LiveCategoryEntity(-1, appCompatActivity2.getString(R.string.favorites), Integer.valueOf(list5.size())));
                            }
                            e0Var2.f33842b.clear();
                            for (LiveCategoryEntity liveCategoryEntity : list6) {
                                if (re.a.u().g(liveCategoryEntity.getCategoryId().intValue())) {
                                    arrayList.add(liveCategoryEntity.clone());
                                }
                                e0Var2.f33842b.add(liveCategoryEntity.clone());
                            }
                            p pVar = e0Var2.f33861u;
                            pVar.f33904u = list5;
                            pVar.f33905v.clear();
                            pVar.f33905v.addAll(list4);
                            pVar.f33891h.clear();
                            pVar.f33890g.clear();
                            pVar.f33889f = arrayList;
                            pVar.f33890g.addAll(p.h(arrayList, new int[0]));
                            if (arrayList.isEmpty()) {
                                return;
                            }
                            if (pVar.B != -4) {
                                for (int i12 = 0; i12 < pVar.f33890g.size(); i12++) {
                                    List list7 = (List) pVar.f33890g.get(i12);
                                    int i13 = 0;
                                    while (true) {
                                        if (i13 >= list7.size()) {
                                            break;
                                        }
                                        if (((LiveCategoryEntity) list7.get(i13)).getCategoryId().intValue() == pVar.B) {
                                            pVar.f33892i = i12;
                                            pVar.f33902s = i13;
                                            break;
                                        }
                                        i13++;
                                    }
                                }
                                if (pVar.f33902s == -1000) {
                                    pVar.f33892i = 0;
                                    pVar.f33902s = list5.isEmpty() ? 2 : 3;
                                }
                            } else {
                                pVar.f33892i = 0;
                                pVar.f33902s = list5.isEmpty() ? 1 : 2;
                            }
                            pVar.f33891h.addAll((Collection) pVar.f33890g.get(pVar.f33892i));
                            pVar.f33893j.notifyDataSetChanged();
                            pVar.f33893j.setOnItemListener(new n(pVar, i11));
                            if (z11) {
                                pVar.c(((LiveCategoryEntity) pVar.f33891h.get(pVar.f33902s)).getCategoryId().intValue(), false);
                                return;
                            }
                            if (pVar.f33909z == null && !pVar.f33890g.isEmpty()) {
                                pVar.e();
                                return;
                            }
                            LiveChannelEntity liveChannelEntity = pVar.f33909z;
                            if (liveChannelEntity != null && v.i(liveChannelEntity) != null && xyz.stream.utils.e.g(v.i(pVar.f33909z))) {
                                re.a aVarU = re.a.u();
                                LiveChannelEntity liveChannelEntity2 = pVar.f33909z;
                                ArrayList arrayListC = xyz.stream.api.live.g.c(aVarU.f35898a);
                                if (liveChannelEntity2 != null && !arrayListC.isEmpty()) {
                                    Iterator it = arrayListC.iterator();
                                    while (it.hasNext()) {
                                        ArrayList arrayListK = xyz.stream.api.live.g.k((LiveCategoryEntity) it.next());
                                        if (!arrayListK.isEmpty()) {
                                            Iterator it2 = arrayListK.iterator();
                                            while (it2.hasNext()) {
                                                if (Objects.equals(((LiveChannelEntity) it2.next()).getId(), liveChannelEntity2.getId())) {
                                                }
                                            }
                                        }
                                    }
                                    pVar.f33909z = null;
                                    pVar.B = -4;
                                    pVar.e();
                                    return;
                                }
                            }
                            if (pVar.f33902s >= pVar.f33891h.size()) {
                                pVar.f33902s = pVar.f33891h.size() - 1;
                            }
                            pVar.B = -4;
                            pVar.c(((LiveCategoryEntity) pVar.f33891h.get(pVar.f33902s)).getCategoryId().intValue(), true);
                            xe.a aVar = pVar.f33908y;
                            if (aVar != null) {
                                re.a aVarU2 = re.a.u();
                                LiveChannelEntity liveChannelEntity3 = pVar.f33909z;
                                ArrayList arrayListC2 = xyz.stream.api.live.g.c(aVarU2.f35898a);
                                if (liveChannelEntity3 != null && !arrayListC2.isEmpty()) {
                                    Iterator it3 = arrayListC2.iterator();
                                    loop5: while (true) {
                                        if (!it3.hasNext()) {
                                            break;
                                        }
                                        ArrayList<LiveChannelEntity> arrayListK2 = xyz.stream.api.live.g.k((LiveCategoryEntity) it3.next());
                                        if (!arrayListK2.isEmpty()) {
                                            for (LiveChannelEntity liveChannelEntity4 : arrayListK2) {
                                                if (Objects.equals(liveChannelEntity4.getId(), liveChannelEntity3.getId()) && Objects.equals(liveChannelEntity4.getCategoryId(), liveChannelEntity3.getCategoryId())) {
                                                    liveChannelEntity3 = liveChannelEntity4;
                                                    break loop5;
                                                }
                                            }
                                        }
                                    }
                                }
                                ((LiveActivity) aVar).L(((LiveCategoryEntity) pVar.f33891h.get(pVar.f33902s)).getCategoryId().intValue(), liveChannelEntity3);
                            }
                        }
                    });
                    break;
                }
                break;
        }
    }
}
