package com.strmr.ps.data.repository;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import androidx.credentials.CredentialOption;
import androidx.credentials.exceptions.publickeycredential.DomExceptionUtils;
import androidx.media3.common.C;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.analytics.AnalyticsListener;
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.media3.session.MediaUtils;
import com.google.android.material.card.MaterialCardViewHelper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.strmr.ps.data.event.TraktErrorNotifier;
import com.strmr.ps.data.local.dao.EpisodeWatchStatusDao;
import com.strmr.ps.data.local.dao.LastWatchedPerShow;
import com.strmr.ps.data.local.dao.TraktUserItemDao;
import com.strmr.ps.data.local.entity.EpisodeWatchStatus;
import com.strmr.ps.data.local.entity.PlaybackProgress;
import com.strmr.ps.data.local.entity.TraktAccount;
import com.strmr.ps.data.local.entity.TraktUserItem;
import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.model.continuewatching.ContinueWatchingItem;
import com.strmr.ps.data.model.continuewatching.ContinueWatchingModelsKt;
import com.strmr.ps.data.model.tmdb.TMDBCast;
import com.strmr.ps.data.model.tmdb.TMDBCredits;
import com.strmr.ps.data.model.tmdb.TMDBEpisode;
import com.strmr.ps.data.model.tmdb.TMDBExternalIds;
import com.strmr.ps.data.model.tmdb.TMDBGenre;
import com.strmr.ps.data.model.tmdb.TMDBImagesKt;
import com.strmr.ps.data.model.tmdb.TMDBMovieDetails;
import com.strmr.ps.data.model.tmdb.TMDBSeason;
import com.strmr.ps.data.model.tmdb.TMDBSeasonDetails;
import com.strmr.ps.data.model.tmdb.TMDBShowDetails;
import com.strmr.ps.data.model.trakt.TraktActivityGroup;
import com.strmr.ps.data.model.trakt.TraktEpisode;
import com.strmr.ps.data.model.trakt.TraktIds;
import com.strmr.ps.data.model.trakt.TraktLastActivities;
import com.strmr.ps.data.model.trakt.TraktMovie;
import com.strmr.ps.data.model.trakt.TraktPlaybackItem;
import com.strmr.ps.data.model.trakt.TraktShow;
import com.strmr.ps.data.model.trakt.TraktWatchedEpisode;
import com.strmr.ps.data.model.trakt.TraktWatchedSeason;
import com.strmr.ps.data.model.trakt.TraktWatchedShow;
import com.strmr.ps.data.remote.api.TMDBApiService;
import com.strmr.ps.data.remote.api.TraktApiService;
import com.strmr.ps.data.repository.ContinueWatchingRepository;
import dagger.hilt.android.qualifiers.ApplicationContext;
import defpackage.ah;
import defpackage.ak1;
import defpackage.bk1;
import defpackage.bz0;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.dg8;
import defpackage.dw7;
import defpackage.e6a;
import defpackage.ez2;
import defpackage.fi7;
import defpackage.gr3;
import defpackage.h32;
import defpackage.hf5;
import defpackage.hx9;
import defpackage.i50;
import defpackage.ik2;
import defpackage.io6;
import defpackage.j65;
import defpackage.jk2;
import defpackage.km8;
import defpackage.kp6;
import defpackage.lj1;
import defpackage.m02;
import defpackage.m12;
import defpackage.me1;
import defpackage.mg6;
import defpackage.n41;
import defpackage.n89;
import defpackage.pk2;
import defpackage.pq6;
import defpackage.q07;
import defpackage.q38;
import defpackage.qq3;
import defpackage.r22;
import defpackage.rg6;
import defpackage.s38;
import defpackage.sc2;
import defpackage.sq3;
import defpackage.st;
import defpackage.uz1;
import defpackage.v65;
import defpackage.vw2;
import defpackage.vx8;
import defpackage.wj0;
import defpackage.wo5;
import defpackage.x71;
import defpackage.xf8;
import defpackage.y41;
import defpackage.zr7;
import java.io.File;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap;
import javax.inject.Inject;
import javax.inject.Singleton;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.ContinuationImpl;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import okhttp3.internal.http2.Http2Connection;
import retrofit2.HttpException;
import retrofit2.Response;

/* JADX INFO: loaded from: classes3.dex */
@Singleton
@Metadata(d1 = {"\u0000\u0088\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\u0006\n\u0002\b\u0006\n\u0002\u0010\t\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\"\n\u0002\b\u0003\n\u0002\u0010#\n\u0002\u0010\u000e\n\u0002\b\n\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\n\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u000f\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0012\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u000e\b\u0007\u0018\u0000 ½\u00012\u00020\u0001:\u0002½\u0001Be\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004\u0012\u0006\u0010\u0007\u001a\u00020\u0006\u0012\u0006\u0010\t\u001a\u00020\b\u0012\u0006\u0010\u000b\u001a\u00020\n\u0012\u0006\u0010\r\u001a\u00020\f\u0012\b\b\u0001\u0010\u000f\u001a\u00020\u000e\u0012\u0006\u0010\u0011\u001a\u00020\u0010\u0012\u0006\u0010\u0013\u001a\u00020\u0012\u0012\u0006\u0010\u0015\u001a\u00020\u0014\u0012\b\b\u0002\u0010\u0017\u001a\u00020\u0016¢\u0006\u0004\b\u0018\u0010\u0019J\u0015\u0010\u001d\u001a\u00020\u001c2\u0006\u0010\u001b\u001a\u00020\u001a¢\u0006\u0004\b\u001d\u0010\u001eJ\u0015\u0010\u001f\u001a\u00020\u001c2\u0006\u0010\u001b\u001a\u00020\u001a¢\u0006\u0004\b\u001f\u0010\u001eJ\u0010\u0010!\u001a\u00020 H\u0086@¢\u0006\u0004\b!\u0010\"J\u0016\u0010%\u001a\b\u0012\u0004\u0012\u00020$0#H\u0086@¢\u0006\u0004\b%\u0010\"J\r\u0010&\u001a\u00020\u001c¢\u0006\u0004\b&\u0010'J\r\u0010(\u001a\u00020 ¢\u0006\u0004\b(\u0010)J\u0018\u0010,\u001a\u00020 2\u0006\u0010+\u001a\u00020*H\u0086@¢\u0006\u0004\b,\u0010-J\u0016\u0010.\u001a\b\u0012\u0004\u0012\u00020$0#H\u0086@¢\u0006\u0004\b.\u0010\"J\u0015\u0010/\u001a\u00020 2\u0006\u0010\u001b\u001a\u00020\u001a¢\u0006\u0004\b/\u00100J\u001d\u00103\u001a\u00020 2\u0006\u0010\u001b\u001a\u00020\u001a2\u0006\u00102\u001a\u000201¢\u0006\u0004\b3\u00104J \u00106\u001a\b\u0012\u0004\u0012\u00020$0#2\b\b\u0002\u00105\u001a\u00020 H\u0086@¢\u0006\u0004\b6\u00107J\u0018\u0010:\u001a\u00020 2\u0006\u00109\u001a\u000208H\u0086@¢\u0006\u0004\b:\u0010;J(\u0010?\u001a\u00020 2\f\u0010=\u001a\b\u0012\u0004\u0012\u00020<0#2\b\b\u0002\u0010>\u001a\u000208H\u0086@¢\u0006\u0004\b?\u0010@J\u0015\u0010B\u001a\b\u0012\u0004\u0012\u00020\u001a0AH\u0002¢\u0006\u0004\bB\u0010CJ\u0016\u0010D\u001a\b\u0012\u0004\u0012\u00020\u001a0AH\u0082@¢\u0006\u0004\bD\u0010\"J\u0015\u0010G\u001a\b\u0012\u0004\u0012\u00020F0EH\u0002¢\u0006\u0004\bG\u0010CJ\u0017\u0010I\u001a\u00020\u001c2\u0006\u0010H\u001a\u00020FH\u0002¢\u0006\u0004\bI\u0010JJ\u000f\u0010K\u001a\u00020\u001cH\u0002¢\u0006\u0004\bK\u0010'J\u0017\u0010L\u001a\n\u0012\u0004\u0012\u00020$\u0018\u00010#H\u0002¢\u0006\u0004\bL\u0010MJ\u001d\u0010N\u001a\u00020\u001c2\f\u0010=\u001a\b\u0012\u0004\u0012\u00020$0#H\u0002¢\u0006\u0004\bN\u0010OJ\u001e\u0010P\u001a\b\u0012\u0004\u0012\u00020$0#2\u0006\u00105\u001a\u00020 H\u0082@¢\u0006\u0004\bP\u00107J#\u0010S\u001a\b\u0012\u0004\u0012\u00020<0#2\f\u0010R\u001a\b\u0012\u0004\u0012\u00020Q0#H\u0002¢\u0006\u0004\bS\u0010TJ2\u0010X\u001a\b\u0012\u0004\u0012\u00020<0#2\f\u0010U\u001a\b\u0012\u0004\u0012\u00020Q0#2\f\u0010W\u001a\b\u0012\u0004\u0012\u00020V0#H\u0082@¢\u0006\u0004\bX\u0010YJ\u0019\u0010[\u001a\u0004\u0018\u00010<2\u0006\u0010Z\u001a\u00020QH\u0002¢\u0006\u0004\b[\u0010\\J,\u0010_\u001a\u0004\u0018\u00010<2\u0006\u0010]\u001a\u00020\u001a2\u0006\u0010^\u001a\u00020V2\b\u0010Z\u001a\u0004\u0018\u00010QH\u0082@¢\u0006\u0004\b_\u0010`J>\u0010e\u001a\u0018\u0012\u0004\u0012\u00020\u001a\u0012\u0004\u0012\u00020\u001a\u0012\u0006\u0012\u0004\u0018\u00010d\u0018\u00010c2\u0006\u0010]\u001a\u00020\u001a2\u0006\u0010a\u001a\u00020\u001a2\u0006\u0010b\u001a\u00020\u001aH\u0082@¢\u0006\u0004\be\u0010fJ\"\u0010i\u001a\u0004\u0018\u00010h2\u0006\u0010]\u001a\u00020\u001a2\u0006\u0010g\u001a\u00020\u001aH\u0082@¢\u0006\u0004\bi\u0010jJ\u001b\u0010l\u001a\u0004\u0018\u0001082\b\u0010k\u001a\u0004\u0018\u00010FH\u0002¢\u0006\u0004\bl\u0010mJ\u0018\u0010o\u001a\u00020 2\u0006\u0010n\u001a\u00020FH\u0082@¢\u0006\u0004\bo\u0010pJ\u001b\u0010r\u001a\u0004\u0018\u0001082\b\u0010q\u001a\u0004\u0018\u00010FH\u0002¢\u0006\u0004\br\u0010mJ&\u0010t\u001a\u0010\u0012\u0004\u0012\u00020 \u0012\u0006\u0012\u0004\u0018\u00010*0s2\u0006\u0010n\u001a\u00020FH\u0082@¢\u0006\u0004\bt\u0010pJ#\u0010u\u001a\b\u0012\u0004\u0012\u00020<0#2\f\u0010=\u001a\b\u0012\u0004\u0012\u00020<0#H\u0002¢\u0006\u0004\bu\u0010TJ$\u0010v\u001a\b\u0012\u0004\u0012\u00020$0#2\f\u0010=\u001a\b\u0012\u0004\u0012\u00020<0#H\u0082@¢\u0006\u0004\bv\u0010wJ\u001a\u0010y\u001a\u0004\u0018\u00010$2\u0006\u0010x\u001a\u00020<H\u0082@¢\u0006\u0004\by\u0010zJ\u001a\u0010|\u001a\u0004\u0018\u00010$2\u0006\u0010x\u001a\u00020{H\u0082@¢\u0006\u0004\b|\u0010}J\u001a\u0010~\u001a\u0004\u0018\u00010$2\u0006\u0010x\u001a\u00020<H\u0082@¢\u0006\u0004\b~\u0010zJ-\u0010\u0081\u0001\u001a\u0004\u0018\u00010F2\u000e\u0010\u007f\u001a\n\u0012\u0004\u0012\u00020d\u0018\u00010#2\u0007\u0010\u0080\u0001\u001a\u00020\u001aH\u0002¢\u0006\u0006\b\u0081\u0001\u0010\u0082\u0001J'\u0010\u0084\u0001\u001a\u0004\u0018\u00010F2\u0006\u0010x\u001a\u00020<2\t\u0010\u0083\u0001\u001a\u0004\u0018\u00010dH\u0002¢\u0006\u0006\b\u0084\u0001\u0010\u0085\u0001J\u001e\u0010\u0086\u0001\u001a\u0004\u0018\u00010F2\b\u0010q\u001a\u0004\u0018\u00010FH\u0002¢\u0006\u0006\b\u0086\u0001\u0010\u0087\u0001Jg\u0010\u0090\u0001\u001a\u0004\u0018\u00018\u0000\"\u0005\b\u0000\u0010\u0088\u00012\t\b\u0002\u0010\u0089\u0001\u001a\u00020\u001a2\t\b\u0002\u0010\u008a\u0001\u001a\u0002082\u0012\b\u0002\u0010\u008c\u0001\u001a\u000b\u0012\u0004\u0012\u00020\u001c\u0018\u00010\u008b\u00012\u001f\u0010\u008f\u0001\u001a\u001a\b\u0001\u0012\u000b\u0012\t\u0012\u0004\u0012\u00028\u00000\u008e\u0001\u0012\u0006\u0012\u0004\u0018\u00010\u00010\u008d\u0001H\u0082@¢\u0006\u0006\b\u0090\u0001\u0010\u0091\u0001R\u0015\u0010\u0003\u001a\u00020\u00028\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\u0003\u0010\u0092\u0001R\u0015\u0010\u0005\u001a\u00020\u00048\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\u0005\u0010\u0093\u0001R\u0015\u0010\u0007\u001a\u00020\u00068\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\u0007\u0010\u0094\u0001R\u0015\u0010\t\u001a\u00020\b8\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\t\u0010\u0095\u0001R\u0015\u0010\u000b\u001a\u00020\n8\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\u000b\u0010\u0096\u0001R\u0015\u0010\r\u001a\u00020\f8\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\r\u0010\u0097\u0001R\u0015\u0010\u000f\u001a\u00020\u000e8\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\u000f\u0010\u0098\u0001R\u0015\u0010\u0011\u001a\u00020\u00108\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\u0011\u0010\u0099\u0001R\u0015\u0010\u0013\u001a\u00020\u00128\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\u0013\u0010\u009a\u0001R\u0015\u0010\u0015\u001a\u00020\u00148\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\u0015\u0010\u009b\u0001R\u0015\u0010\u0017\u001a\u00020\u00168\u0002X\u0082\u0004¢\u0006\u0007\n\u0005\b\u0017\u0010\u009c\u0001R!\u0010\u009d\u0001\u001a\n\u0012\u0004\u0012\u00020$\u0018\u00010#8\u0002@\u0002X\u0082\u000e¢\u0006\b\n\u0006\b\u009d\u0001\u0010\u009e\u0001R\u0019\u0010\u009f\u0001\u001a\u0002088\u0002@\u0002X\u0082\u000e¢\u0006\b\n\u0006\b\u009f\u0001\u0010 \u0001R\u0018\u0010¢\u0001\u001a\u00030¡\u00018\u0002X\u0082\u0004¢\u0006\b\n\u0006\b¢\u0001\u0010£\u0001R$\u0010¥\u0001\u001a\u000f\u0012\u0004\u0012\u00020F\u0012\u0004\u0012\u00020h0¤\u00018\u0002X\u0082\u0004¢\u0006\b\n\u0006\b¥\u0001\u0010¦\u0001R%\u0010ª\u0001\u001a\b\u0012\u0004\u0012\u00020F0E8BX\u0082\u0084\u0002¢\u0006\u000f\n\u0006\b§\u0001\u0010¨\u0001\u001a\u0005\b©\u0001\u0010CR!\u0010¯\u0001\u001a\u00030«\u00018BX\u0082\u0084\u0002¢\u0006\u0010\n\u0006\b¬\u0001\u0010¨\u0001\u001a\u0006\b\u00ad\u0001\u0010®\u0001R+\u0010µ\u0001\u001a\r ±\u0001*\u0005\u0018\u00010°\u00010°\u00018BX\u0082\u0084\u0002¢\u0006\u0010\n\u0006\b²\u0001\u0010¨\u0001\u001a\u0006\b³\u0001\u0010´\u0001R+\u0010¸\u0001\u001a\r ±\u0001*\u0005\u0018\u00010°\u00010°\u00018BX\u0082\u0084\u0002¢\u0006\u0010\n\u0006\b¶\u0001\u0010¨\u0001\u001a\u0006\b·\u0001\u0010´\u0001R$\u0010¹\u0001\u001a\u000f\u0012\u0004\u0012\u00020F\u0012\u0004\u0012\u0002080¤\u00018\u0002X\u0082\u0004¢\u0006\b\n\u0006\b¹\u0001\u0010¦\u0001R\u0017\u0010¼\u0001\u001a\u00020F8BX\u0082\u0004¢\u0006\b\u001a\u0006\bº\u0001\u0010»\u0001¨\u0006¾\u0001"}, d2 = {"Lcom/strmr/ps/data/repository/ContinueWatchingRepository;", "", "Lcom/strmr/ps/data/remote/api/TraktApiService;", "traktApiService", "Lcom/strmr/ps/data/remote/api/TMDBApiService;", "tmdbApiService", "Lcom/strmr/ps/data/repository/TraktAccountRepository;", "accountRepository", "Lcom/strmr/ps/data/repository/SyncMetadataRepository;", "syncMetadataRepository", "Lcom/strmr/ps/data/local/dao/EpisodeWatchStatusDao;", "episodeWatchStatusDao", "Lcom/strmr/ps/data/local/dao/TraktUserItemDao;", "traktUserItemDao", "Landroid/content/Context;", "context", "Lcom/google/gson/Gson;", "gson", "Lcom/strmr/ps/data/event/TraktErrorNotifier;", "traktErrorNotifier", "Lcom/strmr/ps/data/repository/TraktActivitiesCache;", "activitiesCache", "Llj1;", "ioDispatcher", "<init>", "(Lcom/strmr/ps/data/remote/api/TraktApiService;Lcom/strmr/ps/data/remote/api/TMDBApiService;Lcom/strmr/ps/data/repository/TraktAccountRepository;Lcom/strmr/ps/data/repository/SyncMetadataRepository;Lcom/strmr/ps/data/local/dao/EpisodeWatchStatusDao;Lcom/strmr/ps/data/local/dao/TraktUserItemDao;Landroid/content/Context;Lcom/google/gson/Gson;Lcom/strmr/ps/data/event/TraktErrorNotifier;Lcom/strmr/ps/data/repository/TraktActivitiesCache;Llj1;)V", "", "tmdbId", "Le6a;", "hideShow", "(I)V", "unhideShow", "", "hasAccount", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "", "Lcom/strmr/ps/data/model/ContentItem;", "loadFromCache", "invalidateCache", "()V", "hasCachedItems", "()Z", "Lcom/strmr/ps/data/model/trakt/TraktLastActivities;", "activities", "hasRemoteContinueWatchingChanges", "(Lcom/strmr/ps/data/model/trakt/TraktLastActivities;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "loadPlaybackOnly", "optimisticRemove", "(I)Z", "", "progress", "optimisticUpdateProgress", "(ID)Z", "forceRefresh", "load", "(ZLkotlin/coroutines/Continuation;)Ljava/lang/Object;", "", "playbackId", "removePlayback", "(JLkotlin/coroutines/Continuation;)Ljava/lang/Object;", "Lcom/strmr/ps/data/model/continuewatching/ContinueWatchingItem;", "items", "perItemDelayMillis", "clearAll", "(Ljava/util/List;JLkotlin/coroutines/Continuation;)Ljava/lang/Object;", "", "getHiddenShowIds", "()Ljava/util/Set;", "getDroppedShowTmdbIds", "", "", "loadSeasonNotFoundCache", "key", "addToSeasonNotFoundCache", "(Ljava/lang/String;)V", "persistSeasonNotFoundCache", "loadFromDiskCache", "()Ljava/util/List;", "saveToDiskCache", "(Ljava/util/List;)V", "loadInternal", "Lcom/strmr/ps/data/model/trakt/TraktPlaybackItem;", "playbackMovies", "processMovies", "(Ljava/util/List;)Ljava/util/List;", "playbackEpisodes", "Lcom/strmr/ps/data/local/dao/LastWatchedPerShow;", "lastWatchedPerShow", "processShows", "(Ljava/util/List;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "playbackItem", "processPlaybackOnlyShow", "(Lcom/strmr/ps/data/model/trakt/TraktPlaybackItem;)Lcom/strmr/ps/data/model/continuewatching/ContinueWatchingItem;", "showTmdbId", "lastWatched", "processShowEntry", "(ILcom/strmr/ps/data/local/dao/LastWatchedPerShow;Lcom/strmr/ps/data/model/trakt/TraktPlaybackItem;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "currentSeason", "currentEpisode", "Lhx9;", "Lcom/strmr/ps/data/model/tmdb/TMDBEpisode;", "computeNextEpisode", "(IIILkotlin/coroutines/Continuation;)Ljava/lang/Object;", "seasonNumber", "Lcom/strmr/ps/data/model/tmdb/TMDBSeasonDetails;", "fetchSeasonDetails", "(IILkotlin/coroutines/Continuation;)Ljava/lang/Object;", "airDate", "parseAirDate", "(Ljava/lang/String;)Ljava/lang/Long;", "authHeader", "syncEpisodeWatchStatus", "(Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "raw", "parseTraktDateMillis", "Lq07;", "checkRefreshNeeded", "dedupeByShow", "parallelEnrich", "(Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "item", "enrichToContentItem", "(Lcom/strmr/ps/data/model/continuewatching/ContinueWatchingItem;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "Lcom/strmr/ps/data/model/continuewatching/ContinueWatchingItem$Movie;", "enrichMovie", "(Lcom/strmr/ps/data/model/continuewatching/ContinueWatchingItem$Movie;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "enrichEpisode", "seasonEpisodes", "episodeNumber", "detectMidSeasonIndicator", "(Ljava/util/List;I)Ljava/lang/String;", "episodeDetails", "buildEpisodeLabel", "(Lcom/strmr/ps/data/model/continuewatching/ContinueWatchingItem;Lcom/strmr/ps/data/model/tmdb/TMDBEpisode;)Ljava/lang/String;", "formatEpisodeAirDate", "(Ljava/lang/String;)Ljava/lang/String;", "T", "retries", "delayMs", "Lkotlin/Function0;", "onNotFound", "Lkotlin/Function1;", "Lkotlin/coroutines/Continuation;", "block", "retryApiCall", "(IJLqq3;Lsq3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "Lcom/strmr/ps/data/remote/api/TraktApiService;", "Lcom/strmr/ps/data/remote/api/TMDBApiService;", "Lcom/strmr/ps/data/repository/TraktAccountRepository;", "Lcom/strmr/ps/data/repository/SyncMetadataRepository;", "Lcom/strmr/ps/data/local/dao/EpisodeWatchStatusDao;", "Lcom/strmr/ps/data/local/dao/TraktUserItemDao;", "Landroid/content/Context;", "Lcom/google/gson/Gson;", "Lcom/strmr/ps/data/event/TraktErrorNotifier;", "Lcom/strmr/ps/data/repository/TraktActivitiesCache;", "Llj1;", "cachedItems", "Ljava/util/List;", "lastCacheTime", "J", "Lmg6;", "loadMutex", "Lmg6;", "Ljava/util/concurrent/ConcurrentHashMap;", "seasonDetailsCache", "Ljava/util/concurrent/ConcurrentHashMap;", "seasonNotFoundCache$delegate", "Lj65;", "getSeasonNotFoundCache", "seasonNotFoundCache", "Ljava/io/File;", "diskCacheFile$delegate", "getDiskCacheFile", "()Ljava/io/File;", "diskCacheFile", "Landroid/content/SharedPreferences;", "kotlin.jvm.PlatformType", "hiddenShowsPrefs$delegate", "getHiddenShowsPrefs", "()Landroid/content/SharedPreferences;", "hiddenShowsPrefs", "seasonNotFoundPrefs$delegate", "getSeasonNotFoundPrefs", "seasonNotFoundPrefs", "seasonNotFoundTimestamps", "getImgLang", "()Ljava/lang/String;", "imgLang", "Companion", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class ContinueWatchingRepository {
    private static final int API_RETRY_COUNT = 1;
    private static final long API_RETRY_DELAY_MS = 500;
    private static final long CACHE_TTL_MS = 120000;

    /* JADX INFO: renamed from: Companion, reason: from kotlin metadata */
    @kp6
    public static final Companion INSTANCE = new Companion(null);

    @kp6
    private static final String DISK_CACHE_FILENAME = "continue_watching_cache_v2.json";
    private static final int ENRICH_CONCURRENCY = 6;

    @kp6
    private static final DateTimeFormatter EPISODE_AIR_DATE_FORMATTER;

    @kp6
    private static final String HIDDEN_SHOWS_KEY = "hidden_show_ids";

    @kp6
    private static final String HIDDEN_SHOWS_PREFS = "continue_watching_hidden";
    private static final float NEAR_COMPLETE_PROGRESS = 0.9f;
    private static final int PLAYBACK_EPISODE_LIMIT = 50;
    private static final int PLAYBACK_MOVIE_LIMIT = 50;
    private static final long REWATCH_TIMESTAMP_GAP_MS = 3600000;

    @kp6
    private static final String SEASON_NOT_FOUND_KEY = "not_found_keys";

    @kp6
    private static final String SEASON_NOT_FOUND_PREFS = "season_not_found_cache";

    @kp6
    private static final String SEASON_NOT_FOUND_TIMESTAMPS_KEY = "not_found_timestamps";
    private static final long SEASON_NOT_FOUND_TTL_MS = 21600000;

    @kp6
    private static final String SYNC_KEY_CONTINUE_WATCHING = "continue_watching_v2";

    @kp6
    private static final String TAG = "ContinueWatchingRepo";

    @kp6
    private final TraktAccountRepository accountRepository;

    @kp6
    private final TraktActivitiesCache activitiesCache;

    @pq6
    private volatile List<ContentItem> cachedItems;

    @kp6
    private final Context context;

    /* JADX INFO: renamed from: diskCacheFile$delegate, reason: from kotlin metadata */
    @kp6
    private final j65 diskCacheFile;

    @kp6
    private final EpisodeWatchStatusDao episodeWatchStatusDao;

    @kp6
    private final Gson gson;

    /* JADX INFO: renamed from: hiddenShowsPrefs$delegate, reason: from kotlin metadata */
    @kp6
    private final j65 hiddenShowsPrefs;

    @kp6
    private final lj1 ioDispatcher;
    private volatile long lastCacheTime;

    @kp6
    private final mg6 loadMutex;

    @kp6
    private final ConcurrentHashMap<String, TMDBSeasonDetails> seasonDetailsCache;

    /* JADX INFO: renamed from: seasonNotFoundCache$delegate, reason: from kotlin metadata */
    @kp6
    private final j65 seasonNotFoundCache;

    /* JADX INFO: renamed from: seasonNotFoundPrefs$delegate, reason: from kotlin metadata */
    @kp6
    private final j65 seasonNotFoundPrefs;

    @kp6
    private final ConcurrentHashMap<String, Long> seasonNotFoundTimestamps;

    @kp6
    private final SyncMetadataRepository syncMetadataRepository;

    @kp6
    private final TMDBApiService tmdbApiService;

    @kp6
    private final TraktApiService traktApiService;

    @kp6
    private final TraktErrorNotifier traktErrorNotifier;

    @kp6
    private final TraktUserItemDao traktUserItemDao;

    @Metadata(d1 = {"\u00008\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u0007\n\u0002\b\b\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0010\u0006\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0000\b\u0086\u0003\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b\u0002\u0010\u0003J\u0017\u0010\u0014\u001a\u00020\n2\b\u0010\u0015\u001a\u0004\u0018\u00010\u0016H\u0002¢\u0006\u0002\u0010\u0017R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\u0007X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\t\u001a\u00020\nX\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u000b\u001a\u00020\u0005X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\f\u001a\u00020\u0005X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\r\u001a\u00020\u0005X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u000e\u001a\u00020\u0005X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u000f\u001a\u00020\u0005X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0010\u001a\u00020\u0005X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0011\u001a\u00020\u0005X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0012\u001a\u00020\u0013X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0018\u001a\u00020\u0007X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0019\u001a\u00020\u0013X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u001a\u001a\u00020\u0007X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u001b\u001a\u00020\u0013X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u001c\u001a\u00020\u0013X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u001d\u001a\u00020\u001eX\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u001f"}, d2 = {"Lcom/strmr/ps/data/repository/ContinueWatchingRepository$Companion;", "", "<init>", "()V", "TAG", "", "PLAYBACK_MOVIE_LIMIT", "", "PLAYBACK_EPISODE_LIMIT", "NEAR_COMPLETE_PROGRESS", "", "SYNC_KEY_CONTINUE_WATCHING", "DISK_CACHE_FILENAME", "HIDDEN_SHOWS_PREFS", "HIDDEN_SHOWS_KEY", "SEASON_NOT_FOUND_PREFS", "SEASON_NOT_FOUND_KEY", "SEASON_NOT_FOUND_TIMESTAMPS_KEY", "SEASON_NOT_FOUND_TTL_MS", "", "normalizeProgress", "raw", "", "(Ljava/lang/Double;)F", "API_RETRY_COUNT", "API_RETRY_DELAY_MS", "ENRICH_CONCURRENCY", "CACHE_TTL_MS", "REWATCH_TIMESTAMP_GAP_MS", "EPISODE_AIR_DATE_FORMATTER", "Ljava/time/format/DateTimeFormatter;", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class Companion {
        public /* synthetic */ Companion(uz1 uz1Var) {
            this();
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final float normalizeProgress(Double raw) {
            return zr7.b((float) ((raw != null ? raw.doubleValue() : 0.0d) / 100.0d), 0.0f, 1.0f);
        }

        private Companion() {
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$checkRefreshNeeded$1, reason: invalid class name */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0, 1, 2, 2}, l = {1182, 1185, 1196}, m = "checkRefreshNeeded", n = {"this", "this", "activities", "fingerprint"}, s = {"L$0", "L$0", "L$0", "L$1"})
    public static final class AnonymousClass1 extends ContinuationImpl {
        Object L$0;
        Object L$1;
        int label;
        /* synthetic */ Object result;

        public AnonymousClass1(Continuation<? super AnonymousClass1> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.checkRefreshNeeded(null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$clearAll$2, reason: invalid class name */
    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "", "<anonymous>", "(Lak1;)Z"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository$clearAll$2", f = "ContinueWatchingRepository.kt", i = {0, 0, 1, 1}, l = {1245, 1247}, m = "invokeSuspend", n = {"$this$withContext", "allOk", "$this$withContext", "allOk"}, s = {"L$0", "L$1", "L$0", "L$1"})
    @vx8
    public static final class AnonymousClass2 extends SuspendLambda implements gr3<ak1, Continuation<? super Boolean>, Object> {
        final /* synthetic */ List<ContinueWatchingItem> $items;
        final /* synthetic */ long $perItemDelayMillis;
        long J$0;
        private /* synthetic */ Object L$0;
        Object L$1;
        Object L$2;
        Object L$3;
        int label;
        final /* synthetic */ ContinueWatchingRepository this$0;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        /* JADX WARN: Multi-variable type inference failed */
        public AnonymousClass2(List<? extends ContinueWatchingItem> list, long j, ContinueWatchingRepository continueWatchingRepository, Continuation<? super AnonymousClass2> continuation) {
            super(2, continuation);
            this.$items = list;
            this.$perItemDelayMillis = j;
            this.this$0 = continueWatchingRepository;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            AnonymousClass2 anonymousClass2 = new AnonymousClass2(this.$items, this.$perItemDelayMillis, this.this$0, continuation);
            anonymousClass2.L$0 = obj;
            return anonymousClass2;
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super Boolean> continuation) {
            return ((AnonymousClass2) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        /* JADX WARN: Removed duplicated region for block: B:17:0x0068  */
        /* JADX WARN: Removed duplicated region for block: B:28:0x00a0  */
        /* JADX WARN: Removed duplicated region for block: B:38:? A[PHI: r1 r4 r6 r7 r8
          PHI (r1v6 java.util.Iterator) = (r1v2 java.util.Iterator), (r1v4 java.util.Iterator), (r1v10 java.util.Iterator) binds: [B:14:0x0042, B:30:0x00b3, B:6:0x000c] A[DONT_GENERATE, DONT_INLINE]
          PHI (r4v7 long) = (r4v3 long), (r4v5 long), (r4v9 long) binds: [B:14:0x0042, B:30:0x00b3, B:6:0x000c] A[DONT_GENERATE, DONT_INLINE]
          PHI (r6v4 com.strmr.ps.data.repository.ContinueWatchingRepository) = 
          (r6v0 com.strmr.ps.data.repository.ContinueWatchingRepository)
          (r6v2 com.strmr.ps.data.repository.ContinueWatchingRepository)
          (r6v8 com.strmr.ps.data.repository.ContinueWatchingRepository)
         binds: [B:14:0x0042, B:30:0x00b3, B:6:0x000c] A[DONT_GENERATE, DONT_INLINE]
          PHI (r7v5 dw7$a) = (r7v1 dw7$a), (r7v3 dw7$a), (r7v9 dw7$a) binds: [B:14:0x0042, B:30:0x00b3, B:6:0x000c] A[DONT_GENERATE, DONT_INLINE]
          PHI (r8v5 ak1) = (r8v1 ak1), (r8v3 ak1), (r8v9 ak1) binds: [B:14:0x0042, B:30:0x00b3, B:6:0x000c] A[DONT_GENERATE, DONT_INLINE], SYNTHETIC] */
        /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:30:0x00b3 -> B:15:0x0062). Please report as a decompilation issue!!! */
        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            dw7.a aVar;
            Iterator it;
            long j;
            ContinueWatchingRepository continueWatchingRepository;
            ak1 ak1Var;
            Object objA;
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                ak1 ak1Var2 = (ak1) this.L$0;
                dw7.a aVar2 = new dw7.a();
                aVar2.a = true;
                List<ContinueWatchingItem> list = this.$items;
                long j2 = this.$perItemDelayMillis;
                ContinueWatchingRepository continueWatchingRepository2 = this.this$0;
                aVar = aVar2;
                it = list.iterator();
                j = j2;
                continueWatchingRepository = continueWatchingRepository2;
                ak1Var = ak1Var2;
            } else {
                if (i == 1) {
                    j = this.J$0;
                    it = (Iterator) this.L$3;
                    continueWatchingRepository = (ContinueWatchingRepository) this.L$2;
                    aVar = (dw7.a) this.L$1;
                    ak1Var = (ak1) this.L$0;
                    try {
                        s38.b(obj);
                    } catch (Throwable th) {
                        objA = s38.a(th);
                        if (q38.a(objA) != null) {
                        }
                        this.L$0 = ak1Var;
                        this.L$1 = aVar;
                        this.L$2 = continueWatchingRepository;
                        this.L$3 = it;
                        this.J$0 = j;
                        this.label = 2;
                        if (h32.a(j, this) != ck1Var) {
                        }
                        return ck1Var;
                    }
                    objA = Boxing.boxBoolean(((Boolean) obj).booleanValue());
                    if (q38.a(objA) != null) {
                        aVar.a = false;
                    }
                    this.L$0 = ak1Var;
                    this.L$1 = aVar;
                    this.L$2 = continueWatchingRepository;
                    this.L$3 = it;
                    this.J$0 = j;
                    this.label = 2;
                    if (h32.a(j, this) != ck1Var) {
                    }
                    return ck1Var;
                }
                if (i != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                j = this.J$0;
                it = (Iterator) this.L$3;
                continueWatchingRepository = (ContinueWatchingRepository) this.L$2;
                aVar = (dw7.a) this.L$1;
                ak1Var = (ak1) this.L$0;
                s38.b(obj);
            }
            while (it.hasNext()) {
                Long playbackId = ((ContinueWatchingItem) it.next()).getPlaybackId();
                if (playbackId != null) {
                    long jLongValue = playbackId.longValue();
                    this.L$0 = ak1Var;
                    this.L$1 = aVar;
                    this.L$2 = continueWatchingRepository;
                    this.L$3 = it;
                    this.J$0 = j;
                    this.label = 1;
                    obj = continueWatchingRepository.removePlayback(jLongValue, this);
                    if (obj == ck1Var) {
                        return ck1Var;
                    }
                    objA = Boxing.boxBoolean(((Boolean) obj).booleanValue());
                    if (q38.a(objA) != null) {
                    }
                    this.L$0 = ak1Var;
                    this.L$1 = aVar;
                    this.L$2 = continueWatchingRepository;
                    this.L$3 = it;
                    this.J$0 = j;
                    this.label = 2;
                    if (h32.a(j, this) != ck1Var) {
                        while (it.hasNext()) {
                        }
                    }
                    return ck1Var;
                }
            }
            return Boxing.boxBoolean(aVar.a);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$computeNextEpisode$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0, 0, 0, 0, 1, 2, 2, 2}, l = {977, 994, AnalyticsListener.EVENT_AUDIO_INPUT_FORMAT_CHANGED}, m = "computeNextEpisode", n = {"this", "showTmdbId", "currentSeason", "currentEpisode", "currentSeason", "showTmdbId", "currentSeason", "currentEpisode"}, s = {"L$0", "I$0", "I$1", "I$2", "I$0", "I$0", "I$1", "I$2"})
    public static final class C03011 extends ContinuationImpl {
        int I$0;
        int I$1;
        int I$2;
        Object L$0;
        int label;
        /* synthetic */ Object result;

        public C03011(Continuation<? super C03011> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.computeNextEpisode(0, 0, 0, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$enrichEpisode$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, l = {1369, 1408, 1445, 1479, 1493}, m = "enrichEpisode", n = {"this", "item", "showTitle", "showYear", "episodeTitle", "playbackId", "tmdbId", "season", "episodeNumber", "isRewatch", "this", "item", "showTitle", "showYear", "episodeTitle", "playbackId", "showDetails", "tmdbId", "season", "episodeNumber", "isRewatch", "this", "item", "showYear", "episodeTitle", "playbackId", "showDetails", "episodeDetails", "showBackdrop", "showPoster", "episodeStill", "resolvedTitle", "tmdbId", "season", "episodeNumber", "isRewatch", "this", "item", "showYear", "episodeTitle", "playbackId", "showDetails", "episodeDetails", "showBackdrop", "showPoster", "episodeStill", "resolvedTitle", "episodeIndicator", "today", CmcdData.STREAMING_FORMAT_SS, "tmdbId", "season", "episodeNumber", "isRewatch", "isShowEnded", "totalAiredEpisodes", "this", "item", "showYear", "episodeTitle", "playbackId", "showDetails", "episodeDetails", "showBackdrop", "showPoster", "episodeStill", "resolvedTitle", "episodeIndicator", "tmdbId", "season", "episodeNumber", "isRewatch", "totalAiredEpisodes"}, s = {"L$0", "L$1", "L$2", "L$3", "L$4", "L$5", "I$0", "I$1", "I$2", "I$3", "L$0", "L$1", "L$2", "L$3", "L$4", "L$5", "L$6", "I$0", "I$1", "I$2", "I$3", "L$0", "L$1", "L$2", "L$3", "L$4", "L$5", "L$6", "L$7", "L$8", "L$9", "L$10", "I$0", "I$1", "I$2", "I$3", "L$0", "L$1", "L$2", "L$3", "L$4", "L$5", "L$6", "L$7", "L$8", "L$9", "L$10", "L$11", "L$12", "L$14", "I$0", "I$1", "I$2", "I$3", "I$4", "I$5", "L$0", "L$1", "L$2", "L$3", "L$4", "L$5", "L$6", "L$7", "L$8", "L$9", "L$10", "L$11", "I$0", "I$1", "I$2", "I$3", "I$4"})
    public static final class C03021 extends ContinuationImpl {
        int I$0;
        int I$1;
        int I$2;
        int I$3;
        int I$4;
        int I$5;
        Object L$0;
        Object L$1;
        Object L$10;
        Object L$11;
        Object L$12;
        Object L$13;
        Object L$14;
        Object L$2;
        Object L$3;
        Object L$4;
        Object L$5;
        Object L$6;
        Object L$7;
        Object L$8;
        Object L$9;
        int label;
        /* synthetic */ Object result;

        public C03021(Continuation<? super C03021> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.enrichEpisode(null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$enrichMovie$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0, 0, 0}, l = {1291}, m = "enrichMovie", n = {"this", "item", "tmdbId"}, s = {"L$0", "L$1", "I$0"})
    public static final class C03031 extends ContinuationImpl {
        int I$0;
        Object L$0;
        Object L$1;
        int label;
        /* synthetic */ Object result;

        public C03031(Continuation<? super C03031> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.enrichMovie(null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$fetchSeasonDetails$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0, 0, 0}, l = {1038}, m = "fetchSeasonDetails", n = {"this", "cacheKey", "confirmedNotFound"}, s = {"L$0", "L$1", "L$2"})
    public static final class C03041 extends ContinuationImpl {
        Object L$0;
        Object L$1;
        Object L$2;
        int label;
        /* synthetic */ Object result;

        public C03041(Continuation<? super C03041> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.fetchSeasonDetails(0, 0, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$getDroppedShowTmdbIds$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0}, l = {168, 169}, m = "getDroppedShowTmdbIds", n = {"this"}, s = {"L$0"})
    public static final class C03051 extends ContinuationImpl {
        Object L$0;
        int label;
        /* synthetic */ Object result;

        public C03051(Continuation<? super C03051> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.getDroppedShowTmdbIds(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$hasAccount$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {}, l = {234}, m = "hasAccount", n = {}, s = {})
    public static final class C03061 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C03061(Continuation<? super C03061> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.hasAccount(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$hasRemoteContinueWatchingChanges$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0}, l = {274}, m = "hasRemoteContinueWatchingChanges", n = {"fingerprint"}, s = {"L$0"})
    public static final class C03071 extends ContinuationImpl {
        Object L$0;
        int label;
        /* synthetic */ Object result;

        public C03071(Continuation<? super C03071> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.hasRemoteContinueWatchingChanges(null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$load$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lak1;", "", "Lcom/strmr/ps/data/model/ContentItem;", "<anonymous>", "(Lak1;)Ljava/util/List;"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository$load$2", f = "ContinueWatchingRepository.kt", i = {0, 1}, l = {1660, 412}, m = "invokeSuspend", n = {"$this$withLock_u24default$iv", "$this$withLock_u24default$iv"}, s = {"L$0", "L$0"})
    @vx8
    public static final class C03082 extends SuspendLambda implements gr3<ak1, Continuation<? super List<? extends ContentItem>>, Object> {
        final /* synthetic */ boolean $forceRefresh;
        Object L$0;
        Object L$1;
        boolean Z$0;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C03082(boolean z, Continuation<? super C03082> continuation) {
            super(2, continuation);
            this.$forceRefresh = z;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return ContinueWatchingRepository.this.new C03082(this.$forceRefresh, continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super List<ContentItem>> continuation) {
            return ((C03082) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            mg6 mg6Var;
            ContinueWatchingRepository continueWatchingRepository;
            boolean z;
            mg6 mg6Var2;
            Throwable th;
            ck1 ck1Var = ck1.a;
            int i = this.label;
            try {
                if (i == 0) {
                    s38.b(obj);
                    mg6Var = ContinueWatchingRepository.this.loadMutex;
                    ContinueWatchingRepository continueWatchingRepository2 = ContinueWatchingRepository.this;
                    boolean z2 = this.$forceRefresh;
                    this.L$0 = mg6Var;
                    this.L$1 = continueWatchingRepository2;
                    this.Z$0 = z2;
                    this.label = 1;
                    if (mg6Var.a(this) != ck1Var) {
                        continueWatchingRepository = continueWatchingRepository2;
                        z = z2;
                    }
                    return ck1Var;
                }
                if (i != 1) {
                    if (i != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    mg6Var2 = (mg6) this.L$0;
                    try {
                        s38.b(obj);
                        List list = (List) obj;
                        mg6Var2.c(null);
                        return list;
                    } catch (Throwable th2) {
                        th = th2;
                        mg6Var2.c(null);
                        throw th;
                    }
                }
                z = this.Z$0;
                continueWatchingRepository = (ContinueWatchingRepository) this.L$1;
                mg6 mg6Var3 = (mg6) this.L$0;
                s38.b(obj);
                mg6Var = mg6Var3;
                this.L$0 = mg6Var;
                this.L$1 = null;
                this.label = 2;
                Object objLoadInternal = continueWatchingRepository.loadInternal(z, this);
                if (objLoadInternal != ck1Var) {
                    mg6Var2 = mg6Var;
                    obj = objLoadInternal;
                    List list2 = (List) obj;
                    mg6Var2.c(null);
                    return list2;
                }
                return ck1Var;
            } catch (Throwable th3) {
                mg6Var2 = mg6Var;
                th = th3;
                mg6Var2.c(null);
                throw th;
            }
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$loadFromCache$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lak1;", "", "Lcom/strmr/ps/data/model/ContentItem;", "<anonymous>", "(Lak1;)Ljava/util/List;"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository$loadFromCache$2", f = "ContinueWatchingRepository.kt", i = {}, l = {}, m = "invokeSuspend", n = {}, s = {})
    @vx8
    public static final class C03092 extends SuspendLambda implements gr3<ak1, Continuation<? super List<? extends ContentItem>>, Object> {
        int label;

        public C03092(Continuation<? super C03092> continuation) {
            super(2, continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return ContinueWatchingRepository.this.new C03092(continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super List<ContentItem>> continuation) {
            return ((C03092) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            ck1 ck1Var = ck1.a;
            if (this.label != 0) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(obj);
            List list = ContinueWatchingRepository.this.cachedItems;
            if (list != null) {
                return list;
            }
            List listLoadFromDiskCache = ContinueWatchingRepository.this.loadFromDiskCache();
            if (listLoadFromDiskCache == null || listLoadFromDiskCache.isEmpty()) {
                listLoadFromDiskCache = null;
            }
            if (listLoadFromDiskCache != null) {
                ContinueWatchingRepository.this.cachedItems = listLoadFromDiskCache;
                ContinueWatchingRepository.this.lastCacheTime = System.currentTimeMillis();
                listLoadFromDiskCache.size();
            }
            return listLoadFromDiskCache == null ? ik2.a : listLoadFromDiskCache;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$loadInternal$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8}, l = {432, 442, 449, 459, 474, 523, 536, 565, 572}, m = "loadInternal", n = {"this", "forceRefresh", "this", "authHeader", "forceRefresh", "this", "authHeader", "forceRefresh", "this", "authHeader", "forceRefresh", "episodeDataChanged", "this", "preActivities", "forceRefresh", "this", "preActivities", "items", "this", "preActivities", "items", "dedupedCount", "this", "enrichmentDropped", "this", "enrichmentDropped"}, s = {"L$0", "Z$0", "L$0", "L$1", "Z$0", "L$0", "L$1", "Z$0", "L$0", "L$1", "Z$0", "I$0", "L$0", "L$1", "Z$0", "L$0", "L$1", "L$2", "L$0", "L$1", "L$2", "I$0", "L$0", "I$0", "L$0", "I$0"})
    public static final class C03101 extends ContinuationImpl {
        int I$0;
        Object L$0;
        Object L$1;
        Object L$2;
        Object L$3;
        boolean Z$0;
        int label;
        /* synthetic */ Object result;

        public C03101(Continuation<? super C03101> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.loadInternal(false, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$loadInternal$4, reason: invalid class name */
    @Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0005\u001a&\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00030\u0002\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00030\u0002\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00040\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0005\u0010\u0006"}, d2 = {"Lak1;", "Lhx9;", "", "Lcom/strmr/ps/data/model/trakt/TraktPlaybackItem;", "Lcom/strmr/ps/data/local/dao/LastWatchedPerShow;", "<anonymous>", "(Lak1;)Lhx9;"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository$loadInternal$4", f = "ContinueWatchingRepository.kt", i = {0, 0, 1, 1}, l = {491, 492, 510}, m = "invokeSuspend", n = {"episodesResult", "dbDeferred", "dbDeferred", "moviesOutcome"}, s = {"L$0", "L$1", "L$0", "L$1"})
    @vx8
    public static final class AnonymousClass4 extends SuspendLambda implements gr3<ak1, Continuation<? super hx9<? extends List<? extends TraktPlaybackItem>, ? extends List<? extends TraktPlaybackItem>, ? extends List<? extends LastWatchedPerShow>>>, Object> {
        final /* synthetic */ String $authHeader;
        private /* synthetic */ Object L$0;
        Object L$1;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public AnonymousClass4(String str, Continuation<? super AnonymousClass4> continuation) {
            super(2, continuation);
            this.$authHeader = str;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            AnonymousClass4 anonymousClass4 = ContinueWatchingRepository.this.new AnonymousClass4(this.$authHeader, continuation);
            anonymousClass4.L$0 = obj;
            return anonymousClass4;
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super hx9<? extends List<TraktPlaybackItem>, ? extends List<TraktPlaybackItem>, ? extends List<LastWatchedPerShow>>> continuation) {
            return ((AnonymousClass4) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        /* JADX WARN: Removed duplicated region for block: B:32:0x00c3  */
        /* JADX WARN: Removed duplicated region for block: B:43:0x00f3  */
        /* JADX WARN: Removed duplicated region for block: B:46:0x00f8  */
        /* JADX WARN: Removed duplicated region for block: B:50:0x0106  */
        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            r22 r22Var;
            r22 r22Var2;
            Object obj2;
            r22 r22Var3;
            Object obj3;
            boolean z;
            Object objAb;
            Object obj4;
            List listAn;
            Iterator it;
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                ak1 ak1Var = (ak1) this.L$0;
                r22 r22VarA = wj0.a(ak1Var, null, new ContinueWatchingRepository$loadInternal$4$moviesResult$1(ContinueWatchingRepository.this, this.$authHeader, null), 3);
                r22 r22VarA2 = wj0.a(ak1Var, null, new ContinueWatchingRepository$loadInternal$4$episodesResult$1(ContinueWatchingRepository.this, this.$authHeader, null), 3);
                r22 r22VarA3 = wj0.a(ak1Var, null, new ContinueWatchingRepository$loadInternal$4$dbDeferred$1(ContinueWatchingRepository.this, null), 3);
                this.L$0 = r22VarA2;
                this.L$1 = r22VarA3;
                this.label = 1;
                Object objAb2 = r22VarA.ab(this);
                if (objAb2 != ck1Var) {
                    r22Var = r22VarA3;
                    obj = objAb2;
                    r22Var2 = r22VarA2;
                }
                return ck1Var;
            }
            if (i != 1) {
                if (i != 2) {
                    if (i != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    obj4 = this.L$1;
                    obj2 = this.L$0;
                    s38.b(obj);
                    return new hx9(obj2, obj4, obj);
                }
                obj2 = this.L$1;
                r22Var3 = (r22) this.L$0;
                s38.b(obj);
                obj3 = ((q38) obj).a;
                z = obj2 instanceof q38.b;
                if (z && (obj3 instanceof q38.b)) {
                    listAn = y41.an(new q38(obj2), new q38(obj3));
                    if ((listAn instanceof Collection) || !listAn.isEmpty()) {
                        it = listAn.iterator();
                        while (it.hasNext()) {
                            Throwable thA = q38.a(((q38) it.next()).a);
                            HttpException httpException = thA instanceof HttpException ? (HttpException) thA : null;
                            if (httpException != null && httpException.code() == 429) {
                                break;
                            }
                        }
                    }
                    ContinueWatchingRepository.this.traktErrorNotifier.a(TraktErrorNotifier.b.d, "Couldn't refresh continue watching from Trakt.");
                }
                ik2 ik2Var = ik2.a;
                if (z) {
                    obj2 = ik2Var;
                }
                if (obj3 instanceof q38.b) {
                    obj3 = ik2Var;
                }
                this.L$0 = obj2;
                this.L$1 = obj3;
                this.label = 3;
                objAb = r22Var3.ab(this);
                if (objAb != ck1Var) {
                    obj4 = obj3;
                    obj = objAb;
                    return new hx9(obj2, obj4, obj);
                }
                return ck1Var;
            }
            r22Var = (r22) this.L$1;
            r22Var2 = (r22) this.L$0;
            s38.b(obj);
            Object obj5 = ((q38) obj).a;
            this.L$0 = r22Var;
            this.L$1 = obj5;
            this.label = 2;
            Object objAb3 = r22Var2.ab(this);
            if (objAb3 != ck1Var) {
                r22 r22Var4 = r22Var;
                obj2 = obj5;
                obj = objAb3;
                r22Var3 = r22Var4;
                obj3 = ((q38) obj).a;
                z = obj2 instanceof q38.b;
                if (z) {
                    listAn = y41.an(new q38(obj2), new q38(obj3));
                    if (listAn instanceof Collection) {
                    }
                    it = listAn.iterator();
                    while (it.hasNext()) {
                    }
                    ContinueWatchingRepository.this.traktErrorNotifier.a(TraktErrorNotifier.b.d, "Couldn't refresh continue watching from Trakt.");
                }
                ik2 ik2Var2 = ik2.a;
                if (z) {
                }
                if (obj3 instanceof q38.b) {
                }
                this.L$0 = obj2;
                this.L$1 = obj3;
                this.label = 3;
                objAb = r22Var3.ab(this);
                if (objAb != ck1Var) {
                }
            }
            return ck1Var;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$loadPlaybackOnly$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lak1;", "", "Lcom/strmr/ps/data/model/ContentItem;", "<anonymous>", "(Lak1;)Ljava/util/List;"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository$loadPlaybackOnly$2", f = "ContinueWatchingRepository.kt", i = {}, l = {289, 292, 325}, m = "invokeSuspend", n = {}, s = {})
    @vx8
    public static final class C03112 extends SuspendLambda implements gr3<ak1, Continuation<? super List<? extends ContentItem>>, Object> {
        int label;

        /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$loadPlaybackOnly$2$1, reason: invalid class name */
        @Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0004\u001a\u001a\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00030\u0002\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00030\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0004\u0010\u0005"}, d2 = {"Lak1;", "Lq07;", "", "Lcom/strmr/ps/data/model/trakt/TraktPlaybackItem;", "<anonymous>", "(Lak1;)Lq07;"}, k = 3, mv = {2, 0, 0})
        @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository$loadPlaybackOnly$2$1", f = "ContinueWatchingRepository.kt", i = {0, 1}, l = {299, MaterialCardViewHelper.DEFAULT_FADE_ANIM_DURATION}, m = "invokeSuspend", n = {"e", "moviesOutcome"}, s = {"L$0", "L$0"})
        @vx8
        public static final class AnonymousClass1 extends SuspendLambda implements gr3<ak1, Continuation<? super q07<? extends List<? extends TraktPlaybackItem>, ? extends List<? extends TraktPlaybackItem>>>, Object> {
            final /* synthetic */ String $authHeader;
            private /* synthetic */ Object L$0;
            int label;
            final /* synthetic */ ContinueWatchingRepository this$0;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            public AnonymousClass1(ContinueWatchingRepository continueWatchingRepository, String str, Continuation<? super AnonymousClass1> continuation) {
                super(2, continuation);
                this.this$0 = continueWatchingRepository;
                this.$authHeader = str;
            }

            @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
            public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
                AnonymousClass1 anonymousClass1 = new AnonymousClass1(this.this$0, this.$authHeader, continuation);
                anonymousClass1.L$0 = obj;
                return anonymousClass1;
            }

            @Override // defpackage.gr3
            public final Object invoke(ak1 ak1Var, Continuation<? super q07<? extends List<TraktPlaybackItem>, ? extends List<TraktPlaybackItem>>> continuation) {
                return ((AnonymousClass1) create(ak1Var, continuation)).invokeSuspend(e6a.a);
            }

            /* JADX WARN: Removed duplicated region for block: B:27:0x0092  */
            /* JADX WARN: Removed duplicated region for block: B:30:0x009c  */
            /* JADX WARN: Removed duplicated region for block: B:41:0x00cc  */
            /* JADX WARN: Removed duplicated region for block: B:44:0x00d1  */
            @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
            /*
                Code decompiled incorrectly, please refer to instructions dump.
            */
            public final Object invokeSuspend(Object obj) {
                r22 r22Var;
                Object obj2;
                Object obj3;
                boolean z;
                List listAn;
                Iterator it;
                ck1 ck1Var = ck1.a;
                int i = this.label;
                if (i == 0) {
                    s38.b(obj);
                    ak1 ak1Var = (ak1) this.L$0;
                    r22 r22VarA = wj0.a(ak1Var, null, new ContinueWatchingRepository$loadPlaybackOnly$2$1$m$1(this.this$0, this.$authHeader, null), 3);
                    r22 r22VarA2 = wj0.a(ak1Var, null, new ContinueWatchingRepository$loadPlaybackOnly$2$1$e$1(this.this$0, this.$authHeader, null), 3);
                    this.L$0 = r22VarA2;
                    this.label = 1;
                    Object objAb = r22VarA.ab(this);
                    if (objAb != ck1Var) {
                        r22Var = r22VarA2;
                        obj = objAb;
                    }
                    return ck1Var;
                }
                if (i != 1) {
                    if (i != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    obj2 = this.L$0;
                    s38.b(obj);
                    obj3 = ((q38) obj).a;
                    z = obj2 instanceof q38.b;
                    if (z && (obj3 instanceof q38.b)) {
                        listAn = y41.an(new q38(obj2), new q38(obj3));
                        if ((listAn instanceof Collection) || !listAn.isEmpty()) {
                            it = listAn.iterator();
                            while (it.hasNext()) {
                                Throwable thA = q38.a(((q38) it.next()).a);
                                HttpException httpException = thA instanceof HttpException ? (HttpException) thA : null;
                                if (httpException != null && httpException.code() == 429) {
                                    break;
                                }
                            }
                            this.this$0.traktErrorNotifier.a(TraktErrorNotifier.b.d, "Couldn't refresh continue watching from Trakt.");
                        } else {
                            this.this$0.traktErrorNotifier.a(TraktErrorNotifier.b.d, "Couldn't refresh continue watching from Trakt.");
                        }
                    }
                    ik2 ik2Var = ik2.a;
                    if (z) {
                        obj2 = ik2Var;
                    }
                    if (obj3 instanceof q38.b) {
                        obj3 = ik2Var;
                    }
                    return new q07(obj2, obj3);
                }
                r22Var = (r22) this.L$0;
                s38.b(obj);
                Object obj4 = ((q38) obj).a;
                this.L$0 = obj4;
                this.label = 2;
                Object objAb2 = r22Var.ab(this);
                if (objAb2 != ck1Var) {
                    obj2 = obj4;
                    obj = objAb2;
                    obj3 = ((q38) obj).a;
                    z = obj2 instanceof q38.b;
                    if (z) {
                        listAn = y41.an(new q38(obj2), new q38(obj3));
                        if (listAn instanceof Collection) {
                            it = listAn.iterator();
                            while (it.hasNext()) {
                            }
                            this.this$0.traktErrorNotifier.a(TraktErrorNotifier.b.d, "Couldn't refresh continue watching from Trakt.");
                        }
                    }
                    ik2 ik2Var2 = ik2.a;
                    if (z) {
                    }
                    if (obj3 instanceof q38.b) {
                    }
                    return new q07(obj2, obj3);
                }
                return ck1Var;
            }
        }

        public C03112(Continuation<? super C03112> continuation) {
            super(2, continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return ContinueWatchingRepository.this.new C03112(continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super List<ContentItem>> continuation) {
            return ((C03112) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        /* JADX WARN: Code restructure failed: missing block: B:33:0x00c6, code lost:
        
            if (r7 != r0) goto L35;
         */
        /* JADX WARN: Removed duplicated region for block: B:29:0x009c  */
        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            Iterator it;
            ck1 ck1Var = ck1.a;
            int i = this.label;
            ik2 ik2Var = ik2.a;
            if (i == 0) {
                s38.b(obj);
                if (ContinueWatchingRepository.this.cachedItems != null || ContinueWatchingRepository.this.loadFromDiskCache() != null) {
                    return ik2Var;
                }
                TraktAccountRepository traktAccountRepository = ContinueWatchingRepository.this.accountRepository;
                this.label = 1;
                obj = traktAccountRepository.refreshTokenIfNeeded(this);
                if (obj != ck1Var) {
                }
                return ck1Var;
            }
            if (i == 1) {
                s38.b(obj);
            } else {
                if (i != 2) {
                    if (i != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    s38.b(obj);
                    return (List) obj;
                }
                s38.b(obj);
                q07 q07Var = (q07) obj;
                List list = (List) q07Var.a;
                List list2 = (List) q07Var.b;
                ArrayList arrayList = new ArrayList();
                arrayList.addAll(ContinueWatchingRepository.this.processMovies(list));
                ContinueWatchingRepository continueWatchingRepository = ContinueWatchingRepository.this;
                ArrayList arrayList2 = new ArrayList();
                it = list2.iterator();
                while (it.hasNext()) {
                    ContinueWatchingItem continueWatchingItemProcessPlaybackOnlyShow = continueWatchingRepository.processPlaybackOnlyShow((TraktPlaybackItem) it.next());
                    if (continueWatchingItemProcessPlaybackOnlyShow != null) {
                        arrayList2.add(continueWatchingItemProcessPlaybackOnlyShow);
                    }
                }
                arrayList.addAll(arrayList2);
                List listDedupeByShow = ContinueWatchingRepository.this.dedupeByShow(y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.ContinueWatchingRepository$loadPlaybackOnly$2$invokeSuspend$$inlined$sortedByDescending$1
                    /* JADX WARN: Multi-variable type inference failed */
                    @Override // java.util.Comparator
                    public final int compare(T t, T t2) {
                        return x71.b(Long.valueOf(((ContinueWatchingItem) t2).getLastWatchedAtMillis()), Long.valueOf(((ContinueWatchingItem) t).getLastWatchedAtMillis()));
                    }
                }, arrayList));
                ContinueWatchingRepository continueWatchingRepository2 = ContinueWatchingRepository.this;
                this.label = 3;
                obj = continueWatchingRepository2.parallelEnrich(listDedupeByShow, this);
            }
            TraktAccount traktAccount = (TraktAccount) obj;
            if (traktAccount == null) {
                return ik2Var;
            }
            AnonymousClass1 anonymousClass1 = new AnonymousClass1(ContinueWatchingRepository.this, ContinueWatchingRepository.this.accountRepository.buildAuthHeader(traktAccount.getAccessToken()), null);
            this.label = 2;
            obj = bk1.c(anonymousClass1, this);
            if (obj != ck1Var) {
                q07 q07Var2 = (q07) obj;
                List list3 = (List) q07Var2.a;
                List list22 = (List) q07Var2.b;
                ArrayList arrayList3 = new ArrayList();
                arrayList3.addAll(ContinueWatchingRepository.this.processMovies(list3));
                ContinueWatchingRepository continueWatchingRepository3 = ContinueWatchingRepository.this;
                ArrayList arrayList22 = new ArrayList();
                it = list22.iterator();
                while (it.hasNext()) {
                }
                arrayList3.addAll(arrayList22);
                List listDedupeByShow2 = ContinueWatchingRepository.this.dedupeByShow(y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.ContinueWatchingRepository$loadPlaybackOnly$2$invokeSuspend$$inlined$sortedByDescending$1
                    /* JADX WARN: Multi-variable type inference failed */
                    @Override // java.util.Comparator
                    public final int compare(T t, T t2) {
                        return x71.b(Long.valueOf(((ContinueWatchingItem) t2).getLastWatchedAtMillis()), Long.valueOf(((ContinueWatchingItem) t).getLastWatchedAtMillis()));
                    }
                }, arrayList3));
                ContinueWatchingRepository continueWatchingRepository22 = ContinueWatchingRepository.this;
                this.label = 3;
                obj = continueWatchingRepository22.parallelEnrich(listDedupeByShow2, this);
            }
            return ck1Var;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$parallelEnrich$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lak1;", "", "Lcom/strmr/ps/data/model/ContentItem;", "<anonymous>", "(Lak1;)Ljava/util/List;"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository$parallelEnrich$2", f = "ContinueWatchingRepository.kt", i = {}, l = {1269}, m = "invokeSuspend", n = {}, s = {})
    @vx8
    public static final class C03122 extends SuspendLambda implements gr3<ak1, Continuation<? super List<? extends ContentItem>>, Object> {
        final /* synthetic */ List<ContinueWatchingItem> $items;
        private /* synthetic */ Object L$0;
        int label;
        final /* synthetic */ ContinueWatchingRepository this$0;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        /* JADX WARN: Multi-variable type inference failed */
        public C03122(List<? extends ContinueWatchingItem> list, ContinueWatchingRepository continueWatchingRepository, Continuation<? super C03122> continuation) {
            super(2, continuation);
            this.$items = list;
            this.this$0 = continueWatchingRepository;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            C03122 c03122 = new C03122(this.$items, this.this$0, continuation);
            c03122.L$0 = obj;
            return c03122;
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super List<ContentItem>> continuation) {
            return ((C03122) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                ak1 ak1Var = (ak1) this.L$0;
                xf8 xf8VarA = dg8.a(6);
                List<ContinueWatchingItem> list = this.$items;
                ContinueWatchingRepository continueWatchingRepository = this.this$0;
                ArrayList arrayList = new ArrayList(y41.p(list, 10));
                Iterator<T> it = list.iterator();
                while (it.hasNext()) {
                    arrayList.add(wj0.a(ak1Var, null, new ContinueWatchingRepository$parallelEnrich$2$results$1$1(xf8VarA, continueWatchingRepository, (ContinueWatchingItem) it.next(), null), 3));
                }
                this.label = 1;
                obj = i50.a(arrayList, this);
                if (obj == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
            }
            List list2 = (List) obj;
            ArrayList arrayListX = y41.x(list2);
            int size = list2.size() - arrayListX.size();
            if (size > 0) {
                Log.w(ContinueWatchingRepository.TAG, n41.l("parallelEnrich: ", size, DomExceptionUtils.SEPARATOR, " items failed TMDB enrichment", list2.size()));
            }
            return arrayListX;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$processShowEntry$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}, l = {716, 717, 734, 739, 748, 805, 850, 863}, m = "processShowEntry", n = {"this", "lastWatched", "playbackItem", "showTmdbId", "this", "lastWatched", "playbackItem", "showTmdbId", "this", "playbackItem", "showTraktId", "showTitle", "showYear", "showTmdbId", "lastWatchedAtMillis", "lastSeason", "lastEpisodeNum", "this", "playbackItem", "showTraktId", "showTitle", "showYear", "frontier", "showTmdbId", "lastWatchedAtMillis", "lastSeason", "lastEpisodeNum", "this", "playbackItem", "showTraktId", "showTitle", "showYear", "frontier", "fNextDetails", "fAirDateMillis", "showTmdbId", "lastWatchedAtMillis", "lastSeason", "lastEpisodeNum", "fNextSeason", "fNextEpisode", "fHasAired", "this", "playbackItem", "showTraktId", "showTitle", "showYear", "showTmdbId", "lastWatchedAtMillis", "this", "playbackItem", "showTraktId", "showTitle", "showYear", "nextEpisodeDetails", "airDateMillis", "showTmdbId", "lastWatchedAtMillis", "nextSeason", "nextEpisodeNum", "showTraktId", "showTitle", "showYear", "nextEpisodeDetails", "airDateMillis", "inProgressEpisode", "showTmdbId", "lastWatchedAtMillis", "nextSeason", "nextEpisodeNum", "isNew"}, s = {"L$0", "L$1", "L$2", "I$0", "L$0", "L$1", "L$2", "I$0", "L$0", "L$1", "L$2", "L$3", "L$4", "I$0", "J$0", "I$1", "I$2", "L$0", "L$1", "L$2", "L$3", "L$4", "L$5", "I$0", "J$0", "I$1", "I$2", "L$0", "L$1", "L$2", "L$3", "L$4", "L$5", "L$6", "L$7", "I$0", "J$0", "I$1", "I$2", "I$3", "I$4", "I$5", "L$0", "L$1", "L$2", "L$3", "L$4", "I$0", "J$0", "L$0", "L$1", "L$2", "L$3", "L$4", "L$5", "L$6", "I$0", "J$0", "I$1", "I$2", "L$0", "L$1", "L$2", "L$3", "L$4", "L$5", "I$0", "J$0", "I$1", "I$2", "I$3"})
    public static final class C03131 extends ContinuationImpl {
        int I$0;
        int I$1;
        int I$2;
        int I$3;
        int I$4;
        int I$5;
        long J$0;
        Object L$0;
        Object L$1;
        Object L$2;
        Object L$3;
        Object L$4;
        Object L$5;
        Object L$6;
        Object L$7;
        int label;
        /* synthetic */ Object result;

        public C03131(Continuation<? super C03131> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.processShowEntry(0, null, null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$processShows$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010!\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lak1;", "", "Lcom/strmr/ps/data/model/continuewatching/ContinueWatchingItem;", "<anonymous>", "(Lak1;)Ljava/util/List;"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository$processShows$2", f = "ContinueWatchingRepository.kt", i = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2}, l = {640, 654, 666}, m = "invokeSuspend", n = {"$this$coroutineScope", "showToLastWatched", "showToPlayback", "results", "hiddenShowIds", "$this$coroutineScope", "showToLastWatched", "showToPlayback", "results", "excludedShowIds", "results"}, s = {"L$0", "L$1", "L$2", "L$3", "L$4", "L$0", "L$1", "L$2", "L$3", "L$4", "L$0"})
    @vx8
    public static final class C03142 extends SuspendLambda implements gr3<ak1, Continuation<? super List<ContinueWatchingItem>>, Object> {
        final /* synthetic */ List<LastWatchedPerShow> $lastWatchedPerShow;
        final /* synthetic */ List<TraktPlaybackItem> $playbackEpisodes;
        private /* synthetic */ Object L$0;
        Object L$1;
        Object L$2;
        Object L$3;
        Object L$4;
        int label;
        final /* synthetic */ ContinueWatchingRepository this$0;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C03142(List<LastWatchedPerShow> list, List<TraktPlaybackItem> list2, ContinueWatchingRepository continueWatchingRepository, Continuation<? super C03142> continuation) {
            super(2, continuation);
            this.$lastWatchedPerShow = list;
            this.$playbackEpisodes = list2;
            this.this$0 = continueWatchingRepository;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            C03142 c03142 = new C03142(this.$lastWatchedPerShow, this.$playbackEpisodes, this.this$0, continuation);
            c03142.L$0 = obj;
            return c03142;
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super List<ContinueWatchingItem>> continuation) {
            return ((C03142) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        /* JADX WARN: Removed duplicated region for block: B:100:0x02ec  */
        /* JADX WARN: Removed duplicated region for block: B:39:0x00ee  */
        /* JADX WARN: Removed duplicated region for block: B:85:0x0281  */
        /* JADX WARN: Removed duplicated region for block: B:96:0x02c0 A[LOOP:1: B:94:0x02ba->B:96:0x02c0, LOOP_END] */
        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            List arrayList;
            Object droppedShowTmdbIds;
            Map map;
            Map map2;
            ak1 ak1Var;
            Set set;
            Object next;
            boolean z;
            Integer season;
            TraktIds ids;
            Set setF;
            Map map3;
            Object objA;
            Iterator it;
            Object objA2;
            List list;
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                ak1 ak1Var2 = (ak1) this.L$0;
                List<LastWatchedPerShow> list2 = this.$lastWatchedPerShow;
                int iH = wo5.h(y41.p(list2, 10));
                if (iH < 16) {
                    iH = 16;
                }
                LinkedHashMap linkedHashMap = new LinkedHashMap(iH);
                for (Object obj2 : list2) {
                    linkedHashMap.put(Boxing.boxInt(((LastWatchedPerShow) obj2).getShowTmdbId()), obj2);
                }
                List<TraktPlaybackItem> list3 = this.$playbackEpisodes;
                ArrayList arrayList2 = new ArrayList();
                for (Object obj3 : list3) {
                    TraktPlaybackItem traktPlaybackItem = (TraktPlaybackItem) obj3;
                    if (cr4.b(traktPlaybackItem.getType(), PlaybackProgress.TYPE_EPISODE)) {
                        TraktShow show = traktPlaybackItem.getShow();
                        if (((show == null || (ids = show.getIds()) == null) ? null : ids.getTmdb()) != null) {
                            TraktEpisode episode = traktPlaybackItem.getEpisode();
                            if (((episode == null || (season = episode.getSeason()) == null) ? 0 : season.intValue()) > 0) {
                                z = true;
                            }
                        }
                    } else {
                        z = false;
                    }
                    if (z) {
                        arrayList2.add(obj3);
                    }
                }
                LinkedHashMap linkedHashMap2 = new LinkedHashMap();
                for (Object obj4 : arrayList2) {
                    TraktShow show2 = ((TraktPlaybackItem) obj4).getShow();
                    cr4.d(show2);
                    TraktIds ids2 = show2.getIds();
                    cr4.d(ids2);
                    Integer tmdb = ids2.getTmdb();
                    cr4.d(tmdb);
                    Integer numBoxInt = Boxing.boxInt(tmdb.intValue());
                    Object arrayList3 = linkedHashMap2.get(numBoxInt);
                    if (arrayList3 == null) {
                        arrayList3 = new ArrayList();
                        linkedHashMap2.put(numBoxInt, arrayList3);
                    }
                    ((List) arrayList3).add(obj4);
                }
                LinkedHashMap linkedHashMap3 = new LinkedHashMap(wo5.h(linkedHashMap2.size()));
                for (Map.Entry entry : linkedHashMap2.entrySet()) {
                    Object key = entry.getKey();
                    Iterator it2 = ((List) entry.getValue()).iterator();
                    if (it2.hasNext()) {
                        next = it2.next();
                        if (it2.hasNext()) {
                            long zonedMillisOrNow = ContinueWatchingModelsKt.toZonedMillisOrNow(((TraktPlaybackItem) next).getPausedAt());
                            do {
                                Object next2 = it2.next();
                                long zonedMillisOrNow2 = ContinueWatchingModelsKt.toZonedMillisOrNow(((TraktPlaybackItem) next2).getPausedAt());
                                if (zonedMillisOrNow < zonedMillisOrNow2) {
                                    next = next2;
                                    zonedMillisOrNow = zonedMillisOrNow2;
                                }
                            } while (it2.hasNext());
                        }
                    } else {
                        next = null;
                    }
                    cr4.d(next);
                    linkedHashMap3.put(key, (TraktPlaybackItem) next);
                }
                arrayList = new ArrayList();
                Set hiddenShowIds = this.this$0.getHiddenShowIds();
                ContinueWatchingRepository continueWatchingRepository = this.this$0;
                this.L$0 = ak1Var2;
                this.L$1 = linkedHashMap;
                this.L$2 = linkedHashMap3;
                this.L$3 = arrayList;
                this.L$4 = hiddenShowIds;
                this.label = 1;
                droppedShowTmdbIds = continueWatchingRepository.getDroppedShowTmdbIds(this);
                if (droppedShowTmdbIds != ck1Var) {
                    map = linkedHashMap3;
                    map2 = linkedHashMap;
                    ak1Var = ak1Var2;
                    set = hiddenShowIds;
                }
                return ck1Var;
            }
            if (i != 1) {
                if (i != 2) {
                    if (i != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    list = (List) this.L$0;
                    s38.b(obj);
                    objA2 = obj;
                    list.addAll(y41.x((Iterable) objA2));
                    return list;
                }
                setF = (Set) this.L$4;
                List list4 = (List) this.L$3;
                Map map4 = (Map) this.L$2;
                map2 = (Map) this.L$1;
                ak1Var = (ak1) this.L$0;
                s38.b(obj);
                map3 = map4;
                arrayList = list4;
                objA = obj;
                arrayList.addAll(y41.x((Iterable) objA));
                Set setKeySet = map2.keySet();
                Set setEntrySet = map3.entrySet();
                ArrayList arrayList4 = new ArrayList();
                for (Object obj5 : setEntrySet) {
                    int iIntValue = ((Number) ((Map.Entry) obj5).getKey()).intValue();
                    if ((setKeySet.contains(Boxing.boxInt(iIntValue)) || setF.contains(Boxing.boxInt(iIntValue))) ? false : true) {
                        arrayList4.add(obj5);
                    }
                }
                ContinueWatchingRepository continueWatchingRepository2 = this.this$0;
                ArrayList arrayList5 = new ArrayList();
                it = arrayList4.iterator();
                while (it.hasNext()) {
                    arrayList5.add(wj0.a(ak1Var, null, new ContinueWatchingRepository$processShows$2$playbackOnlyResults$2$1(continueWatchingRepository2, (TraktPlaybackItem) ((Map.Entry) it.next()).getValue(), null), 3));
                }
                this.L$0 = arrayList;
                this.L$1 = null;
                this.L$2 = null;
                this.L$3 = null;
                this.L$4 = null;
                this.label = 3;
                objA2 = i50.a(arrayList5, this);
                if (objA2 != ck1Var) {
                    list = arrayList;
                    list.addAll(y41.x((Iterable) objA2));
                    return list;
                }
                return ck1Var;
            }
            set = (Set) this.L$4;
            arrayList = (List) this.L$3;
            Map map5 = (Map) this.L$2;
            Map map6 = (Map) this.L$1;
            ak1 ak1Var3 = (ak1) this.L$0;
            s38.b(obj);
            droppedShowTmdbIds = obj;
            map = map5;
            map2 = map6;
            ak1Var = ak1Var3;
            setF = km8.f(set, (Set) droppedShowTmdbIds);
            Set setEntrySet2 = map2.entrySet();
            ArrayList<Map.Entry> arrayList6 = new ArrayList();
            for (Object obj6 : setEntrySet2) {
                if (!setF.contains(Boxing.boxInt(((Number) ((Map.Entry) obj6).getKey()).intValue()))) {
                    arrayList6.add(obj6);
                }
            }
            ContinueWatchingRepository continueWatchingRepository3 = this.this$0;
            ArrayList arrayList7 = new ArrayList();
            for (Map.Entry entry2 : arrayList6) {
                arrayList7.add(wj0.a(ak1Var, null, new ContinueWatchingRepository$processShows$2$historyResults$2$1(continueWatchingRepository3, ((Number) entry2.getKey()).intValue(), (LastWatchedPerShow) entry2.getValue(), map, null), 3));
            }
            map3 = map;
            this.L$0 = ak1Var;
            this.L$1 = map2;
            this.L$2 = map3;
            this.L$3 = arrayList;
            this.L$4 = setF;
            this.label = 2;
            objA = i50.a(arrayList7, this);
            if (objA != ck1Var) {
                arrayList.addAll(y41.x((Iterable) objA));
                Set setKeySet2 = map2.keySet();
                Set setEntrySet3 = map3.entrySet();
                ArrayList arrayList42 = new ArrayList();
                while (r9.hasNext()) {
                }
                ContinueWatchingRepository continueWatchingRepository22 = this.this$0;
                ArrayList arrayList52 = new ArrayList();
                it = arrayList42.iterator();
                while (it.hasNext()) {
                }
                this.L$0 = arrayList;
                this.L$1 = null;
                this.L$2 = null;
                this.L$3 = null;
                this.L$4 = null;
                this.label = 3;
                objA2 = i50.a(arrayList52, this);
                if (objA2 != ck1Var) {
                }
            }
            return ck1Var;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$removePlayback$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "", "<anonymous>", "(Lak1;)Z"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository$removePlayback$2", f = "ContinueWatchingRepository.kt", i = {}, l = {1229, 1231}, m = "invokeSuspend", n = {}, s = {})
    public static final class C03152 extends SuspendLambda implements gr3<ak1, Continuation<? super Boolean>, Object> {
        final /* synthetic */ long $playbackId;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C03152(long j, Continuation<? super C03152> continuation) {
            super(2, continuation);
            this.$playbackId = j;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return ContinueWatchingRepository.this.new C03152(this.$playbackId, continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super Boolean> continuation) {
            return ((C03152) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        /* JADX WARN: Code restructure failed: missing block: B:18:0x0054, code lost:
        
            if (r6 == r0) goto L19;
         */
        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                TraktAccountRepository traktAccountRepository = ContinueWatchingRepository.this.accountRepository;
                this.label = 1;
                obj = traktAccountRepository.refreshTokenIfNeeded(this);
                if (obj != ck1Var) {
                }
                return ck1Var;
            }
            if (i != 1) {
                if (i != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
                return Boxing.boxBoolean(((Response) obj).isSuccessful());
            }
            s38.b(obj);
            TraktAccount traktAccount = (TraktAccount) obj;
            if (traktAccount == null) {
                return Boxing.boxBoolean(false);
            }
            String strBuildAuthHeader = ContinueWatchingRepository.this.accountRepository.buildAuthHeader(traktAccount.getAccessToken());
            TraktApiService traktApiService = ContinueWatchingRepository.this.traktApiService;
            long j = this.$playbackId;
            this.label = 2;
            obj = traktApiService.removePlayback(strBuildAuthHeader, j, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$retryApiCall$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3}, l = {1614, 1623, 1636, 1645}, m = "retryApiCall", n = {"onNotFound", "block", "retries", "delayMs", "attempt", "onNotFound", "block", "retries", "delayMs", "onNotFound", "block", "retries", "delayMs", "onNotFound", "block", "retries", "delayMs"}, s = {"L$0", "L$1", "I$0", "J$0", "I$3", "L$0", "L$1", "I$0", "J$0", "L$0", "L$1", "I$0", "J$0", "L$0", "L$1", "I$0", "J$0"})
    public static final class C03161<T> extends ContinuationImpl {
        int I$0;
        int I$1;
        int I$2;
        int I$3;
        long J$0;
        Object L$0;
        Object L$1;
        int label;
        /* synthetic */ Object result;

        public C03161(Continuation<? super C03161> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.retryApiCall(0, 0L, null, null, this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.ContinueWatchingRepository$syncEpisodeWatchStatus$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.ContinueWatchingRepository", f = "ContinueWatchingRepository.kt", i = {0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4}, l = {1093, 1137, 1141, 1146, 1151, 1157}, m = "syncEpisodeWatchStatus", n = {"this", "this", "remoteShowIds", "allStatuses", "this", "remoteShowIds", "allStatuses", "removedShows", "this", "remoteShowIds", "allStatuses", "removedShows", "this", "remoteShowIds", "allStatuses", "removedShows"}, s = {"L$0", "L$0", "L$1", "L$2", "L$0", "L$1", "L$2", "L$3", "L$0", "L$1", "L$2", "L$3", "L$0", "L$1", "L$2", "L$3"})
    public static final class C03171 extends ContinuationImpl {
        Object L$0;
        Object L$1;
        Object L$2;
        Object L$3;
        Object L$4;
        int label;
        /* synthetic */ Object result;

        public C03171(Continuation<? super C03171> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return ContinueWatchingRepository.this.syncEpisodeWatchStatus(null, this);
        }
    }

    static {
        DateTimeFormatter dateTimeFormatterOfPattern = DateTimeFormatter.ofPattern("MMM d, yyyy", Locale.US);
        cr4.f(dateTimeFormatterOfPattern, "ofPattern(...)");
        EPISODE_AIR_DATE_FORMATTER = dateTimeFormatterOfPattern;
    }

    @Inject
    public ContinueWatchingRepository(@kp6 TraktApiService traktApiService, @kp6 TMDBApiService tMDBApiService, @kp6 TraktAccountRepository traktAccountRepository, @kp6 SyncMetadataRepository syncMetadataRepository, @kp6 EpisodeWatchStatusDao episodeWatchStatusDao, @kp6 TraktUserItemDao traktUserItemDao, @ApplicationContext @kp6 Context context, @kp6 Gson gson, @kp6 TraktErrorNotifier traktErrorNotifier, @kp6 TraktActivitiesCache traktActivitiesCache, @kp6 lj1 lj1Var) {
        cr4.g(traktApiService, "traktApiService");
        cr4.g(tMDBApiService, "tmdbApiService");
        cr4.g(traktAccountRepository, "accountRepository");
        cr4.g(syncMetadataRepository, "syncMetadataRepository");
        cr4.g(episodeWatchStatusDao, "episodeWatchStatusDao");
        cr4.g(traktUserItemDao, "traktUserItemDao");
        cr4.g(context, "context");
        cr4.g(gson, "gson");
        cr4.g(traktErrorNotifier, "traktErrorNotifier");
        cr4.g(traktActivitiesCache, "activitiesCache");
        cr4.g(lj1Var, "ioDispatcher");
        this.traktApiService = traktApiService;
        this.tmdbApiService = tMDBApiService;
        this.accountRepository = traktAccountRepository;
        this.syncMetadataRepository = syncMetadataRepository;
        this.episodeWatchStatusDao = episodeWatchStatusDao;
        this.traktUserItemDao = traktUserItemDao;
        this.context = context;
        this.gson = gson;
        this.traktErrorNotifier = traktErrorNotifier;
        this.activitiesCache = traktActivitiesCache;
        this.ioDispatcher = lj1Var;
        this.loadMutex = rg6.a();
        this.seasonDetailsCache = new ConcurrentHashMap<>();
        final int i = 0;
        this.seasonNotFoundCache = v65.a(new qq3(this) { // from class: dh1
            public final /* synthetic */ ContinueWatchingRepository b;

            {
                this.b = this;
            }

            @Override // defpackage.qq3
            public final Object invoke() {
                switch (i) {
                    case 0:
                        return this.b.loadSeasonNotFoundCache();
                    case 1:
                        return ContinueWatchingRepository.diskCacheFile_delegate$lambda$1(this.b);
                    case 2:
                        return ContinueWatchingRepository.hiddenShowsPrefs_delegate$lambda$2(this.b);
                    default:
                        return ContinueWatchingRepository.seasonNotFoundPrefs_delegate$lambda$3(this.b);
                }
            }
        });
        final int i2 = 1;
        this.diskCacheFile = v65.a(new qq3(this) { // from class: dh1
            public final /* synthetic */ ContinueWatchingRepository b;

            {
                this.b = this;
            }

            @Override // defpackage.qq3
            public final Object invoke() {
                switch (i2) {
                    case 0:
                        return this.b.loadSeasonNotFoundCache();
                    case 1:
                        return ContinueWatchingRepository.diskCacheFile_delegate$lambda$1(this.b);
                    case 2:
                        return ContinueWatchingRepository.hiddenShowsPrefs_delegate$lambda$2(this.b);
                    default:
                        return ContinueWatchingRepository.seasonNotFoundPrefs_delegate$lambda$3(this.b);
                }
            }
        });
        final int i3 = 2;
        this.hiddenShowsPrefs = v65.a(new qq3(this) { // from class: dh1
            public final /* synthetic */ ContinueWatchingRepository b;

            {
                this.b = this;
            }

            @Override // defpackage.qq3
            public final Object invoke() {
                switch (i3) {
                    case 0:
                        return this.b.loadSeasonNotFoundCache();
                    case 1:
                        return ContinueWatchingRepository.diskCacheFile_delegate$lambda$1(this.b);
                    case 2:
                        return ContinueWatchingRepository.hiddenShowsPrefs_delegate$lambda$2(this.b);
                    default:
                        return ContinueWatchingRepository.seasonNotFoundPrefs_delegate$lambda$3(this.b);
                }
            }
        });
        final int i4 = 3;
        this.seasonNotFoundPrefs = v65.a(new qq3(this) { // from class: dh1
            public final /* synthetic */ ContinueWatchingRepository b;

            {
                this.b = this;
            }

            @Override // defpackage.qq3
            public final Object invoke() {
                switch (i4) {
                    case 0:
                        return this.b.loadSeasonNotFoundCache();
                    case 1:
                        return ContinueWatchingRepository.diskCacheFile_delegate$lambda$1(this.b);
                    case 2:
                        return ContinueWatchingRepository.hiddenShowsPrefs_delegate$lambda$2(this.b);
                    default:
                        return ContinueWatchingRepository.seasonNotFoundPrefs_delegate$lambda$3(this.b);
                }
            }
        });
        this.seasonNotFoundTimestamps = new ConcurrentHashMap<>();
    }

    private final void addToSeasonNotFoundCache(String key) {
        getSeasonNotFoundCache().add(key);
        this.seasonNotFoundTimestamps.put(key, Long.valueOf(System.currentTimeMillis()));
    }

    private final String buildEpisodeLabel(ContinueWatchingItem item, TMDBEpisode episodeDetails) {
        hx9 hx9Var;
        String strH;
        String name;
        if (!(item instanceof ContinueWatchingItem.Episode)) {
            if (item instanceof ContinueWatchingItem.NextEpisode) {
                ContinueWatchingItem.NextEpisode nextEpisode = (ContinueWatchingItem.NextEpisode) item;
                hx9Var = new hx9(Integer.valueOf(nextEpisode.getSeason()), Integer.valueOf(nextEpisode.getEpisode()), nextEpisode.getEpisodeTitle());
            }
            return null;
        }
        ContinueWatchingItem.Episode episode = (ContinueWatchingItem.Episode) item;
        hx9Var = new hx9(Integer.valueOf(episode.getSeason()), Integer.valueOf(episode.getEpisode()), episode.getEpisodeTitle());
        int iIntValue = ((Number) hx9Var.a).intValue();
        int iIntValue2 = ((Number) hx9Var.b).intValue();
        String str = (String) hx9Var.c;
        Integer numValueOf = Integer.valueOf(iIntValue);
        if (iIntValue <= 0) {
            numValueOf = null;
        }
        if (numValueOf != null) {
            int iIntValue3 = numValueOf.intValue();
            Integer numValueOf2 = Integer.valueOf(iIntValue2);
            if (iIntValue2 <= 0) {
                numValueOf2 = null;
            }
            if (numValueOf2 != null) {
                int iIntValue4 = numValueOf2.intValue();
                String strAg = n89.ag(2, String.valueOf(iIntValue3));
                String strAg2 = n89.ag(2, String.valueOf(iIntValue4));
                if (episodeDetails != null && (name = episodeDetails.getName()) != null) {
                    str = name;
                }
                String episodeAirDate = formatEpisodeAirDate(episodeDetails != null ? episodeDetails.getAirDate() : null);
                if (str == null || n89.ab(str)) {
                    strH = fi7.h("S", strAg, "E", strAg2);
                } else {
                    StringBuilder sbM = fi7.m("S", strAg, "E", strAg2, " - ");
                    sbM.append(str);
                    strH = sbM.toString();
                }
                return episodeAirDate != null ? vw2.l(strH, " - ", episodeAirDate) : strH;
            }
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:31:0x0087  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0091  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object checkRefreshNeeded(String str, Continuation<? super q07<Boolean, TraktLastActivities>> continuation) {
        AnonymousClass1 anonymousClass1;
        ContinueWatchingRepository continueWatchingRepository;
        TraktLastActivities traktLastActivities;
        TraktLastActivities traktLastActivities2;
        String str2;
        if (continuation instanceof AnonymousClass1) {
            anonymousClass1 = (AnonymousClass1) continuation;
            int i = anonymousClass1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                anonymousClass1.label = i - Integer.MIN_VALUE;
            } else {
                anonymousClass1 = new AnonymousClass1(continuation);
            }
        }
        Object objIsStale = anonymousClass1.result;
        ck1 ck1Var = ck1.a;
        int i2 = anonymousClass1.label;
        boolean z = false;
        if (i2 == 0) {
            s38.b(objIsStale);
            SyncMetadataRepository syncMetadataRepository = this.syncMetadataRepository;
            anonymousClass1.L$0 = this;
            anonymousClass1.label = 1;
            objIsStale = syncMetadataRepository.isStale(SYNC_KEY_CONTINUE_WATCHING, anonymousClass1);
            if (objIsStale != ck1Var) {
                continueWatchingRepository = this;
            }
            return ck1Var;
        }
        if (i2 != 1) {
            if (i2 != 2) {
                if (i2 != 3) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                str2 = (String) anonymousClass1.L$1;
                traktLastActivities2 = (TraktLastActivities) anonymousClass1.L$0;
                s38.b(objIsStale);
                String str3 = (String) objIsStale;
                if (str2.length() > 0 && !str2.equals(str3)) {
                    z = true;
                }
                return new q07(Boxing.boxBoolean(z), traktLastActivities2);
            }
            continueWatchingRepository = (ContinueWatchingRepository) anonymousClass1.L$0;
            s38.b(objIsStale);
            traktLastActivities = (TraktLastActivities) objIsStale;
            if (traktLastActivities != null) {
                return new q07(Boxing.boxBoolean(false), null);
            }
            TraktActivityGroup movies = traktLastActivities.getMovies();
            String pausedAt = movies != null ? movies.getPausedAt() : null;
            TraktActivityGroup movies2 = traktLastActivities.getMovies();
            String watchedAt = movies2 != null ? movies2.getWatchedAt() : null;
            TraktActivityGroup episodes = traktLastActivities.getEpisodes();
            String pausedAt2 = episodes != null ? episodes.getPausedAt() : null;
            TraktActivityGroup episodes2 = traktLastActivities.getEpisodes();
            String strAi = y41.ai(st.w(new String[]{pausedAt, watchedAt, pausedAt2, episodes2 != null ? episodes2.getWatchedAt() : null}), "|", null, null, null, 62);
            SyncMetadataRepository syncMetadataRepository2 = continueWatchingRepository.syncMetadataRepository;
            anonymousClass1.L$0 = traktLastActivities;
            anonymousClass1.L$1 = strAi;
            anonymousClass1.label = 3;
            Object traktTimestamp = syncMetadataRepository2.getTraktTimestamp(SYNC_KEY_CONTINUE_WATCHING, anonymousClass1);
            if (traktTimestamp != ck1Var) {
                objIsStale = traktTimestamp;
                traktLastActivities2 = traktLastActivities;
                str2 = strAi;
                String str32 = (String) objIsStale;
                if (str2.length() > 0) {
                    z = true;
                }
                return new q07(Boxing.boxBoolean(z), traktLastActivities2);
            }
            return ck1Var;
        }
        continueWatchingRepository = (ContinueWatchingRepository) anonymousClass1.L$0;
        s38.b(objIsStale);
        if (((Boolean) objIsStale).booleanValue()) {
            return new q07(Boxing.boxBoolean(true), null);
        }
        TraktActivitiesCache traktActivitiesCache = continueWatchingRepository.activitiesCache;
        anonymousClass1.L$0 = continueWatchingRepository;
        anonymousClass1.label = 2;
        objIsStale = traktActivitiesCache.getActivities(anonymousClass1);
        if (objIsStale != ck1Var) {
            traktLastActivities = (TraktLastActivities) objIsStale;
            if (traktLastActivities != null) {
            }
        }
        return ck1Var;
    }

    public static /* synthetic */ Object clearAll$default(ContinueWatchingRepository continueWatchingRepository, List list, long j, Continuation continuation, int i, Object obj) {
        if ((i & 2) != 0) {
            j = 1050;
        }
        return continueWatchingRepository.clearAll(list, j, continuation);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:52:0x00e4  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x00e7  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x0102 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:67:0x011d  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x0139  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object computeNextEpisode(int i, int i2, int i3, Continuation<? super hx9<Integer, Integer, TMDBEpisode>> continuation) {
        C03011 c03011;
        ContinueWatchingRepository continueWatchingRepository;
        int i4;
        int i5;
        Object next;
        int i6;
        TMDBEpisode tMDBEpisode;
        List<TMDBEpisode> episodes;
        EpisodeWatchStatus episodeWatchStatus;
        if (continuation instanceof C03011) {
            c03011 = (C03011) continuation;
            int i7 = c03011.label;
            if ((i7 & Integer.MIN_VALUE) != 0) {
                c03011.label = i7 - Integer.MIN_VALUE;
            } else {
                c03011 = new C03011(continuation);
            }
        }
        Object objFetchSeasonDetails = c03011.result;
        ck1 ck1Var = ck1.a;
        int i8 = c03011.label;
        if (i8 == 0) {
            s38.b(objFetchSeasonDetails);
            c03011.L$0 = this;
            c03011.I$0 = i;
            c03011.I$1 = i2;
            c03011.I$2 = i3;
            c03011.label = 1;
            objFetchSeasonDetails = fetchSeasonDetails(i, i2, c03011);
            if (objFetchSeasonDetails != ck1Var) {
                continueWatchingRepository = this;
            }
            return ck1Var;
        }
        if (i8 != 1) {
            if (i8 == 2) {
                i6 = c03011.I$0;
                s38.b(objFetchSeasonDetails);
                TMDBSeasonDetails tMDBSeasonDetails = (TMDBSeasonDetails) objFetchSeasonDetails;
                tMDBEpisode = (tMDBSeasonDetails != null || (episodes = tMDBSeasonDetails.getEpisodes()) == null) ? null : (TMDBEpisode) y41.ab(y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.ContinueWatchingRepository$computeNextEpisode$$inlined$sortedBy$2
                    /* JADX WARN: Multi-variable type inference failed */
                    @Override // java.util.Comparator
                    public final int compare(T t, T t2) {
                        Integer episodeNumber = ((TMDBEpisode) t).getEpisodeNumber();
                        Integer numValueOf = Integer.valueOf(episodeNumber != null ? episodeNumber.intValue() : Integer.MAX_VALUE);
                        Integer episodeNumber2 = ((TMDBEpisode) t2).getEpisodeNumber();
                        return x71.b(numValueOf, Integer.valueOf(episodeNumber2 != null ? episodeNumber2.intValue() : Integer.MAX_VALUE));
                    }
                }, episodes));
                if (tMDBEpisode != null) {
                    return null;
                }
                Integer episodeNumber = tMDBEpisode.getEpisodeNumber();
                return new hx9(Boxing.boxInt(i6 + 1), Boxing.boxInt(episodeNumber != null ? episodeNumber.intValue() : 1), tMDBEpisode);
            }
            if (i8 != 3) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i5 = c03011.I$2;
            i2 = c03011.I$1;
            i4 = c03011.I$0;
            s38.b(objFetchSeasonDetails);
            episodeWatchStatus = (EpisodeWatchStatus) objFetchSeasonDetails;
            if (episodeWatchStatus == null) {
                episodeWatchStatus.getSeason();
                episodeWatchStatus.getEpisode();
                return new hx9(Boxing.boxInt(episodeWatchStatus.getSeason()), Boxing.boxInt(episodeWatchStatus.getEpisode()), null);
            }
            StringBuilder sbR = vw2.r("computeNextEpisode: TMDB + DB both unavailable for show ", i4, " S", "E", i2);
            sbR.append(i5);
            sbR.append(", using best-guess next episode");
            Log.w(TAG, sbR.toString());
            return new hx9(Boxing.boxInt(i2), Boxing.boxInt(i5 + 1), null);
        }
        i3 = c03011.I$2;
        i2 = c03011.I$1;
        i = c03011.I$0;
        continueWatchingRepository = (ContinueWatchingRepository) c03011.L$0;
        s38.b(objFetchSeasonDetails);
        TMDBSeasonDetails tMDBSeasonDetails2 = (TMDBSeasonDetails) objFetchSeasonDetails;
        if (tMDBSeasonDetails2 != null) {
            List<TMDBEpisode> episodes2 = tMDBSeasonDetails2.getEpisodes();
            Iterator it = (episodes2 != null ? y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.ContinueWatchingRepository$computeNextEpisode$$inlined$sortedBy$1
                /* JADX WARN: Multi-variable type inference failed */
                @Override // java.util.Comparator
                public final int compare(T t, T t2) {
                    Integer episodeNumber2 = ((TMDBEpisode) t).getEpisodeNumber();
                    Integer numValueOf = Integer.valueOf(episodeNumber2 != null ? episodeNumber2.intValue() : Integer.MAX_VALUE);
                    Integer episodeNumber3 = ((TMDBEpisode) t2).getEpisodeNumber();
                    return x71.b(numValueOf, Integer.valueOf(episodeNumber3 != null ? episodeNumber3.intValue() : Integer.MAX_VALUE));
                }
            }, episodes2) : ik2.a).iterator();
            while (true) {
                if (!it.hasNext()) {
                    next = null;
                    break;
                }
                next = it.next();
                Integer episodeNumber2 = ((TMDBEpisode) next).getEpisodeNumber();
                if ((episodeNumber2 != null ? episodeNumber2.intValue() : 0) == i3 + 1) {
                    break;
                }
            }
            TMDBEpisode tMDBEpisode2 = (TMDBEpisode) next;
            if (tMDBEpisode2 != null) {
                return new hx9(Boxing.boxInt(i2), Boxing.boxInt(i3 + 1), tMDBEpisode2);
            }
            c03011.L$0 = null;
            c03011.I$0 = i2;
            c03011.label = 2;
            objFetchSeasonDetails = continueWatchingRepository.fetchSeasonDetails(i, i2 + 1, c03011);
            if (objFetchSeasonDetails != ck1Var) {
                i6 = i2;
                TMDBSeasonDetails tMDBSeasonDetails3 = (TMDBSeasonDetails) objFetchSeasonDetails;
                if (tMDBSeasonDetails3 != null) {
                }
                if (tMDBEpisode != null) {
                }
            }
        } else {
            EpisodeWatchStatusDao episodeWatchStatusDao = continueWatchingRepository.episodeWatchStatusDao;
            c03011.L$0 = null;
            c03011.I$0 = i;
            c03011.I$1 = i2;
            c03011.I$2 = i3;
            c03011.label = 3;
            objFetchSeasonDetails = episodeWatchStatusDao.getNextEpisodeAfter(i, i2, i3, c03011);
            if (objFetchSeasonDetails != ck1Var) {
                int i9 = i3;
                i4 = i;
                i5 = i9;
                episodeWatchStatus = (EpisodeWatchStatus) objFetchSeasonDetails;
                if (episodeWatchStatus == null) {
                }
            }
        }
        return ck1Var;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final List<ContinueWatchingItem> dedupeByShow(List<? extends ContinueWatchingItem> items) {
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        LinkedHashSet linkedHashSet2 = new LinkedHashSet();
        ArrayList arrayList = new ArrayList();
        for (ContinueWatchingItem continueWatchingItem : items) {
            if (!(continueWatchingItem instanceof ContinueWatchingItem.Movie)) {
                Integer numValueOf = continueWatchingItem instanceof ContinueWatchingItem.Episode ? Integer.valueOf(((ContinueWatchingItem.Episode) continueWatchingItem).getShowTmdbId()) : continueWatchingItem instanceof ContinueWatchingItem.NextEpisode ? Integer.valueOf(((ContinueWatchingItem.NextEpisode) continueWatchingItem).getShowTmdbId()) : null;
                if (numValueOf != null && linkedHashSet.add(numValueOf)) {
                    arrayList.add(continueWatchingItem);
                }
            } else if (linkedHashSet2.add(Integer.valueOf(((ContinueWatchingItem.Movie) continueWatchingItem).getTmdbId()))) {
                arrayList.add(continueWatchingItem);
            }
        }
        return arrayList;
    }

    private final String detectMidSeasonIndicator(List<TMDBEpisode> seasonEpisodes, int episodeNumber) {
        String airDate;
        if (seasonEpisodes == null) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        for (Object obj : seasonEpisodes) {
            TMDBEpisode tMDBEpisode = (TMDBEpisode) obj;
            if (tMDBEpisode.getEpisodeNumber() != null && (airDate = tMDBEpisode.getAirDate()) != null && !n89.ab(airDate)) {
                arrayList.add(obj);
            }
        }
        List listBj = y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.ContinueWatchingRepository$detectMidSeasonIndicator$$inlined$sortedBy$1
            /* JADX WARN: Multi-variable type inference failed */
            @Override // java.util.Comparator
            public final int compare(T t, T t2) {
                return x71.b(((TMDBEpisode) t).getEpisodeNumber(), ((TMDBEpisode) t2).getEpisodeNumber());
            }
        }, arrayList);
        if (listBj.size() < 2) {
            return null;
        }
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        LinkedHashSet linkedHashSet2 = new LinkedHashSet();
        int size = listBj.size() - 1;
        for (int i = 0; i < size; i++) {
            try {
                String airDate2 = ((TMDBEpisode) listBj.get(i)).getAirDate();
                cr4.d(airDate2);
                LocalDate localDate = LocalDate.parse(airDate2);
                int i2 = i + 1;
                String airDate3 = ((TMDBEpisode) listBj.get(i2)).getAirDate();
                cr4.d(airDate3);
                if (ChronoUnit.DAYS.between(localDate, LocalDate.parse(airDate3)) >= 21) {
                    Integer episodeNumber2 = ((TMDBEpisode) listBj.get(i)).getEpisodeNumber();
                    cr4.d(episodeNumber2);
                    linkedHashSet2.add(episodeNumber2);
                    Integer episodeNumber3 = ((TMDBEpisode) listBj.get(i2)).getEpisodeNumber();
                    cr4.d(episodeNumber3);
                    linkedHashSet.add(episodeNumber3);
                }
            } catch (Exception unused) {
            }
        }
        if (linkedHashSet.contains(Integer.valueOf(episodeNumber))) {
            return "MID-SEASON PREMIERE";
        }
        if (linkedHashSet2.contains(Integer.valueOf(episodeNumber))) {
            return "MID-SEASON FINALE";
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final File diskCacheFile_delegate$lambda$1(ContinueWatchingRepository continueWatchingRepository) {
        return new File(continueWatchingRepository.context.getCacheDir(), DISK_CACHE_FILENAME);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Code restructure failed: missing block: B:124:0x04b5, code lost:
    
        if (defpackage.n89.l(r7, r12, true) == true) goto L125;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Path cross not found for [B:118:0x049c, B:121:0x04a7], limit reached: 372 */
    /* JADX WARN: Path cross not found for [B:125:0x04b7, B:134:0x04d8], limit reached: 372 */
    /* JADX WARN: Path cross not found for [B:134:0x04d8, B:125:0x04b7], limit reached: 372 */
    /* JADX WARN: Path cross not found for [B:157:0x0525, B:138:0x04e9], limit reached: 372 */
    /* JADX WARN: Path cross not found for [B:168:0x058d, B:184:0x05bf], limit reached: 372 */
    /* JADX WARN: Path cross not found for [B:220:0x065a, B:229:0x0672], limit reached: 372 */
    /* JADX WARN: Path cross not found for [B:229:0x0672, B:220:0x065a], limit reached: 372 */
    /* JADX WARN: Path cross not found for [B:359:0x04fe, B:153:0x051c], limit reached: 372 */
    /* JADX WARN: Path cross not found for [B:99:0x045d, B:103:0x046b], limit reached: 372 */
    /* JADX WARN: Removed duplicated region for block: B:105:0x046f  */
    /* JADX WARN: Removed duplicated region for block: B:106:0x0471  */
    /* JADX WARN: Removed duplicated region for block: B:109:0x0478  */
    /* JADX WARN: Removed duplicated region for block: B:115:0x048a  */
    /* JADX WARN: Removed duplicated region for block: B:123:0x04b1  */
    /* JADX WARN: Removed duplicated region for block: B:136:0x04de  */
    /* JADX WARN: Removed duplicated region for block: B:155:0x0520  */
    /* JADX WARN: Removed duplicated region for block: B:159:0x0529  */
    /* JADX WARN: Removed duplicated region for block: B:161:0x052e  */
    /* JADX WARN: Removed duplicated region for block: B:162:0x0531  */
    /* JADX WARN: Removed duplicated region for block: B:186:0x05c2  */
    /* JADX WARN: Removed duplicated region for block: B:187:0x05c7  */
    /* JADX WARN: Removed duplicated region for block: B:190:0x05d0  */
    /* JADX WARN: Removed duplicated region for block: B:192:0x05e4  */
    /* JADX WARN: Removed duplicated region for block: B:198:0x05fb  */
    /* JADX WARN: Removed duplicated region for block: B:211:0x0638  */
    /* JADX WARN: Removed duplicated region for block: B:214:0x0648  */
    /* JADX WARN: Removed duplicated region for block: B:218:0x0656  */
    /* JADX WARN: Removed duplicated region for block: B:220:0x065a  */
    /* JADX WARN: Removed duplicated region for block: B:233:0x069e  */
    /* JADX WARN: Removed duplicated region for block: B:256:0x0758  */
    /* JADX WARN: Removed duplicated region for block: B:257:0x075d  */
    /* JADX WARN: Removed duplicated region for block: B:259:0x0761  */
    /* JADX WARN: Removed duplicated region for block: B:288:0x07d9  */
    /* JADX WARN: Removed duplicated region for block: B:295:0x07f2  */
    /* JADX WARN: Removed duplicated region for block: B:300:0x085d  */
    /* JADX WARN: Removed duplicated region for block: B:303:0x0879  */
    /* JADX WARN: Removed duplicated region for block: B:306:0x0885  */
    /* JADX WARN: Removed duplicated region for block: B:307:0x088c  */
    /* JADX WARN: Removed duplicated region for block: B:310:0x08ac  */
    /* JADX WARN: Removed duplicated region for block: B:314:0x08b6  */
    /* JADX WARN: Removed duplicated region for block: B:315:0x08b8  */
    /* JADX WARN: Removed duplicated region for block: B:319:0x08cc  */
    /* JADX WARN: Removed duplicated region for block: B:321:0x08d4  */
    /* JADX WARN: Removed duplicated region for block: B:326:0x08eb  */
    /* JADX WARN: Removed duplicated region for block: B:332:0x08fb  */
    /* JADX WARN: Removed duplicated region for block: B:340:0x0916  */
    /* JADX WARN: Removed duplicated region for block: B:343:0x0932  */
    /* JADX WARN: Removed duplicated region for block: B:346:0x094b  */
    /* JADX WARN: Removed duplicated region for block: B:347:0x094e  */
    /* JADX WARN: Removed duplicated region for block: B:350:0x0956  */
    /* JADX WARN: Removed duplicated region for block: B:351:0x095d  */
    /* JADX WARN: Removed duplicated region for block: B:74:0x0317  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x001a  */
    /* JADX WARN: Removed duplicated region for block: B:93:0x0445  */
    /* JADX WARN: Removed duplicated region for block: B:95:0x044b  */
    /* JADX WARN: Removed duplicated region for block: B:96:0x0452  */
    /* JADX WARN: Type inference failed for: r18v0 */
    /* JADX WARN: Type inference failed for: r1v126 */
    /* JADX WARN: Type inference failed for: r1v4 */
    /* JADX WARN: Type inference failed for: r1v8, types: [int] */
    /* JADX WARN: Type inference failed for: r20v18 */
    /* JADX WARN: Type inference failed for: r20v21 */
    /* JADX WARN: Type inference failed for: r20v30 */
    /* JADX WARN: Type inference failed for: r23v12 */
    /* JADX WARN: Type inference failed for: r23v6 */
    /* JADX WARN: Type inference failed for: r23v9 */
    /* JADX WARN: Type inference failed for: r41v0 */
    /* JADX WARN: Type inference failed for: r41v1, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r41v2 */
    /* JADX WARN: Type inference failed for: r8v31 */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:253:0x0734 -> B:254:0x0754). Please report as a decompilation issue!!! */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object enrichEpisode(ContinueWatchingItem continueWatchingItem, Continuation<? super ContentItem> continuation) {
        C03021 c03021;
        int showTmdbId;
        int i;
        int season;
        int episode;
        CharSequence charSequence;
        ?? r1;
        CharSequence charSequence2;
        TMDBEpisode tMDBEpisode;
        int i2;
        Object objRetryApiCall$default;
        ContinueWatchingRepository continueWatchingRepository;
        ContinueWatchingItem continueWatchingItem2;
        int i3;
        Integer num;
        int i4;
        int i5;
        String str;
        String str2;
        Long l;
        boolean zIsRewatch;
        C03021 c030212;
        Integer num2;
        String str3;
        String str4;
        Object objRetryApiCall$default2;
        int i6;
        int i7;
        ContinueWatchingItem continueWatchingItem3;
        int i8;
        int i9;
        String str5;
        Long l2;
        TMDBShowDetails tMDBShowDetails;
        TMDBEpisode tMDBEpisode2;
        String str6;
        String preferredBackdropPath;
        String strConcat;
        String posterUrl;
        String str7;
        String str8;
        ck1 ck1Var;
        String str9;
        String status;
        String str10;
        CharSequence charSequence3;
        String str11;
        String status2;
        CharSequence charSequence4;
        CharSequence charSequence5;
        String status3;
        CharSequence charSequence6;
        int i10;
        String str12;
        Long l3;
        int i11;
        int i12;
        ck1 ck1Var2;
        String str13;
        Object obj;
        String str14;
        String str15;
        int i13;
        TMDBEpisode tMDBEpisode3;
        int i14;
        String str16;
        boolean z;
        int i15;
        String str17;
        Integer numberOfSeasons;
        String stillUrl;
        List<TMDBSeason> seasons;
        String str18;
        String str19;
        List list;
        String status4;
        boolean z2;
        boolean z3;
        boolean z4;
        String str20;
        Iterator it;
        ContinueWatchingItem continueWatchingItem4;
        TMDBEpisode tMDBEpisode4;
        ck1 ck1Var3;
        int i16;
        C03021 c030213;
        String str21;
        int i17;
        String str22;
        String str23;
        int i18;
        LocalDate localDate;
        ?? r23;
        int i19;
        int iIntValue;
        String overview;
        ContinueWatchingRepository continueWatchingRepository2;
        TMDBShowDetails tMDBShowDetails2;
        TMDBSeasonDetails tMDBSeasonDetails;
        TMDBEpisode tMDBEpisode5;
        List<TMDBEpisode> episodes;
        Object next;
        int i20;
        String str24;
        String str25;
        String str26;
        String str27;
        int i21;
        int i22;
        int i23;
        ContinueWatchingItem continueWatchingItem5;
        int iIntValue2;
        Long l4;
        int i24;
        String str28;
        Object obj2;
        ContinueWatchingItem continueWatchingItem6;
        int i25;
        TMDBEpisode tMDBEpisode6;
        String str29;
        int i26;
        String str30;
        String str31;
        String str32;
        String str33;
        int i27;
        LocalDate localDate2;
        int i28;
        LocalDate localDate3;
        String str34;
        int iIntValue3;
        int i29;
        LocalDate localDate4;
        String str35;
        LocalDate localDate5;
        int i30;
        String str36;
        String firstAirDate;
        String str37;
        String string;
        List<Integer> episodeRunTime;
        String str38;
        Integer num3;
        List<TMDBCast> cast;
        Integer runtime;
        String overview2;
        if (continuation instanceof C03021) {
            c03021 = (C03021) continuation;
            int i31 = c03021.label;
            if ((i31 & Integer.MIN_VALUE) != 0) {
                c03021.label = i31 - Integer.MIN_VALUE;
            } else {
                c03021 = new C03021(continuation);
            }
        }
        C03021 c030214 = c03021;
        Object obj3 = c030214.result;
        ck1 ck1Var4 = ck1.a;
        int i32 = c030214.label;
        if (i32 == 0) {
            s38.b(obj3);
            boolean z5 = continueWatchingItem instanceof ContinueWatchingItem.Episode;
            if (z5) {
                showTmdbId = ((ContinueWatchingItem.Episode) continueWatchingItem).getShowTmdbId();
            } else {
                if (!(continueWatchingItem instanceof ContinueWatchingItem.NextEpisode)) {
                    return null;
                }
                showTmdbId = ((ContinueWatchingItem.NextEpisode) continueWatchingItem).getShowTmdbId();
            }
            i = showTmdbId;
            if (z5) {
                season = ((ContinueWatchingItem.Episode) continueWatchingItem).getSeason();
            } else {
                if (!(continueWatchingItem instanceof ContinueWatchingItem.NextEpisode)) {
                    return null;
                }
                season = ((ContinueWatchingItem.NextEpisode) continueWatchingItem).getSeason();
            }
            if (z5) {
                episode = ((ContinueWatchingItem.Episode) continueWatchingItem).getEpisode();
            } else {
                if (!(continueWatchingItem instanceof ContinueWatchingItem.NextEpisode)) {
                    return null;
                }
                episode = ((ContinueWatchingItem.NextEpisode) continueWatchingItem).getEpisode();
            }
            String showTitle = z5 ? ((ContinueWatchingItem.Episode) continueWatchingItem).getShowTitle() : continueWatchingItem instanceof ContinueWatchingItem.NextEpisode ? ((ContinueWatchingItem.NextEpisode) continueWatchingItem).getShowTitle() : "";
            Integer showYear = z5 ? ((ContinueWatchingItem.Episode) continueWatchingItem).getShowYear() : continueWatchingItem instanceof ContinueWatchingItem.NextEpisode ? ((ContinueWatchingItem.NextEpisode) continueWatchingItem).getShowYear() : null;
            String episodeTitle = z5 ? ((ContinueWatchingItem.Episode) continueWatchingItem).getEpisodeTitle() : continueWatchingItem instanceof ContinueWatchingItem.NextEpisode ? ((ContinueWatchingItem.NextEpisode) continueWatchingItem).getEpisodeTitle() : null;
            Long playbackId = z5 ? ((ContinueWatchingItem.Episode) continueWatchingItem).getPlaybackId() : continueWatchingItem instanceof ContinueWatchingItem.NextEpisode ? ((ContinueWatchingItem.NextEpisode) continueWatchingItem).getPlaybackId() : null;
            if (z5) {
                zIsRewatch = ((ContinueWatchingItem.Episode) continueWatchingItem).isRewatch();
            } else {
                if (!(continueWatchingItem instanceof ContinueWatchingItem.NextEpisode)) {
                    charSequence = "Cancel";
                    r1 = 0;
                    charSequence2 = "Ended";
                    ContinueWatchingRepository$enrichEpisode$showDetails$1 continueWatchingRepository$enrichEpisode$showDetails$1 = new ContinueWatchingRepository$enrichEpisode$showDetails$1(this, i, null);
                    c030214.L$0 = this;
                    c030214.L$1 = continueWatchingItem;
                    c030214.L$2 = showTitle;
                    c030214.L$3 = showYear;
                    c030214.L$4 = episodeTitle;
                    c030214.L$5 = playbackId;
                    c030214.I$0 = i;
                    c030214.I$1 = season;
                    c030214.I$2 = episode;
                    c030214.I$3 = r1;
                    c030214.label = 1;
                    ?? r18 = r1;
                    int i33 = season;
                    int i34 = episode;
                    String str39 = showTitle;
                    String str40 = episodeTitle;
                    Long l5 = playbackId;
                    Integer num4 = showYear;
                    tMDBEpisode = null;
                    i2 = 2;
                    objRetryApiCall$default = retryApiCall$default(this, 0, 0L, null, continueWatchingRepository$enrichEpisode$showDetails$1, c030214, 7, null);
                    if (objRetryApiCall$default != ck1Var4) {
                        continueWatchingRepository = this;
                        continueWatchingItem2 = continueWatchingItem;
                        i3 = r18 == true ? 1 : 0;
                        num = num4;
                        i4 = i33;
                        i5 = i34;
                        str = str39;
                        str2 = str40;
                        l = l5;
                    }
                    return ck1Var4;
                }
                zIsRewatch = ((ContinueWatchingItem.NextEpisode) continueWatchingItem).isRewatch();
            }
            charSequence = "Cancel";
            r1 = zIsRewatch;
            charSequence2 = "Ended";
            ContinueWatchingRepository$enrichEpisode$showDetails$1 continueWatchingRepository$enrichEpisode$showDetails$12 = new ContinueWatchingRepository$enrichEpisode$showDetails$1(this, i, null);
            c030214.L$0 = this;
            c030214.L$1 = continueWatchingItem;
            c030214.L$2 = showTitle;
            c030214.L$3 = showYear;
            c030214.L$4 = episodeTitle;
            c030214.L$5 = playbackId;
            c030214.I$0 = i;
            c030214.I$1 = season;
            c030214.I$2 = episode;
            c030214.I$3 = r1;
            c030214.label = 1;
            ?? r182 = r1;
            int i332 = season;
            int i342 = episode;
            String str392 = showTitle;
            String str402 = episodeTitle;
            Long l52 = playbackId;
            Integer num42 = showYear;
            tMDBEpisode = null;
            i2 = 2;
            objRetryApiCall$default = retryApiCall$default(this, 0, 0L, null, continueWatchingRepository$enrichEpisode$showDetails$12, c030214, 7, null);
            if (objRetryApiCall$default != ck1Var4) {
            }
            return ck1Var4;
        }
        if (i32 == 1) {
            int i35 = c030214.I$3;
            int i36 = c030214.I$2;
            int i37 = c030214.I$1;
            int i38 = c030214.I$0;
            Long l6 = (Long) c030214.L$5;
            String str41 = (String) c030214.L$4;
            Integer num5 = (Integer) c030214.L$3;
            String str42 = (String) c030214.L$2;
            ContinueWatchingItem continueWatchingItem7 = (ContinueWatchingItem) c030214.L$1;
            ContinueWatchingRepository continueWatchingRepository3 = (ContinueWatchingRepository) c030214.L$0;
            s38.b(obj3);
            continueWatchingItem2 = continueWatchingItem7;
            l = l6;
            str2 = str41;
            num = num5;
            str = str42;
            i5 = i36;
            i = i38;
            i3 = i35;
            i4 = i37;
            charSequence2 = "Ended";
            i2 = 2;
            continueWatchingRepository = continueWatchingRepository3;
            objRetryApiCall$default = obj3;
            charSequence = "Cancel";
            tMDBEpisode = null;
        } else if (i32 == 2) {
            int i39 = c030214.I$3;
            int i40 = c030214.I$2;
            int i41 = c030214.I$1;
            int i42 = c030214.I$0;
            TMDBShowDetails tMDBShowDetails3 = (TMDBShowDetails) c030214.L$6;
            Long l7 = (Long) c030214.L$5;
            String str43 = (String) c030214.L$4;
            Integer num6 = (Integer) c030214.L$3;
            String str44 = (String) c030214.L$2;
            ContinueWatchingItem continueWatchingItem8 = (ContinueWatchingItem) c030214.L$1;
            ContinueWatchingRepository continueWatchingRepository4 = (ContinueWatchingRepository) c030214.L$0;
            s38.b(obj3);
            str4 = str44;
            str3 = " S";
            charSequence2 = "Ended";
            continueWatchingRepository = continueWatchingRepository4;
            i9 = i41;
            num2 = num6;
            objRetryApiCall$default2 = obj3;
            i8 = i42;
            str5 = str43;
            charSequence = "Cancel";
            continueWatchingItem3 = continueWatchingItem8;
            c030212 = c030214;
            l2 = l7;
            i7 = i40;
            tMDBShowDetails = tMDBShowDetails3;
            i6 = i39;
            tMDBEpisode2 = (TMDBEpisode) objRetryApiCall$default2;
            str6 = "E";
            preferredBackdropPath = TMDBImagesKt.getPreferredBackdropPath(tMDBShowDetails.getImages(), continueWatchingRepository.getImgLang());
            if (preferredBackdropPath == null) {
                preferredBackdropPath = tMDBShowDetails.getBackdropPath();
            }
            strConcat = preferredBackdropPath == null ? "https://image.tmdb.org/t/p/w1280".concat(preferredBackdropPath) : null;
            posterUrl = tMDBShowDetails.getPosterUrl(continueWatchingRepository.getImgLang());
            if (tMDBEpisode2 != null || (stillUrl = tMDBEpisode2.getStillUrl()) == null) {
                str7 = str3;
                str8 = strConcat != null ? posterUrl : strConcat;
            } else {
                str7 = str3;
                str8 = stillUrl;
            }
            if (n89.ab(str4)) {
                ck1Var = ck1Var4;
                str9 = str4;
            } else {
                String name = tMDBShowDetails.getName();
                ck1Var = ck1Var4;
                str9 = name != null ? name : "";
            }
            int i43 = i6;
            status = tMDBShowDetails.getStatus();
            str10 = str9;
            charSequence3 = charSequence2;
            str11 = str8;
            if (status == null && n89.l(status, charSequence3, true)) {
                charSequence4 = charSequence3;
                charSequence5 = charSequence;
            } else {
                status2 = tMDBShowDetails.getStatus();
                charSequence4 = charSequence3;
                charSequence5 = charSequence;
                if (status2 != null) {
                }
                status3 = tMDBShowDetails.getStatus();
                if (status3 != null) {
                    charSequence6 = charSequence5;
                    if (n89.l(status3, "Returning", true)) {
                        Integer numberOfSeasons2 = tMDBShowDetails.getNumberOfSeasons();
                        if ((numberOfSeasons2 != null ? numberOfSeasons2.intValue() : 0) == 1) {
                            String firstAirDate2 = tMDBShowDetails.getFirstAirDate();
                            if (firstAirDate2 != null) {
                                boolean z6 = ChronoUnit.DAYS.between(LocalDate.parse(firstAirDate2), LocalDate.now()) < 30;
                                z = z6;
                                if (z) {
                                    str16 = "NEW SERIES";
                                    str12 = str5;
                                    ck1Var2 = ck1Var;
                                    i15 = i43 == true ? 1 : 0;
                                    str17 = str10;
                                    LocalDate localDateNow = LocalDate.now();
                                    seasons = tMDBShowDetails.getSeasons();
                                    if (seasons != null) {
                                    }
                                    status4 = tMDBShowDetails.getStatus();
                                    List list2 = list;
                                    TMDBShowDetails tMDBShowDetails4 = tMDBShowDetails;
                                    if (status4 != null) {
                                    }
                                    if (!z3) {
                                    }
                                    z4 = z2;
                                    TMDBEpisode tMDBEpisode7 = tMDBEpisode2;
                                    str20 = str18;
                                    it = list2.iterator();
                                    continueWatchingItem4 = continueWatchingItem3;
                                    tMDBEpisode4 = tMDBEpisode7;
                                    ck1Var3 = ck1Var2;
                                    i16 = i8;
                                    c030213 = c030212;
                                    str21 = str11;
                                    i17 = i15;
                                    str22 = str17;
                                    str23 = str19;
                                    i18 = i7;
                                    localDate = localDateNow;
                                    r23 = z4;
                                    i19 = i9;
                                    iIntValue = 0;
                                    overview = str12;
                                    continueWatchingRepository2 = continueWatchingRepository;
                                    tMDBShowDetails2 = tMDBShowDetails4;
                                    while (it.hasNext()) {
                                    }
                                    int i44 = i19;
                                    int i45 = i16;
                                    ck1 ck1Var5 = ck1Var3;
                                    if (iIntValue > 0) {
                                    }
                                }
                            }
                            if (z) {
                            }
                        } else {
                            i10 = 1;
                            if (i7 != i10) {
                                str16 = "PREMIERE";
                                str12 = str5;
                                ck1Var2 = ck1Var;
                                i15 = i43 == true ? 1 : 0;
                                str17 = str10;
                                LocalDate localDateNow2 = LocalDate.now();
                                seasons = tMDBShowDetails.getSeasons();
                                if (seasons != null) {
                                }
                                status4 = tMDBShowDetails.getStatus();
                                List list22 = list;
                                TMDBShowDetails tMDBShowDetails42 = tMDBShowDetails;
                                if (status4 != null) {
                                }
                                if (!z3) {
                                }
                                z4 = z2;
                                TMDBEpisode tMDBEpisode72 = tMDBEpisode2;
                                str20 = str18;
                                it = list22.iterator();
                                continueWatchingItem4 = continueWatchingItem3;
                                tMDBEpisode4 = tMDBEpisode72;
                                ck1Var3 = ck1Var2;
                                i16 = i8;
                                c030213 = c030212;
                                str21 = str11;
                                i17 = i15;
                                str22 = str17;
                                str23 = str19;
                                i18 = i7;
                                localDate = localDateNow2;
                                r23 = z4;
                                i19 = i9;
                                iIntValue = 0;
                                overview = str12;
                                continueWatchingRepository2 = continueWatchingRepository;
                                tMDBShowDetails2 = tMDBShowDetails42;
                                while (it.hasNext()) {
                                }
                                int i442 = i19;
                                int i452 = i16;
                                ck1 ck1Var52 = ck1Var3;
                                if (iIntValue > 0) {
                                }
                            } else {
                                ContinueWatchingRepository$enrichEpisode$episodeIndicator$seasonDetails$1 continueWatchingRepository$enrichEpisode$episodeIndicator$seasonDetails$1 = new ContinueWatchingRepository$enrichEpisode$episodeIndicator$seasonDetails$1(continueWatchingRepository, i8, i9, null);
                                c030212.L$0 = continueWatchingRepository;
                                c030212.L$1 = continueWatchingItem3;
                                c030212.L$2 = num2;
                                c030212.L$3 = str5;
                                c030212.L$4 = l2;
                                c030212.L$5 = tMDBShowDetails;
                                c030212.L$6 = tMDBEpisode2;
                                c030212.L$7 = strConcat;
                                c030212.L$8 = posterUrl;
                                c030212.L$9 = str11;
                                c030212.L$10 = str10;
                                c030212.I$0 = i8;
                                c030212.I$1 = i9;
                                c030212.I$2 = i7;
                                c030212.I$3 = i43 == true ? 1 : 0;
                                c030212.label = 3;
                                str12 = str5;
                                l3 = l2;
                                i11 = i9;
                                int i46 = i8;
                                i12 = i7;
                                Object objRetryApiCall$default3 = retryApiCall$default(continueWatchingRepository, 0, 0L, null, continueWatchingRepository$enrichEpisode$episodeIndicator$seasonDetails$1, c030212, 7, null);
                                ck1Var2 = ck1Var;
                                if (objRetryApiCall$default3 == ck1Var2) {
                                    return ck1Var2;
                                }
                                str13 = strConcat;
                                obj = objRetryApiCall$default3;
                                str14 = str11;
                                str15 = posterUrl;
                                i13 = i43 == true ? 1 : 0;
                                tMDBEpisode3 = tMDBEpisode2;
                                i14 = i46;
                                tMDBSeasonDetails = (TMDBSeasonDetails) obj;
                                if (tMDBSeasonDetails != null) {
                                }
                                tMDBEpisode5 = null;
                                if (cr4.b(tMDBEpisode5 == null ? tMDBEpisode5.getEpisodeType() : null, "finale")) {
                                }
                                TMDBEpisode tMDBEpisode8 = tMDBEpisode3;
                                i8 = i14;
                                tMDBEpisode2 = tMDBEpisode8;
                                str11 = str14;
                                posterUrl = str15;
                                i15 = i13;
                                str17 = str10;
                                i9 = i11;
                                i7 = i12;
                                str16 = strDetectMidSeasonIndicator;
                                strConcat = str13;
                                l2 = l3;
                                LocalDate localDateNow22 = LocalDate.now();
                                seasons = tMDBShowDetails.getSeasons();
                                if (seasons != null) {
                                }
                                status4 = tMDBShowDetails.getStatus();
                                List list222 = list;
                                TMDBShowDetails tMDBShowDetails422 = tMDBShowDetails;
                                if (status4 != null) {
                                }
                                if (!z3) {
                                }
                                z4 = z2;
                                TMDBEpisode tMDBEpisode722 = tMDBEpisode2;
                                str20 = str18;
                                it = list222.iterator();
                                continueWatchingItem4 = continueWatchingItem3;
                                tMDBEpisode4 = tMDBEpisode722;
                                ck1Var3 = ck1Var2;
                                i16 = i8;
                                c030213 = c030212;
                                str21 = str11;
                                i17 = i15;
                                str22 = str17;
                                str23 = str19;
                                i18 = i7;
                                localDate = localDateNow22;
                                r23 = z4;
                                i19 = i9;
                                iIntValue = 0;
                                overview = str12;
                                continueWatchingRepository2 = continueWatchingRepository;
                                tMDBShowDetails2 = tMDBShowDetails422;
                                while (it.hasNext()) {
                                }
                                int i4422 = i19;
                                int i4522 = i16;
                                ck1 ck1Var522 = ck1Var3;
                                if (iIntValue > 0) {
                                }
                            }
                        }
                    }
                } else {
                    charSequence6 = charSequence5;
                }
                i10 = 1;
                if (i7 != i10) {
                }
            }
            if (tMDBShowDetails.getNumberOfSeasons() == null || (numberOfSeasons = tMDBShowDetails.getNumberOfSeasons()) == null || i9 != numberOfSeasons.intValue()) {
                status3 = tMDBShowDetails.getStatus();
                if (status3 != null) {
                }
                i10 = 1;
                if (i7 != i10) {
                }
            } else {
                str16 = "FINAL SEASON";
                str12 = str5;
                charSequence6 = charSequence5;
            }
            ck1Var2 = ck1Var;
            i15 = i43 == true ? 1 : 0;
            str17 = str10;
            LocalDate localDateNow222 = LocalDate.now();
            seasons = tMDBShowDetails.getSeasons();
            if (seasons != null) {
            }
            status4 = tMDBShowDetails.getStatus();
            List list2222 = list;
            TMDBShowDetails tMDBShowDetails4222 = tMDBShowDetails;
            if (status4 != null) {
            }
            if (!z3) {
            }
            z4 = z2;
            TMDBEpisode tMDBEpisode7222 = tMDBEpisode2;
            str20 = str18;
            it = list2222.iterator();
            continueWatchingItem4 = continueWatchingItem3;
            tMDBEpisode4 = tMDBEpisode7222;
            ck1Var3 = ck1Var2;
            i16 = i8;
            c030213 = c030212;
            str21 = str11;
            i17 = i15;
            str22 = str17;
            str23 = str19;
            i18 = i7;
            localDate = localDateNow222;
            r23 = z4;
            i19 = i9;
            iIntValue = 0;
            overview = str12;
            continueWatchingRepository2 = continueWatchingRepository;
            tMDBShowDetails2 = tMDBShowDetails4222;
            while (it.hasNext()) {
            }
            int i44222 = i19;
            int i45222 = i16;
            ck1 ck1Var5222 = ck1Var3;
            if (iIntValue > 0) {
            }
        } else {
            if (i32 != 3) {
                if (i32 != 4) {
                    if (i32 != 5) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    i26 = c030214.I$4;
                    int i47 = c030214.I$3;
                    i27 = c030214.I$2;
                    i23 = c030214.I$1;
                    i25 = c030214.I$0;
                    str33 = (String) c030214.L$11;
                    str30 = (String) c030214.L$10;
                    String str45 = (String) c030214.L$9;
                    str29 = (String) c030214.L$8;
                    str32 = (String) c030214.L$7;
                    tMDBEpisode6 = (TMDBEpisode) c030214.L$6;
                    TMDBShowDetails tMDBShowDetails5 = (TMDBShowDetails) c030214.L$5;
                    Long l8 = (Long) c030214.L$4;
                    String str46 = (String) c030214.L$3;
                    Integer num7 = (Integer) c030214.L$2;
                    ContinueWatchingItem continueWatchingItem9 = (ContinueWatchingItem) c030214.L$1;
                    ContinueWatchingRepository continueWatchingRepository5 = (ContinueWatchingRepository) c030214.L$0;
                    s38.b(obj3);
                    continueWatchingItem6 = continueWatchingItem9;
                    i17 = i47;
                    str7 = " S";
                    str6 = "E";
                    obj2 = obj3;
                    tMDBShowDetails2 = tMDBShowDetails5;
                    continueWatchingRepository2 = continueWatchingRepository5;
                    str31 = str45;
                    l2 = l8;
                    str28 = str46;
                    num2 = num7;
                    iIntValue2 = ((Number) obj2).intValue();
                    str27 = str29;
                    str26 = str32;
                    i20 = i25;
                    str24 = str33;
                    str22 = str30;
                    str25 = str31;
                    i22 = i27;
                    tMDBEpisode4 = tMDBEpisode6;
                    i21 = i26;
                    continueWatchingItem5 = continueWatchingItem6;
                    l4 = l2;
                    i24 = i17;
                    overview = str28;
                    i30 = i21 - iIntValue2;
                    if (i30 < 0) {
                        i30 = 0;
                    }
                    ContentItem.ItemType itemType = ContentItem.ItemType.TV_SHOW;
                    TMDBExternalIds externalIds = tMDBShowDetails2.getExternalIds();
                    String imdbId = externalIds != null ? externalIds.getImdbId() : null;
                    String str47 = str22 + str7 + i23 + str6 + i22;
                    if (tMDBEpisode4 == null || (overview2 = tMDBEpisode4.getOverview()) == null) {
                        if (overview == null) {
                            overview = tMDBShowDetails2.getOverview();
                        }
                        str36 = overview;
                    } else {
                        str36 = overview2;
                    }
                    String logoUrl = tMDBShowDetails2.getLogoUrl(continueWatchingRepository2.getImgLang());
                    firstAirDate = tMDBShowDetails2.getFirstAirDate();
                    if (firstAirDate != null) {
                        string = n89.bb(4, firstAirDate);
                    } else {
                        if (num2 == null) {
                            str37 = null;
                            Double voteAverage = tMDBShowDetails2.getVoteAverage();
                            Integer ratingPercentage = tMDBShowDetails2.getRatingPercentage();
                            String strBuildEpisodeLabel = continueWatchingRepository2.buildEpisodeLabel(continueWatchingItem5, tMDBEpisode4);
                            if (tMDBEpisode4 != null || (runtime = tMDBEpisode4.getRuntime()) == null || (string = runtime.toString()) == null) {
                                episodeRunTime = tMDBShowDetails2.getEpisodeRunTime();
                                if (episodeRunTime != null || (num3 = (Integer) y41.ab(episodeRunTime)) == null) {
                                    str38 = null;
                                } else {
                                    String string2 = num3.toString();
                                    str38 = string2;
                                }
                            } else {
                                str38 = string2;
                            }
                            TMDBCredits credits = tMDBShowDetails2.getCredits();
                            return new ContentItem(i20, itemType, i20, imdbId, str47, str36, str27, str26, logoUrl, str25, str37, voteAverage, ratingPercentage, strBuildEpisodeLabel, str38, (credits != null || (cast = credits.getCast()) == null) ? null : y41.ai(cast, ",", null, null, new me1(7), 30), tMDBShowDetails2.getCertification(), null, null, null, Boxing.boxDouble(continueWatchingItem5.getProgress()), l4, Boxing.boxInt(i23), Boxing.boxInt(i22), i24 == 0, str22, null, null, null, null, 0, null, tMDBShowDetails2.getStatus(), str24, i30 <= 0 ? Boxing.boxInt(i30) : null, null, null, null, null, null, null, null, null, -67108864, 2040, null);
                        }
                        string = num2.toString();
                    }
                    str37 = string;
                    Double voteAverage2 = tMDBShowDetails2.getVoteAverage();
                    Integer ratingPercentage2 = tMDBShowDetails2.getRatingPercentage();
                    String strBuildEpisodeLabel2 = continueWatchingRepository2.buildEpisodeLabel(continueWatchingItem5, tMDBEpisode4);
                    if (tMDBEpisode4 != null) {
                        episodeRunTime = tMDBShowDetails2.getEpisodeRunTime();
                        if (episodeRunTime != null) {
                        }
                        str38 = null;
                    }
                    TMDBCredits credits2 = tMDBShowDetails2.getCredits();
                    return new ContentItem(i20, itemType, i20, imdbId, str47, str36, str27, str26, logoUrl, str25, str37, voteAverage2, ratingPercentage2, strBuildEpisodeLabel2, str38, (credits2 != null || (cast = credits2.getCast()) == null) ? null : y41.ai(cast, ",", null, null, new me1(7), 30), tMDBShowDetails2.getCertification(), null, null, null, Boxing.boxDouble(continueWatchingItem5.getProgress()), l4, Boxing.boxInt(i23), Boxing.boxInt(i22), i24 == 0, str22, null, null, null, null, 0, null, tMDBShowDetails2.getStatus(), str24, i30 <= 0 ? Boxing.boxInt(i30) : null, null, null, null, null, null, null, null, null, -67108864, 2040, null);
                }
                int i48 = c030214.I$5;
                int i49 = c030214.I$4;
                int i50 = c030214.I$3;
                int i51 = c030214.I$2;
                int i52 = c030214.I$1;
                int i53 = c030214.I$0;
                TMDBSeason tMDBSeason = (TMDBSeason) c030214.L$14;
                Iterator it2 = (Iterator) c030214.L$13;
                LocalDate localDate6 = (LocalDate) c030214.L$12;
                String str48 = (String) c030214.L$11;
                String str49 = (String) c030214.L$10;
                int i54 = i48;
                String str50 = (String) c030214.L$9;
                String str51 = (String) c030214.L$8;
                String str52 = (String) c030214.L$7;
                TMDBEpisode tMDBEpisode9 = (TMDBEpisode) c030214.L$6;
                TMDBShowDetails tMDBShowDetails6 = (TMDBShowDetails) c030214.L$5;
                Long l9 = (Long) c030214.L$4;
                String str53 = (String) c030214.L$3;
                Integer num8 = (Integer) c030214.L$2;
                ContinueWatchingItem continueWatchingItem10 = (ContinueWatchingItem) c030214.L$1;
                ContinueWatchingRepository continueWatchingRepository6 = (ContinueWatchingRepository) c030214.L$0;
                s38.b(obj3);
                int i55 = i50;
                tMDBShowDetails2 = tMDBShowDetails6;
                int i56 = i51;
                str20 = str48;
                C03021 c030215 = c030214;
                l2 = l9;
                str7 = " S";
                str6 = "E";
                posterUrl = str51;
                overview = str53;
                TMDBSeason tMDBSeason2 = tMDBSeason;
                ck1 ck1Var6 = ck1Var4;
                ContinueWatchingRepository continueWatchingRepository7 = continueWatchingRepository6;
                Object obj4 = obj3;
                ?? r20 = i49;
                i19 = i52;
                i16 = i53;
                str22 = str49;
                String str54 = str50;
                TMDBSeasonDetails tMDBSeasonDetails2 = (TMDBSeasonDetails) obj4;
                if ((tMDBSeasonDetails2 == null ? tMDBSeasonDetails2.getEpisodes() : null) == null) {
                    List<TMDBEpisode> episodes2 = tMDBSeasonDetails2.getEpisodes();
                    if ((episodes2 instanceof Collection) && episodes2.isEmpty()) {
                        i29 = 0;
                    } else {
                        Iterator it3 = episodes2.iterator();
                        i29 = 0;
                        while (it3.hasNext()) {
                            String airDate = ((TMDBEpisode) it3.next()).getAirDate();
                            if (airDate != null) {
                                try {
                                    localDate4 = LocalDate.parse(airDate);
                                } catch (Exception unused) {
                                    localDate4 = null;
                                }
                                str35 = overview;
                                localDate5 = localDate4;
                            } else {
                                str35 = overview;
                                localDate5 = null;
                            }
                            if (((localDate5 == null || localDate5.isAfter(localDate6)) ? false : true) && (i29 = i29 + 1) < 0) {
                                y41.bl();
                                throw null;
                            }
                            overview = str35;
                        }
                    }
                    str34 = overview;
                    iIntValue3 = i54 + i29;
                } else {
                    str34 = overview;
                    Integer episodeCount = tMDBSeason2.getEpisodeCount();
                    iIntValue3 = i54 + (episodeCount != null ? episodeCount.intValue() : 0);
                }
                ck1Var3 = ck1Var6;
                continueWatchingRepository2 = continueWatchingRepository7;
                localDate = localDate6;
                str23 = str52;
                tMDBEpisode4 = tMDBEpisode9;
                i17 = i55;
                i18 = i56;
                continueWatchingItem4 = continueWatchingItem10;
                r23 = r20;
                iIntValue = iIntValue3;
                overview = str34;
                it = it2;
                str21 = str54;
                c030213 = c030215;
                num2 = num8;
                while (it.hasNext()) {
                    int i57 = i19;
                    TMDBSeason tMDBSeason3 = (TMDBSeason) it.next();
                    String airDate2 = tMDBSeason3.getAirDate();
                    if (airDate2 != null) {
                        try {
                        } catch (Exception unused2) {
                            localDate2 = null;
                        }
                        localDate2 = LocalDate.parse(airDate2);
                        LocalDate localDate7 = localDate2;
                        i28 = i16;
                        localDate3 = localDate7;
                    } else {
                        i28 = i16;
                        localDate3 = null;
                    }
                    if (localDate3 == null || !localDate3.isAfter(localDate)) {
                        if (r23 != 0) {
                            Integer episodeCount2 = tMDBSeason3.getEpisodeCount();
                            iIntValue += episodeCount2 != null ? episodeCount2.intValue() : 0;
                        } else {
                            Integer seasonNumber = tMDBSeason3.getSeasonNumber();
                            cr4.d(seasonNumber);
                            int iIntValue4 = seasonNumber.intValue();
                            c030213.L$0 = continueWatchingRepository2;
                            c030213.L$1 = continueWatchingItem4;
                            c030213.L$2 = num2;
                            c030213.L$3 = overview;
                            c030213.L$4 = l2;
                            c030213.L$5 = tMDBShowDetails2;
                            c030213.L$6 = tMDBEpisode4;
                            c030213.L$7 = str23;
                            c030213.L$8 = posterUrl;
                            c030213.L$9 = str21;
                            c030213.L$10 = str22;
                            c030213.L$11 = str20;
                            c030213.L$12 = localDate;
                            LocalDate localDate8 = localDate;
                            Iterator it4 = it;
                            c030213.L$13 = it4;
                            c030213.L$14 = tMDBSeason3;
                            int i58 = i28;
                            c030213.I$0 = i58;
                            c030213.I$1 = i57;
                            c030213.I$2 = i18;
                            c030213.I$3 = i17 == true ? 1 : 0 ? 1 : 0;
                            c030213.I$4 = r23 == true ? 1 : 0;
                            c030213.I$5 = iIntValue;
                            c030213.label = 4;
                            Object objFetchSeasonDetails = continueWatchingRepository2.fetchSeasonDetails(i58, iIntValue4, c030213);
                            ck1Var6 = ck1Var3;
                            if (objFetchSeasonDetails == ck1Var6) {
                                return ck1Var6;
                            }
                            C03021 c030216 = c030213;
                            str54 = str21;
                            it2 = it4;
                            i56 = i18;
                            i55 = i17 == true ? 1 : 0;
                            tMDBEpisode9 = tMDBEpisode4;
                            localDate6 = localDate8;
                            num8 = num2;
                            c030215 = c030216;
                            continueWatchingItem10 = continueWatchingItem4;
                            obj4 = objFetchSeasonDetails;
                            i54 = iIntValue;
                            r20 = r23;
                            i16 = i58;
                            str52 = str23;
                            i19 = i57;
                            continueWatchingRepository7 = continueWatchingRepository2;
                            tMDBSeason2 = tMDBSeason3;
                            TMDBSeasonDetails tMDBSeasonDetails22 = (TMDBSeasonDetails) obj4;
                            if ((tMDBSeasonDetails22 == null ? tMDBSeasonDetails22.getEpisodes() : null) == null) {
                            }
                            ck1Var3 = ck1Var6;
                            continueWatchingRepository2 = continueWatchingRepository7;
                            localDate = localDate6;
                            str23 = str52;
                            tMDBEpisode4 = tMDBEpisode9;
                            i17 = i55;
                            i18 = i56;
                            continueWatchingItem4 = continueWatchingItem10;
                            r23 = r20;
                            iIntValue = iIntValue3;
                            overview = str34;
                            it = it2;
                            str21 = str54;
                            c030213 = c030215;
                            num2 = num8;
                            while (it.hasNext()) {
                            }
                        }
                    }
                    i16 = i28;
                    i19 = i57;
                }
                int i442222 = i19;
                int i452222 = i16;
                ck1 ck1Var52222 = ck1Var3;
                if (iIntValue > 0) {
                    i20 = i452222;
                    str24 = str20;
                    str25 = str21;
                    str26 = str23;
                    str27 = posterUrl;
                    i21 = iIntValue;
                    i22 = i18;
                    i23 = i442222;
                    continueWatchingItem5 = continueWatchingItem4;
                    iIntValue2 = 0;
                    l4 = l2;
                    i24 = i17 == true ? 1 : 0;
                    i30 = i21 - iIntValue2;
                    if (i30 < 0) {
                    }
                    ContentItem.ItemType itemType2 = ContentItem.ItemType.TV_SHOW;
                    TMDBExternalIds externalIds2 = tMDBShowDetails2.getExternalIds();
                    if (externalIds2 != null) {
                    }
                    String str472 = str22 + str7 + i23 + str6 + i22;
                    if (tMDBEpisode4 == null) {
                    }
                    String logoUrl2 = tMDBShowDetails2.getLogoUrl(continueWatchingRepository2.getImgLang());
                    firstAirDate = tMDBShowDetails2.getFirstAirDate();
                    if (firstAirDate != null) {
                    }
                    str37 = string;
                    Double voteAverage22 = tMDBShowDetails2.getVoteAverage();
                    Integer ratingPercentage22 = tMDBShowDetails2.getRatingPercentage();
                    String strBuildEpisodeLabel22 = continueWatchingRepository2.buildEpisodeLabel(continueWatchingItem5, tMDBEpisode4);
                    if (tMDBEpisode4 != null) {
                    }
                    TMDBCredits credits22 = tMDBShowDetails2.getCredits();
                    return new ContentItem(i20, itemType2, i20, imdbId, str472, str36, str27, str26, logoUrl2, str25, str37, voteAverage22, ratingPercentage22, strBuildEpisodeLabel22, str38, (credits22 != null || (cast = credits22.getCast()) == null) ? null : y41.ai(cast, ",", null, null, new me1(7), 30), tMDBShowDetails2.getCertification(), null, null, null, Boxing.boxDouble(continueWatchingItem5.getProgress()), l4, Boxing.boxInt(i23), Boxing.boxInt(i22), i24 == 0, str22, null, null, null, null, 0, null, tMDBShowDetails2.getStatus(), str24, i30 <= 0 ? Boxing.boxInt(i30) : null, null, null, null, null, null, null, null, null, -67108864, 2040, null);
                }
                EpisodeWatchStatusDao episodeWatchStatusDao = continueWatchingRepository2.episodeWatchStatusDao;
                c030213.L$0 = continueWatchingRepository2;
                c030213.L$1 = continueWatchingItem4;
                c030213.L$2 = num2;
                c030213.L$3 = overview;
                c030213.L$4 = l2;
                c030213.L$5 = tMDBShowDetails2;
                c030213.L$6 = tMDBEpisode4;
                c030213.L$7 = str23;
                c030213.L$8 = posterUrl;
                c030213.L$9 = str21;
                c030213.L$10 = str22;
                c030213.L$11 = str20;
                str28 = overview;
                c030213.L$12 = null;
                c030213.L$13 = null;
                c030213.L$14 = null;
                c030213.I$0 = i452222;
                c030213.I$1 = i442222;
                c030213.I$2 = i18;
                c030213.I$3 = i17 == true ? 1 : 0 ? 1 : 0;
                c030213.I$4 = iIntValue;
                c030213.label = 5;
                Object watchedEpisodeCount = episodeWatchStatusDao.getWatchedEpisodeCount(i452222, c030213);
                if (watchedEpisodeCount == ck1Var52222) {
                    return ck1Var52222;
                }
                ContinueWatchingItem continueWatchingItem11 = continueWatchingItem4;
                obj2 = watchedEpisodeCount;
                continueWatchingItem6 = continueWatchingItem11;
                i25 = i452222;
                tMDBEpisode6 = tMDBEpisode4;
                str29 = posterUrl;
                i26 = iIntValue;
                str30 = str22;
                str31 = str21;
                str32 = str23;
                i23 = i442222;
                str33 = str20;
                i27 = i18;
                iIntValue2 = ((Number) obj2).intValue();
                str27 = str29;
                str26 = str32;
                i20 = i25;
                str24 = str33;
                str22 = str30;
                str25 = str31;
                i22 = i27;
                tMDBEpisode4 = tMDBEpisode6;
                i21 = i26;
                continueWatchingItem5 = continueWatchingItem6;
                l4 = l2;
                i24 = i17;
                overview = str28;
                i30 = i21 - iIntValue2;
                if (i30 < 0) {
                }
                ContentItem.ItemType itemType22 = ContentItem.ItemType.TV_SHOW;
                TMDBExternalIds externalIds22 = tMDBShowDetails2.getExternalIds();
                if (externalIds22 != null) {
                }
                String str4722 = str22 + str7 + i23 + str6 + i22;
                if (tMDBEpisode4 == null) {
                    if (overview == null) {
                    }
                    str36 = overview;
                }
                String logoUrl22 = tMDBShowDetails2.getLogoUrl(continueWatchingRepository2.getImgLang());
                firstAirDate = tMDBShowDetails2.getFirstAirDate();
                if (firstAirDate != null) {
                }
                str37 = string;
                Double voteAverage222 = tMDBShowDetails2.getVoteAverage();
                Integer ratingPercentage222 = tMDBShowDetails2.getRatingPercentage();
                String strBuildEpisodeLabel222 = continueWatchingRepository2.buildEpisodeLabel(continueWatchingItem5, tMDBEpisode4);
                if (tMDBEpisode4 != null) {
                }
                TMDBCredits credits222 = tMDBShowDetails2.getCredits();
                return new ContentItem(i20, itemType22, i20, imdbId, str4722, str36, str27, str26, logoUrl22, str25, str37, voteAverage222, ratingPercentage222, strBuildEpisodeLabel222, str38, (credits222 != null || (cast = credits222.getCast()) == null) ? null : y41.ai(cast, ",", null, null, new me1(7), 30), tMDBShowDetails2.getCertification(), null, null, null, Boxing.boxDouble(continueWatchingItem5.getProgress()), l4, Boxing.boxInt(i23), Boxing.boxInt(i22), i24 == 0, str22, null, null, null, null, 0, null, tMDBShowDetails2.getStatus(), str24, i30 <= 0 ? Boxing.boxInt(i30) : null, null, null, null, null, null, null, null, null, -67108864, 2040, null);
            }
            int i59 = c030214.I$3;
            int i60 = c030214.I$2;
            int i61 = c030214.I$1;
            i14 = c030214.I$0;
            String str55 = (String) c030214.L$10;
            str14 = (String) c030214.L$9;
            str15 = (String) c030214.L$8;
            String str56 = (String) c030214.L$7;
            tMDBEpisode3 = (TMDBEpisode) c030214.L$6;
            i13 = i59;
            TMDBShowDetails tMDBShowDetails7 = (TMDBShowDetails) c030214.L$5;
            Long l10 = (Long) c030214.L$4;
            String str57 = (String) c030214.L$3;
            Integer num9 = (Integer) c030214.L$2;
            ContinueWatchingItem continueWatchingItem12 = (ContinueWatchingItem) c030214.L$1;
            ContinueWatchingRepository continueWatchingRepository8 = (ContinueWatchingRepository) c030214.L$0;
            s38.b(obj3);
            c030212 = c030214;
            str13 = str56;
            i12 = i60;
            i11 = i61;
            str7 = " S";
            charSequence4 = "Ended";
            str6 = "E";
            l3 = l10;
            str12 = str57;
            num2 = num9;
            tMDBShowDetails = tMDBShowDetails7;
            continueWatchingRepository = continueWatchingRepository8;
            obj = obj3;
            charSequence6 = "Cancel";
            continueWatchingItem3 = continueWatchingItem12;
            str10 = str55;
            ck1Var2 = ck1Var4;
            tMDBSeasonDetails = (TMDBSeasonDetails) obj;
            if (tMDBSeasonDetails != null || (episodes = tMDBSeasonDetails.getEpisodes()) == null) {
                tMDBEpisode5 = null;
            } else {
                Iterator it5 = episodes.iterator();
                while (true) {
                    if (!it5.hasNext()) {
                        next = null;
                        break;
                    }
                    next = it5.next();
                    Integer episodeNumber = ((TMDBEpisode) next).getEpisodeNumber();
                    if (episodeNumber != null && episodeNumber.intValue() == i12) {
                        break;
                    }
                }
                tMDBEpisode5 = (TMDBEpisode) next;
            }
            String strDetectMidSeasonIndicator = cr4.b(tMDBEpisode5 == null ? tMDBEpisode5.getEpisodeType() : null, "finale") ? continueWatchingRepository.detectMidSeasonIndicator(tMDBSeasonDetails != null ? tMDBSeasonDetails.getEpisodes() : null, i12) : "FINALE";
            TMDBEpisode tMDBEpisode82 = tMDBEpisode3;
            i8 = i14;
            tMDBEpisode2 = tMDBEpisode82;
            str11 = str14;
            posterUrl = str15;
            i15 = i13;
            str17 = str10;
            i9 = i11;
            i7 = i12;
            str16 = strDetectMidSeasonIndicator;
            strConcat = str13;
            l2 = l3;
            LocalDate localDateNow2222 = LocalDate.now();
            seasons = tMDBShowDetails.getSeasons();
            if (seasons != null) {
                str18 = str16;
                ArrayList arrayList = new ArrayList();
                for (Object obj5 : seasons) {
                    String str58 = strConcat;
                    TMDBSeason tMDBSeason4 = (TMDBSeason) obj5;
                    if (tMDBSeason4.getSeasonNumber() != null && tMDBSeason4.getSeasonNumber().intValue() > 0) {
                        arrayList.add(obj5);
                    }
                    strConcat = str58;
                }
                str19 = strConcat;
                list = arrayList;
            } else {
                str18 = str16;
                str19 = strConcat;
                list = ik2.a;
            }
            status4 = tMDBShowDetails.getStatus();
            List list22222 = list;
            TMDBShowDetails tMDBShowDetails42222 = tMDBShowDetails;
            if (status4 != null) {
                z2 = true;
                z3 = n89.l(status4, charSequence4, true);
                if (!z3) {
                    String status5 = tMDBShowDetails42222.getStatus();
                    if (!((status5 == null || n89.l(status5, charSequence6, z2) != z2) ? false : z2)) {
                        z4 = false;
                    }
                    TMDBEpisode tMDBEpisode72222 = tMDBEpisode2;
                    str20 = str18;
                    it = list22222.iterator();
                    continueWatchingItem4 = continueWatchingItem3;
                    tMDBEpisode4 = tMDBEpisode72222;
                    ck1Var3 = ck1Var2;
                    i16 = i8;
                    c030213 = c030212;
                    str21 = str11;
                    i17 = i15;
                    str22 = str17;
                    str23 = str19;
                    i18 = i7;
                    localDate = localDateNow2222;
                    r23 = z4;
                    i19 = i9;
                    iIntValue = 0;
                    overview = str12;
                    continueWatchingRepository2 = continueWatchingRepository;
                    tMDBShowDetails2 = tMDBShowDetails42222;
                    while (it.hasNext()) {
                    }
                    int i4422222 = i19;
                    int i4522222 = i16;
                    ck1 ck1Var522222 = ck1Var3;
                    if (iIntValue > 0) {
                    }
                }
                z4 = z2;
                TMDBEpisode tMDBEpisode722222 = tMDBEpisode2;
                str20 = str18;
                it = list22222.iterator();
                continueWatchingItem4 = continueWatchingItem3;
                tMDBEpisode4 = tMDBEpisode722222;
                ck1Var3 = ck1Var2;
                i16 = i8;
                c030213 = c030212;
                str21 = str11;
                i17 = i15;
                str22 = str17;
                str23 = str19;
                i18 = i7;
                localDate = localDateNow2222;
                r23 = z4;
                i19 = i9;
                iIntValue = 0;
                overview = str12;
                continueWatchingRepository2 = continueWatchingRepository;
                tMDBShowDetails2 = tMDBShowDetails42222;
                while (it.hasNext()) {
                }
                int i44222222 = i19;
                int i45222222 = i16;
                ck1 ck1Var5222222 = ck1Var3;
                if (iIntValue > 0) {
                }
            } else {
                z2 = true;
            }
            if (!z3) {
            }
            z4 = z2;
            TMDBEpisode tMDBEpisode7222222 = tMDBEpisode2;
            str20 = str18;
            it = list22222.iterator();
            continueWatchingItem4 = continueWatchingItem3;
            tMDBEpisode4 = tMDBEpisode7222222;
            ck1Var3 = ck1Var2;
            i16 = i8;
            c030213 = c030212;
            str21 = str11;
            i17 = i15;
            str22 = str17;
            str23 = str19;
            i18 = i7;
            localDate = localDateNow2222;
            r23 = z4;
            i19 = i9;
            iIntValue = 0;
            overview = str12;
            continueWatchingRepository2 = continueWatchingRepository;
            tMDBShowDetails2 = tMDBShowDetails42222;
            while (it.hasNext()) {
            }
            int i442222222 = i19;
            int i452222222 = i16;
            ck1 ck1Var52222222 = ck1Var3;
            if (iIntValue > 0) {
            }
        }
        TMDBShowDetails tMDBShowDetails8 = (TMDBShowDetails) objRetryApiCall$default;
        if (tMDBShowDetails8 == null) {
            Log.w(TAG, "enrichEpisode: TMDB unavailable for show " + i + ", using local-only data");
            return new ContentItem(i, ContentItem.ItemType.TV_SHOW, i, null, str + " S" + i4 + "E" + i5, str2, null, null, null, null, num != null ? num.toString() : tMDBEpisode, null, null, continueWatchingRepository.buildEpisodeLabel(continueWatchingItem2, tMDBEpisode), null, null, null, null, null, null, Boxing.boxDouble(continueWatchingItem2.getProgress()), l, Boxing.boxInt(i4), Boxing.boxInt(i5), i3 != 0, str, null, null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, -67108864, 2047, null);
        }
        int i62 = i;
        int i63 = i5;
        int i64 = i4;
        ContinueWatchingRepository$enrichEpisode$episodeDetails$1 continueWatchingRepository$enrichEpisode$episodeDetails$1 = new ContinueWatchingRepository$enrichEpisode$episodeDetails$1(continueWatchingRepository, i62, i64, i63, null);
        c030214.L$0 = continueWatchingRepository;
        c030214.L$1 = continueWatchingItem2;
        c030214.L$2 = str;
        c030214.L$3 = num;
        c030214.L$4 = str2;
        c030214.L$5 = l;
        c030214.L$6 = tMDBShowDetails8;
        c030214.I$0 = i62;
        c030214.I$1 = i4;
        c030214.I$2 = i63;
        c030214.I$3 = i3;
        c030214.label = i2;
        c030212 = c030214;
        num2 = num;
        ContinueWatchingItem continueWatchingItem13 = continueWatchingItem2;
        str3 = " S";
        str4 = str;
        objRetryApiCall$default2 = retryApiCall$default(continueWatchingRepository, 0, 0L, null, continueWatchingRepository$enrichEpisode$episodeDetails$1, c030212, 7, null);
        if (objRetryApiCall$default2 != ck1Var4) {
            i6 = i3;
            i7 = i63;
            continueWatchingItem3 = continueWatchingItem13;
            i8 = i62;
            i9 = i64;
            str5 = str2;
            l2 = l;
            tMDBShowDetails = tMDBShowDetails8;
            tMDBEpisode2 = (TMDBEpisode) objRetryApiCall$default2;
            str6 = "E";
            preferredBackdropPath = TMDBImagesKt.getPreferredBackdropPath(tMDBShowDetails.getImages(), continueWatchingRepository.getImgLang());
            if (preferredBackdropPath == null) {
            }
            if (preferredBackdropPath == null) {
            }
            posterUrl = tMDBShowDetails.getPosterUrl(continueWatchingRepository.getImgLang());
            if (tMDBEpisode2 != null) {
            }
            str7 = str3;
            if (strConcat != null) {
            }
            if (n89.ab(str4)) {
            }
            int i432 = i6;
            status = tMDBShowDetails.getStatus();
            str10 = str9;
            charSequence3 = charSequence2;
            str11 = str8;
            if (status == null) {
            }
            status2 = tMDBShowDetails.getStatus();
            charSequence4 = charSequence3;
            charSequence5 = charSequence;
            if (status2 != null) {
            }
            status3 = tMDBShowDetails.getStatus();
            if (status3 != null) {
            }
            i10 = 1;
            if (i7 != i10) {
            }
        }
        return ck1Var4;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final CharSequence enrichEpisode$lambda$51(TMDBCast tMDBCast) {
        cr4.g(tMDBCast, "it");
        String name = tMDBCast.getName();
        return name != null ? name : "";
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:54:0x00e3  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00fe  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x0106  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x010d  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x0136  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object enrichMovie(ContinueWatchingItem.Movie movie, Continuation<? super ContentItem> continuation) {
        C03031 c03031;
        ContinueWatchingItem.Movie movie2;
        ContinueWatchingRepository continueWatchingRepository;
        int i;
        ContinueWatchingItem.Movie movie3;
        Object objA;
        String str;
        String string;
        List<TMDBCast> cast;
        if (continuation instanceof C03031) {
            c03031 = (C03031) continuation;
            int i2 = c03031.label;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                c03031.label = i2 - Integer.MIN_VALUE;
            } else {
                c03031 = new C03031(continuation);
            }
        }
        Object movieDetails = c03031.result;
        ck1 ck1Var = ck1.a;
        int i3 = c03031.label;
        if (i3 == 0) {
            s38.b(movieDetails);
            int tmdbId = movie.getTmdbId();
            try {
                TMDBApiService tMDBApiService = this.tmdbApiService;
                c03031.L$0 = this;
                movie2 = movie;
                try {
                    c03031.L$1 = movie2;
                    c03031.I$0 = tmdbId;
                    c03031.label = 1;
                    movieDetails = tMDBApiService.getMovieDetails(tmdbId, "images,credits,release_dates", c03031);
                    if (movieDetails == ck1Var) {
                        return ck1Var;
                    }
                    continueWatchingRepository = this;
                    i = tmdbId;
                    movie3 = movie2;
                } catch (Throwable th) {
                    th = th;
                    continueWatchingRepository = this;
                    i = tmdbId;
                    objA = s38.a(th);
                }
            } catch (Throwable th2) {
                th = th2;
                movie2 = movie;
            }
        } else {
            if (i3 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i = c03031.I$0;
            movie3 = (ContinueWatchingItem.Movie) c03031.L$1;
            continueWatchingRepository = (ContinueWatchingRepository) c03031.L$0;
            try {
                s38.b(movieDetails);
            } catch (Throwable th3) {
                th = th3;
                movie2 = movie3;
                objA = s38.a(th);
            }
        }
        objA = (TMDBMovieDetails) movieDetails;
        movie2 = movie3;
        int i4 = i;
        Throwable thA = q38.a(objA);
        if (thA != null) {
            String title = movie2.getTitle();
            String message = thA.getMessage();
            StringBuilder sbK = fi7.k("enrichMovie failed for tmdbId=", i4, " (", title, "): ");
            sbK.append(message);
            Log.w(TAG, sbK.toString());
            return null;
        }
        TMDBMovieDetails tMDBMovieDetails = (TMDBMovieDetails) objA;
        ContentItem.ItemType itemType = ContentItem.ItemType.MOVIE;
        ContinueWatchingItem.Movie movie4 = movie2;
        String imdbId = tMDBMovieDetails.getImdbId();
        String title2 = tMDBMovieDetails.getTitle();
        if (title2 == null) {
            title2 = movie4.getTitle();
        }
        String overview = tMDBMovieDetails.getOverview();
        String posterUrl = tMDBMovieDetails.getPosterUrl(continueWatchingRepository.getImgLang());
        String preferredBackdropPath = TMDBImagesKt.getPreferredBackdropPath(tMDBMovieDetails.getImages(), continueWatchingRepository.getImgLang());
        if (preferredBackdropPath == null) {
            preferredBackdropPath = tMDBMovieDetails.getBackdropPath();
        }
        String strConcat = preferredBackdropPath != null ? "https://image.tmdb.org/t/p/w1280".concat(preferredBackdropPath) : null;
        String logoUrl = tMDBMovieDetails.getLogoUrl(continueWatchingRepository.getImgLang());
        String releaseDate = tMDBMovieDetails.getReleaseDate();
        if (releaseDate != null) {
            string = n89.bb(4, releaseDate);
        } else {
            Integer year = movie4.getYear();
            if (year == null) {
                str = null;
                Double voteAverage = tMDBMovieDetails.getVoteAverage();
                Integer ratingPercentage = tMDBMovieDetails.getRatingPercentage();
                List<TMDBGenre> genres = tMDBMovieDetails.getGenres();
                String strAi = genres == null ? y41.ai(genres, ",", null, null, new me1(5), 30) : null;
                Integer runtime = tMDBMovieDetails.getRuntime();
                String string2 = runtime == null ? runtime.toString() : null;
                TMDBCredits credits = tMDBMovieDetails.getCredits();
                return new ContentItem(i4, itemType, i4, imdbId, title2, overview, posterUrl, strConcat, logoUrl, null, str, voteAverage, ratingPercentage, strAi, string2, (credits != null || (cast = credits.getCast()) == null) ? null : y41.ai(cast, ",", null, null, new me1(6), 30), tMDBMovieDetails.getCertification(), null, null, null, Boxing.boxDouble(movie4.getProgress()), movie4.getPlaybackId(), null, null, false, null, null, null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, -4193792, 2047, null);
            }
            string = year.toString();
        }
        str = string;
        Double voteAverage2 = tMDBMovieDetails.getVoteAverage();
        Integer ratingPercentage2 = tMDBMovieDetails.getRatingPercentage();
        List<TMDBGenre> genres2 = tMDBMovieDetails.getGenres();
        if (genres2 == null) {
        }
        Integer runtime2 = tMDBMovieDetails.getRuntime();
        if (runtime2 == null) {
        }
        TMDBCredits credits2 = tMDBMovieDetails.getCredits();
        return new ContentItem(i4, itemType, i4, imdbId, title2, overview, posterUrl, strConcat, logoUrl, null, str, voteAverage2, ratingPercentage2, strAi, string2, (credits2 != null || (cast = credits2.getCast()) == null) ? null : y41.ai(cast, ",", null, null, new me1(6), 30), tMDBMovieDetails.getCertification(), null, null, null, Boxing.boxDouble(movie4.getProgress()), movie4.getPlaybackId(), null, null, false, null, null, null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, -4193792, 2047, null);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final CharSequence enrichMovie$lambda$41(TMDBGenre tMDBGenre) {
        cr4.g(tMDBGenre, "it");
        String name = tMDBGenre.getName();
        return name != null ? name : "";
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final CharSequence enrichMovie$lambda$42(TMDBCast tMDBCast) {
        cr4.g(tMDBCast, "it");
        String name = tMDBCast.getName();
        return name != null ? name : "";
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Object enrichToContentItem(ContinueWatchingItem continueWatchingItem, Continuation<? super ContentItem> continuation) {
        if (continueWatchingItem instanceof ContinueWatchingItem.Movie) {
            return enrichMovie((ContinueWatchingItem.Movie) continueWatchingItem, continuation);
        }
        if (!(continueWatchingItem instanceof ContinueWatchingItem.Episode) && !(continueWatchingItem instanceof ContinueWatchingItem.NextEpisode)) {
            throw new io6();
        }
        return enrichEpisode(continueWatchingItem, continuation);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0014  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object fetchSeasonDetails(int i, int i2, Continuation<? super TMDBSeasonDetails> continuation) {
        C03041 c03041;
        ContinueWatchingRepository continueWatchingRepository;
        String str;
        dw7.a aVar;
        if (continuation instanceof C03041) {
            c03041 = (C03041) continuation;
            int i3 = c03041.label;
            if ((i3 & Integer.MIN_VALUE) != 0) {
                c03041.label = i3 - Integer.MIN_VALUE;
            } else {
                c03041 = new C03041(continuation);
            }
        }
        C03041 c030412 = c03041;
        Object obj = c030412.result;
        ck1 ck1Var = ck1.a;
        int i4 = c030412.label;
        if (i4 == 0) {
            s38.b(obj);
            String str2 = i + "_" + i2;
            TMDBSeasonDetails tMDBSeasonDetails = this.seasonDetailsCache.get(str2);
            if (tMDBSeasonDetails != null) {
                return tMDBSeasonDetails;
            }
            if (getSeasonNotFoundCache().contains(str2)) {
                return null;
            }
            dw7.a aVar2 = new dw7.a();
            ah ahVar = new ah(aVar2, 7);
            ContinueWatchingRepository$fetchSeasonDetails$result$2 continueWatchingRepository$fetchSeasonDetails$result$2 = new ContinueWatchingRepository$fetchSeasonDetails$result$2(this, i, i2, null);
            c030412.L$0 = this;
            c030412.L$1 = str2;
            c030412.L$2 = aVar2;
            c030412.label = 1;
            Object objRetryApiCall$default = retryApiCall$default(this, 0, 0L, ahVar, continueWatchingRepository$fetchSeasonDetails$result$2, c030412, 3, null);
            if (objRetryApiCall$default == ck1Var) {
                return ck1Var;
            }
            continueWatchingRepository = this;
            str = str2;
            obj = objRetryApiCall$default;
            aVar = aVar2;
        } else {
            if (i4 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            aVar = (dw7.a) c030412.L$2;
            str = (String) c030412.L$1;
            continueWatchingRepository = (ContinueWatchingRepository) c030412.L$0;
            s38.b(obj);
        }
        TMDBSeasonDetails tMDBSeasonDetails2 = (TMDBSeasonDetails) obj;
        if (tMDBSeasonDetails2 != null) {
            continueWatchingRepository.seasonDetailsCache.put(str, tMDBSeasonDetails2);
            return tMDBSeasonDetails2;
        }
        if (aVar.a) {
            continueWatchingRepository.addToSeasonNotFoundCache(str);
        }
        return tMDBSeasonDetails2;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final e6a fetchSeasonDetails$lambda$34(dw7.a aVar) {
        aVar.a = true;
        return e6a.a;
    }

    private final String formatEpisodeAirDate(String raw) {
        if (raw != null) {
            if (n89.ab(raw)) {
                raw = null;
            }
            if (raw != null) {
                try {
                    return LocalDate.parse(raw).format(EPISODE_AIR_DATE_FORMATTER);
                } catch (DateTimeParseException unused) {
                }
            }
        }
        return null;
    }

    private final File getDiskCacheFile() {
        return (File) this.diskCacheFile.getValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Code restructure failed: missing block: B:25:0x0065, code lost:
    
        if (r6 == r1) goto L26;
     */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object getDroppedShowTmdbIds(Continuation<? super Set<Integer>> continuation) {
        C03051 c03051;
        ContinueWatchingRepository continueWatchingRepository;
        if (continuation instanceof C03051) {
            c03051 = (C03051) continuation;
            int i = c03051.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c03051.label = i - Integer.MIN_VALUE;
            } else {
                c03051 = new C03051(continuation);
            }
        }
        Object activeAccount = c03051.result;
        ck1 ck1Var = ck1.a;
        int i2 = c03051.label;
        if (i2 == 0) {
            s38.b(activeAccount);
            TraktAccountRepository traktAccountRepository = this.accountRepository;
            c03051.L$0 = this;
            c03051.label = 1;
            activeAccount = traktAccountRepository.getActiveAccount(c03051);
            if (activeAccount != ck1Var) {
                continueWatchingRepository = this;
            }
            return ck1Var;
        }
        if (i2 != 1) {
            if (i2 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(activeAccount);
            ArrayList arrayList = new ArrayList();
            Iterator it = ((Iterable) activeAccount).iterator();
            while (it.hasNext()) {
                Integer tmdbId = ((TraktUserItem) it.next()).getTmdbId();
                if (tmdbId != null) {
                    arrayList.add(tmdbId);
                }
            }
            return y41.br(arrayList);
        }
        continueWatchingRepository = (ContinueWatchingRepository) c03051.L$0;
        s38.b(activeAccount);
        TraktAccount traktAccount = (TraktAccount) activeAccount;
        if (traktAccount == null) {
            return pk2.a;
        }
        TraktUserItemDao traktUserItemDao = continueWatchingRepository.traktUserItemDao;
        String userSlug = traktAccount.getUserSlug();
        c03051.L$0 = null;
        c03051.label = 2;
        activeAccount = traktUserItemDao.getItems("DROPPED", "SHOW", userSlug, c03051);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Set<Integer> getHiddenShowIds() {
        SharedPreferences hiddenShowsPrefs = getHiddenShowsPrefs();
        pk2 pk2Var = pk2.a;
        Set<String> stringSet = hiddenShowsPrefs.getStringSet(HIDDEN_SHOWS_KEY, pk2Var);
        if (stringSet == null) {
            return pk2Var;
        }
        ArrayList arrayList = new ArrayList();
        for (String str : stringSet) {
            cr4.d(str);
            Integer numBe = n89.be(str);
            if (numBe != null) {
                arrayList.add(numBe);
            }
        }
        return y41.br(arrayList);
    }

    private final SharedPreferences getHiddenShowsPrefs() {
        return (SharedPreferences) this.hiddenShowsPrefs.getValue();
    }

    private final String getImgLang() {
        LinkedHashMap linkedHashMap = hf5.a;
        return hf5.c(this.context);
    }

    private final Set<String> getSeasonNotFoundCache() {
        return (Set) this.seasonNotFoundCache.getValue();
    }

    private final SharedPreferences getSeasonNotFoundPrefs() {
        return (SharedPreferences) this.seasonNotFoundPrefs.getValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final SharedPreferences hiddenShowsPrefs_delegate$lambda$2(ContinueWatchingRepository continueWatchingRepository) {
        return continueWatchingRepository.context.getSharedPreferences(HIDDEN_SHOWS_PREFS, 0);
    }

    public static /* synthetic */ Object load$default(ContinueWatchingRepository continueWatchingRepository, boolean z, Continuation continuation, int i, Object obj) {
        if ((i & 1) != 0) {
            z = false;
        }
        return continueWatchingRepository.load(z, continuation);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final List<ContentItem> loadFromDiskCache() {
        try {
            if (!getDiskCacheFile().exists()) {
                return null;
            }
            return (List) this.gson.fromJson(ez2.b(getDiskCacheFile(), bz0.a), new TypeToken<List<? extends ContentItem>>() { // from class: com.strmr.ps.data.repository.ContinueWatchingRepository$loadFromDiskCache$type$1
            }.getType());
        } catch (Exception e) {
            Log.w(TAG, "Failed to load disk cache", e);
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Code restructure failed: missing block: B:40:0x012d, code lost:
    
        if (r2 == r4) goto L131;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:100:0x032c  */
    /* JADX WARN: Removed duplicated region for block: B:105:0x0348  */
    /* JADX WARN: Removed duplicated region for block: B:107:0x034c  */
    /* JADX WARN: Removed duplicated region for block: B:112:0x035a  */
    /* JADX WARN: Removed duplicated region for block: B:117:0x0368  */
    /* JADX WARN: Removed duplicated region for block: B:122:0x0376  */
    /* JADX WARN: Removed duplicated region for block: B:128:0x039d  */
    /* JADX WARN: Removed duplicated region for block: B:132:0x03b3  */
    /* JADX WARN: Removed duplicated region for block: B:134:0x03b6  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x010a  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x010d  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x013d  */
    /* JADX WARN: Removed duplicated region for block: B:48:0x0142  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x0161  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x0163  */
    /* JADX WARN: Removed duplicated region for block: B:70:0x01b6  */
    /* JADX WARN: Removed duplicated region for block: B:74:0x0225  */
    /* JADX WARN: Removed duplicated region for block: B:78:0x0258  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0019  */
    /* JADX WARN: Removed duplicated region for block: B:81:0x026f  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x0278  */
    /* JADX WARN: Type inference failed for: r16v0 */
    /* JADX WARN: Type inference failed for: r6v0 */
    /* JADX WARN: Type inference failed for: r6v2, types: [int] */
    /* JADX WARN: Type inference failed for: r6v5 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object loadInternal(boolean z, Continuation<? super List<ContentItem>> continuation) {
        C03101 c03101;
        ContinueWatchingRepository continueWatchingRepository;
        List<ContentItem> list;
        TraktAccount traktAccount;
        String strBuildAuthHeader;
        boolean z2;
        ContinueWatchingRepository continueWatchingRepository2;
        boolean z3;
        String str;
        ContinueWatchingRepository continueWatchingRepository3;
        String str2;
        int i;
        TraktLastActivities traktLastActivities;
        Object objC;
        boolean z4;
        TraktLastActivities traktLastActivities2;
        boolean zBooleanValue;
        List<ContentItem> listLoadFromDiskCache;
        TraktLastActivities traktLastActivities3;
        List list2;
        List list3;
        Object objParallelEnrich;
        int i2;
        List list4;
        List<ContentItem> list5;
        int size;
        ContinueWatchingRepository continueWatchingRepository4;
        int i3;
        String strAi;
        SyncMetadataRepository syncMetadataRepository;
        ContinueWatchingRepository continueWatchingRepository5;
        TraktActivityGroup episodes;
        TraktActivityGroup episodes2;
        TraktActivityGroup movies;
        TraktActivityGroup movies2;
        boolean z5 = z;
        if (continuation instanceof C03101) {
            c03101 = (C03101) continuation;
            int i4 = c03101.label;
            if ((i4 & Integer.MIN_VALUE) != 0) {
                c03101.label = i4 - Integer.MIN_VALUE;
            } else {
                c03101 = new C03101(continuation);
            }
        }
        Object objRefreshTokenIfNeeded = c03101.result;
        ck1 ck1Var = ck1.a;
        ?? BooleanValue = 0;
        switch (c03101.label) {
            case 0:
                s38.b(objRefreshTokenIfNeeded);
                if (!z5 && (list = this.cachedItems) != null) {
                    if (System.currentTimeMillis() - this.lastCacheTime < CACHE_TTL_MS) {
                        return list;
                    }
                    Boxing.boxInt(Log.d(TAG, "In-memory cache expired (age=" + (System.currentTimeMillis() - this.lastCacheTime) + "ms), checking for changes"));
                }
                TraktAccountRepository traktAccountRepository = this.accountRepository;
                c03101.L$0 = this;
                c03101.Z$0 = z5;
                c03101.label = 1;
                objRefreshTokenIfNeeded = traktAccountRepository.refreshTokenIfNeeded(c03101);
                if (objRefreshTokenIfNeeded != ck1Var) {
                    continueWatchingRepository = this;
                    traktAccount = (TraktAccount) objRefreshTokenIfNeeded;
                    if (traktAccount != null) {
                        return ik2.a;
                    }
                    strBuildAuthHeader = continueWatchingRepository.accountRepository.buildAuthHeader(traktAccount.getAccessToken());
                    if (!z5) {
                        SyncMetadataRepository syncMetadataRepository2 = continueWatchingRepository.syncMetadataRepository;
                        c03101.L$0 = continueWatchingRepository;
                        c03101.L$1 = strBuildAuthHeader;
                        c03101.Z$0 = z5;
                        c03101.label = 2;
                        objRefreshTokenIfNeeded = syncMetadataRepository2.isSyncedWithin(TraktSyncRepository.SYNC_KEY_EPISODE_WATCH_STATUS, 300000L, c03101);
                    }
                    if (z2) {
                        c03101.L$0 = continueWatchingRepository;
                        c03101.L$1 = strBuildAuthHeader;
                        c03101.Z$0 = z5;
                        c03101.label = 3;
                        objRefreshTokenIfNeeded = continueWatchingRepository.syncEpisodeWatchStatus(strBuildAuthHeader, c03101);
                        if (objRefreshTokenIfNeeded != ck1Var) {
                            continueWatchingRepository2 = continueWatchingRepository;
                            String str3 = strBuildAuthHeader;
                            z3 = z5;
                            str = str3;
                            continueWatchingRepository3 = continueWatchingRepository2;
                            BooleanValue = ((Boolean) objRefreshTokenIfNeeded).booleanValue();
                            if (z3) {
                            }
                        }
                    } else {
                        String str4 = strBuildAuthHeader;
                        z3 = z5;
                        str = str4;
                        continueWatchingRepository3 = continueWatchingRepository;
                        if (z3) {
                            traktLastActivities = null;
                            AnonymousClass4 anonymousClass4 = continueWatchingRepository3.new AnonymousClass4(str, null);
                            c03101.L$0 = continueWatchingRepository3;
                            c03101.L$1 = traktLastActivities;
                            c03101.Z$0 = z3;
                            c03101.label = 5;
                            objC = bk1.c(anonymousClass4, c03101);
                            if (objC != ck1Var) {
                                TraktLastActivities traktLastActivities4 = traktLastActivities;
                                objRefreshTokenIfNeeded = objC;
                                z4 = z3;
                                traktLastActivities2 = traktLastActivities4;
                                hx9 hx9Var = (hx9) objRefreshTokenIfNeeded;
                                List<TraktPlaybackItem> list6 = (List) hx9Var.a;
                                List<TraktPlaybackItem> list7 = (List) hx9Var.b;
                                List<LastWatchedPerShow> list8 = (List) hx9Var.c;
                                Log.w(TAG, "load(force=" + z4 + "): " + list6.size() + " playback movies, " + list7.size() + " playback episodes, " + list8.size() + " shows with history");
                                ArrayList arrayList = new ArrayList();
                                arrayList.addAll(continueWatchingRepository3.processMovies(list6));
                                c03101.L$0 = continueWatchingRepository3;
                                c03101.L$1 = traktLastActivities2;
                                c03101.L$2 = arrayList;
                                c03101.L$3 = arrayList;
                                c03101.label = 6;
                                objRefreshTokenIfNeeded = continueWatchingRepository3.processShows(list7, list8, c03101);
                                if (objRefreshTokenIfNeeded != ck1Var) {
                                    traktLastActivities3 = traktLastActivities2;
                                    list2 = arrayList;
                                    list3 = arrayList;
                                    list3.addAll((Collection) objRefreshTokenIfNeeded);
                                    continueWatchingRepository3.persistSeasonNotFoundCache();
                                    List<ContinueWatchingItem> listDedupeByShow = continueWatchingRepository3.dedupeByShow(y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.ContinueWatchingRepository$loadInternal$$inlined$sortedByDescending$1
                                        /* JADX WARN: Multi-variable type inference failed */
                                        @Override // java.util.Comparator
                                        public final int compare(T t, T t2) {
                                            return x71.b(Long.valueOf(((ContinueWatchingItem) t2).getLastWatchedAtMillis()), Long.valueOf(((ContinueWatchingItem) t).getLastWatchedAtMillis()));
                                        }
                                    }, list2));
                                    int size2 = listDedupeByShow.size();
                                    c03101.L$0 = continueWatchingRepository3;
                                    c03101.L$1 = traktLastActivities3;
                                    c03101.L$2 = list2;
                                    c03101.L$3 = null;
                                    c03101.I$0 = size2;
                                    c03101.label = 7;
                                    objParallelEnrich = continueWatchingRepository3.parallelEnrich(listDedupeByShow, c03101);
                                    if (objParallelEnrich != ck1Var) {
                                        objRefreshTokenIfNeeded = objParallelEnrich;
                                        i2 = size2;
                                        list4 = list2;
                                        list5 = (List) objRefreshTokenIfNeeded;
                                        size = i2 - list5.size();
                                        int size3 = list4.size();
                                        int size4 = list5.size();
                                        String strI = size <= 0 ? n41.i(size, " (", " DROPPED)") : "";
                                        StringBuilder sbR = vw2.r("load: ", size3, " raw → ", " deduped → ", i2);
                                        sbR.append(size4);
                                        sbR.append(" enriched");
                                        sbR.append(strI);
                                        Log.w(TAG, sbR.toString());
                                        if (size > 0 || continueWatchingRepository3.cachedItems == null) {
                                            continueWatchingRepository3.cachedItems = list5;
                                            continueWatchingRepository3.lastCacheTime = System.currentTimeMillis();
                                            continueWatchingRepository3.saveToDiskCache(list5);
                                        } else {
                                            LinkedHashSet linkedHashSet = new LinkedHashSet();
                                            Iterator it = list5.iterator();
                                            while (it.hasNext()) {
                                                linkedHashSet.add(Boxing.boxInt(((ContentItem) it.next()).getTmdbId()));
                                            }
                                            List<ContentItem> list9 = continueWatchingRepository3.cachedItems;
                                            cr4.d(list9);
                                            ArrayList arrayList2 = new ArrayList();
                                            for (Object obj : list9) {
                                                if (!linkedHashSet.contains(Boxing.boxInt(((ContentItem) obj).getTmdbId()))) {
                                                    arrayList2.add(obj);
                                                }
                                            }
                                            StringBuilder sbR2 = vw2.r("Merged ", arrayList2.size(), " cached items with ", " fresh (", list5.size());
                                            sbR2.append(size);
                                            sbR2.append(" failed enrichment)");
                                            Log.w(TAG, sbR2.toString());
                                            continueWatchingRepository3.cachedItems = y41.au(arrayList2, list5);
                                            continueWatchingRepository3.lastCacheTime = System.currentTimeMillis();
                                        }
                                        if (traktLastActivities3 != null) {
                                            TraktActivitiesCache traktActivitiesCache = continueWatchingRepository3.activitiesCache;
                                            c03101.L$0 = continueWatchingRepository3;
                                            c03101.L$1 = null;
                                            c03101.L$2 = null;
                                            c03101.I$0 = size;
                                            c03101.label = 8;
                                            objRefreshTokenIfNeeded = traktActivitiesCache.getActivities(c03101);
                                            if (objRefreshTokenIfNeeded != ck1Var) {
                                                continueWatchingRepository4 = continueWatchingRepository3;
                                                i3 = size;
                                                traktLastActivities3 = (TraktLastActivities) objRefreshTokenIfNeeded;
                                                strAi = y41.ai(st.w(new String[]{(traktLastActivities3 != null || (movies2 = traktLastActivities3.getMovies()) == null) ? null : movies2.getPausedAt(), (traktLastActivities3 != null || (movies = traktLastActivities3.getMovies()) == null) ? null : movies.getWatchedAt(), (traktLastActivities3 != null || (episodes2 = traktLastActivities3.getEpisodes()) == null) ? null : episodes2.getPausedAt(), (traktLastActivities3 != null || (episodes = traktLastActivities3.getEpisodes()) == null) ? null : episodes.getWatchedAt()}), "|", null, null, null, 62);
                                                syncMetadataRepository = continueWatchingRepository4.syncMetadataRepository;
                                                if (strAi.length() == 0) {
                                                    strAi = null;
                                                }
                                                c03101.L$0 = continueWatchingRepository4;
                                                c03101.L$1 = null;
                                                c03101.L$2 = null;
                                                c03101.I$0 = i3;
                                                c03101.label = 9;
                                                if (syncMetadataRepository.markSynced(SYNC_KEY_CONTINUE_WATCHING, strAi, c03101) != ck1Var) {
                                                    continueWatchingRepository5 = continueWatchingRepository4;
                                                    if (i3 > 0) {
                                                        Log.w(TAG, "Saved fingerprint despite " + i3 + " enrichment failures (merged with cache)");
                                                    }
                                                    List<ContentItem> list10 = continueWatchingRepository5.cachedItems;
                                                    cr4.d(list10);
                                                    return list10;
                                                }
                                            }
                                        } else {
                                            continueWatchingRepository4 = continueWatchingRepository3;
                                            i3 = size;
                                            strAi = y41.ai(st.w(new String[]{(traktLastActivities3 != null || (movies2 = traktLastActivities3.getMovies()) == null) ? null : movies2.getPausedAt(), (traktLastActivities3 != null || (movies = traktLastActivities3.getMovies()) == null) ? null : movies.getWatchedAt(), (traktLastActivities3 != null || (episodes2 = traktLastActivities3.getEpisodes()) == null) ? null : episodes2.getPausedAt(), (traktLastActivities3 != null || (episodes = traktLastActivities3.getEpisodes()) == null) ? null : episodes.getWatchedAt()}), "|", null, null, null, 62);
                                            syncMetadataRepository = continueWatchingRepository4.syncMetadataRepository;
                                            if (strAi.length() == 0) {
                                            }
                                            c03101.L$0 = continueWatchingRepository4;
                                            c03101.L$1 = null;
                                            c03101.L$2 = null;
                                            c03101.I$0 = i3;
                                            c03101.label = 9;
                                            if (syncMetadataRepository.markSynced(SYNC_KEY_CONTINUE_WATCHING, strAi, c03101) != ck1Var) {
                                            }
                                        }
                                    }
                                }
                            }
                        } else {
                            c03101.L$0 = continueWatchingRepository3;
                            c03101.L$1 = str;
                            c03101.Z$0 = z3;
                            c03101.I$0 = BooleanValue;
                            c03101.label = 4;
                            objRefreshTokenIfNeeded = continueWatchingRepository3.checkRefreshNeeded(str, c03101);
                            if (objRefreshTokenIfNeeded != ck1Var) {
                                ?? r16 = BooleanValue;
                                str2 = str;
                                i = r16 == true ? 1 : 0;
                                q07 q07Var = (q07) objRefreshTokenIfNeeded;
                                zBooleanValue = ((Boolean) q07Var.a).booleanValue();
                                traktLastActivities = (TraktLastActivities) q07Var.b;
                                if (zBooleanValue && i == 0 && (listLoadFromDiskCache = continueWatchingRepository3.loadFromDiskCache()) != null) {
                                    listLoadFromDiskCache.size();
                                    continueWatchingRepository3.cachedItems = listLoadFromDiskCache;
                                    continueWatchingRepository3.lastCacheTime = System.currentTimeMillis();
                                    return listLoadFromDiskCache;
                                }
                                str = str2;
                                AnonymousClass4 anonymousClass42 = continueWatchingRepository3.new AnonymousClass4(str, null);
                                c03101.L$0 = continueWatchingRepository3;
                                c03101.L$1 = traktLastActivities;
                                c03101.Z$0 = z3;
                                c03101.label = 5;
                                objC = bk1.c(anonymousClass42, c03101);
                                if (objC != ck1Var) {
                                }
                            }
                        }
                    }
                    break;
                }
                return ck1Var;
            case 1:
                z5 = c03101.Z$0;
                ContinueWatchingRepository continueWatchingRepository6 = (ContinueWatchingRepository) c03101.L$0;
                s38.b(objRefreshTokenIfNeeded);
                continueWatchingRepository = continueWatchingRepository6;
                traktAccount = (TraktAccount) objRefreshTokenIfNeeded;
                if (traktAccount != null) {
                }
                break;
            case 2:
                z5 = c03101.Z$0;
                strBuildAuthHeader = (String) c03101.L$1;
                continueWatchingRepository = (ContinueWatchingRepository) c03101.L$0;
                s38.b(objRefreshTokenIfNeeded);
                z2 = ((Boolean) objRefreshTokenIfNeeded).booleanValue();
                if (z2) {
                }
                break;
            case 3:
                z5 = c03101.Z$0;
                strBuildAuthHeader = (String) c03101.L$1;
                continueWatchingRepository2 = (ContinueWatchingRepository) c03101.L$0;
                s38.b(objRefreshTokenIfNeeded);
                String str32 = strBuildAuthHeader;
                z3 = z5;
                str = str32;
                continueWatchingRepository3 = continueWatchingRepository2;
                BooleanValue = ((Boolean) objRefreshTokenIfNeeded).booleanValue();
                if (z3) {
                }
                break;
            case 4:
                i = c03101.I$0;
                z3 = c03101.Z$0;
                str2 = (String) c03101.L$1;
                continueWatchingRepository3 = (ContinueWatchingRepository) c03101.L$0;
                s38.b(objRefreshTokenIfNeeded);
                q07 q07Var2 = (q07) objRefreshTokenIfNeeded;
                zBooleanValue = ((Boolean) q07Var2.a).booleanValue();
                traktLastActivities = (TraktLastActivities) q07Var2.b;
                if (zBooleanValue) {
                }
                str = str2;
                AnonymousClass4 anonymousClass422 = continueWatchingRepository3.new AnonymousClass4(str, null);
                c03101.L$0 = continueWatchingRepository3;
                c03101.L$1 = traktLastActivities;
                c03101.Z$0 = z3;
                c03101.label = 5;
                objC = bk1.c(anonymousClass422, c03101);
                if (objC != ck1Var) {
                }
                return ck1Var;
            case 5:
                z4 = c03101.Z$0;
                traktLastActivities2 = (TraktLastActivities) c03101.L$1;
                ContinueWatchingRepository continueWatchingRepository7 = (ContinueWatchingRepository) c03101.L$0;
                s38.b(objRefreshTokenIfNeeded);
                continueWatchingRepository3 = continueWatchingRepository7;
                hx9 hx9Var2 = (hx9) objRefreshTokenIfNeeded;
                List<TraktPlaybackItem> list62 = (List) hx9Var2.a;
                List<TraktPlaybackItem> list72 = (List) hx9Var2.b;
                List<LastWatchedPerShow> list82 = (List) hx9Var2.c;
                Log.w(TAG, "load(force=" + z4 + "): " + list62.size() + " playback movies, " + list72.size() + " playback episodes, " + list82.size() + " shows with history");
                ArrayList arrayList3 = new ArrayList();
                arrayList3.addAll(continueWatchingRepository3.processMovies(list62));
                c03101.L$0 = continueWatchingRepository3;
                c03101.L$1 = traktLastActivities2;
                c03101.L$2 = arrayList3;
                c03101.L$3 = arrayList3;
                c03101.label = 6;
                objRefreshTokenIfNeeded = continueWatchingRepository3.processShows(list72, list82, c03101);
                if (objRefreshTokenIfNeeded != ck1Var) {
                }
                return ck1Var;
            case 6:
                List list11 = (List) c03101.L$3;
                List list12 = (List) c03101.L$2;
                traktLastActivities3 = (TraktLastActivities) c03101.L$1;
                continueWatchingRepository3 = (ContinueWatchingRepository) c03101.L$0;
                s38.b(objRefreshTokenIfNeeded);
                list3 = list11;
                list2 = list12;
                list3.addAll((Collection) objRefreshTokenIfNeeded);
                continueWatchingRepository3.persistSeasonNotFoundCache();
                List<ContinueWatchingItem> listDedupeByShow2 = continueWatchingRepository3.dedupeByShow(y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.ContinueWatchingRepository$loadInternal$$inlined$sortedByDescending$1
                    /* JADX WARN: Multi-variable type inference failed */
                    @Override // java.util.Comparator
                    public final int compare(T t, T t2) {
                        return x71.b(Long.valueOf(((ContinueWatchingItem) t2).getLastWatchedAtMillis()), Long.valueOf(((ContinueWatchingItem) t).getLastWatchedAtMillis()));
                    }
                }, list2));
                int size22 = listDedupeByShow2.size();
                c03101.L$0 = continueWatchingRepository3;
                c03101.L$1 = traktLastActivities3;
                c03101.L$2 = list2;
                c03101.L$3 = null;
                c03101.I$0 = size22;
                c03101.label = 7;
                objParallelEnrich = continueWatchingRepository3.parallelEnrich(listDedupeByShow2, c03101);
                if (objParallelEnrich != ck1Var) {
                }
                return ck1Var;
            case 7:
                i2 = c03101.I$0;
                List list13 = (List) c03101.L$2;
                traktLastActivities3 = (TraktLastActivities) c03101.L$1;
                continueWatchingRepository3 = (ContinueWatchingRepository) c03101.L$0;
                s38.b(objRefreshTokenIfNeeded);
                list4 = list13;
                list5 = (List) objRefreshTokenIfNeeded;
                size = i2 - list5.size();
                int size32 = list4.size();
                int size42 = list5.size();
                if (size <= 0) {
                }
                StringBuilder sbR3 = vw2.r("load: ", size32, " raw → ", " deduped → ", i2);
                sbR3.append(size42);
                sbR3.append(" enriched");
                sbR3.append(strI);
                Log.w(TAG, sbR3.toString());
                if (size > 0) {
                }
                continueWatchingRepository3.cachedItems = list5;
                continueWatchingRepository3.lastCacheTime = System.currentTimeMillis();
                continueWatchingRepository3.saveToDiskCache(list5);
                if (traktLastActivities3 != null) {
                }
                break;
            case 8:
                i3 = c03101.I$0;
                continueWatchingRepository4 = (ContinueWatchingRepository) c03101.L$0;
                s38.b(objRefreshTokenIfNeeded);
                traktLastActivities3 = (TraktLastActivities) objRefreshTokenIfNeeded;
                strAi = y41.ai(st.w(new String[]{(traktLastActivities3 != null || (movies2 = traktLastActivities3.getMovies()) == null) ? null : movies2.getPausedAt(), (traktLastActivities3 != null || (movies = traktLastActivities3.getMovies()) == null) ? null : movies.getWatchedAt(), (traktLastActivities3 != null || (episodes2 = traktLastActivities3.getEpisodes()) == null) ? null : episodes2.getPausedAt(), (traktLastActivities3 != null || (episodes = traktLastActivities3.getEpisodes()) == null) ? null : episodes.getWatchedAt()}), "|", null, null, null, 62);
                syncMetadataRepository = continueWatchingRepository4.syncMetadataRepository;
                if (strAi.length() == 0) {
                }
                c03101.L$0 = continueWatchingRepository4;
                c03101.L$1 = null;
                c03101.L$2 = null;
                c03101.I$0 = i3;
                c03101.label = 9;
                if (syncMetadataRepository.markSynced(SYNC_KEY_CONTINUE_WATCHING, strAi, c03101) != ck1Var) {
                }
                return ck1Var;
            case 9:
                i3 = c03101.I$0;
                continueWatchingRepository5 = (ContinueWatchingRepository) c03101.L$0;
                s38.b(objRefreshTokenIfNeeded);
                if (i3 > 0) {
                }
                List<ContentItem> list102 = continueWatchingRepository5.cachedItems;
                cr4.d(list102);
                return list102;
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Set<String> loadSeasonNotFoundCache() {
        Object objA;
        Map map;
        SharedPreferences seasonNotFoundPrefs = getSeasonNotFoundPrefs();
        Set<String> set = pk2.a;
        Set<String> stringSet = seasonNotFoundPrefs.getStringSet(SEASON_NOT_FOUND_KEY, set);
        if (stringSet != null) {
            set = stringSet;
        }
        String string = getSeasonNotFoundPrefs().getString(SEASON_NOT_FOUND_TIMESTAMPS_KEY, null);
        if (string != null) {
            try {
                objA = (Map) this.gson.fromJson(string, new TypeToken<Map<String, ? extends Long>>() { // from class: com.strmr.ps.data.repository.ContinueWatchingRepository$loadSeasonNotFoundCache$timestamps$1$type$1
                }.getType());
            } catch (Throwable th) {
                objA = s38.a(th);
            }
            Object obj = jk2.a;
            if (objA instanceof q38.b) {
                objA = obj;
            }
            map = (Map) objA;
        } else {
            map = jk2.a;
        }
        long jCurrentTimeMillis = System.currentTimeMillis();
        ArrayList arrayList = new ArrayList();
        for (Object obj2 : set) {
            Long l = (Long) map.get((String) obj2);
            if (l != null && jCurrentTimeMillis - l.longValue() <= SEASON_NOT_FOUND_TTL_MS) {
                arrayList.add(obj2);
            }
        }
        LinkedHashSet linkedHashSetBq = y41.bq(arrayList);
        if (linkedHashSetBq.size() < set.size()) {
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            for (Map.Entry entry : map.entrySet()) {
                if (linkedHashSetBq.contains((String) entry.getKey())) {
                    linkedHashMap.put(entry.getKey(), entry.getValue());
                }
            }
            getSeasonNotFoundPrefs().edit().putStringSet(SEASON_NOT_FOUND_KEY, y41.br(linkedHashSetBq)).putString(SEASON_NOT_FOUND_TIMESTAMPS_KEY, this.gson.toJson(linkedHashMap)).apply();
        }
        Set<String> setNewSetFromMap = Collections.newSetFromMap(new ConcurrentHashMap());
        setNewSetFromMap.addAll(linkedHashSetBq);
        return setNewSetFromMap;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Object parallelEnrich(List<? extends ContinueWatchingItem> list, Continuation<? super List<ContentItem>> continuation) {
        return bk1.c(new C03122(list, this, null), continuation);
    }

    private final Long parseAirDate(String airDate) {
        if (airDate == null || n89.ab(airDate)) {
            return null;
        }
        try {
            try {
                return Long.valueOf(ZonedDateTime.parse(airDate, DateTimeFormatter.ISO_DATE_TIME).toInstant().toEpochMilli());
            } catch (Exception unused) {
                return null;
            }
        } catch (Exception unused2) {
            return Long.valueOf(LocalDate.parse(airDate, DateTimeFormatter.ISO_LOCAL_DATE).atTime(3, 0).atZone(ZoneId.of("America/New_York")).toInstant().toEpochMilli());
        }
    }

    private final Long parseTraktDateMillis(String raw) {
        if (raw == null) {
            return null;
        }
        try {
            return Long.valueOf(OffsetDateTime.parse(raw, DateTimeFormatter.ISO_OFFSET_DATE_TIME).toInstant().toEpochMilli());
        } catch (DateTimeParseException unused) {
            return null;
        }
    }

    private final void persistSeasonNotFoundCache() {
        Object objA;
        Map linkedHashMap;
        String string = getSeasonNotFoundPrefs().getString(SEASON_NOT_FOUND_TIMESTAMPS_KEY, null);
        if (string != null) {
            try {
                objA = (Map) this.gson.fromJson(string, new TypeToken<Map<String, Long>>() { // from class: com.strmr.ps.data.repository.ContinueWatchingRepository$persistSeasonNotFoundCache$timestamps$1$type$1
                }.getType());
            } catch (Throwable th) {
                objA = s38.a(th);
            }
            Object linkedHashMap2 = new LinkedHashMap();
            if (objA instanceof q38.b) {
                objA = linkedHashMap2;
            }
            linkedHashMap = (Map) objA;
        } else {
            linkedHashMap = new LinkedHashMap();
        }
        linkedHashMap.putAll(this.seasonNotFoundTimestamps);
        this.seasonNotFoundTimestamps.clear();
        getSeasonNotFoundPrefs().edit().putStringSet(SEASON_NOT_FOUND_KEY, y41.br(getSeasonNotFoundCache())).putString(SEASON_NOT_FOUND_TIMESTAMPS_KEY, this.gson.toJson(linkedHashMap)).apply();
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Multi-variable type inference failed */
    public final List<ContinueWatchingItem> processMovies(List<TraktPlaybackItem> playbackMovies) {
        TraktMovie movie;
        TraktIds ids;
        Integer tmdb;
        ArrayList arrayList = new ArrayList();
        for (TraktPlaybackItem traktPlaybackItem : playbackMovies) {
            if (cr4.b(traktPlaybackItem.getType(), PlaybackProgress.TYPE_MOVIE) && (movie = traktPlaybackItem.getMovie()) != null && (ids = movie.getIds()) != null && (tmdb = ids.getTmdb()) != null) {
                int iIntValue = tmdb.intValue();
                float fNormalizeProgress = INSTANCE.normalizeProgress(traktPlaybackItem.getProgress());
                if (fNormalizeProgress < NEAR_COMPLETE_PROGRESS) {
                    Long id = traktPlaybackItem.getId();
                    long zonedMillisOrNow = ContinueWatchingModelsKt.toZonedMillisOrNow(traktPlaybackItem.getPausedAt());
                    Long lValueOf = movie.getIds() != null ? Long.valueOf(r1.getTrakt()) : null;
                    String title = movie.getTitle();
                    if (title == null) {
                        title = "";
                    }
                    movie = new ContinueWatchingItem.Movie(id, fNormalizeProgress, zonedMillisOrNow, lValueOf, iIntValue, title, movie.getYear());
                }
            }
            if (movie != null) {
                arrayList.add(movie);
            }
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final ContinueWatchingItem processPlaybackOnlyShow(TraktPlaybackItem playbackItem) {
        TraktEpisode episode;
        TraktIds ids;
        Integer tmdb;
        TraktShow show = playbackItem.getShow();
        if (show != null && (episode = playbackItem.getEpisode()) != null && (ids = show.getIds()) != null && (tmdb = ids.getTmdb()) != null) {
            int iIntValue = tmdb.intValue();
            TraktIds ids2 = show.getIds();
            if (ids2 != null) {
                long trakt = ids2.getTrakt();
                String title = show.getTitle();
                if (title == null) {
                    return null;
                }
                float fNormalizeProgress = INSTANCE.normalizeProgress(playbackItem.getProgress());
                if (fNormalizeProgress >= NEAR_COMPLETE_PROGRESS) {
                    return null;
                }
                Long id = playbackItem.getId();
                long zonedMillisOrNow = ContinueWatchingModelsKt.toZonedMillisOrNow(playbackItem.getPausedAt());
                Long lValueOf = Long.valueOf(trakt);
                Integer year = show.getYear();
                Integer season = episode.getSeason();
                if (season != null) {
                    int iIntValue2 = season.intValue();
                    Integer number = episode.getNumber();
                    if (number != null) {
                        return new ContinueWatchingItem.Episode(id, fNormalizeProgress, zonedMillisOrNow, lValueOf, iIntValue, title, year, iIntValue2, number.intValue(), episode.getTitle(), false, 1024, null);
                    }
                }
            }
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:127:0x03ac  */
    /* JADX WARN: Removed duplicated region for block: B:147:0x0425  */
    /* JADX WARN: Removed duplicated region for block: B:152:0x0456  */
    /* JADX WARN: Removed duplicated region for block: B:155:0x0460  */
    /* JADX WARN: Removed duplicated region for block: B:171:0x04ba  */
    /* JADX WARN: Removed duplicated region for block: B:190:0x0535  */
    /* JADX WARN: Removed duplicated region for block: B:195:0x054c  */
    /* JADX WARN: Removed duplicated region for block: B:206:0x058b  */
    /* JADX WARN: Removed duplicated region for block: B:215:0x05ab  */
    /* JADX WARN: Removed duplicated region for block: B:218:0x05c5 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:241:0x062b  */
    /* JADX WARN: Removed duplicated region for block: B:262:0x069a  */
    /* JADX WARN: Removed duplicated region for block: B:292:? A[RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:33:0x01e8  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x0201  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x0219  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x0225  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x023f  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x024c  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x0253  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x0258  */
    /* JADX WARN: Removed duplicated region for block: B:70:0x0283  */
    /* JADX WARN: Removed duplicated region for block: B:87:0x02d8  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0018  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object processShowEntry(int i, LastWatchedPerShow lastWatchedPerShow, TraktPlaybackItem traktPlaybackItem, Continuation<? super ContinueWatchingItem> continuation) {
        C03131 c03131;
        float f;
        float f2;
        ContinueWatchingRepository continueWatchingRepository;
        Object obj;
        LastWatchedPerShow lastWatchedPerShow2;
        TraktPlaybackItem traktPlaybackItem2;
        int i2;
        Object objFindByTmdbId;
        int i3;
        LastWatchedPerShow lastWatchedPerShow3;
        Object obj2;
        TraktPlaybackItem traktPlaybackItem3;
        String userSlug;
        TraktUserItem traktUserItem;
        Long lBoxLong;
        TraktShow show;
        Integer year;
        TraktShow show2;
        long jLongValue;
        int episode;
        Object highestWatchedEpisode;
        Integer num;
        Object obj3;
        TraktPlaybackItem traktPlaybackItem4;
        int i4;
        String year2;
        String title;
        Integer traktId;
        EpisodeWatchStatus episodeWatchStatus;
        ck1 ck1Var;
        Long l;
        int i5;
        Integer num2;
        String str;
        TraktPlaybackItem traktPlaybackItem5;
        Object obj4;
        int i6;
        int i7;
        EpisodeWatchStatus episodeWatchStatus2;
        Integer num3;
        int i8;
        TraktPlaybackItem traktPlaybackItem6;
        hx9 hx9Var;
        int iIntValue;
        int i9;
        int i10;
        int i11;
        Object obj5;
        EpisodeWatchStatus episodeWatchStatus3;
        Long l2;
        int i12;
        String str2;
        Long l3;
        TMDBEpisode tMDBEpisode;
        int i13;
        String airDate;
        Long l4;
        long j;
        ContinueWatchingRepository continueWatchingRepository2;
        Integer num4;
        TraktEpisode episode2;
        Integer season;
        TraktEpisode episode3;
        Integer number;
        TraktPlaybackItem traktPlaybackItem7;
        hx9 hx9Var2;
        Long l5;
        Long airDate2;
        TMDBEpisode tMDBEpisode2;
        Integer num5;
        int i14;
        int i15;
        String str3;
        int i16;
        long j2;
        String airDate3;
        TraktEpisode episode4;
        int i17;
        TraktPlaybackItem traktPlaybackItem8;
        String str4;
        long j3;
        int i18;
        Long l6;
        Integer num6;
        boolean z;
        TraktPlaybackItem traktPlaybackItem9;
        Long l7;
        TMDBEpisode tMDBEpisode3;
        String str5;
        String pausedAt;
        TraktEpisode episode5;
        Integer season2;
        Integer number2;
        Long watchedAt;
        if (continuation instanceof C03131) {
            c03131 = (C03131) continuation;
            int i19 = c03131.label;
            if ((i19 & Integer.MIN_VALUE) != 0) {
                c03131.label = i19 - Integer.MIN_VALUE;
            } else {
                c03131 = new C03131(continuation);
            }
        }
        C03131 c031312 = c03131;
        Object objComputeNextEpisode = c031312.result;
        ck1 ck1Var2 = ck1.a;
        String title2 = "";
        switch (c031312.label) {
            case 0:
                f = 0.0f;
                f2 = NEAR_COMPLETE_PROGRESS;
                s38.b(objComputeNextEpisode);
                TraktAccountRepository traktAccountRepository = this.accountRepository;
                c031312.L$0 = this;
                c031312.L$1 = lastWatchedPerShow;
                c031312.L$2 = traktPlaybackItem;
                c031312.I$0 = i;
                c031312.label = 1;
                Object activeAccount = traktAccountRepository.getActiveAccount(c031312);
                if (activeAccount != ck1Var2) {
                    continueWatchingRepository = this;
                    obj = activeAccount;
                    lastWatchedPerShow2 = lastWatchedPerShow;
                    traktPlaybackItem2 = traktPlaybackItem;
                    i2 = i;
                    TraktAccount traktAccount = (TraktAccount) obj;
                    String str6 = (traktAccount != null || (userSlug = traktAccount.getUserSlug()) == null) ? "" : userSlug;
                    TraktUserItemDao traktUserItemDao = continueWatchingRepository.traktUserItemDao;
                    c031312.L$0 = continueWatchingRepository;
                    c031312.L$1 = lastWatchedPerShow2;
                    c031312.L$2 = traktPlaybackItem2;
                    c031312.I$0 = i2;
                    c031312.label = 2;
                    objFindByTmdbId = traktUserItemDao.findByTmdbId(i2, "HISTORY", "SHOW", str6, c031312);
                    if (objFindByTmdbId != ck1Var2) {
                        i3 = i2;
                        lastWatchedPerShow3 = lastWatchedPerShow2;
                        obj2 = objFindByTmdbId;
                        traktPlaybackItem3 = traktPlaybackItem2;
                        traktUserItem = (TraktUserItem) obj2;
                        lBoxLong = (traktUserItem != null || (traktId = traktUserItem.getTraktId()) == null) ? null : Boxing.boxLong(traktId.intValue());
                        if (traktUserItem == null && (title = traktUserItem.getTitle()) != null) {
                            title2 = title;
                        } else if (traktPlaybackItem3 != null && (show = traktPlaybackItem3.getShow()) != null) {
                            title2 = show.getTitle();
                        }
                        if (traktUserItem != null || (year2 = traktUserItem.getYear()) == null || (year = n89.be(year2)) == null) {
                            year = (traktPlaybackItem3 != null || (show2 = traktPlaybackItem3.getShow()) == null) ? null : show2.getYear();
                        }
                        Long watchedAt2 = lastWatchedPerShow3.getWatchedAt();
                        jLongValue = watchedAt2 == null ? watchedAt2.longValue() : System.currentTimeMillis();
                        int season3 = lastWatchedPerShow3.getSeason();
                        episode = lastWatchedPerShow3.getEpisode();
                        EpisodeWatchStatusDao episodeWatchStatusDao = continueWatchingRepository.episodeWatchStatusDao;
                        c031312.L$0 = continueWatchingRepository;
                        c031312.L$1 = traktPlaybackItem3;
                        c031312.L$2 = lBoxLong;
                        c031312.L$3 = title2;
                        c031312.L$4 = year;
                        c031312.I$0 = i3;
                        c031312.J$0 = jLongValue;
                        c031312.I$1 = season3;
                        c031312.I$2 = episode;
                        c031312.label = 3;
                        highestWatchedEpisode = episodeWatchStatusDao.getHighestWatchedEpisode(i3, c031312);
                        if (highestWatchedEpisode != ck1Var2) {
                            num = year;
                            obj3 = highestWatchedEpisode;
                            traktPlaybackItem4 = traktPlaybackItem3;
                            i4 = season3;
                            episodeWatchStatus = (EpisodeWatchStatus) obj3;
                            if (episodeWatchStatus != null || (episodeWatchStatus.getSeason() <= i4 && (episodeWatchStatus.getSeason() != i4 || episodeWatchStatus.getEpisode() <= episode))) {
                                ck1Var = ck1Var2;
                                TraktPlaybackItem traktPlaybackItem10 = traktPlaybackItem4;
                                l = lBoxLong;
                                i5 = i3;
                                num2 = num;
                                str = title2;
                                traktPlaybackItem5 = traktPlaybackItem10;
                                c031312.L$0 = continueWatchingRepository;
                                c031312.L$1 = traktPlaybackItem5;
                                c031312.L$2 = l;
                                c031312.L$3 = str;
                                c031312.L$4 = num2;
                                c031312.L$5 = null;
                                c031312.L$6 = null;
                                c031312.L$7 = null;
                                c031312.I$0 = i5;
                                c031312.J$0 = jLongValue;
                                c031312.label = 6;
                                objComputeNextEpisode = continueWatchingRepository.computeNextEpisode(i5, i4, episode, c031312);
                                if (objComputeNextEpisode == ck1Var) {
                                    return ck1Var;
                                }
                                l4 = l;
                                j = jLongValue;
                                continueWatchingRepository2 = continueWatchingRepository;
                                int i20 = i5;
                                Integer num7 = num2;
                                String str7 = str;
                                traktPlaybackItem7 = traktPlaybackItem5;
                                hx9Var2 = (hx9) objComputeNextEpisode;
                                if (hx9Var2 != null) {
                                    Float fBoxFloat = traktPlaybackItem7 != null ? Boxing.boxFloat(INSTANCE.normalizeProgress(traktPlaybackItem7.getProgress())) : null;
                                    if (traktPlaybackItem7 == null || fBoxFloat == null || fBoxFloat.floatValue() >= f2 || (episode4 = traktPlaybackItem7.getEpisode()) == null) {
                                        return null;
                                    }
                                    Long id = traktPlaybackItem7.getId();
                                    float fFloatValue = fBoxFloat.floatValue();
                                    long zonedMillisOrNow = ContinueWatchingModelsKt.toZonedMillisOrNow(traktPlaybackItem7.getPausedAt());
                                    Integer season4 = episode4.getSeason();
                                    if (season4 == null) {
                                        return null;
                                    }
                                    int iIntValue2 = season4.intValue();
                                    Integer number3 = episode4.getNumber();
                                    if (number3 != null) {
                                        return new ContinueWatchingItem.Episode(id, fFloatValue, zonedMillisOrNow, l4, i20, str7, num7, iIntValue2, number3.intValue(), episode4.getTitle(), false, 1024, null);
                                    }
                                    return null;
                                }
                                l5 = l4;
                                int iIntValue3 = ((Number) hx9Var2.a).intValue();
                                int iIntValue4 = ((Number) hx9Var2.b).intValue();
                                TMDBEpisode tMDBEpisode4 = (TMDBEpisode) hx9Var2.c;
                                airDate2 = (tMDBEpisode4 == null || (airDate3 = tMDBEpisode4.getAirDate()) == null) ? null : continueWatchingRepository2.parseAirDate(airDate3);
                                if (tMDBEpisode4 != null && (airDate2 == null || airDate2.longValue() > System.currentTimeMillis())) {
                                    tMDBEpisode4.getAirDate();
                                    return null;
                                }
                                EpisodeWatchStatusDao episodeWatchStatusDao2 = continueWatchingRepository2.episodeWatchStatusDao;
                                c031312.L$0 = continueWatchingRepository2;
                                c031312.L$1 = traktPlaybackItem7;
                                c031312.L$2 = l5;
                                c031312.L$3 = str7;
                                c031312.L$4 = num7;
                                c031312.L$5 = tMDBEpisode4;
                                c031312.L$6 = airDate2;
                                c031312.I$0 = i20;
                                c031312.J$0 = j;
                                c031312.I$1 = iIntValue3;
                                c031312.I$2 = iIntValue4;
                                c031312.label = 7;
                                Object objHasEverWatched = episodeWatchStatusDao2.hasEverWatched(i20, iIntValue3, iIntValue4, c031312);
                                if (objHasEverWatched == ck1Var) {
                                    return ck1Var;
                                }
                                tMDBEpisode2 = tMDBEpisode4;
                                objComputeNextEpisode = objHasEverWatched;
                                num5 = num7;
                                long j4 = j;
                                i14 = iIntValue3;
                                i15 = iIntValue4;
                                str3 = str7;
                                i16 = i20;
                                j2 = j4;
                                boolean zBooleanValue = ((Boolean) objComputeNextEpisode).booleanValue();
                                i17 = !zBooleanValue ? 1 : 0;
                                if (traktPlaybackItem7 == null) {
                                    TraktPlaybackItem traktPlaybackItem11 = traktPlaybackItem7;
                                    float fNormalizeProgress = INSTANCE.normalizeProgress(traktPlaybackItem11.getProgress());
                                    traktPlaybackItem8 = (fNormalizeProgress <= f || fNormalizeProgress >= f2) ? null : traktPlaybackItem11;
                                    if (zBooleanValue) {
                                        EpisodeWatchStatusDao episodeWatchStatusDao3 = continueWatchingRepository2.episodeWatchStatusDao;
                                        c031312.L$0 = l5;
                                        c031312.L$1 = str3;
                                        c031312.L$2 = num5;
                                        c031312.L$3 = tMDBEpisode2;
                                        c031312.L$4 = airDate2;
                                        c031312.L$5 = traktPlaybackItem8;
                                        c031312.L$6 = null;
                                        c031312.I$0 = i16;
                                        c031312.J$0 = j2;
                                        c031312.I$1 = i14;
                                        c031312.I$2 = i15;
                                        c031312.I$3 = i17;
                                        c031312.label = 8;
                                        Object episodeStatus = episodeWatchStatusDao3.getEpisodeStatus(i16, i14, i15, c031312);
                                        if (episodeStatus == ck1Var) {
                                            return ck1Var;
                                        }
                                        traktPlaybackItem9 = traktPlaybackItem8;
                                        objComputeNextEpisode = episodeStatus;
                                        l7 = l5;
                                        tMDBEpisode3 = tMDBEpisode2;
                                        str5 = str3;
                                        EpisodeWatchStatus episodeWatchStatus4 = (EpisodeWatchStatus) objComputeNextEpisode;
                                        long jLongValue2 = (episodeWatchStatus4 != null || (watchedAt = episodeWatchStatus4.getWatchedAt()) == null) ? 0L : watchedAt.longValue();
                                        if (j2 > 0 || jLongValue2 <= 0 || j2 - jLongValue2 <= REWATCH_TIMESTAMP_GAP_MS) {
                                            j3 = j2;
                                            i18 = i16;
                                            l6 = l7;
                                            traktPlaybackItem8 = traktPlaybackItem9;
                                            str4 = str5;
                                            num6 = num5;
                                            z = false;
                                        } else {
                                            j3 = j2;
                                            i18 = i16;
                                            l6 = l7;
                                            traktPlaybackItem8 = traktPlaybackItem9;
                                            str4 = str5;
                                            num6 = num5;
                                            z = true;
                                        }
                                        tMDBEpisode2 = tMDBEpisode3;
                                    } else {
                                        str4 = str3;
                                        j3 = j2;
                                        i18 = i16;
                                        l6 = l5;
                                        num6 = num5;
                                        z = false;
                                    }
                                }
                                if (i17 == 0 && traktPlaybackItem8 != null && (episode5 = traktPlaybackItem8.getEpisode()) != null && (season2 = episode5.getSeason()) != null && season2.intValue() == i14 && (number2 = episode5.getNumber()) != null && number2.intValue() == i15) {
                                    TraktEpisode episode6 = traktPlaybackItem8.getEpisode();
                                    if (episode6 == null) {
                                        return null;
                                    }
                                    float fNormalizeProgress2 = INSTANCE.normalizeProgress(traktPlaybackItem8.getProgress());
                                    Long id2 = traktPlaybackItem8.getId();
                                    long zonedMillisOrNow2 = ContinueWatchingModelsKt.toZonedMillisOrNow(traktPlaybackItem8.getPausedAt());
                                    Integer season5 = episode6.getSeason();
                                    if (season5 == null) {
                                        return null;
                                    }
                                    int iIntValue5 = season5.intValue();
                                    Integer number4 = episode6.getNumber();
                                    if (number4 != null) {
                                        return new ContinueWatchingItem.Episode(id2, fNormalizeProgress2, zonedMillisOrNow2, l6, i18, str4, num6, iIntValue5, number4.intValue(), episode6.getTitle(), false, 1024, null);
                                    }
                                    return null;
                                }
                                if (i17 != 0) {
                                    Iterator it = st.w(new Long[]{Boxing.boxLong(j3), airDate2, (traktPlaybackItem8 == null || (pausedAt = traktPlaybackItem8.getPausedAt()) == null) ? null : Boxing.boxLong(ContinueWatchingModelsKt.toZonedMillisOrNow(pausedAt))}).iterator();
                                    if (!it.hasNext()) {
                                        throw new NoSuchElementException();
                                    }
                                    Comparable comparable = (Comparable) it.next();
                                    while (it.hasNext()) {
                                        Comparable comparable2 = (Comparable) it.next();
                                        if (comparable.compareTo(comparable2) < 0) {
                                            comparable = comparable2;
                                        }
                                    }
                                    return new ContinueWatchingItem.NextEpisode(null, 0.0f, ((Number) comparable).longValue(), l6, i18, str4, num6, i14, i15, tMDBEpisode2 != null ? tMDBEpisode2.getName() : null, airDate2, false, 2048, null);
                                }
                                int i21 = i15;
                                int i22 = i14;
                                Long l8 = airDate2;
                                if (traktPlaybackItem8 == null) {
                                    if (z) {
                                        return new ContinueWatchingItem.NextEpisode(null, 0.0f, j3, l6, i18, str4, num6, i22, i21, tMDBEpisode2 != null ? tMDBEpisode2.getName() : null, l8, true);
                                    }
                                    return null;
                                }
                                TraktEpisode episode7 = traktPlaybackItem8.getEpisode();
                                if (episode7 == null) {
                                    return null;
                                }
                                float fNormalizeProgress3 = INSTANCE.normalizeProgress(traktPlaybackItem8.getProgress());
                                episode7.getSeason();
                                episode7.getNumber();
                                Long id3 = traktPlaybackItem8.getId();
                                long zonedMillisOrNow3 = ContinueWatchingModelsKt.toZonedMillisOrNow(traktPlaybackItem8.getPausedAt());
                                Integer season6 = episode7.getSeason();
                                if (season6 == null) {
                                    return null;
                                }
                                int iIntValue6 = season6.intValue();
                                Integer number5 = episode7.getNumber();
                                if (number5 != null) {
                                    return new ContinueWatchingItem.Episode(id3, fNormalizeProgress3, zonedMillisOrNow3, l6, i18, str4, num6, iIntValue6, number5.intValue(), episode7.getTitle(), i17 == 0);
                                }
                                return null;
                            }
                            int season7 = episodeWatchStatus.getSeason();
                            int episode8 = episodeWatchStatus.getEpisode();
                            c031312.L$0 = continueWatchingRepository;
                            c031312.L$1 = traktPlaybackItem4;
                            c031312.L$2 = lBoxLong;
                            c031312.L$3 = title2;
                            c031312.L$4 = num;
                            c031312.L$5 = episodeWatchStatus;
                            c031312.I$0 = i3;
                            c031312.J$0 = jLongValue;
                            c031312.I$1 = i4;
                            c031312.I$2 = episode;
                            c031312.label = 4;
                            Object objComputeNextEpisode2 = continueWatchingRepository.computeNextEpisode(i3, season7, episode8, c031312);
                            if (objComputeNextEpisode2 != ck1Var2) {
                                obj4 = objComputeNextEpisode2;
                                i6 = i3;
                                i7 = episode;
                                episodeWatchStatus2 = episodeWatchStatus;
                                num3 = num;
                                i8 = i4;
                                traktPlaybackItem6 = traktPlaybackItem4;
                                l = lBoxLong;
                                hx9Var = (hx9) obj4;
                                if (hx9Var == null) {
                                    iIntValue = ((Number) hx9Var.a).intValue();
                                    int iIntValue7 = ((Number) hx9Var.b).intValue();
                                    TMDBEpisode tMDBEpisode5 = (TMDBEpisode) hx9Var.c;
                                    Long airDate4 = (tMDBEpisode5 == null || (airDate = tMDBEpisode5.getAirDate()) == null) ? null : continueWatchingRepository.parseAirDate(airDate);
                                    if (tMDBEpisode5 == null || (airDate4 != null && airDate4.longValue() <= System.currentTimeMillis())) {
                                        i9 = iIntValue7;
                                        i10 = 1;
                                    } else {
                                        i9 = iIntValue7;
                                        i10 = 0;
                                    }
                                    EpisodeWatchStatusDao episodeWatchStatusDao4 = continueWatchingRepository.episodeWatchStatusDao;
                                    c031312.L$0 = continueWatchingRepository;
                                    c031312.L$1 = traktPlaybackItem6;
                                    c031312.L$2 = l;
                                    c031312.L$3 = title2;
                                    c031312.L$4 = num3;
                                    c031312.L$5 = episodeWatchStatus2;
                                    c031312.L$6 = tMDBEpisode5;
                                    c031312.L$7 = airDate4;
                                    c031312.I$0 = i6;
                                    c031312.J$0 = jLongValue;
                                    c031312.I$1 = i8;
                                    c031312.I$2 = i7;
                                    c031312.I$3 = iIntValue;
                                    int i23 = i9;
                                    c031312.I$4 = i23;
                                    Long l9 = airDate4;
                                    int i24 = i10;
                                    c031312.I$5 = i24;
                                    c031312.label = 5;
                                    Object objHasEverWatched2 = episodeWatchStatusDao4.hasEverWatched(i6, iIntValue, i23, c031312);
                                    ck1Var = ck1Var2;
                                    if (objHasEverWatched2 == ck1Var) {
                                        return ck1Var;
                                    }
                                    EpisodeWatchStatus episodeWatchStatus5 = episodeWatchStatus2;
                                    i11 = i23;
                                    obj5 = objHasEverWatched2;
                                    episodeWatchStatus3 = episodeWatchStatus5;
                                    l2 = l9;
                                    i12 = i6;
                                    str2 = title2;
                                    l3 = l;
                                    tMDBEpisode = tMDBEpisode5;
                                    traktPlaybackItem5 = traktPlaybackItem6;
                                    i13 = i24;
                                    num4 = num3;
                                    boolean zBooleanValue2 = ((Boolean) obj5).booleanValue();
                                    if (i13 == 0 && !zBooleanValue2) {
                                        episodeWatchStatus3.getSeason();
                                        episodeWatchStatus3.getEpisode();
                                        if (traktPlaybackItem5 != null) {
                                            float fNormalizeProgress4 = INSTANCE.normalizeProgress(traktPlaybackItem5.getProgress());
                                            if (fNormalizeProgress4 <= f || fNormalizeProgress4 >= f2 || (episode2 = traktPlaybackItem5.getEpisode()) == null || (season = episode2.getSeason()) == null || season.intValue() != iIntValue || (episode3 = traktPlaybackItem5.getEpisode()) == null || (number = episode3.getNumber()) == null || number.intValue() != i11) {
                                                traktPlaybackItem5 = null;
                                            }
                                        }
                                        if (traktPlaybackItem5 == null) {
                                            if (l2 != null) {
                                                jLongValue = l2.longValue();
                                            }
                                            return new ContinueWatchingItem.NextEpisode(null, 0.0f, jLongValue, l3, i12, str2, num4, iIntValue, i11, tMDBEpisode != null ? tMDBEpisode.getName() : null, l2, false, 2048, null);
                                        }
                                        TraktEpisode episode9 = traktPlaybackItem5.getEpisode();
                                        if (episode9 == null) {
                                            return null;
                                        }
                                        float fNormalizeProgress5 = INSTANCE.normalizeProgress(traktPlaybackItem5.getProgress());
                                        Long id4 = traktPlaybackItem5.getId();
                                        long zonedMillisOrNow4 = ContinueWatchingModelsKt.toZonedMillisOrNow(traktPlaybackItem5.getPausedAt());
                                        Integer season8 = episode9.getSeason();
                                        if (season8 == null) {
                                            return null;
                                        }
                                        int iIntValue8 = season8.intValue();
                                        Integer number6 = episode9.getNumber();
                                        if (number6 != null) {
                                            return new ContinueWatchingItem.Episode(id4, fNormalizeProgress5, zonedMillisOrNow4, l3, i12, str2, num4, iIntValue8, number6.intValue(), episode9.getTitle(), false, 1024, null);
                                        }
                                        return null;
                                    }
                                    episode = i7;
                                    i4 = i8;
                                    l = l3;
                                    i5 = i12;
                                    str = str2;
                                    num2 = num4;
                                    c031312.L$0 = continueWatchingRepository;
                                    c031312.L$1 = traktPlaybackItem5;
                                    c031312.L$2 = l;
                                    c031312.L$3 = str;
                                    c031312.L$4 = num2;
                                    c031312.L$5 = null;
                                    c031312.L$6 = null;
                                    c031312.L$7 = null;
                                    c031312.I$0 = i5;
                                    c031312.J$0 = jLongValue;
                                    c031312.label = 6;
                                    objComputeNextEpisode = continueWatchingRepository.computeNextEpisode(i5, i4, episode, c031312);
                                    if (objComputeNextEpisode == ck1Var) {
                                    }
                                } else {
                                    ck1Var = ck1Var2;
                                    String str8 = title2;
                                    traktPlaybackItem5 = traktPlaybackItem6;
                                    i4 = i8;
                                    str = str8;
                                    i5 = i6;
                                    episode = i7;
                                    num2 = num3;
                                    c031312.L$0 = continueWatchingRepository;
                                    c031312.L$1 = traktPlaybackItem5;
                                    c031312.L$2 = l;
                                    c031312.L$3 = str;
                                    c031312.L$4 = num2;
                                    c031312.L$5 = null;
                                    c031312.L$6 = null;
                                    c031312.L$7 = null;
                                    c031312.I$0 = i5;
                                    c031312.J$0 = jLongValue;
                                    c031312.label = 6;
                                    objComputeNextEpisode = continueWatchingRepository.computeNextEpisode(i5, i4, episode, c031312);
                                    if (objComputeNextEpisode == ck1Var) {
                                    }
                                }
                            }
                        }
                    }
                }
                return ck1Var2;
            case 1:
                obj = objComputeNextEpisode;
                f = 0.0f;
                f2 = NEAR_COMPLETE_PROGRESS;
                int i25 = c031312.I$0;
                TraktPlaybackItem traktPlaybackItem12 = (TraktPlaybackItem) c031312.L$2;
                LastWatchedPerShow lastWatchedPerShow4 = (LastWatchedPerShow) c031312.L$1;
                ContinueWatchingRepository continueWatchingRepository3 = (ContinueWatchingRepository) c031312.L$0;
                s38.b(obj);
                i2 = i25;
                lastWatchedPerShow2 = lastWatchedPerShow4;
                traktPlaybackItem2 = traktPlaybackItem12;
                continueWatchingRepository = continueWatchingRepository3;
                TraktAccount traktAccount2 = (TraktAccount) obj;
                if (traktAccount2 != null) {
                    TraktUserItemDao traktUserItemDao2 = continueWatchingRepository.traktUserItemDao;
                    c031312.L$0 = continueWatchingRepository;
                    c031312.L$1 = lastWatchedPerShow2;
                    c031312.L$2 = traktPlaybackItem2;
                    c031312.I$0 = i2;
                    c031312.label = 2;
                    objFindByTmdbId = traktUserItemDao2.findByTmdbId(i2, "HISTORY", "SHOW", str6, c031312);
                    if (objFindByTmdbId != ck1Var2) {
                    }
                    return ck1Var2;
                }
                if (i17 == 0) {
                }
                if (i17 != 0) {
                }
                break;
            case 2:
                f = 0.0f;
                f2 = NEAR_COMPLETE_PROGRESS;
                int i26 = c031312.I$0;
                traktPlaybackItem3 = (TraktPlaybackItem) c031312.L$2;
                lastWatchedPerShow3 = (LastWatchedPerShow) c031312.L$1;
                ContinueWatchingRepository continueWatchingRepository4 = (ContinueWatchingRepository) c031312.L$0;
                s38.b(objComputeNextEpisode);
                i3 = i26;
                continueWatchingRepository = continueWatchingRepository4;
                obj2 = objComputeNextEpisode;
                traktUserItem = (TraktUserItem) obj2;
                if (traktUserItem != null) {
                    if (traktUserItem == null) {
                        if (traktPlaybackItem3 != null) {
                            title2 = show.getTitle();
                        }
                        if (traktUserItem != null) {
                            if (traktPlaybackItem3 != null) {
                                Long watchedAt22 = lastWatchedPerShow3.getWatchedAt();
                                if (watchedAt22 == null) {
                                }
                                int season32 = lastWatchedPerShow3.getSeason();
                                episode = lastWatchedPerShow3.getEpisode();
                                EpisodeWatchStatusDao episodeWatchStatusDao5 = continueWatchingRepository.episodeWatchStatusDao;
                                c031312.L$0 = continueWatchingRepository;
                                c031312.L$1 = traktPlaybackItem3;
                                c031312.L$2 = lBoxLong;
                                c031312.L$3 = title2;
                                c031312.L$4 = year;
                                c031312.I$0 = i3;
                                c031312.J$0 = jLongValue;
                                c031312.I$1 = season32;
                                c031312.I$2 = episode;
                                c031312.label = 3;
                                highestWatchedEpisode = episodeWatchStatusDao5.getHighestWatchedEpisode(i3, c031312);
                                if (highestWatchedEpisode != ck1Var2) {
                                }
                                return ck1Var2;
                            }
                        }
                    }
                }
                if (i17 == 0) {
                }
                if (i17 != 0) {
                }
                break;
            case 3:
                f = 0.0f;
                f2 = NEAR_COMPLETE_PROGRESS;
                int i27 = c031312.I$2;
                i4 = c031312.I$1;
                long j5 = c031312.J$0;
                i3 = c031312.I$0;
                num = (Integer) c031312.L$4;
                String str9 = (String) c031312.L$3;
                Long l10 = (Long) c031312.L$2;
                traktPlaybackItem4 = (TraktPlaybackItem) c031312.L$1;
                continueWatchingRepository = (ContinueWatchingRepository) c031312.L$0;
                s38.b(objComputeNextEpisode);
                jLongValue = j5;
                lBoxLong = l10;
                episode = i27;
                title2 = str9;
                obj3 = objComputeNextEpisode;
                episodeWatchStatus = (EpisodeWatchStatus) obj3;
                if (episodeWatchStatus != null) {
                }
                ck1Var = ck1Var2;
                TraktPlaybackItem traktPlaybackItem102 = traktPlaybackItem4;
                l = lBoxLong;
                i5 = i3;
                num2 = num;
                str = title2;
                traktPlaybackItem5 = traktPlaybackItem102;
                c031312.L$0 = continueWatchingRepository;
                c031312.L$1 = traktPlaybackItem5;
                c031312.L$2 = l;
                c031312.L$3 = str;
                c031312.L$4 = num2;
                c031312.L$5 = null;
                c031312.L$6 = null;
                c031312.L$7 = null;
                c031312.I$0 = i5;
                c031312.J$0 = jLongValue;
                c031312.label = 6;
                objComputeNextEpisode = continueWatchingRepository.computeNextEpisode(i5, i4, episode, c031312);
                if (objComputeNextEpisode == ck1Var) {
                }
                break;
            case 4:
                f = 0.0f;
                f2 = NEAR_COMPLETE_PROGRESS;
                int i28 = c031312.I$2;
                int i29 = c031312.I$1;
                long j6 = c031312.J$0;
                int i30 = c031312.I$0;
                EpisodeWatchStatus episodeWatchStatus6 = (EpisodeWatchStatus) c031312.L$5;
                Integer num8 = (Integer) c031312.L$4;
                title2 = (String) c031312.L$3;
                l = (Long) c031312.L$2;
                TraktPlaybackItem traktPlaybackItem13 = (TraktPlaybackItem) c031312.L$1;
                ContinueWatchingRepository continueWatchingRepository5 = (ContinueWatchingRepository) c031312.L$0;
                s38.b(objComputeNextEpisode);
                i8 = i29;
                traktPlaybackItem6 = traktPlaybackItem13;
                continueWatchingRepository = continueWatchingRepository5;
                jLongValue = j6;
                episodeWatchStatus2 = episodeWatchStatus6;
                i6 = i30;
                num3 = num8;
                i7 = i28;
                obj4 = objComputeNextEpisode;
                hx9Var = (hx9) obj4;
                if (hx9Var == null) {
                }
                break;
            case 5:
                f = 0.0f;
                f2 = NEAR_COMPLETE_PROGRESS;
                i13 = c031312.I$5;
                i11 = c031312.I$4;
                iIntValue = c031312.I$3;
                i7 = c031312.I$2;
                i8 = c031312.I$1;
                long j7 = c031312.J$0;
                int i31 = c031312.I$0;
                Long l11 = (Long) c031312.L$7;
                TMDBEpisode tMDBEpisode6 = (TMDBEpisode) c031312.L$6;
                EpisodeWatchStatus episodeWatchStatus7 = (EpisodeWatchStatus) c031312.L$5;
                num3 = (Integer) c031312.L$4;
                String str10 = (String) c031312.L$3;
                Long l12 = (Long) c031312.L$2;
                TraktPlaybackItem traktPlaybackItem14 = (TraktPlaybackItem) c031312.L$1;
                ContinueWatchingRepository continueWatchingRepository6 = (ContinueWatchingRepository) c031312.L$0;
                s38.b(objComputeNextEpisode);
                str2 = str10;
                l3 = l12;
                i12 = i31;
                l2 = l11;
                tMDBEpisode = tMDBEpisode6;
                continueWatchingRepository = continueWatchingRepository6;
                obj5 = objComputeNextEpisode;
                traktPlaybackItem5 = traktPlaybackItem14;
                ck1Var = ck1Var2;
                episodeWatchStatus3 = episodeWatchStatus7;
                jLongValue = j7;
                num4 = num3;
                boolean zBooleanValue22 = ((Boolean) obj5).booleanValue();
                if (i13 == 0) {
                }
                episode = i7;
                i4 = i8;
                l = l3;
                i5 = i12;
                str = str2;
                num2 = num4;
                c031312.L$0 = continueWatchingRepository;
                c031312.L$1 = traktPlaybackItem5;
                c031312.L$2 = l;
                c031312.L$3 = str;
                c031312.L$4 = num2;
                c031312.L$5 = null;
                c031312.L$6 = null;
                c031312.L$7 = null;
                c031312.I$0 = i5;
                c031312.J$0 = jLongValue;
                c031312.label = 6;
                objComputeNextEpisode = continueWatchingRepository.computeNextEpisode(i5, i4, episode, c031312);
                if (objComputeNextEpisode == ck1Var) {
                }
                break;
            case 6:
                f = 0.0f;
                f2 = NEAR_COMPLETE_PROGRESS;
                j = c031312.J$0;
                i5 = c031312.I$0;
                num2 = (Integer) c031312.L$4;
                str = (String) c031312.L$3;
                Long l13 = (Long) c031312.L$2;
                traktPlaybackItem5 = (TraktPlaybackItem) c031312.L$1;
                ContinueWatchingRepository continueWatchingRepository7 = (ContinueWatchingRepository) c031312.L$0;
                s38.b(objComputeNextEpisode);
                l4 = l13;
                continueWatchingRepository2 = continueWatchingRepository7;
                ck1Var = ck1Var2;
                int i202 = i5;
                Integer num72 = num2;
                String str72 = str;
                traktPlaybackItem7 = traktPlaybackItem5;
                hx9Var2 = (hx9) objComputeNextEpisode;
                if (hx9Var2 != null) {
                }
                break;
            case 7:
                i15 = c031312.I$2;
                i14 = c031312.I$1;
                j2 = c031312.J$0;
                i16 = c031312.I$0;
                airDate2 = (Long) c031312.L$6;
                tMDBEpisode2 = (TMDBEpisode) c031312.L$5;
                num5 = (Integer) c031312.L$4;
                f = 0.0f;
                String str11 = (String) c031312.L$3;
                f2 = NEAR_COMPLETE_PROGRESS;
                l5 = (Long) c031312.L$2;
                traktPlaybackItem7 = (TraktPlaybackItem) c031312.L$1;
                continueWatchingRepository2 = (ContinueWatchingRepository) c031312.L$0;
                s38.b(objComputeNextEpisode);
                str3 = str11;
                ck1Var = ck1Var2;
                boolean zBooleanValue3 = ((Boolean) objComputeNextEpisode).booleanValue();
                i17 = !zBooleanValue3 ? 1 : 0;
                if (traktPlaybackItem7 == null) {
                }
                if (i17 == 0) {
                }
                if (i17 != 0) {
                }
                break;
            case 8:
                i17 = c031312.I$3;
                i15 = c031312.I$2;
                i14 = c031312.I$1;
                j2 = c031312.J$0;
                i16 = c031312.I$0;
                traktPlaybackItem9 = (TraktPlaybackItem) c031312.L$5;
                airDate2 = (Long) c031312.L$4;
                tMDBEpisode3 = (TMDBEpisode) c031312.L$3;
                num5 = (Integer) c031312.L$2;
                str5 = (String) c031312.L$1;
                l7 = (Long) c031312.L$0;
                s38.b(objComputeNextEpisode);
                EpisodeWatchStatus episodeWatchStatus42 = (EpisodeWatchStatus) objComputeNextEpisode;
                if (episodeWatchStatus42 != null) {
                    if (j2 > 0) {
                        j3 = j2;
                        i18 = i16;
                        l6 = l7;
                        traktPlaybackItem8 = traktPlaybackItem9;
                        str4 = str5;
                        num6 = num5;
                        z = false;
                        tMDBEpisode2 = tMDBEpisode3;
                    }
                }
                if (i17 == 0) {
                }
                if (i17 != 0) {
                }
                break;
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Object processShows(List<TraktPlaybackItem> list, List<LastWatchedPerShow> list2, Continuation<? super List<? extends ContinueWatchingItem>> continuation) {
        return bk1.c(new C03142(list2, list, this, null), continuation);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Can't wrap try/catch for region: R(7:(1:83)|30|80|31|(1:34)|33|72) */
    /* JADX WARN: Code restructure failed: missing block: B:37:0x0101, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:38:0x0102, code lost:
    
        r7 = r8;
        r15 = r11;
     */
    /* JADX WARN: Code restructure failed: missing block: B:39:0x0104, code lost:
    
        r8 = r1;
        r1 = r13;
        r5 = r12;
        r12 = r4;
        r4 = r14;
     */
    /* JADX WARN: Code restructure failed: missing block: B:51:0x0184, code lost:
    
        if (r4 < r8) goto L52;
     */
    /* JADX WARN: Code restructure failed: missing block: B:52:0x0186, code lost:
    
        r4 = r4 + 1;
        r11 = r3;
        r2 = ((long) r4) * r12;
        android.util.Log.w(com.strmr.ps.data.repository.ContinueWatchingRepository.TAG, "Rate limited (429), retrying in " + r2 + "ms (attempt " + r4 + ")");
        r1.L$0 = r7;
        r1.L$1 = r9;
        r1.I$0 = r8;
        r1.J$0 = r12;
        r1.I$1 = r5;
        r1.I$2 = r14;
        r1.label = 2;
     */
    /* JADX WARN: Code restructure failed: missing block: B:53:0x01bc, code lost:
    
        if (defpackage.h32.a(r2, r1) == r11) goto L89;
     */
    /* JADX WARN: Code restructure failed: missing block: B:55:0x01c0, code lost:
    
        r4 = r14;
        r14 = r9;
     */
    /* JADX WARN: Code restructure failed: missing block: B:59:0x01cf, code lost:
    
        r11 = r3;
        kotlin.coroutines.jvm.internal.Boxing.boxInt(android.util.Log.w(com.strmr.ps.data.repository.ContinueWatchingRepository.TAG, "Rate limited (429) after " + (r8 + 1) + " attempts"));
     */
    /* JADX WARN: Code restructure failed: missing block: B:60:0x01ef, code lost:
    
        r11 = r3;
        r2 = r0.code();
     */
    /* JADX WARN: Code restructure failed: missing block: B:61:0x01f7, code lost:
    
        if (400 > r2) goto L69;
     */
    /* JADX WARN: Code restructure failed: missing block: B:64:0x01fd, code lost:
    
        r0.code();
        r0.message();
     */
    /* JADX WARN: Code restructure failed: missing block: B:65:0x0209, code lost:
    
        if (r0.code() == 404) goto L66;
     */
    /* JADX WARN: Code restructure failed: missing block: B:67:0x020d, code lost:
    
        r7.invoke();
     */
    /* JADX WARN: Code restructure failed: missing block: B:68:0x0210, code lost:
    
        return r25;
     */
    /* JADX WARN: Code restructure failed: missing block: B:69:0x0211, code lost:
    
        if (r4 < r8) goto L70;
     */
    /* JADX WARN: Code restructure failed: missing block: B:70:0x0213, code lost:
    
        r0.code();
        r1.L$0 = r7;
        r1.L$1 = r9;
        r1.I$0 = r8;
        r1.J$0 = r12;
        r1.I$1 = r5;
        r1.I$2 = r14;
        r1.label = 3;
     */
    /* JADX WARN: Code restructure failed: missing block: B:71:0x0229, code lost:
    
        if (defpackage.h32.a(r12, r1) == r11) goto L88;
     */
    /* JADX WARN: Code restructure failed: missing block: B:73:0x022c, code lost:
    
        r4 = r14;
        r14 = r9;
     */
    /* JADX WARN: Code restructure failed: missing block: B:75:0x0230, code lost:
    
        kotlin.coroutines.jvm.internal.Boxing.boxInt(android.util.Log.w(com.strmr.ps.data.repository.ContinueWatchingRepository.TAG, "API call failed after " + (r8 + 1) + " attempts: HTTP " + r0.code()));
     */
    /* JADX WARN: Code restructure failed: missing block: B:88:?, code lost:
    
        return r11;
     */
    /* JADX WARN: Code restructure failed: missing block: B:89:?, code lost:
    
        return r11;
     */
    /* JADX WARN: Removed duplicated region for block: B:41:0x0110  */
    /* JADX WARN: Removed duplicated region for block: B:46:0x0142  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x0184  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x01ef  */
    /* JADX WARN: Removed duplicated region for block: B:79:0x0266 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    /* JADX WARN: Removed duplicated region for block: B:83:0x00da A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:44:0x0129 -> B:45:0x0130). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:46:0x0142 -> B:77:0x025b). Please report as a decompilation issue!!! */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final <T> Object retryApiCall(int i, long j, qq3<e6a> qq3Var, sq3<? super Continuation<? super T>, ? extends Object> sq3Var, Continuation<? super T> continuation) {
        C03161 c03161;
        Object obj;
        qq3<e6a> qq3Var2;
        sq3<? super Continuation<? super T>, ? extends Object> sq3Var2;
        int i2;
        C03161 c031612;
        int i3;
        int i4;
        long j2;
        int i5;
        int i6;
        long j3;
        int i7;
        sq3<? super Continuation<? super T>, ? extends Object> sq3Var3;
        int i8;
        Exception e;
        int i9;
        ck1 ck1Var;
        long j4;
        int i10;
        qq3<e6a> qq3Var3;
        int i11;
        int i12;
        int i13;
        HttpException e2;
        if (continuation instanceof C03161) {
            c03161 = (C03161) continuation;
            int i14 = c03161.label;
            if ((i14 & Integer.MIN_VALUE) != 0) {
                c03161.label = i14 - Integer.MIN_VALUE;
            } else {
                c03161 = new C03161(continuation);
            }
        }
        Object obj2 = c03161.result;
        ck1 ck1Var2 = ck1.a;
        int i15 = c03161.label;
        int i16 = 4;
        int i17 = 1;
        try {
            if (i15 == 0) {
                obj = null;
                s38.b(obj2);
                qq3Var2 = qq3Var;
                sq3Var2 = sq3Var;
                i2 = i + 1;
                c031612 = c03161;
                i3 = 0;
                i4 = i;
                j2 = j;
                if (i3 < i2) {
                }
            } else if (i15 == 1) {
                obj = null;
                i8 = c03161.I$3;
                int i18 = c03161.I$2;
                int i19 = c03161.I$1;
                j4 = c03161.J$0;
                int i20 = c03161.I$0;
                sq3<? super Continuation<? super T>, ? extends Object> sq3Var4 = (sq3) c03161.L$1;
                qq3<e6a> qq3Var4 = (qq3) c03161.L$0;
                try {
                    s38.b(obj2);
                    return obj2;
                } catch (HttpException e3) {
                    e2 = e3;
                    i3 = i18;
                    i11 = i19;
                    i10 = i20;
                    qq3Var3 = qq3Var4;
                    sq3Var2 = sq3Var4;
                    i13 = 1;
                    i9 = i13;
                    if (e2.code() != 429) {
                    }
                    long j5 = j4;
                    i2 = i11;
                    j2 = j5;
                    c031612 = c03161;
                    i4 = i10;
                    qq3Var2 = qq3Var3;
                    i3++;
                    ck1Var2 = ck1Var;
                    i16 = 4;
                    i17 = i9;
                    if (i3 < i2) {
                    }
                } catch (Exception e4) {
                    e = e4;
                    i3 = i18;
                    sq3Var3 = sq3Var4;
                    i5 = 1;
                    j3 = j4;
                    i6 = i20;
                    i7 = i19;
                    qq3Var2 = qq3Var4;
                    if (i8 >= i6) {
                    }
                }
            } else if (i15 == 2) {
                obj = null;
                i12 = c03161.I$2;
                i11 = c03161.I$1;
                j4 = c03161.J$0;
                i10 = c03161.I$0;
                sq3<? super Continuation<? super T>, ? extends Object> sq3Var5 = (sq3) c03161.L$1;
                qq3<e6a> qq3Var5 = (qq3) c03161.L$0;
                s38.b(obj2);
                i9 = 1;
                qq3Var3 = qq3Var5;
                ck1Var = ck1Var2;
                sq3Var2 = sq3Var5;
                i3 = i12;
                long j6 = j4;
                c031612 = c03161;
                i2 = i11;
                i4 = i10;
                j2 = j6;
                qq3Var2 = qq3Var3;
                i3++;
                ck1Var2 = ck1Var;
                i16 = 4;
                i17 = i9;
                if (i3 < i2) {
                }
            } else {
                if (i15 != 3) {
                    if (i15 != 4) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    int i21 = c03161.I$2;
                    i2 = c03161.I$1;
                    long j7 = c03161.J$0;
                    int i22 = c03161.I$0;
                    obj = null;
                    sq3Var3 = (sq3) c03161.L$1;
                    qq3Var2 = (qq3) c03161.L$0;
                    s38.b(obj2);
                    int i23 = i22;
                    i5 = 1;
                    ck1Var = ck1Var2;
                    sq3Var2 = sq3Var3;
                    i9 = i5;
                    C03161 c031613 = c03161;
                    i4 = i23;
                    long j8 = j7;
                    c031612 = c031613;
                    i3 = i21;
                    j2 = j8;
                    i3++;
                    ck1Var2 = ck1Var;
                    i16 = 4;
                    i17 = i9;
                    if (i3 < i2) {
                        return obj;
                    }
                    try {
                        try {
                        } catch (HttpException e5) {
                            e2 = e5;
                            i13 = i17;
                            qq3Var3 = qq3Var2;
                        }
                    } catch (Exception e6) {
                        e = e6;
                        C03161 c031614 = c031612;
                        i6 = i4;
                        c03161 = c031614;
                        i5 = i17;
                        long j9 = j2;
                        sq3Var3 = sq3Var2;
                        i7 = i2;
                        i8 = i3;
                        j3 = j9;
                        if (i8 >= i6) {
                            e.getMessage();
                            c03161.L$0 = qq3Var2;
                            c03161.L$1 = sq3Var3;
                            c03161.I$0 = i6;
                            c03161.J$0 = j3;
                            int i24 = i7;
                            c03161.I$1 = i24;
                            c03161.I$2 = i3;
                            c03161.label = i16;
                            if (h32.a(j3, c03161) != ck1Var2) {
                                i23 = i6;
                                i2 = i24;
                                i21 = i3;
                                j7 = j3;
                                ck1Var = ck1Var2;
                                sq3Var2 = sq3Var3;
                                i9 = i5;
                                C03161 c0316132 = c03161;
                                i4 = i23;
                                long j82 = j7;
                                c031612 = c0316132;
                                i3 = i21;
                                j2 = j82;
                                i3++;
                                ck1Var2 = ck1Var;
                                i16 = 4;
                                i17 = i9;
                                if (i3 < i2) {
                                }
                            }
                            return ck1Var2;
                        }
                        int i25 = i7;
                        Boxing.boxInt(Log.w(TAG, "API call failed after " + (i6 + 1) + " attempts: " + e.getMessage()));
                        int i26 = i6;
                        c031612 = c03161;
                        i4 = i26;
                        sq3Var2 = sq3Var3;
                        i9 = i5;
                        long j10 = j3;
                        ck1Var = ck1Var2;
                        i2 = i25;
                        j2 = j10;
                        i3++;
                        ck1Var2 = ck1Var;
                        i16 = 4;
                        i17 = i9;
                        if (i3 < i2) {
                        }
                    }
                    c031612.L$0 = qq3Var2;
                    c031612.L$1 = sq3Var2;
                    c031612.I$0 = i4;
                    c031612.J$0 = j2;
                    c031612.I$1 = i2;
                    c031612.I$2 = i3;
                    c031612.I$3 = i3;
                    c031612.label = i17;
                    Object objInvoke = sq3Var2.invoke(c031612);
                    if (objInvoke != ck1Var2) {
                        return objInvoke;
                    }
                    return ck1Var2;
                }
                obj = null;
                i12 = c03161.I$2;
                i11 = c03161.I$1;
                j4 = c03161.J$0;
                i10 = c03161.I$0;
                sq3<? super Continuation<? super T>, ? extends Object> sq3Var6 = (sq3) c03161.L$1;
                qq3<e6a> qq3Var6 = (qq3) c03161.L$0;
                s38.b(obj2);
                i9 = 1;
                qq3Var3 = qq3Var6;
                ck1Var = ck1Var2;
                sq3Var2 = sq3Var6;
                i3 = i12;
                long j62 = j4;
                c031612 = c03161;
                i2 = i11;
                i4 = i10;
                j2 = j62;
                qq3Var2 = qq3Var3;
                i3++;
                ck1Var2 = ck1Var;
                i16 = 4;
                i17 = i9;
                if (i3 < i2) {
                }
            }
        } catch (CancellationException e7) {
            throw e7;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static /* synthetic */ Object retryApiCall$default(ContinueWatchingRepository continueWatchingRepository, int i, long j, qq3 qq3Var, sq3 sq3Var, Continuation continuation, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            i = 1;
        }
        if ((i2 & 2) != 0) {
            j = 500;
        }
        if ((i2 & 4) != 0) {
            qq3Var = null;
        }
        return continueWatchingRepository.retryApiCall(i, j, qq3Var, sq3Var, continuation);
    }

    private final void saveToDiskCache(List<ContentItem> items) {
        try {
            String json = this.gson.toJson(items);
            File diskCacheFile = getDiskCacheFile();
            cr4.d(json);
            ez2.c(diskCacheFile, json, bz0.a);
            items.size();
        } catch (Exception e) {
            Log.w(TAG, "Failed to save disk cache", e);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final SharedPreferences seasonNotFoundPrefs_delegate$lambda$3(ContinueWatchingRepository continueWatchingRepository) {
        return continueWatchingRepository.context.getSharedPreferences(SEASON_NOT_FOUND_PREFS, 0);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Code restructure failed: missing block: B:113:0x02a8, code lost:
    
        if (com.strmr.ps.data.repository.SyncMetadataRepository.markSynced$default(r15, com.strmr.ps.data.repository.TraktSyncRepository.SYNC_KEY_EPISODE_WATCH_STATUS, null, r9, 2, null) == r3) goto L114;
     */
    /* JADX WARN: Removed duplicated region for block: B:103:0x024b A[Catch: Exception -> 0x003a, CancellationException -> 0x003d, TryCatch #2 {CancellationException -> 0x003d, Exception -> 0x003a, blocks: (B:13:0x0035, B:115:0x02ab, B:20:0x0054, B:104:0x0259, B:106:0x025f, B:109:0x027b, B:111:0x0287, B:112:0x028a, B:23:0x006d, B:96:0x021c, B:98:0x0222, B:101:0x0242, B:103:0x024b, B:26:0x0086, B:90:0x01f0, B:92:0x01f6, B:95:0x0217, B:29:0x0097, B:85:0x01b6, B:86:0x01c7, B:88:0x01cd, B:89:0x01df, B:32:0x00a0, B:39:0x00bf, B:41:0x00c9, B:43:0x00ce, B:45:0x00d4, B:47:0x00ec, B:51:0x00f7, B:52:0x0109, B:54:0x010f, B:56:0x011b, B:58:0x0121, B:60:0x0127, B:63:0x0139, B:64:0x013d, B:66:0x0143, B:68:0x014f, B:71:0x015a, B:72:0x015e, B:74:0x0164, B:76:0x0170, B:78:0x017c, B:80:0x0185, B:81:0x01a2, B:35:0x00a8), top: B:120:0x002a }] */
    /* JADX WARN: Removed duplicated region for block: B:106:0x025f A[Catch: Exception -> 0x003a, CancellationException -> 0x003d, TryCatch #2 {CancellationException -> 0x003d, Exception -> 0x003a, blocks: (B:13:0x0035, B:115:0x02ab, B:20:0x0054, B:104:0x0259, B:106:0x025f, B:109:0x027b, B:111:0x0287, B:112:0x028a, B:23:0x006d, B:96:0x021c, B:98:0x0222, B:101:0x0242, B:103:0x024b, B:26:0x0086, B:90:0x01f0, B:92:0x01f6, B:95:0x0217, B:29:0x0097, B:85:0x01b6, B:86:0x01c7, B:88:0x01cd, B:89:0x01df, B:32:0x00a0, B:39:0x00bf, B:41:0x00c9, B:43:0x00ce, B:45:0x00d4, B:47:0x00ec, B:51:0x00f7, B:52:0x0109, B:54:0x010f, B:56:0x011b, B:58:0x0121, B:60:0x0127, B:63:0x0139, B:64:0x013d, B:66:0x0143, B:68:0x014f, B:71:0x015a, B:72:0x015e, B:74:0x0164, B:76:0x0170, B:78:0x017c, B:80:0x0185, B:81:0x01a2, B:35:0x00a8), top: B:120:0x002a }] */
    /* JADX WARN: Removed duplicated region for block: B:111:0x0287 A[Catch: Exception -> 0x003a, CancellationException -> 0x003d, TryCatch #2 {CancellationException -> 0x003d, Exception -> 0x003a, blocks: (B:13:0x0035, B:115:0x02ab, B:20:0x0054, B:104:0x0259, B:106:0x025f, B:109:0x027b, B:111:0x0287, B:112:0x028a, B:23:0x006d, B:96:0x021c, B:98:0x0222, B:101:0x0242, B:103:0x024b, B:26:0x0086, B:90:0x01f0, B:92:0x01f6, B:95:0x0217, B:29:0x0097, B:85:0x01b6, B:86:0x01c7, B:88:0x01cd, B:89:0x01df, B:32:0x00a0, B:39:0x00bf, B:41:0x00c9, B:43:0x00ce, B:45:0x00d4, B:47:0x00ec, B:51:0x00f7, B:52:0x0109, B:54:0x010f, B:56:0x011b, B:58:0x0121, B:60:0x0127, B:63:0x0139, B:64:0x013d, B:66:0x0143, B:68:0x014f, B:71:0x015a, B:72:0x015e, B:74:0x0164, B:76:0x0170, B:78:0x017c, B:80:0x0185, B:81:0x01a2, B:35:0x00a8), top: B:120:0x002a }] */
    /* JADX WARN: Removed duplicated region for block: B:41:0x00c9 A[Catch: Exception -> 0x003a, CancellationException -> 0x003d, TryCatch #2 {CancellationException -> 0x003d, Exception -> 0x003a, blocks: (B:13:0x0035, B:115:0x02ab, B:20:0x0054, B:104:0x0259, B:106:0x025f, B:109:0x027b, B:111:0x0287, B:112:0x028a, B:23:0x006d, B:96:0x021c, B:98:0x0222, B:101:0x0242, B:103:0x024b, B:26:0x0086, B:90:0x01f0, B:92:0x01f6, B:95:0x0217, B:29:0x0097, B:85:0x01b6, B:86:0x01c7, B:88:0x01cd, B:89:0x01df, B:32:0x00a0, B:39:0x00bf, B:41:0x00c9, B:43:0x00ce, B:45:0x00d4, B:47:0x00ec, B:51:0x00f7, B:52:0x0109, B:54:0x010f, B:56:0x011b, B:58:0x0121, B:60:0x0127, B:63:0x0139, B:64:0x013d, B:66:0x0143, B:68:0x014f, B:71:0x015a, B:72:0x015e, B:74:0x0164, B:76:0x0170, B:78:0x017c, B:80:0x0185, B:81:0x01a2, B:35:0x00a8), top: B:120:0x002a }] */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00ce A[Catch: Exception -> 0x003a, CancellationException -> 0x003d, TryCatch #2 {CancellationException -> 0x003d, Exception -> 0x003a, blocks: (B:13:0x0035, B:115:0x02ab, B:20:0x0054, B:104:0x0259, B:106:0x025f, B:109:0x027b, B:111:0x0287, B:112:0x028a, B:23:0x006d, B:96:0x021c, B:98:0x0222, B:101:0x0242, B:103:0x024b, B:26:0x0086, B:90:0x01f0, B:92:0x01f6, B:95:0x0217, B:29:0x0097, B:85:0x01b6, B:86:0x01c7, B:88:0x01cd, B:89:0x01df, B:32:0x00a0, B:39:0x00bf, B:41:0x00c9, B:43:0x00ce, B:45:0x00d4, B:47:0x00ec, B:51:0x00f7, B:52:0x0109, B:54:0x010f, B:56:0x011b, B:58:0x0121, B:60:0x0127, B:63:0x0139, B:64:0x013d, B:66:0x0143, B:68:0x014f, B:71:0x015a, B:72:0x015e, B:74:0x0164, B:76:0x0170, B:78:0x017c, B:80:0x0185, B:81:0x01a2, B:35:0x00a8), top: B:120:0x002a }] */
    /* JADX WARN: Removed duplicated region for block: B:88:0x01cd A[Catch: Exception -> 0x003a, CancellationException -> 0x003d, LOOP:3: B:86:0x01c7->B:88:0x01cd, LOOP_END, TryCatch #2 {CancellationException -> 0x003d, Exception -> 0x003a, blocks: (B:13:0x0035, B:115:0x02ab, B:20:0x0054, B:104:0x0259, B:106:0x025f, B:109:0x027b, B:111:0x0287, B:112:0x028a, B:23:0x006d, B:96:0x021c, B:98:0x0222, B:101:0x0242, B:103:0x024b, B:26:0x0086, B:90:0x01f0, B:92:0x01f6, B:95:0x0217, B:29:0x0097, B:85:0x01b6, B:86:0x01c7, B:88:0x01cd, B:89:0x01df, B:32:0x00a0, B:39:0x00bf, B:41:0x00c9, B:43:0x00ce, B:45:0x00d4, B:47:0x00ec, B:51:0x00f7, B:52:0x0109, B:54:0x010f, B:56:0x011b, B:58:0x0121, B:60:0x0127, B:63:0x0139, B:64:0x013d, B:66:0x0143, B:68:0x014f, B:71:0x015a, B:72:0x015e, B:74:0x0164, B:76:0x0170, B:78:0x017c, B:80:0x0185, B:81:0x01a2, B:35:0x00a8), top: B:120:0x002a }] */
    /* JADX WARN: Removed duplicated region for block: B:8:0x001a  */
    /* JADX WARN: Removed duplicated region for block: B:92:0x01f6 A[Catch: Exception -> 0x003a, CancellationException -> 0x003d, TryCatch #2 {CancellationException -> 0x003d, Exception -> 0x003a, blocks: (B:13:0x0035, B:115:0x02ab, B:20:0x0054, B:104:0x0259, B:106:0x025f, B:109:0x027b, B:111:0x0287, B:112:0x028a, B:23:0x006d, B:96:0x021c, B:98:0x0222, B:101:0x0242, B:103:0x024b, B:26:0x0086, B:90:0x01f0, B:92:0x01f6, B:95:0x0217, B:29:0x0097, B:85:0x01b6, B:86:0x01c7, B:88:0x01cd, B:89:0x01df, B:32:0x00a0, B:39:0x00bf, B:41:0x00c9, B:43:0x00ce, B:45:0x00d4, B:47:0x00ec, B:51:0x00f7, B:52:0x0109, B:54:0x010f, B:56:0x011b, B:58:0x0121, B:60:0x0127, B:63:0x0139, B:64:0x013d, B:66:0x0143, B:68:0x014f, B:71:0x015a, B:72:0x015e, B:74:0x0164, B:76:0x0170, B:78:0x017c, B:80:0x0185, B:81:0x01a2, B:35:0x00a8), top: B:120:0x002a }] */
    /* JADX WARN: Removed duplicated region for block: B:98:0x0222 A[Catch: Exception -> 0x003a, CancellationException -> 0x003d, TryCatch #2 {CancellationException -> 0x003d, Exception -> 0x003a, blocks: (B:13:0x0035, B:115:0x02ab, B:20:0x0054, B:104:0x0259, B:106:0x025f, B:109:0x027b, B:111:0x0287, B:112:0x028a, B:23:0x006d, B:96:0x021c, B:98:0x0222, B:101:0x0242, B:103:0x024b, B:26:0x0086, B:90:0x01f0, B:92:0x01f6, B:95:0x0217, B:29:0x0097, B:85:0x01b6, B:86:0x01c7, B:88:0x01cd, B:89:0x01df, B:32:0x00a0, B:39:0x00bf, B:41:0x00c9, B:43:0x00ce, B:45:0x00d4, B:47:0x00ec, B:51:0x00f7, B:52:0x0109, B:54:0x010f, B:56:0x011b, B:58:0x0121, B:60:0x0127, B:63:0x0139, B:64:0x013d, B:66:0x0143, B:68:0x014f, B:71:0x015a, B:72:0x015e, B:74:0x0164, B:76:0x0170, B:78:0x017c, B:80:0x0185, B:81:0x01a2, B:35:0x00a8), top: B:120:0x002a }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object syncEpisodeWatchStatus(String str, Continuation<? super Boolean> continuation) {
        C03171 c03171;
        ContinueWatchingRepository continueWatchingRepository;
        Response response;
        Set linkedHashSet;
        List list;
        TraktIds ids;
        Integer tmdb;
        Iterator it;
        ContinueWatchingRepository continueWatchingRepository2;
        List list2;
        Iterator it2;
        Set set;
        Set set2;
        Iterator it3;
        Iterator it4;
        if (continuation instanceof C03171) {
            c03171 = (C03171) continuation;
            int i = c03171.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c03171.label = i - Integer.MIN_VALUE;
            } else {
                c03171 = new C03171(continuation);
            }
        }
        C03171 c031712 = c03171;
        Object watchedShowsWithHeaders$default = c031712.result;
        ck1 ck1Var = ck1.a;
        try {
            switch (c031712.label) {
                case 0:
                    s38.b(watchedShowsWithHeaders$default);
                    TraktApiService traktApiService = this.traktApiService;
                    c031712.L$0 = this;
                    c031712.label = 1;
                    watchedShowsWithHeaders$default = TraktApiService.DefaultImpls.getWatchedShowsWithHeaders$default(traktApiService, str, null, 0, 0, c031712, 14, null);
                    if (watchedShowsWithHeaders$default == ck1Var) {
                        return ck1Var;
                    }
                    continueWatchingRepository = this;
                    response = (Response) watchedShowsWithHeaders$default;
                    if (response.code() != 304) {
                        return Boxing.boxBoolean(false);
                    }
                    if (!response.isSuccessful()) {
                        Log.w(TAG, "Failed to fetch watched shows: HTTP " + response.code());
                        return Boxing.boxBoolean(false);
                    }
                    List<TraktWatchedShow> list3 = (List) response.body();
                    ik2 ik2Var = ik2.a;
                    if (list3 == null) {
                        list3 = ik2Var;
                    }
                    long jCurrentTimeMillis = System.currentTimeMillis();
                    linkedHashSet = new LinkedHashSet();
                    ArrayList arrayList = new ArrayList();
                    for (TraktWatchedShow traktWatchedShow : list3) {
                        TraktShow show = traktWatchedShow.getShow();
                        if (show != null && (ids = show.getIds()) != null && (tmdb = ids.getTmdb()) != null) {
                            int iIntValue = tmdb.intValue();
                            linkedHashSet.add(Boxing.boxInt(iIntValue));
                            List<TraktWatchedSeason> seasons = traktWatchedShow.getSeasons();
                            if (seasons != null) {
                                for (TraktWatchedSeason traktWatchedSeason : seasons) {
                                    Integer number = traktWatchedSeason.getNumber();
                                    if (number != null) {
                                        int iIntValue2 = number.intValue();
                                        List<TraktWatchedEpisode> episodes = traktWatchedSeason.getEpisodes();
                                        if (episodes == null) {
                                            episodes = ik2Var;
                                        }
                                        for (TraktWatchedEpisode traktWatchedEpisode : episodes) {
                                            Integer number2 = traktWatchedEpisode.getNumber();
                                            if (number2 != null) {
                                                int iIntValue3 = number2.intValue();
                                                Integer plays = traktWatchedEpisode.getPlays();
                                                arrayList.add(new EpisodeWatchStatus(iIntValue, iIntValue2, iIntValue3, null, null, true, plays != null ? plays.intValue() : 1, continueWatchingRepository.parseTraktDateMillis(traktWatchedEpisode.getLastWatchedAt()), null, null, jCurrentTimeMillis, 792, null));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    EpisodeWatchStatusDao episodeWatchStatusDao = continueWatchingRepository.episodeWatchStatusDao;
                    c031712.L$0 = continueWatchingRepository;
                    c031712.L$1 = linkedHashSet;
                    c031712.L$2 = arrayList;
                    c031712.label = 2;
                    watchedShowsWithHeaders$default = episodeWatchStatusDao.getLastWatchedEpisodePerShow(c031712);
                    if (watchedShowsWithHeaders$default == ck1Var) {
                        return ck1Var;
                    }
                    list = arrayList;
                    Iterable iterable = (Iterable) watchedShowsWithHeaders$default;
                    ArrayList arrayList2 = new ArrayList(y41.p(iterable, 10));
                    it = iterable.iterator();
                    while (it.hasNext()) {
                        arrayList2.add(Boxing.boxInt(((LastWatchedPerShow) it.next()).getShowTmdbId()));
                    }
                    Set setD = km8.d(y41.br(arrayList2), linkedHashSet);
                    continueWatchingRepository2 = continueWatchingRepository;
                    list2 = list;
                    it2 = setD.iterator();
                    set = linkedHashSet;
                    set2 = setD;
                    while (it2.hasNext()) {
                        int iIntValue4 = ((Number) it2.next()).intValue();
                        EpisodeWatchStatusDao episodeWatchStatusDao2 = continueWatchingRepository2.episodeWatchStatusDao;
                        c031712.L$0 = continueWatchingRepository2;
                        c031712.L$1 = set;
                        c031712.L$2 = list2;
                        c031712.L$3 = set2;
                        c031712.L$4 = it2;
                        c031712.label = 3;
                        if (episodeWatchStatusDao2.deleteForShow(iIntValue4, c031712) == ck1Var) {
                            return ck1Var;
                        }
                    }
                    it3 = set.iterator();
                    while (it3.hasNext()) {
                        int iIntValue5 = ((Number) it3.next()).intValue();
                        EpisodeWatchStatusDao episodeWatchStatusDao3 = continueWatchingRepository2.episodeWatchStatusDao;
                        c031712.L$0 = continueWatchingRepository2;
                        c031712.L$1 = set;
                        c031712.L$2 = list2;
                        c031712.L$3 = set2;
                        c031712.L$4 = it3;
                        c031712.label = 4;
                        if (episodeWatchStatusDao3.deleteForShow(iIntValue5, c031712) == ck1Var) {
                            return ck1Var;
                        }
                    }
                    if (!list2.isEmpty()) {
                        it4 = y41.o(list2, CredentialOption.PRIORITY_OIDC_OR_SIMILAR).iterator();
                        while (it4.hasNext()) {
                            List<EpisodeWatchStatus> list4 = (List) it4.next();
                            EpisodeWatchStatusDao episodeWatchStatusDao4 = continueWatchingRepository2.episodeWatchStatusDao;
                            c031712.L$0 = continueWatchingRepository2;
                            c031712.L$1 = set;
                            c031712.L$2 = list2;
                            c031712.L$3 = set2;
                            c031712.L$4 = it4;
                            c031712.label = 5;
                            if (episodeWatchStatusDao4.upsertAll(list4, c031712) == ck1Var) {
                                return ck1Var;
                            }
                        }
                    }
                    list2.size();
                    set.size();
                    if (!set2.isEmpty()) {
                        set2.size();
                    }
                    SyncMetadataRepository syncMetadataRepository = continueWatchingRepository2.syncMetadataRepository;
                    c031712.L$0 = null;
                    c031712.L$1 = null;
                    c031712.L$2 = null;
                    c031712.L$3 = null;
                    c031712.L$4 = null;
                    c031712.label = 6;
                    break;
                    break;
                case 1:
                    ContinueWatchingRepository continueWatchingRepository3 = (ContinueWatchingRepository) c031712.L$0;
                    s38.b(watchedShowsWithHeaders$default);
                    continueWatchingRepository = continueWatchingRepository3;
                    response = (Response) watchedShowsWithHeaders$default;
                    if (response.code() != 304) {
                    }
                    break;
                case 2:
                    list = (List) c031712.L$2;
                    linkedHashSet = (Set) c031712.L$1;
                    continueWatchingRepository = (ContinueWatchingRepository) c031712.L$0;
                    s38.b(watchedShowsWithHeaders$default);
                    Iterable iterable2 = (Iterable) watchedShowsWithHeaders$default;
                    ArrayList arrayList22 = new ArrayList(y41.p(iterable2, 10));
                    it = iterable2.iterator();
                    while (it.hasNext()) {
                    }
                    Set setD2 = km8.d(y41.br(arrayList22), linkedHashSet);
                    continueWatchingRepository2 = continueWatchingRepository;
                    list2 = list;
                    it2 = setD2.iterator();
                    set = linkedHashSet;
                    set2 = setD2;
                    while (it2.hasNext()) {
                    }
                    it3 = set.iterator();
                    while (it3.hasNext()) {
                    }
                    if (!list2.isEmpty()) {
                    }
                    list2.size();
                    set.size();
                    if (!set2.isEmpty()) {
                    }
                    SyncMetadataRepository syncMetadataRepository2 = continueWatchingRepository2.syncMetadataRepository;
                    c031712.L$0 = null;
                    c031712.L$1 = null;
                    c031712.L$2 = null;
                    c031712.L$3 = null;
                    c031712.L$4 = null;
                    c031712.label = 6;
                    break;
                case 3:
                    it2 = (Iterator) c031712.L$4;
                    set2 = (Set) c031712.L$3;
                    list2 = (List) c031712.L$2;
                    set = (Set) c031712.L$1;
                    continueWatchingRepository2 = (ContinueWatchingRepository) c031712.L$0;
                    s38.b(watchedShowsWithHeaders$default);
                    while (it2.hasNext()) {
                    }
                    it3 = set.iterator();
                    while (it3.hasNext()) {
                    }
                    if (!list2.isEmpty()) {
                    }
                    list2.size();
                    set.size();
                    if (!set2.isEmpty()) {
                    }
                    SyncMetadataRepository syncMetadataRepository22 = continueWatchingRepository2.syncMetadataRepository;
                    c031712.L$0 = null;
                    c031712.L$1 = null;
                    c031712.L$2 = null;
                    c031712.L$3 = null;
                    c031712.L$4 = null;
                    c031712.label = 6;
                    break;
                case 4:
                    it3 = (Iterator) c031712.L$4;
                    set2 = (Set) c031712.L$3;
                    list2 = (List) c031712.L$2;
                    set = (Set) c031712.L$1;
                    continueWatchingRepository2 = (ContinueWatchingRepository) c031712.L$0;
                    s38.b(watchedShowsWithHeaders$default);
                    while (it3.hasNext()) {
                    }
                    if (!list2.isEmpty()) {
                    }
                    list2.size();
                    set.size();
                    if (!set2.isEmpty()) {
                    }
                    SyncMetadataRepository syncMetadataRepository222 = continueWatchingRepository2.syncMetadataRepository;
                    c031712.L$0 = null;
                    c031712.L$1 = null;
                    c031712.L$2 = null;
                    c031712.L$3 = null;
                    c031712.L$4 = null;
                    c031712.label = 6;
                    break;
                case 5:
                    it4 = (Iterator) c031712.L$4;
                    set2 = (Set) c031712.L$3;
                    list2 = (List) c031712.L$2;
                    set = (Set) c031712.L$1;
                    continueWatchingRepository2 = (ContinueWatchingRepository) c031712.L$0;
                    s38.b(watchedShowsWithHeaders$default);
                    while (it4.hasNext()) {
                    }
                    list2.size();
                    set.size();
                    if (!set2.isEmpty()) {
                    }
                    SyncMetadataRepository syncMetadataRepository2222 = continueWatchingRepository2.syncMetadataRepository;
                    c031712.L$0 = null;
                    c031712.L$1 = null;
                    c031712.L$2 = null;
                    c031712.L$3 = null;
                    c031712.L$4 = null;
                    c031712.label = 6;
                    break;
                case 6:
                    s38.b(watchedShowsWithHeaders$default);
                    return Boxing.boxBoolean(true);
                default:
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e2) {
            Log.w(TAG, "Failed to sync episode watch status from Trakt, using local data", e2);
            return Boxing.boxBoolean(false);
        }
    }

    @pq6
    public final Object clearAll(@kp6 List<? extends ContinueWatchingItem> list, long j, @kp6 Continuation<? super Boolean> continuation) {
        return wj0.f(this.ioDispatcher, new AnonymousClass2(list, j, this, null), continuation);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object hasAccount(@kp6 Continuation<? super Boolean> continuation) {
        C03061 c03061;
        if (continuation instanceof C03061) {
            c03061 = (C03061) continuation;
            int i = c03061.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c03061.label = i - Integer.MIN_VALUE;
            } else {
                c03061 = new C03061(continuation);
            }
        }
        Object activeAccount = c03061.result;
        ck1 ck1Var = ck1.a;
        int i2 = c03061.label;
        if (i2 == 0) {
            s38.b(activeAccount);
            TraktAccountRepository traktAccountRepository = this.accountRepository;
            c03061.label = 1;
            activeAccount = traktAccountRepository.getActiveAccount(c03061);
            if (activeAccount == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(activeAccount);
        }
        return Boxing.boxBoolean(activeAccount != null);
    }

    public final boolean hasCachedItems() {
        return this.cachedItems != null || getDiskCacheFile().exists();
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object hasRemoteContinueWatchingChanges(@kp6 TraktLastActivities traktLastActivities, @kp6 Continuation<? super Boolean> continuation) {
        C03071 c03071;
        String strAi;
        if (continuation instanceof C03071) {
            c03071 = (C03071) continuation;
            int i = c03071.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c03071.label = i - Integer.MIN_VALUE;
            } else {
                c03071 = new C03071(continuation);
            }
        }
        Object traktTimestamp = c03071.result;
        ck1 ck1Var = ck1.a;
        int i2 = c03071.label;
        if (i2 == 0) {
            s38.b(traktTimestamp);
            TraktActivityGroup movies = traktLastActivities.getMovies();
            String pausedAt = movies != null ? movies.getPausedAt() : null;
            TraktActivityGroup movies2 = traktLastActivities.getMovies();
            String watchedAt = movies2 != null ? movies2.getWatchedAt() : null;
            TraktActivityGroup episodes = traktLastActivities.getEpisodes();
            String pausedAt2 = episodes != null ? episodes.getPausedAt() : null;
            TraktActivityGroup episodes2 = traktLastActivities.getEpisodes();
            strAi = y41.ai(st.w(new String[]{pausedAt, watchedAt, pausedAt2, episodes2 != null ? episodes2.getWatchedAt() : null}), "|", null, null, null, 62);
            SyncMetadataRepository syncMetadataRepository = this.syncMetadataRepository;
            c03071.L$0 = strAi;
            c03071.label = 1;
            traktTimestamp = syncMetadataRepository.getTraktTimestamp(SYNC_KEY_CONTINUE_WATCHING, c03071);
            if (traktTimestamp == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            strAi = (String) c03071.L$0;
            s38.b(traktTimestamp);
        }
        return Boxing.boxBoolean(strAi.length() > 0 && !strAi.equals((String) traktTimestamp));
    }

    public final void hideShow(int tmdbId) {
        LinkedHashSet linkedHashSetBq = y41.bq(getHiddenShowIds());
        linkedHashSetBq.add(Integer.valueOf(tmdbId));
        SharedPreferences.Editor editorEdit = getHiddenShowsPrefs().edit();
        ArrayList arrayList = new ArrayList(y41.p(linkedHashSetBq, 10));
        Iterator it = linkedHashSetBq.iterator();
        while (it.hasNext()) {
            arrayList.add(String.valueOf(((Number) it.next()).intValue()));
        }
        editorEdit.putStringSet(HIDDEN_SHOWS_KEY, y41.br(arrayList)).apply();
    }

    public final void invalidateCache() {
        this.cachedItems = null;
        this.lastCacheTime = 0L;
        try {
            getDiskCacheFile().delete();
        } catch (Throwable th) {
            s38.a(th);
        }
    }

    @pq6
    public final Object load(boolean z, @kp6 Continuation<? super List<ContentItem>> continuation) {
        return wj0.f(this.ioDispatcher, new C03082(z, null), continuation);
    }

    @pq6
    public final Object loadFromCache(@kp6 Continuation<? super List<ContentItem>> continuation) {
        return wj0.f(this.ioDispatcher, new C03092(null), continuation);
    }

    @pq6
    public final Object loadPlaybackOnly(@kp6 Continuation<? super List<ContentItem>> continuation) {
        return wj0.f(this.ioDispatcher, new C03112(null), continuation);
    }

    public final boolean optimisticRemove(int tmdbId) {
        List<ContentItem> list;
        if (tmdbId == -1 || (list = this.cachedItems) == null) {
            return false;
        }
        ArrayList arrayList = new ArrayList();
        for (Object obj : list) {
            if (((ContentItem) obj).getTmdbId() != tmdbId) {
                arrayList.add(obj);
            }
        }
        if (arrayList.size() == list.size()) {
            return false;
        }
        this.cachedItems = arrayList;
        saveToDiskCache(arrayList);
        list.size();
        arrayList.size();
        return true;
    }

    public final boolean optimisticUpdateProgress(int tmdbId, double progress) {
        List<ContentItem> list;
        if (tmdbId == -1 || progress < 0.0d || (list = this.cachedItems) == null) {
            return false;
        }
        List<ContentItem> list2 = list;
        ArrayList arrayList = new ArrayList(y41.p(list2, 10));
        boolean z = false;
        for (ContentItem contentItemCopy : list2) {
            if (contentItemCopy.getTmdbId() == tmdbId && contentItemCopy.getWatchProgress() != null) {
                contentItemCopy = contentItemCopy.copy(((-1179113) & 1) != 0 ? contentItemCopy.id : 0, ((-1179113) & 2) != 0 ? contentItemCopy.itemType : null, ((-1179113) & 4) != 0 ? contentItemCopy.tmdbId : 0, ((-1179113) & 8) != 0 ? contentItemCopy.imdbId : null, ((-1179113) & 16) != 0 ? contentItemCopy.title : null, ((-1179113) & 32) != 0 ? contentItemCopy.overview : null, ((-1179113) & 64) != 0 ? contentItemCopy.posterUrl : null, ((-1179113) & 128) != 0 ? contentItemCopy.backdropUrl : null, ((-1179113) & 256) != 0 ? contentItemCopy.logoUrl : null, ((-1179113) & 512) != 0 ? contentItemCopy.episodeStillUrl : null, ((-1179113) & 1024) != 0 ? contentItemCopy.year : null, ((-1179113) & 2048) != 0 ? contentItemCopy.rating : null, ((-1179113) & 4096) != 0 ? contentItemCopy.ratingPercentage : null, ((-1179113) & 8192) != 0 ? contentItemCopy.genres : null, ((-1179113) & 16384) != 0 ? contentItemCopy.runtime : null, ((-1179113) & 32768) != 0 ? contentItemCopy.cast : null, ((-1179113) & 65536) != 0 ? contentItemCopy.certification : null, ((-1179113) & 131072) != 0 ? contentItemCopy.imdbRating : null, ((-1179113) & MediaUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES) != 0 ? contentItemCopy.rottenTomatoesRating : null, ((-1179113) & 524288) != 0 ? contentItemCopy.traktRating : null, ((-1179113) & ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES) != 0 ? contentItemCopy.watchProgress : Double.valueOf(progress), ((-1179113) & 2097152) != 0 ? contentItemCopy.continueWatchingPlaybackId : null, ((-1179113) & 4194304) != 0 ? contentItemCopy.continueWatchingSeason : null, ((-1179113) & 8388608) != 0 ? contentItemCopy.continueWatchingEpisode : null, ((-1179113) & Http2Connection.OKHTTP_CLIENT_WINDOW_SIZE) != 0 ? contentItemCopy.continueWatchingIsRewatch : false, ((-1179113) & 33554432) != 0 ? contentItemCopy.showTitle : null, ((-1179113) & C.BUFFER_FLAG_NOT_DEPENDED_ON) != 0 ? contentItemCopy.sourceAddonUrl : null, ((-1179113) & C.BUFFER_FLAG_FIRST_SAMPLE) != 0 ? contentItemCopy.directStreamUrl : null, ((-1179113) & 268435456) != 0 ? contentItemCopy.calendarDate : null, ((-1179113) & 536870912) != 0 ? contentItemCopy.calendarDayLabel : null, ((-1179113) & 1073741824) != 0 ? contentItemCopy.calendarShowCount : 0, ((-1179113) & Integer.MIN_VALUE) != 0 ? contentItemCopy.calendarEpisodes : null, (2047 & 1) != 0 ? contentItemCopy.showStatus : null, (2047 & 2) != 0 ? contentItemCopy.episodeIndicator : null, (2047 & 4) != 0 ? contentItemCopy.unwatchedEpisodeCount : null, (2047 & 8) != 0 ? contentItemCopy.addedAt : null, (2047 & 16) != 0 ? contentItemCopy.watchedAt : null, (2047 & 32) != 0 ? contentItemCopy.watchers : null, (2047 & 64) != 0 ? contentItemCopy.tagline : null, (2047 & 128) != 0 ? contentItemCopy.stremioId : null, (2047 & 256) != 0 ? contentItemCopy.stremioType : null, (2047 & 512) != 0 ? contentItemCopy.extraData : null, (2047 & 1024) != 0 ? contentItemCopy.focusGifUrl : null);
                z = true;
            }
            arrayList.add(contentItemCopy);
        }
        if (!z) {
            return false;
        }
        this.cachedItems = arrayList;
        saveToDiskCache(arrayList);
        return true;
    }

    @pq6
    public final Object removePlayback(long j, @kp6 Continuation<? super Boolean> continuation) {
        return wj0.f(this.ioDispatcher, new C03152(j, null), continuation);
    }

    public final void unhideShow(int tmdbId) {
        LinkedHashSet linkedHashSetBq = y41.bq(getHiddenShowIds());
        if (linkedHashSetBq.remove(Integer.valueOf(tmdbId))) {
            SharedPreferences.Editor editorEdit = getHiddenShowsPrefs().edit();
            ArrayList arrayList = new ArrayList(y41.p(linkedHashSetBq, 10));
            Iterator it = linkedHashSetBq.iterator();
            while (it.hasNext()) {
                arrayList.add(String.valueOf(((Number) it.next()).intValue()));
            }
            editorEdit.putStringSet(HIDDEN_SHOWS_KEY, y41.br(arrayList)).apply();
        }
    }

    /* JADX WARN: Illegal instructions before constructor call */
    public ContinueWatchingRepository(TraktApiService traktApiService, TMDBApiService tMDBApiService, TraktAccountRepository traktAccountRepository, SyncMetadataRepository syncMetadataRepository, EpisodeWatchStatusDao episodeWatchStatusDao, TraktUserItemDao traktUserItemDao, Context context, Gson gson, TraktErrorNotifier traktErrorNotifier, TraktActivitiesCache traktActivitiesCache, lj1 lj1Var, int i, uz1 uz1Var) {
        lj1 lj1Var2;
        if ((i & 1024) != 0) {
            m12 m12Var = sc2.a;
            lj1Var2 = m02.c;
        } else {
            lj1Var2 = lj1Var;
        }
        this(traktApiService, tMDBApiService, traktAccountRepository, syncMetadataRepository, episodeWatchStatusDao, traktUserItemDao, context, gson, traktErrorNotifier, traktActivitiesCache, lj1Var2);
    }
}
