package com.strmr.ps.ui.details;

import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.leanback.widget.HorizontalGridView;
import androidx.media3.common.C;
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
import androidx.media3.session.MediaUtils;
import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.model.tmdb.TMDBCollectionDetails;
import com.strmr.ps.data.model.tmdb.TMDBCredits;
import com.strmr.ps.data.model.tmdb.TMDBExternalIds;
import com.strmr.ps.data.model.tmdb.TMDBMovie;
import com.strmr.ps.data.model.tmdb.TMDBMovieDetails;
import com.strmr.ps.data.repository.MoviePlaybackProgress;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.i85;
import defpackage.kd7;
import defpackage.mb1;
import defpackage.n89;
import defpackage.qw8;
import defpackage.s38;
import defpackage.sy2;
import defpackage.vx8;
import defpackage.x24;
import defpackage.y41;
import defpackage.y52;
import java.util.ArrayList;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import okhttp3.internal.http2.Http2Connection;

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public e(DetailsFragment detailsFragment, MoviePlaybackProgress moviePlaybackProgress, TMDBMovieDetails tMDBMovieDetails, List list, TMDBCollectionDetails tMDBCollectionDetails, int i, Continuation continuation) {
        super(2, continuation);
        this.a = detailsFragment;
        this.b = moviePlaybackProgress;
        this.c = tMDBMovieDetails;
        this.d = list;
        this.e = tMDBCollectionDetails;
        this.f = i;
    }

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

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) throws Throwable {
        e eVar = (e) create((ak1) obj, (Continuation) obj2);
        e6a e6aVar = e6a.a;
        eVar.invokeSuspend(e6aVar);
        return e6aVar;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r23v2 */
    /* JADX WARN: Type inference failed for: r23v3, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r23v4 */
    /* JADX WARN: Type inference failed for: r25v2 */
    /* JADX WARN: Type inference failed for: r25v3, types: [java.lang.Integer] */
    /* JADX WARN: Type inference failed for: r25v4 */
    /* JADX WARN: Type inference failed for: r3v15 */
    /* JADX WARN: Type inference failed for: r3v2 */
    /* JADX WARN: Type inference failed for: r3v3 */
    /* JADX WARN: Type inference failed for: r3v4 */
    /* JADX WARN: Type inference failed for: r3v5, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r3v6 */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Object invokeSuspend(Object obj) throws Throwable {
        String logoUrl$default;
        String tagline;
        Throwable th;
        String str;
        ?? ValueOf;
        ck1 ck1Var = ck1.a;
        s38.b(obj);
        MoviePlaybackProgress moviePlaybackProgress = this.b;
        DetailsFragment detailsFragment = this.a;
        detailsFragment.bz = moviePlaybackProgress;
        DetailsFragment.s(detailsFragment);
        ContentItem contentItem = detailsFragment.f;
        Throwable th2 = null;
        String logoUrl = contentItem != null ? contentItem.getLogoUrl() : null;
        TMDBMovieDetails tMDBMovieDetails = this.c;
        if ((logoUrl == null || n89.ab(logoUrl)) && (logoUrl$default = TMDBMovieDetails.getLogoUrl$default(tMDBMovieDetails, null, 1, null)) != null) {
            detailsFragment.ac(logoUrl$default);
            ContentItem contentItem2 = detailsFragment.f;
            detailsFragment.f = contentItem2 != null ? contentItem2.copy(((-1179113) & 1) != 0 ? contentItem2.id : 0, ((-1179113) & 2) != 0 ? contentItem2.itemType : null, ((-1179113) & 4) != 0 ? contentItem2.tmdbId : 0, ((-1179113) & 8) != 0 ? contentItem2.imdbId : null, ((-1179113) & 16) != 0 ? contentItem2.title : null, ((-1179113) & 32) != 0 ? contentItem2.overview : null, ((-1179113) & 64) != 0 ? contentItem2.posterUrl : null, ((-1179113) & 128) != 0 ? contentItem2.backdropUrl : null, ((-1179113) & 256) != 0 ? contentItem2.logoUrl : logoUrl$default, ((-1179113) & 512) != 0 ? contentItem2.episodeStillUrl : null, ((-1179113) & 1024) != 0 ? contentItem2.year : null, ((-1179113) & 2048) != 0 ? contentItem2.rating : null, ((-1179113) & 4096) != 0 ? contentItem2.ratingPercentage : null, ((-1179113) & 8192) != 0 ? contentItem2.genres : null, ((-1179113) & 16384) != 0 ? contentItem2.runtime : null, ((-1179113) & 32768) != 0 ? contentItem2.cast : null, ((-1179113) & 65536) != 0 ? contentItem2.certification : null, ((-1179113) & 131072) != 0 ? contentItem2.imdbRating : null, ((-1179113) & MediaUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES) != 0 ? contentItem2.rottenTomatoesRating : null, ((-1179113) & 524288) != 0 ? contentItem2.traktRating : null, ((-1179113) & ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES) != 0 ? contentItem2.watchProgress : null, ((-1179113) & 2097152) != 0 ? contentItem2.continueWatchingPlaybackId : null, ((-1179113) & 4194304) != 0 ? contentItem2.continueWatchingSeason : null, ((-1179113) & 8388608) != 0 ? contentItem2.continueWatchingEpisode : null, ((-1179113) & Http2Connection.OKHTTP_CLIENT_WINDOW_SIZE) != 0 ? contentItem2.continueWatchingIsRewatch : false, ((-1179113) & 33554432) != 0 ? contentItem2.showTitle : null, ((-1179113) & C.BUFFER_FLAG_NOT_DEPENDED_ON) != 0 ? contentItem2.sourceAddonUrl : null, ((-1179113) & C.BUFFER_FLAG_FIRST_SAMPLE) != 0 ? contentItem2.directStreamUrl : null, ((-1179113) & 268435456) != 0 ? contentItem2.calendarDate : null, ((-1179113) & 536870912) != 0 ? contentItem2.calendarDayLabel : null, ((-1179113) & 1073741824) != 0 ? contentItem2.calendarShowCount : 0, ((-1179113) & Integer.MIN_VALUE) != 0 ? contentItem2.calendarEpisodes : null, (2047 & 1) != 0 ? contentItem2.showStatus : null, (2047 & 2) != 0 ? contentItem2.episodeIndicator : null, (2047 & 4) != 0 ? contentItem2.unwatchedEpisodeCount : null, (2047 & 8) != 0 ? contentItem2.addedAt : null, (2047 & 16) != 0 ? contentItem2.watchedAt : null, (2047 & 32) != 0 ? contentItem2.watchers : null, (2047 & 64) != 0 ? contentItem2.tagline : null, (2047 & 128) != 0 ? contentItem2.stremioId : null, (2047 & 256) != 0 ? contentItem2.stremioType : null, (2047 & 512) != 0 ? contentItem2.extraData : null, (2047 & 1024) != 0 ? contentItem2.focusGifUrl : null) : null;
        }
        ContentItem contentItem3 = detailsFragment.f;
        String tagline2 = contentItem3 != null ? contentItem3.getTagline() : null;
        if ((tagline2 == null || n89.ab(tagline2)) && (tagline = tMDBMovieDetails.getTagline()) != null) {
            if (n89.ab(tagline)) {
                tagline = null;
            }
            if (tagline != null) {
                TextView textView = detailsFragment.o;
                if (textView == null) {
                    cr4.n("detailsTagline");
                    throw null;
                }
                x24.g(textView, tagline);
                ContentItem contentItem4 = detailsFragment.f;
                detailsFragment.f = contentItem4 != null ? contentItem4.copy(((-1179113) & 1) != 0 ? contentItem4.id : 0, ((-1179113) & 2) != 0 ? contentItem4.itemType : null, ((-1179113) & 4) != 0 ? contentItem4.tmdbId : 0, ((-1179113) & 8) != 0 ? contentItem4.imdbId : null, ((-1179113) & 16) != 0 ? contentItem4.title : null, ((-1179113) & 32) != 0 ? contentItem4.overview : null, ((-1179113) & 64) != 0 ? contentItem4.posterUrl : null, ((-1179113) & 128) != 0 ? contentItem4.backdropUrl : null, ((-1179113) & 256) != 0 ? contentItem4.logoUrl : null, ((-1179113) & 512) != 0 ? contentItem4.episodeStillUrl : null, ((-1179113) & 1024) != 0 ? contentItem4.year : null, ((-1179113) & 2048) != 0 ? contentItem4.rating : null, ((-1179113) & 4096) != 0 ? contentItem4.ratingPercentage : null, ((-1179113) & 8192) != 0 ? contentItem4.genres : null, ((-1179113) & 16384) != 0 ? contentItem4.runtime : null, ((-1179113) & 32768) != 0 ? contentItem4.cast : null, ((-1179113) & 65536) != 0 ? contentItem4.certification : null, ((-1179113) & 131072) != 0 ? contentItem4.imdbRating : null, ((-1179113) & MediaUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES) != 0 ? contentItem4.rottenTomatoesRating : null, ((-1179113) & 524288) != 0 ? contentItem4.traktRating : null, ((-1179113) & ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES) != 0 ? contentItem4.watchProgress : null, ((-1179113) & 2097152) != 0 ? contentItem4.continueWatchingPlaybackId : null, ((-1179113) & 4194304) != 0 ? contentItem4.continueWatchingSeason : null, ((-1179113) & 8388608) != 0 ? contentItem4.continueWatchingEpisode : null, ((-1179113) & Http2Connection.OKHTTP_CLIENT_WINDOW_SIZE) != 0 ? contentItem4.continueWatchingIsRewatch : false, ((-1179113) & 33554432) != 0 ? contentItem4.showTitle : null, ((-1179113) & C.BUFFER_FLAG_NOT_DEPENDED_ON) != 0 ? contentItem4.sourceAddonUrl : null, ((-1179113) & C.BUFFER_FLAG_FIRST_SAMPLE) != 0 ? contentItem4.directStreamUrl : null, ((-1179113) & 268435456) != 0 ? contentItem4.calendarDate : null, ((-1179113) & 536870912) != 0 ? contentItem4.calendarDayLabel : null, ((-1179113) & 1073741824) != 0 ? contentItem4.calendarShowCount : 0, ((-1179113) & Integer.MIN_VALUE) != 0 ? contentItem4.calendarEpisodes : null, (2047 & 1) != 0 ? contentItem4.showStatus : null, (2047 & 2) != 0 ? contentItem4.episodeIndicator : null, (2047 & 4) != 0 ? contentItem4.unwatchedEpisodeCount : null, (2047 & 8) != 0 ? contentItem4.addedAt : null, (2047 & 16) != 0 ? contentItem4.watchedAt : null, (2047 & 32) != 0 ? contentItem4.watchers : null, (2047 & 64) != 0 ? contentItem4.tagline : tagline, (2047 & 128) != 0 ? contentItem4.stremioId : null, (2047 & 256) != 0 ? contentItem4.stremioType : null, (2047 & 512) != 0 ? contentItem4.extraData : null, (2047 & 1024) != 0 ? contentItem4.focusGifUrl : null) : null;
            }
        }
        detailsFragment.bt = tMDBMovieDetails.getTrailerKey();
        TMDBCredits credits = tMDBMovieDetails.getCredits();
        DetailsFragment.p(detailsFragment, credits != null ? credits.getCast() : null);
        DetailsFragment.q(detailsFragment, this.d);
        TMDBCollectionDetails tMDBCollectionDetails = this.e;
        if (tMDBCollectionDetails != null) {
            String name = tMDBMovieDetails.getBelongsToCollection().getName();
            List<TMDBMovie> parts = tMDBCollectionDetails.getParts();
            List<TMDBMovie> list = parts;
            String str2 = "collectionSection";
            if (list == null || list.isEmpty()) {
                th = null;
                LinearLayout linearLayout = detailsFragment.aa;
                if (linearLayout == null) {
                    cr4.n("collectionSection");
                    throw null;
                }
                linearLayout.setVisibility(8);
            } else {
                TextView textView2 = detailsFragment.ab;
                if (textView2 == null) {
                    cr4.n("collectionSectionTitle");
                    throw null;
                }
                textView2.setText(name);
                List<TMDBMovie> listBk = y41.bk(parts, 20);
                ArrayList arrayList = new ArrayList(y41.p(listBk, 10));
                for (TMDBMovie tMDBMovie : listBk) {
                    int id = tMDBMovie.getId();
                    ContentItem.ItemType itemType = ContentItem.ItemType.MOVIE;
                    int id2 = tMDBMovie.getId();
                    String imdbId = tMDBMovie.getImdbId();
                    String title = tMDBMovie.getTitle();
                    String overview = tMDBMovie.getOverview();
                    String posterUrl = tMDBMovie.getPosterUrl();
                    String backdropUrl = tMDBMovie.getBackdropUrl();
                    Throwable th3 = th2;
                    String releaseDate = tMDBMovie.getReleaseDate();
                    ?? Bb = releaseDate != null ? n89.bb(4, releaseDate) : th3;
                    Double voteAverage = tMDBMovie.getVoteAverage();
                    Double voteAverage2 = tMDBMovie.getVoteAverage();
                    if (voteAverage2 != null) {
                        str = str2;
                        ValueOf = Integer.valueOf((int) (voteAverage2.doubleValue() * ((double) 10)));
                    } else {
                        str = str2;
                        ValueOf = th3;
                    }
                    arrayList.add(new ContentItem(id, itemType, id2, imdbId, title, overview, posterUrl, backdropUrl, null, null, Bb, voteAverage, ValueOf, null, null, null, null, null, null, null, null, null, null, null, false, null, null, null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, -1048064, 2047, null));
                    th2 = th3;
                    str2 = str;
                }
                th = th2;
                String str3 = str2;
                y52 y52Var = new y52(detailsFragment, 3);
                mb1 mb1Var = new mb1(10);
                sy2 sy2Var = new sy2(9);
                sy2 sy2Var2 = new sy2(9);
                y52 y52Var2 = new y52(detailsFragment, 4);
                i85 viewLifecycleOwner = detailsFragment.getViewLifecycleOwner();
                cr4.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
                kd7 kd7Var = new kd7(y52Var, mb1Var, sy2Var, sy2Var2, y52Var2, null, androidx.lifecycle.s.a(viewLifecycleOwner), null, 1952);
                kd7Var.e(arrayList);
                HorizontalGridView horizontalGridView = detailsFragment.ae;
                if (horizontalGridView == null) {
                    cr4.n("collectionRow");
                    throw th;
                }
                horizontalGridView.setAdapter(kd7Var);
                HorizontalGridView horizontalGridView2 = detailsFragment.ae;
                if (horizontalGridView2 == null) {
                    cr4.n("collectionRow");
                    throw th;
                }
                horizontalGridView2.setNumRows(1);
                HorizontalGridView horizontalGridView3 = detailsFragment.ae;
                if (horizontalGridView3 == null) {
                    cr4.n("collectionRow");
                    throw th;
                }
                horizontalGridView3.setItemSpacing(0);
                HorizontalGridView horizontalGridView4 = detailsFragment.ae;
                if (horizontalGridView4 == null) {
                    cr4.n("collectionRow");
                    throw th;
                }
                horizontalGridView4.setHasFixedSize(true);
                HorizontalGridView horizontalGridView5 = detailsFragment.ae;
                if (horizontalGridView5 == null) {
                    cr4.n("collectionRow");
                    throw th;
                }
                horizontalGridView5.setItemViewCacheSize(10);
                HorizontalGridView horizontalGridView6 = detailsFragment.ae;
                if (horizontalGridView6 == null) {
                    cr4.n("collectionRow");
                    throw th;
                }
                horizontalGridView6.setFocusScrollStrategy(0);
                HorizontalGridView horizontalGridView7 = detailsFragment.ae;
                if (horizontalGridView7 == null) {
                    cr4.n("collectionRow");
                    throw th;
                }
                horizontalGridView7.setWindowAlignment(1);
                horizontalGridView7.setWindowAlignmentOffset(horizontalGridView7.getPaddingStart());
                horizontalGridView7.setWindowAlignmentOffsetPercent(-1.0f);
                horizontalGridView7.setItemAlignmentOffset(10);
                horizontalGridView7.setItemAlignmentOffsetPercent(-1.0f);
                HorizontalGridView horizontalGridView8 = detailsFragment.ae;
                if (horizontalGridView8 == null) {
                    cr4.n("collectionRow");
                    throw th;
                }
                qw8.a(horizontalGridView8);
                HorizontalGridView horizontalGridView9 = detailsFragment.ae;
                if (horizontalGridView9 == null) {
                    cr4.n("collectionRow");
                    throw th;
                }
                horizontalGridView9.setOnKeyInterceptListener(detailsFragment.au);
                TextView textView3 = detailsFragment.ah;
                if (textView3 == null) {
                    cr4.n("collectionEmpty");
                    throw th;
                }
                textView3.setVisibility(8);
                HorizontalGridView horizontalGridView10 = detailsFragment.ae;
                if (horizontalGridView10 == null) {
                    cr4.n("collectionRow");
                    throw th;
                }
                horizontalGridView10.setVisibility(0);
                LinearLayout linearLayout2 = detailsFragment.aa;
                if (linearLayout2 == null) {
                    cr4.n(str3);
                    throw th;
                }
                linearLayout2.setVisibility(0);
            }
        } else {
            th = null;
        }
        String imdbId2 = tMDBMovieDetails.getImdbId();
        TMDBExternalIds externalIds = tMDBMovieDetails.getExternalIds();
        ?? imdbId3 = externalIds != null ? externalIds.getImdbId() : th;
        if (imdbId2 != null) {
            imdbId3 = imdbId2;
        } else if (imdbId3 == 0) {
            imdbId3 = th;
        }
        DetailsFragment.n(detailsFragment, Boxing.boxInt(this.f), true, imdbId3, tMDBMovieDetails.getTitle());
        return e6a.a;
    }
}
