package defpackage;

import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import androidx.lifecycle.n;
import androidx.lifecycle.s;
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 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.settings.fragments.AddonsFragment$checkAndHandleAddonType$1", f = "AddonsFragment.kt", i = {}, l = {360}, m = "invokeSuspend", n = {}, s = {})
@vx8
final class ge extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public int a;
    public final /* synthetic */ InstalledAddon b;
    public final /* synthetic */ ff c;
    public final /* synthetic */ String d;

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

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

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

    /* JADX WARN: Removed duplicated region for block: B:20:0x006d  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x00d8  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x0124  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x014f  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x0168  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x016f  */
    /* JADX WARN: Removed duplicated region for block: B:72:0x025e  */
    @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;
        ArrayList arrayList3;
        ck1 ck1Var = ck1.a;
        int i2 = this.a;
        e6a e6aVar = e6a.a;
        ff ffVar = this.c;
        InstalledAddon installedAddon = this.b;
        if (i2 == 0) {
            s38.b(obj);
            if (!installedAddon.getParsedCatalogs().isEmpty()) {
                parsedCatalogs = installedAddon.getParsedCatalogs();
                installedAddon.getName();
                parsedCatalogs.size();
                List<StremioCatalog> list = parsedCatalogs;
                for (StremioCatalog stremioCatalog : list) {
                    stremioCatalog.getId();
                    stremioCatalog.getType();
                    stremioCatalog.getName();
                    List<StremioCatalogExtra> extra = stremioCatalog.getExtra();
                    if (extra != null) {
                        List<StremioCatalogExtra> list2 = extra;
                        arrayList3 = new ArrayList(y41.p(list2, 10));
                        for (StremioCatalogExtra stremioCatalogExtra : list2) {
                            arrayList3.add(stremioCatalogExtra.getName() + "(required=" + stremioCatalogExtra.isRequired() + ")");
                        }
                    } else {
                        arrayList3 = null;
                    }
                    Objects.toString(arrayList3);
                }
                arrayList = new ArrayList();
                for (Object obj2 : list) {
                    List<StremioCatalogExtra> extra2 = ((StremioCatalog) obj2).getExtra();
                    if (extra2 != null) {
                        List<StremioCatalogExtra> list3 = extra2;
                        if (!(list3 instanceof Collection) || !list3.isEmpty()) {
                            Iterator<T> it = list3.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 stremioCatalog2 = (StremioCatalog) obj3;
                    if (!cr4.b(stremioCatalog2.getType(), "other") && stremioCatalog2.shouldShowOnHome()) {
                        arrayList2.add(obj3);
                    }
                }
                installedAddon.getName();
                arrayList.size();
                arrayList2.size();
                if (arrayList.isEmpty()) {
                    i85 viewLifecycleOwner = ffVar.getViewLifecycleOwner();
                    cr4.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
                    n nVarA = s.a(viewLifecycleOwner);
                    m12 m12Var = sc2.a;
                    wj0.c(nVarA, m02.c, null, new ne(ffVar, arrayList, installedAddon, null), 2);
                    i = 1;
                } else {
                    i = 0;
                }
                if (!arrayList2.isEmpty()) {
                    arrayList2.size();
                    ffVar.getClass();
                    ArrayList arrayList4 = new ArrayList();
                    for (Object obj4 : arrayList2) {
                        StremioCatalog stremioCatalog3 = (StremioCatalog) obj4;
                        if (!cr4.b(stremioCatalog3.getType(), "other") && stremioCatalog3.shouldShowOnHome()) {
                            arrayList4.add(obj4);
                        }
                    }
                    if (!arrayList4.isEmpty()) {
                        LinearLayout linearLayout = new LinearLayout(ffVar.requireContext());
                        linearLayout.setOrientation(1);
                        linearLayout.setPadding(48, 32, 48, 16);
                        CheckBox checkBox = new CheckBox(ffVar.requireContext());
                        checkBox.setText(ffVar.getString(R.string.addon_page_home));
                        checkBox.setChecked(true);
                        CheckBox checkBox2 = new CheckBox(ffVar.requireContext());
                        checkBox2.setText(ffVar.getString(R.string.addon_page_movies));
                        checkBox2.setChecked(false);
                        CheckBox checkBox3 = new CheckBox(ffVar.requireContext());
                        checkBox3.setText(ffVar.getString(R.string.addon_page_tv_shows));
                        checkBox3.setChecked(false);
                        linearLayout.addView(checkBox);
                        linearLayout.addView(checkBox2);
                        linearLayout.addView(checkBox3);
                        Context contextRequireContext = ffVar.requireContext();
                        cr4.f(contextRequireContext, "requireContext(...)");
                        new gv3(contextRequireContext, R.style.Theme_Strmr_Dialog_TV).setTitle((CharSequence) ffVar.getString(R.string.addon_add_catalogs_title, installedAddon.getDisplayName())).setMessage((CharSequence) ffVar.getString(R.string.addon_add_catalogs_message)).setView((View) linearLayout).setPositiveButton((CharSequence) ffVar.getString(R.string.addon_add_button), (DialogInterface.OnClickListener) new yd(checkBox, checkBox2, checkBox3, ffVar, installedAddon, arrayList4, 0)).setNegativeButton((CharSequence) ffVar.getString(R.string.addon_skip_button), (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;
            fe feVar = new fe(ffVar, this.d, null);
            this.a = 1;
            objF = wj0.f(m02Var, feVar, 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 = ffVar.getViewLifecycleOwner();
                cr4.f(viewLifecycleOwner2, "getViewLifecycleOwner(...)");
                n nVarA2 = s.a(viewLifecycleOwner2);
                m12 m12Var3 = sc2.a;
                wj0.c(nVarA2, m02.c, null, new le(ffVar, installedAddon, null), 2);
            }
            return e6aVar;
        }
        parsedCatalogs = ((StremioAddonService.c.b) cVar).a.getParsedCatalogs();
        installedAddon.getName();
        parsedCatalogs.size();
        List<StremioCatalog> list4 = parsedCatalogs;
        while (r2.hasNext()) {
        }
        arrayList = new ArrayList();
        while (r8.hasNext()) {
        }
        arrayList2 = new ArrayList();
        while (r1.hasNext()) {
        }
        installedAddon.getName();
        arrayList.size();
        arrayList2.size();
        if (arrayList.isEmpty()) {
        }
        if (!arrayList2.isEmpty()) {
        }
        if (i == 0) {
        }
        return e6aVar;
    }
}
