package com.strmr.ps.ui.networkcontent;

import android.util.Log;
import com.strmr.ps.data.model.trakt.TraktListItem;
import defpackage.ak1;
import defpackage.bk1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.ik2;
import defpackage.q07;
import defpackage.re6;
import defpackage.s38;
import defpackage.vx8;
import defpackage.y41;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
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.networkcontent.NetworkContentViewModel$loadMore$1", f = "NetworkContentViewModel.kt", i = {0, 1}, l = {157, 170, 182}, m = "invokeSuspend", n = {"newItems", "newItems"}, s = {"L$0", "L$0"})
@vx8
final class o extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public List a;
    public int b;
    public final /* synthetic */ NetworkContentViewModel c;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public o(NetworkContentViewModel networkContentViewModel, Continuation continuation) {
        super(2, continuation);
        this.c = networkContentViewModel;
    }

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

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

    /* JADX WARN: Code restructure failed: missing block: B:67:0x013c, code lost:
    
        if (r4 == r3) goto L68;
     */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00e5 A[Catch: all -> 0x0021, Exception -> 0x0024, TryCatch #1 {Exception -> 0x0024, blocks: (B:7:0x001a, B:69:0x013f, B:71:0x0149, B:72:0x014b, B:16:0x0033, B:53:0x00dd, B:55:0x00e5, B:56:0x00e7, B:58:0x00f0, B:59:0x0106, B:61:0x010c, B:62:0x011f, B:63:0x0122, B:64:0x0125, B:66:0x012e, B:19:0x0040, B:31:0x006b, B:33:0x0073, B:34:0x0075, B:36:0x007e, B:37:0x0093, B:39:0x0099, B:40:0x00b0, B:42:0x00b8, B:44:0x00be, B:46:0x00c2, B:48:0x00c6, B:50:0x00ca, B:22:0x0049, B:24:0x0052, B:26:0x0056, B:28:0x005a), top: B:80:0x0012, outer: #0 }] */
    /* JADX WARN: Removed duplicated region for block: B:58:0x00f0 A[Catch: all -> 0x0021, Exception -> 0x0024, TryCatch #1 {Exception -> 0x0024, blocks: (B:7:0x001a, B:69:0x013f, B:71:0x0149, B:72:0x014b, B:16:0x0033, B:53:0x00dd, B:55:0x00e5, B:56:0x00e7, B:58:0x00f0, B:59:0x0106, B:61:0x010c, B:62:0x011f, B:63:0x0122, B:64:0x0125, B:66:0x012e, B:19:0x0040, B:31:0x006b, B:33:0x0073, B:34:0x0075, B:36:0x007e, B:37:0x0093, B:39:0x0099, B:40:0x00b0, B:42:0x00b8, B:44:0x00be, B:46:0x00c2, B:48:0x00c6, B:50:0x00ca, B:22:0x0049, B:24:0x0052, B:26:0x0056, B:28:0x005a), top: B:80:0x0012, outer: #0 }] */
    /* JADX WARN: Removed duplicated region for block: B:64:0x0125 A[Catch: all -> 0x0021, Exception -> 0x0024, PHI: r4
      0x0125: PHI (r4v5 java.util.List) = (r4v3 java.util.List), (r4v3 java.util.List), (r4v3 java.util.List), (r4v7 java.util.List) binds: [B:45:0x00c0, B:47:0x00c4, B:49:0x00c8, B:63:0x0122] A[DONT_GENERATE, DONT_INLINE], TryCatch #1 {Exception -> 0x0024, blocks: (B:7:0x001a, B:69:0x013f, B:71:0x0149, B:72:0x014b, B:16:0x0033, B:53:0x00dd, B:55:0x00e5, B:56:0x00e7, B:58:0x00f0, B:59:0x0106, B:61:0x010c, B:62:0x011f, B:63:0x0122, B:64:0x0125, B:66:0x012e, B:19:0x0040, B:31:0x006b, B:33:0x0073, B:34:0x0075, B:36:0x007e, B:37:0x0093, B:39:0x0099, B:40:0x00b0, B:42:0x00b8, B:44:0x00be, B:46:0x00c2, B:48:0x00c6, B:50:0x00ca, B:22:0x0049, B:24:0x0052, B:26:0x0056, B:28:0x005a), top: B:80:0x0012, outer: #0 }] */
    /* JADX WARN: Removed duplicated region for block: B:66:0x012e A[Catch: all -> 0x0021, Exception -> 0x0024, TryCatch #1 {Exception -> 0x0024, blocks: (B:7:0x001a, B:69:0x013f, B:71:0x0149, B:72:0x014b, B:16:0x0033, B:53:0x00dd, B:55:0x00e5, B:56:0x00e7, B:58:0x00f0, B:59:0x0106, B:61:0x010c, B:62:0x011f, B:63:0x0122, B:64:0x0125, B:66:0x012e, B:19:0x0040, B:31:0x006b, B:33:0x0073, B:34:0x0075, B:36:0x007e, B:37:0x0093, B:39:0x0099, B:40:0x00b0, B:42:0x00b8, B:44:0x00be, B:46:0x00c2, B:48:0x00c6, B:50:0x00ca, B:22:0x0049, B:24:0x0052, B:26:0x0056, B:28:0x005a), top: B:80:0x0012, outer: #0 }] */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        List arrayList;
        String str;
        String str2;
        Object objB;
        String str3;
        String str4;
        Object objC;
        Object objC2;
        List list;
        NetworkContentViewModel networkContentViewModel = this.c;
        re6 re6Var = networkContentViewModel.h;
        ck1 ck1Var = ck1.a;
        int i = this.b;
        boolean z = true;
        try {
            try {
            } catch (Exception e) {
                Log.e("NetworkContentVM", "Error loading more content", e);
            }
            if (i == 0) {
                s38.b(obj);
                arrayList = new ArrayList();
                if (!networkContentViewModel.r || (str = networkContentViewModel.u) == null || (str2 = networkContentViewModel.v) == null) {
                    if (networkContentViewModel.s || (str3 = networkContentViewModel.w) == null || (str4 = networkContentViewModel.x) == null) {
                        if (!arrayList.isEmpty()) {
                        }
                        return e6a.a;
                    }
                    cr4.d(str4);
                    int i2 = networkContentViewModel.q;
                    this.a = arrayList;
                    this.b = 2;
                    objC = NetworkContentViewModel.c(networkContentViewModel, str3, str4, i2, this);
                    if (objC == ck1Var) {
                    }
                    list = (List) objC;
                    if (list.size() < 20) {
                    }
                    if (!list.isEmpty()) {
                    }
                    list.size();
                    if (!arrayList.isEmpty()) {
                    }
                    return e6a.a;
                    return ck1Var;
                }
                cr4.d(str2);
                int i3 = networkContentViewModel.p;
                this.a = arrayList;
                this.b = 1;
                objB = NetworkContentViewModel.b(networkContentViewModel, str, str2, i3, this);
                if (objB == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    if (i != 2) {
                        if (i != 3) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        s38.b(obj);
                        objC2 = obj;
                        List list2 = (List) objC2;
                        Collection collection = (List) re6Var.e();
                        if (collection == null) {
                            collection = ik2.a;
                        }
                        ArrayList arrayListAu = y41.au(list2, collection);
                        re6Var.l(arrayListAu);
                        arrayListAu.size();
                        return e6a.a;
                    }
                    arrayList = this.a;
                    s38.b(obj);
                    objC = obj;
                    list = (List) objC;
                    if (list.size() < 20) {
                        networkContentViewModel.s = false;
                    }
                    if (!list.isEmpty()) {
                        networkContentViewModel.q++;
                        List list3 = list;
                        ArrayList arrayList2 = new ArrayList(y41.p(list3, 10));
                        Iterator it = list3.iterator();
                        while (it.hasNext()) {
                            arrayList2.add(new q07((TraktListItem) it.next(), Boxing.boxBoolean(false)));
                        }
                        arrayList.addAll(arrayList2);
                    }
                    list.size();
                    if (!arrayList.isEmpty()) {
                        this.a = null;
                        this.b = 3;
                        objC2 = bk1.c(new d(arrayList, networkContentViewModel, null), this);
                    }
                    return e6a.a;
                }
                arrayList = this.a;
                s38.b(obj);
                objB = obj;
            }
            List list4 = (List) objB;
            if (list4.size() < 20) {
                networkContentViewModel.r = false;
            }
            if (!list4.isEmpty()) {
                networkContentViewModel.p++;
                List list5 = list4;
                ArrayList arrayList3 = new ArrayList(y41.p(list5, 10));
                Iterator it2 = list5.iterator();
                while (it2.hasNext()) {
                    arrayList3.add(new q07((TraktListItem) it2.next(), Boxing.boxBoolean(z)));
                    z = z;
                }
                arrayList.addAll(arrayList3);
            }
            list4.size();
            if (networkContentViewModel.s) {
                if (!arrayList.isEmpty()) {
                }
            }
            return e6a.a;
        } finally {
            networkContentViewModel.t = false;
        }
    }
}
