package com.strmr.ps.ui.mobile.settings;

import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import com.strmr.ps.R;
import com.strmr.ps.data.model.addon.InstalledAddon;
import com.strmr.ps.data.model.addon.StremioCatalog;
import com.strmr.ps.data.model.addon.StremioCatalogExtra;
import com.strmr.ps.data.service.StremioAddonService;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.gv3;
import defpackage.i85;
import defpackage.m02;
import defpackage.m12;
import defpackage.s38;
import defpackage.sc2;
import defpackage.vx8;
import defpackage.wj0;
import defpackage.yd;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.ui.mobile.settings.MobileAddonsFragment$checkAndHandleAddonType$1", f = "MobileAddonsFragment.kt", i = {}, l = {406}, m = "invokeSuspend", n = {}, s = {})
@vx8
final class k extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public int a;
    public final /* synthetic */ InstalledAddon b;
    public final /* synthetic */ MobileAddonsFragment c;
    public final /* synthetic */ String d;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public k(InstalledAddon installedAddon, MobileAddonsFragment mobileAddonsFragment, String str, Continuation continuation) {
        super(2, continuation);
        this.b = installedAddon;
        this.c = mobileAddonsFragment;
        this.d = str;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        return new k(this.b, this.c, this.d, continuation);
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((k) create((ak1) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x006c  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x00b8  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00da  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00f3  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x00fa  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x01d0  */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws Throwable {
        Object objF;
        List<StremioCatalog> parsedCatalogs;
        ArrayList arrayList;
        ArrayList arrayList2;
        int i;
        ck1 ck1Var = ck1.a;
        int i2 = this.a;
        e6a e6aVar = e6a.a;
        MobileAddonsFragment mobileAddonsFragment = this.c;
        InstalledAddon installedAddon = this.b;
        if (i2 == 0) {
            s38.b(obj);
            if (!installedAddon.getParsedCatalogs().isEmpty()) {
                parsedCatalogs = installedAddon.getParsedCatalogs();
                List<StremioCatalog> list = parsedCatalogs;
                arrayList = new ArrayList();
                for (Object obj2 : list) {
                    List<StremioCatalogExtra> extra = ((StremioCatalog) obj2).getExtra();
                    if (extra != null) {
                        List<StremioCatalogExtra> list2 = extra;
                        if (!(list2 instanceof Collection) || !list2.isEmpty()) {
                            Iterator<T> it = list2.iterator();
                            while (true) {
                                if (!it.hasNext()) {
                                    break;
                                }
                                if (cr4.b(((StremioCatalogExtra) it.next()).getName(), "search")) {
                                    arrayList.add(obj2);
                                    break;
                                }
                            }
                        }
                    }
                }
                arrayList2 = new ArrayList();
                for (Object obj3 : list) {
                    StremioCatalog stremioCatalog = (StremioCatalog) obj3;
                    if (!cr4.b(stremioCatalog.getType(), "other") && stremioCatalog.shouldShowOnHome()) {
                        arrayList2.add(obj3);
                    }
                }
                if (arrayList.isEmpty()) {
                    i85 viewLifecycleOwner = mobileAddonsFragment.getViewLifecycleOwner();
                    cr4.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
                    androidx.lifecycle.n nVarA = androidx.lifecycle.s.a(viewLifecycleOwner);
                    m12 m12Var = sc2.a;
                    wj0.c(nVarA, m02.c, null, new o(mobileAddonsFragment, arrayList, installedAddon, null), 2);
                    i = 1;
                } else {
                    i = 0;
                }
                if (!arrayList2.isEmpty()) {
                    mobileAddonsFragment.getClass();
                    ArrayList arrayList3 = new ArrayList();
                    for (Object obj4 : arrayList2) {
                        StremioCatalog stremioCatalog2 = (StremioCatalog) obj4;
                        if (!cr4.b(stremioCatalog2.getType(), "other") && stremioCatalog2.shouldShowOnHome()) {
                            arrayList3.add(obj4);
                        }
                    }
                    if (!arrayList3.isEmpty()) {
                        LinearLayout linearLayout = new LinearLayout(mobileAddonsFragment.requireContext());
                        linearLayout.setOrientation(1);
                        linearLayout.setPadding(48, 32, 48, 16);
                        CheckBox checkBox = new CheckBox(mobileAddonsFragment.requireContext());
                        checkBox.setText("Home Page");
                        checkBox.setChecked(true);
                        CheckBox checkBox2 = new CheckBox(mobileAddonsFragment.requireContext());
                        checkBox2.setText("Movies Page");
                        checkBox2.setChecked(false);
                        CheckBox checkBox3 = new CheckBox(mobileAddonsFragment.requireContext());
                        checkBox3.setText("TV Shows Page");
                        checkBox3.setChecked(false);
                        linearLayout.addView(checkBox);
                        linearLayout.addView(checkBox2);
                        linearLayout.addView(checkBox3);
                        Context contextRequireContext = mobileAddonsFragment.requireContext();
                        cr4.f(contextRequireContext, "requireContext(...)");
                        new gv3(contextRequireContext, R.style.StrmrDialogTheme).setTitle((CharSequence) ("Add " + installedAddon.getDisplayName() + " Catalogs")).setMessage((CharSequence) "Select which pages to add catalog rows to:").setView((View) linearLayout).setPositiveButton((CharSequence) "Add", (DialogInterface.OnClickListener) new yd(checkBox, checkBox2, checkBox3, mobileAddonsFragment, installedAddon, arrayList3, 1)).setNegativeButton((CharSequence) "Skip", (DialogInterface.OnClickListener) null).show();
                    }
                    i++;
                }
                if (i == 0) {
                    installedAddon.getName();
                    Objects.toString(installedAddon.getCapabilities());
                    return e6aVar;
                }
                return e6aVar;
            }
            m12 m12Var2 = sc2.a;
            m02 m02Var = m02.c;
            j jVar = new j(mobileAddonsFragment, this.d, null);
            this.a = 1;
            objF = wj0.f(m02Var, jVar, this);
            if (objF == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(obj);
            objF = obj;
        }
        StremioAddonService.c cVar = (StremioAddonService.c) objF;
        if (!(cVar instanceof StremioAddonService.c.b)) {
            if (installedAddon.getCapabilities().contains("search")) {
                i85 viewLifecycleOwner2 = mobileAddonsFragment.getViewLifecycleOwner();
                cr4.f(viewLifecycleOwner2, "getViewLifecycleOwner(...)");
                androidx.lifecycle.n nVarA2 = androidx.lifecycle.s.a(viewLifecycleOwner2);
                m12 m12Var3 = sc2.a;
                wj0.c(nVarA2, m02.c, null, new m(mobileAddonsFragment, installedAddon, null), 2);
            }
            return e6aVar;
        }
        parsedCatalogs = ((StremioAddonService.c.b) cVar).a.getParsedCatalogs();
        List<StremioCatalog> list3 = parsedCatalogs;
        arrayList = new ArrayList();
        while (r9.hasNext()) {
        }
        arrayList2 = new ArrayList();
        while (r1.hasNext()) {
        }
        if (arrayList.isEmpty()) {
        }
        if (!arrayList2.isEmpty()) {
        }
        if (i == 0) {
        }
        return e6aVar;
    }
}
