package com.strmr.ps.ui.details;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
import android.os.Parcelable;
import android.transition.AutoTransition;
import android.transition.TransitionManager;
import android.util.AndroidRuntimeException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.leanback.widget.HorizontalGridView;
import androidx.lifecycle.s;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import androidx.media3.exoplayer.upstream.CmcdData;
import com.google.android.material.button.MaterialButton;
import com.strmr.ps.R;
import com.strmr.ps.data.auth.FeatureGateManager;
import com.strmr.ps.data.event.PlaybackStateManager;
import com.strmr.ps.data.local.dao.EpisodeWatchStatusDao;
import com.strmr.ps.data.local.entity.ContentImageOverrideEntity;
import com.strmr.ps.data.local.entity.EpisodeWatchStatus;
import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.model.tmdb.TMDBEpisode;
import com.strmr.ps.data.model.tmdb.TMDBSeason;
import com.strmr.ps.data.model.trakt.TraktEpisode;
import com.strmr.ps.data.model.trakt.TraktShowProgress;
import com.strmr.ps.data.remote.AddonMetadataClient;
import com.strmr.ps.data.remote.RateLimiter;
import com.strmr.ps.data.remote.api.TMDBApiService;
import com.strmr.ps.data.remote.api.TraktApiService;
import com.strmr.ps.data.repository.MoviePlaybackProgress;
import com.strmr.ps.data.repository.PreferencesRepository;
import com.strmr.ps.data.repository.TraktAccountRepository;
import com.strmr.ps.data.repository.TraktStatusProvider;
import com.strmr.ps.data.repository.TraktSyncRepository;
import com.strmr.ps.data.service.StreamingDeepLinkService;
import com.strmr.ps.ui.WatchedBadgeManager;
import com.strmr.ps.ui.contextmenu.ContextMenuActionHandler;
import com.strmr.ps.ui.details.DetailsFragment;
import com.strmr.ps.ui.widget.ManualScrollNestedScrollView;
import dagger.hilt.android.AndroidEntryPoint;
import defpackage.C0609lc;
import defpackage.a62;
import defpackage.b62;
import defpackage.c43;
import defpackage.c62;
import defpackage.ck1;
import defpackage.co2;
import defpackage.cr4;
import defpackage.dh2;
import defpackage.dj1;
import defpackage.e24;
import defpackage.e62;
import defpackage.e6a;
import defpackage.i85;
import defpackage.ir3;
import defpackage.jk2;
import defpackage.k67;
import defpackage.kd7;
import defpackage.m02;
import defpackage.m12;
import defpackage.m44;
import defpackage.mb1;
import defpackage.me1;
import defpackage.n41;
import defpackage.n89;
import defpackage.p09;
import defpackage.p62;
import defpackage.pk2;
import defpackage.pw7;
import defpackage.q07;
import defpackage.q09;
import defpackage.qw8;
import defpackage.rw8;
import defpackage.s38;
import defpackage.sc2;
import defpackage.st;
import defpackage.sy2;
import defpackage.tp5;
import defpackage.u24;
import defpackage.u69;
import defpackage.uo2;
import defpackage.v62;
import defpackage.vw2;
import defpackage.vx8;
import defpackage.w62;
import defpackage.wa;
import defpackage.wj0;
import defpackage.x24;
import defpackage.x71;
import defpackage.y41;
import defpackage.y52;
import defpackage.z69;
import defpackage.zd8;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.ContinuationImpl;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0007\u0018\u00002\u00020\u0001:\u0001\u0004B\u0007¢\u0006\u0004\b\u0002\u0010\u0003¨\u0006\u0005"}, d2 = {"Lcom/strmr/ps/ui/details/DetailsFragment;", "Landroidx/fragment/app/o;", "<init>", "()V", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@AndroidEntryPoint
@vx8
public final class DetailsFragment extends m44 {
    public static final /* synthetic */ int cn = 0;
    public LinearLayout aa;
    public TextView ab;
    public HorizontalGridView ac;
    public HorizontalGridView ad;
    public HorizontalGridView ae;
    public TextView af;
    public TextView ag;
    public TextView ah;
    public ManualScrollNestedScrollView ai;
    public LinearLayout aj;
    public HorizontalGridView ak;
    public HorizontalGridView al;
    public LinearLayout am;
    public LinearLayout an;
    public TextView ao;
    public TextView ap;
    public LinearLayout aq;
    public HorizontalGridView ar;
    public LinearLayout as;
    public LinearLayout at;
    public p09 av;
    public View aw;
    public zd8 ax;
    public co2 ay;
    public RateLimiter az;
    public TMDBApiService ba;
    public TraktApiService bb;
    public ContextMenuActionHandler bc;
    public TraktStatusProvider bd;
    public WatchedBadgeManager be;
    public TraktSyncRepository bf;
    public EpisodeWatchStatusDao bg;
    public TraktAccountRepository bh;
    public PlaybackStateManager bi;
    public PreferencesRepository bj;
    public StreamingDeepLinkService bk;
    public FeatureGateManager bl;
    public AddonMetadataClient bm;
    public com.strmr.ps.ui.contextmenu.h bn;
    public uo2 bo;
    public TraktShowProgress bp;
    public String bs;
    public String bt;
    public String bu;
    public int bv;
    public String bx;
    public MoviePlaybackProgress bz;
    public Integer ca;
    public List cb;
    public Integer ce;
    public String cf;
    public Integer cg;
    public Integer ch;
    public Float ci;
    public boolean cj;
    public e24 ck;
    public u24 cl;
    public List cm;
    public ContentItem f;
    public u69 i;
    public ImageView j;
    public ImageView k;
    public View l;
    public ImageView m;
    public TextView n;
    public TextView o;
    public TextView p;
    public TextView q;
    public TextView r;
    public TextView s;
    public MaterialButton t;
    public MaterialButton u;
    public MaterialButton v;
    public MaterialButton w;
    public MaterialButton x;
    public LinearLayout y;
    public LinearLayout z;
    public final rw8 au = new rw8(1);
    public final LinkedHashSet bq = new LinkedHashSet();
    public Map br = jk2.a;
    public String bw = "";
    public int cc = 1;
    public int cd = 1;

    @Metadata(d1 = {"\u0000 \n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001R\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0003\u0010\u0004R\u0014\u0010\u0005\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0005\u0010\u0004R\u0014\u0010\u0007\u001a\u00020\u00068\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0007\u0010\bR\u0014\u0010\n\u001a\u00020\t8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\n\u0010\u000b¨\u0006\f"}, d2 = {"Lcom/strmr/ps/ui/details/DetailsFragment$a;", "", "", "TAG", "Ljava/lang/String;", "ARG_CONTENT_ITEM", "", "AMBIENT_ANIMATION_DURATION", "J", "", "DEFAULT_AMBIENT_COLOR", "I", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a {
    }

    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public /* synthetic */ class b {
        public static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[ContentItem.ItemType.values().length];
            try {
                iArr[ContentItem.ItemType.MOVIE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[ContentItem.ItemType.TV_SHOW.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            a = iArr;
        }
    }

    static {
        Color.parseColor("#0A0F1F");
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Serializable l(DetailsFragment detailsFragment, int i, ContinuationImpl continuationImpl) throws Throwable {
        com.strmr.ps.ui.details.b bVar;
        q07 q07Var;
        if (continuationImpl instanceof com.strmr.ps.ui.details.b) {
            bVar = (com.strmr.ps.ui.details.b) continuationImpl;
            int i2 = bVar.c;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                bVar.c = i2 - Integer.MIN_VALUE;
            } else {
                bVar = new com.strmr.ps.ui.details.b(detailsFragment, continuationImpl);
            }
        }
        Object objF = bVar.a;
        ck1 ck1Var = ck1.a;
        int i3 = bVar.c;
        if (i3 == 0) {
            s38.b(objF);
            if (detailsFragment.br.isEmpty()) {
                q07Var = null;
            } else {
                Set setKeySet = detailsFragment.br.keySet();
                ArrayList arrayList = new ArrayList();
                Iterator it = setKeySet.iterator();
                while (it.hasNext()) {
                    tp5 tp5VarC = new pw7("S(\\d+)E(\\d+)").c((String) it.next());
                    q07 q07Var2 = tp5VarC != null ? new q07(Boxing.boxInt(Integer.parseInt((String) tp5VarC.b().get(1))), Boxing.boxInt(Integer.parseInt((String) tp5VarC.b().get(2)))) : null;
                    if (q07Var2 != null) {
                        arrayList.add(q07Var2);
                    }
                }
                q07Var = (q07) y41.aq(x71.a(new me1(17), new me1(18)), arrayList);
            }
            if (q07Var != null) {
                return q07Var;
            }
            TraktShowProgress traktShowProgress = detailsFragment.bp;
            TraktEpisode nextEpisode = traktShowProgress != null ? traktShowProgress.getNextEpisode() : null;
            if ((nextEpisode != null ? nextEpisode.getSeason() : null) != null && nextEpisode.getNumber() != null) {
                return new q07(nextEpisode.getSeason(), nextEpisode.getNumber());
            }
            m12 m12Var = sc2.a;
            m02 m02Var = m02.c;
            c cVar = new c(i, detailsFragment, null);
            bVar.c = 1;
            objF = wj0.f(m02Var, cVar, bVar);
            if (objF == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i3 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(objF);
        }
        EpisodeWatchStatus episodeWatchStatus = (EpisodeWatchStatus) objF;
        if (episodeWatchStatus != null) {
            return new q07(Boxing.boxInt(episodeWatchStatus.getSeason()), Boxing.boxInt(episodeWatchStatus.getEpisode()));
        }
        return null;
    }

    public static final Object m(int i, DetailsFragment detailsFragment, Continuation continuation) throws Throwable {
        m12 m12Var = sc2.a;
        Object objF = wj0.f(m02.c, new n(i, detailsFragment, null), continuation);
        return objF == ck1.a ? objF : e6a.a;
    }

    public static final void n(DetailsFragment detailsFragment, Integer num, boolean z, String str, String str2) {
        if (num != null) {
            i85 viewLifecycleOwner = detailsFragment.getViewLifecycleOwner();
            cr4.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
            wj0.c(androidx.lifecycle.s.a(viewLifecycleOwner), null, null, new p(num, detailsFragment, z, str, str2, null), 3);
        } else {
            LinearLayout linearLayout = detailsFragment.aq;
            if (linearLayout != null) {
                linearLayout.setVisibility(8);
            } else {
                cr4.n("streamingSection");
                throw null;
            }
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r3v1, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r3v2, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r3v4, types: [java.util.ArrayList] */
    public static final void o(DetailsFragment detailsFragment, u69 u69Var) {
        ?? Am;
        int i;
        List listO = u69Var != null ? u69Var.getVideos() : null;
        List list = listO;
        if (list == null || list.isEmpty()) {
            return;
        }
        detailsFragment.cm = listO;
        List list2 = listO;
        ArrayList arrayList = new ArrayList();
        Iterator it = list2.iterator();
        while (it.hasNext()) {
            Integer numE = ((z69) it.next()).getSeason();
            if (numE != null) {
                arrayList.add(numE);
            }
        }
        List listBi = y41.bi(y41.t(arrayList));
        if (listBi.isEmpty()) {
            Am = y41.am(new TMDBSeason(1, "Season 1", 1, Integer.valueOf(listO.size()), null, null));
        } else {
            List list3 = listBi;
            Am = new ArrayList(y41.p(list3, 10));
            Iterator it2 = list3.iterator();
            while (it2.hasNext()) {
                int iIntValue = ((Number) it2.next()).intValue();
                Integer numValueOf = Integer.valueOf(iIntValue);
                String strK = n41.k("Season ", iIntValue);
                Integer numValueOf2 = Integer.valueOf(iIntValue);
                if ((list2 instanceof Collection) && list2.isEmpty()) {
                    i = 0;
                } else {
                    Iterator it3 = list2.iterator();
                    i = 0;
                    while (it3.hasNext()) {
                        Integer numE2 = ((z69) it3.next()).getSeason();
                        if (numE2 != null && numE2.intValue() == iIntValue && (i = i + 1) < 0) {
                            y41.bl();
                            throw null;
                        }
                    }
                }
                Am.add(new TMDBSeason(numValueOf, strK, numValueOf2, Integer.valueOf(i), null, null));
            }
        }
        LinearLayout linearLayout = detailsFragment.aj;
        if (linearLayout == null) {
            cr4.n("tvShowSection");
            throw null;
        }
        linearLayout.setVisibility(0);
        HorizontalGridView horizontalGridView = detailsFragment.ak;
        if (horizontalGridView == null) {
            cr4.n("seasonRow");
            throw null;
        }
        horizontalGridView.setVisibility(0);
        zd8 zd8Var = new zd8(Am, new y52(detailsFragment, 0), new mb1(8));
        detailsFragment.ax = zd8Var;
        HorizontalGridView horizontalGridView2 = detailsFragment.ak;
        if (horizontalGridView2 == null) {
            cr4.n("seasonRow");
            throw null;
        }
        horizontalGridView2.setAdapter(zd8Var);
        HorizontalGridView horizontalGridView3 = detailsFragment.ak;
        if (horizontalGridView3 == null) {
            cr4.n("seasonRow");
            throw null;
        }
        horizontalGridView3.setNumRows(1);
        HorizontalGridView horizontalGridView4 = detailsFragment.ak;
        if (horizontalGridView4 == null) {
            cr4.n("seasonRow");
            throw null;
        }
        horizontalGridView4.setItemSpacing(0);
        HorizontalGridView horizontalGridView5 = detailsFragment.ak;
        if (horizontalGridView5 == null) {
            cr4.n("seasonRow");
            throw null;
        }
        horizontalGridView5.setHasFixedSize(true);
        HorizontalGridView horizontalGridView6 = detailsFragment.ak;
        if (horizontalGridView6 == null) {
            cr4.n("seasonRow");
            throw null;
        }
        horizontalGridView6.setFocusScrollStrategy(1);
        Integer num = (Integer) y41.ab(listBi);
        detailsFragment.x(num != null ? num.intValue() : 1);
    }

    public static final void p(DetailsFragment detailsFragment, List list) {
        List list2 = list;
        if (list2 == null || list2.isEmpty()) {
            TextView textView = detailsFragment.af;
            if (textView == null) {
                cr4.n("castEmpty");
                throw null;
            }
            textView.setVisibility(0);
            HorizontalGridView horizontalGridView = detailsFragment.ac;
            if (horizontalGridView != null) {
                horizontalGridView.setVisibility(8);
                return;
            } else {
                cr4.n("castRow");
                throw null;
            }
        }
        k67 k67Var = new k67(y41.bk(y41.bj(new v62(), list), 8), new a62(detailsFragment, 0));
        HorizontalGridView horizontalGridView2 = detailsFragment.ac;
        if (horizontalGridView2 == null) {
            cr4.n("castRow");
            throw null;
        }
        horizontalGridView2.setAdapter(k67Var);
        HorizontalGridView horizontalGridView3 = detailsFragment.ac;
        if (horizontalGridView3 == null) {
            cr4.n("castRow");
            throw null;
        }
        horizontalGridView3.setNumRows(1);
        HorizontalGridView horizontalGridView4 = detailsFragment.ac;
        if (horizontalGridView4 == null) {
            cr4.n("castRow");
            throw null;
        }
        horizontalGridView4.setItemSpacing(0);
        HorizontalGridView horizontalGridView5 = detailsFragment.ac;
        if (horizontalGridView5 == null) {
            cr4.n("castRow");
            throw null;
        }
        horizontalGridView5.setHasFixedSize(true);
        HorizontalGridView horizontalGridView6 = detailsFragment.ac;
        if (horizontalGridView6 == null) {
            cr4.n("castRow");
            throw null;
        }
        horizontalGridView6.setItemViewCacheSize(10);
        HorizontalGridView horizontalGridView7 = detailsFragment.ac;
        if (horizontalGridView7 == null) {
            cr4.n("castRow");
            throw null;
        }
        horizontalGridView7.setFocusScrollStrategy(0);
        HorizontalGridView horizontalGridView8 = detailsFragment.ac;
        if (horizontalGridView8 == null) {
            cr4.n("castRow");
            throw null;
        }
        horizontalGridView8.setWindowAlignment(1);
        horizontalGridView8.setWindowAlignmentOffset(horizontalGridView8.getPaddingStart());
        horizontalGridView8.setWindowAlignmentOffsetPercent(-1.0f);
        horizontalGridView8.setItemAlignmentOffset(10);
        horizontalGridView8.setItemAlignmentOffsetPercent(-1.0f);
        HorizontalGridView horizontalGridView9 = detailsFragment.ac;
        if (horizontalGridView9 == null) {
            cr4.n("castRow");
            throw null;
        }
        qw8.a(horizontalGridView9);
        HorizontalGridView horizontalGridView10 = detailsFragment.ac;
        if (horizontalGridView10 == null) {
            cr4.n("castRow");
            throw null;
        }
        horizontalGridView10.setOnKeyInterceptListener(detailsFragment.au);
        TextView textView2 = detailsFragment.af;
        if (textView2 == null) {
            cr4.n("castEmpty");
            throw null;
        }
        textView2.setVisibility(8);
        HorizontalGridView horizontalGridView11 = detailsFragment.ac;
        if (horizontalGridView11 != null) {
            horizontalGridView11.setVisibility(0);
        } else {
            cr4.n("castRow");
            throw null;
        }
    }

    public static final void q(DetailsFragment detailsFragment, List list) {
        List list2 = list;
        if (list2 == null || list2.isEmpty()) {
            TextView textView = detailsFragment.ag;
            if (textView == null) {
                cr4.n("similarEmpty");
                throw null;
            }
            textView.setVisibility(0);
            HorizontalGridView horizontalGridView = detailsFragment.ad;
            if (horizontalGridView != null) {
                horizontalGridView.setVisibility(8);
                return;
            } else {
                cr4.n("similarRow");
                throw null;
            }
        }
        y52 y52Var = new y52(detailsFragment, 1);
        int i = 9;
        mb1 mb1Var = new mb1(i);
        sy2 sy2Var = new sy2(i);
        sy2 sy2Var2 = new sy2(i);
        y52 y52Var2 = new y52(detailsFragment, 2);
        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(y41.bk(list, 20));
        HorizontalGridView horizontalGridView2 = detailsFragment.ad;
        if (horizontalGridView2 == null) {
            cr4.n("similarRow");
            throw null;
        }
        horizontalGridView2.setAdapter(kd7Var);
        HorizontalGridView horizontalGridView3 = detailsFragment.ad;
        if (horizontalGridView3 == null) {
            cr4.n("similarRow");
            throw null;
        }
        horizontalGridView3.setNumRows(1);
        HorizontalGridView horizontalGridView4 = detailsFragment.ad;
        if (horizontalGridView4 == null) {
            cr4.n("similarRow");
            throw null;
        }
        horizontalGridView4.setItemSpacing(0);
        HorizontalGridView horizontalGridView5 = detailsFragment.ad;
        if (horizontalGridView5 == null) {
            cr4.n("similarRow");
            throw null;
        }
        horizontalGridView5.setHasFixedSize(true);
        HorizontalGridView horizontalGridView6 = detailsFragment.ad;
        if (horizontalGridView6 == null) {
            cr4.n("similarRow");
            throw null;
        }
        horizontalGridView6.setItemViewCacheSize(10);
        HorizontalGridView horizontalGridView7 = detailsFragment.ad;
        if (horizontalGridView7 == null) {
            cr4.n("similarRow");
            throw null;
        }
        horizontalGridView7.setFocusScrollStrategy(0);
        HorizontalGridView horizontalGridView8 = detailsFragment.ad;
        if (horizontalGridView8 == null) {
            cr4.n("similarRow");
            throw null;
        }
        horizontalGridView8.setWindowAlignment(1);
        horizontalGridView8.setWindowAlignmentOffset(horizontalGridView8.getPaddingStart());
        horizontalGridView8.setWindowAlignmentOffsetPercent(-1.0f);
        horizontalGridView8.setItemAlignmentOffset(10);
        horizontalGridView8.setItemAlignmentOffsetPercent(-1.0f);
        HorizontalGridView horizontalGridView9 = detailsFragment.ad;
        if (horizontalGridView9 == null) {
            cr4.n("similarRow");
            throw null;
        }
        qw8.a(horizontalGridView9);
        HorizontalGridView horizontalGridView10 = detailsFragment.ad;
        if (horizontalGridView10 == null) {
            cr4.n("similarRow");
            throw null;
        }
        horizontalGridView10.setOnKeyInterceptListener(detailsFragment.au);
        TextView textView2 = detailsFragment.ag;
        if (textView2 == null) {
            cr4.n("similarEmpty");
            throw null;
        }
        textView2.setVisibility(8);
        HorizontalGridView horizontalGridView11 = detailsFragment.ad;
        if (horizontalGridView11 != null) {
            horizontalGridView11.setVisibility(0);
        } else {
            cr4.n("similarRow");
            throw null;
        }
    }

    public static final void r(DetailsFragment detailsFragment) {
        TextView textView = detailsFragment.af;
        if (textView == null) {
            cr4.n("castEmpty");
            throw null;
        }
        textView.setVisibility(0);
        HorizontalGridView horizontalGridView = detailsFragment.ac;
        if (horizontalGridView == null) {
            cr4.n("castRow");
            throw null;
        }
        horizontalGridView.setVisibility(8);
        TextView textView2 = detailsFragment.ag;
        if (textView2 == null) {
            cr4.n("similarEmpty");
            throw null;
        }
        textView2.setVisibility(0);
        HorizontalGridView horizontalGridView2 = detailsFragment.ad;
        if (horizontalGridView2 == null) {
            cr4.n("similarRow");
            throw null;
        }
        horizontalGridView2.setVisibility(8);
        LinearLayout linearLayout = detailsFragment.aa;
        if (linearLayout == null) {
            cr4.n("collectionSection");
            throw null;
        }
        linearLayout.setVisibility(8);
        LinearLayout linearLayout2 = detailsFragment.aj;
        if (linearLayout2 == null) {
            cr4.n("tvShowSection");
            throw null;
        }
        linearLayout2.setVisibility(8);
        HorizontalGridView horizontalGridView3 = detailsFragment.al;
        if (horizontalGridView3 != null) {
            horizontalGridView3.setVisibility(8);
        } else {
            cr4.n("episodeRow");
            throw null;
        }
    }

    public static final void s(DetailsFragment detailsFragment) {
        MoviePlaybackProgress moviePlaybackProgress = detailsFragment.bz;
        Integer num = detailsFragment.ca;
        if (moviePlaybackProgress == null || num == null || num.intValue() <= 0) {
            MaterialButton materialButton = detailsFragment.t;
            if (materialButton != null) {
                materialButton.setText(detailsFragment.getString(R.string.details_play));
                return;
            } else {
                cr4.n("buttonPlay");
                throw null;
            }
        }
        String position = moviePlaybackProgress.formatPosition(((long) (num.intValue() * 60)) * 1000);
        MaterialButton materialButton2 = detailsFragment.t;
        if (materialButton2 == null) {
            cr4.n("buttonPlay");
            throw null;
        }
        materialButton2.setText("Continue from " + position);
        moviePlaybackProgress.getProgress();
    }

    public final void aa(MaterialButton materialButton, String str) {
        materialButton.setText("");
        materialButton.setOnFocusChangeListener(new e62(str, this));
        if (!materialButton.isLaidOut() || materialButton.isLayoutRequested()) {
            materialButton.addOnLayoutChangeListener(new w62(materialButton));
            return;
        }
        ViewGroup.LayoutParams layoutParams = materialButton.getLayoutParams();
        layoutParams.width = layoutParams.height;
        materialButton.setLayoutParams(layoutParams);
        materialButton.setPadding(0, 0, 0, 0);
        materialButton.setIconPadding(0);
        materialButton.setIconGravity(2);
    }

    /* JADX WARN: Removed duplicated region for block: B:31:0x00a6  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void ab(TMDBEpisode tMDBEpisode) {
        String string;
        String strH;
        String strConcat;
        String strAi;
        if (tMDBEpisode == null) {
            return;
        }
        this.ce = tMDBEpisode.getRuntime();
        this.cf = tMDBEpisode.getAirDate();
        Integer seasonNumber = tMDBEpisode.getSeasonNumber();
        if (seasonNumber != null) {
            int iIntValue = seasonNumber.intValue();
            Integer episodeNumber = tMDBEpisode.getEpisodeNumber();
            if (episodeNumber != null) {
                ad(Integer.valueOf(iIntValue), Integer.valueOf(episodeNumber.intValue()));
            }
        }
        Integer seasonNumber2 = tMDBEpisode.getSeasonNumber();
        Integer episodeNumber2 = tMDBEpisode.getEpisodeNumber();
        if (seasonNumber2 == null && episodeNumber2 == null) {
            string = "";
        } else {
            StringBuilder sb = new StringBuilder();
            if (seasonNumber2 != null) {
                sb.append("S" + seasonNumber2.intValue());
            }
            if (episodeNumber2 != null) {
                if (sb.length() > 0) {
                    sb.append(" ");
                }
                sb.append("E" + episodeNumber2);
            }
            string = sb.toString();
        }
        String airDate = tMDBEpisode.getAirDate();
        if (airDate == null || n89.ab(airDate)) {
            airDate = null;
        } else {
            try {
                Locale locale = Locale.US;
                Date date = new SimpleDateFormat("yyyy-MM-dd", locale).parse(airDate);
                if (date != null) {
                    airDate = new SimpleDateFormat("MMM d, yyyy", locale).format(date);
                }
            } catch (Exception unused) {
            }
        }
        Integer runtime = tMDBEpisode.getRuntime();
        if (runtime == null || runtime.intValue() <= 0) {
            strH = null;
        } else if (runtime.intValue() >= 60) {
            int iIntValue2 = runtime.intValue() / 60;
            int iIntValue3 = runtime.intValue() % 60;
            if (iIntValue3 == 0) {
                strH = n41.h(iIntValue2, CmcdData.STREAMING_FORMAT_HLS);
            } else {
                strH = iIntValue2 + "h " + iIntValue3 + CmcdData.OBJECT_TYPE_MANIFEST;
            }
        } else {
            strH = runtime + CmcdData.OBJECT_TYPE_MANIFEST;
        }
        String name = tMDBEpisode.getName();
        if (name == null || n89.ab(name) || n89.ab(string)) {
            String name2 = tMDBEpisode.getName();
            if (name2 != null && !n89.ab(name2)) {
                string = tMDBEpisode.getName();
            }
        } else {
            string = String.valueOf(tMDBEpisode.getName());
        }
        ArrayList arrayListW = st.w(new String[]{airDate, strH});
        ArrayList arrayList = !arrayListW.isEmpty() ? arrayListW : null;
        if (arrayList == null || (strAi = y41.ai(arrayList, " • ", null, null, null, 62)) == null || (strConcat = " • ".concat(strAi)) == null) {
            strConcat = "";
        }
        String strK = vw2.k(string, strConcat);
        String overview = tMDBEpisode.getOverview();
        String str = (overview == null && (overview = this.bs) == null) ? "" : overview;
        TextView textView = this.ao;
        if (textView == null) {
            cr4.n("shelfEpisodeTitle");
            throw null;
        }
        textView.setText(strK);
        TextView textView2 = this.ap;
        if (textView2 == null) {
            cr4.n("shelfEpisodeOverview");
            throw null;
        }
        textView2.setText(str);
        LinearLayout linearLayout = this.an;
        if (linearLayout == null) {
            cr4.n("episodeInfoShelf");
            throw null;
        }
        if (linearLayout.getVisibility() != 0) {
            AutoTransition autoTransition = new AutoTransition();
            autoTransition.setDuration(200L);
            LinearLayout linearLayout2 = this.am;
            if (linearLayout2 == null) {
                cr4.n("rowsContainer");
                throw null;
            }
            TransitionManager.beginDelayedTransition(linearLayout2, autoTransition);
            LinearLayout linearLayout3 = this.an;
            if (linearLayout3 != null) {
                linearLayout3.setVisibility(0);
            } else {
                cr4.n("episodeInfoShelf");
                throw null;
            }
        }
    }

    public final void ac(String str) {
        u24 u24Var = this.cl;
        if (u24Var != null) {
            u24Var.b(str, true);
        } else {
            cr4.n("heroLogoLoader");
            throw null;
        }
    }

    public final void ad(Integer num, Integer num2) {
        if (num == null || num2 == null) {
            MaterialButton materialButton = this.t;
            if (materialButton != null) {
                materialButton.setText(getString(R.string.details_play));
                return;
            } else {
                cr4.n("buttonPlay");
                throw null;
            }
        }
        this.cc = num.intValue();
        this.cd = num2.intValue();
        Float f = (Float) this.br.get("S" + num + "E" + num2);
        Integer num3 = this.ce;
        if (f == null || f.floatValue() <= 0.05f || num3 == null || num3.intValue() <= 0) {
            MaterialButton materialButton2 = this.t;
            if (materialButton2 == null) {
                cr4.n("buttonPlay");
                throw null;
            }
            materialButton2.setText(getString(R.string.details_play) + " S" + num + " E" + num2);
            return;
        }
        long jFloatValue = ((long) (f.floatValue() * (((long) (num3.intValue() * 60)) * 1000))) / ((long) 1000);
        long j = 3600;
        long j2 = jFloatValue / j;
        long j3 = 60;
        long j4 = (jFloatValue % j) / j3;
        long j5 = jFloatValue % j3;
        String str = j2 > 0 ? String.format(Locale.US, "%d:%02d:%02d", Arrays.copyOf(new Object[]{Long.valueOf(j2), Long.valueOf(j4), Long.valueOf(j5)}, 3)) : String.format(Locale.US, "%d:%02d", Arrays.copyOf(new Object[]{Long.valueOf(j4), Long.valueOf(j5)}, 2));
        MaterialButton materialButton3 = this.t;
        if (materialButton3 == null) {
            cr4.n("buttonPlay");
            throw null;
        }
        materialButton3.setText("Continue S" + num + "E" + num2 + " from " + str);
    }

    public final void ae() {
        int i = this.cj ? R.drawable.ic_check_circle_24 : R.drawable.ic_check_circle_outline_24;
        MaterialButton materialButton = this.w;
        if (materialButton == null) {
            cr4.n("buttonWatched");
            throw null;
        }
        materialButton.setIcon(getResources().getDrawable(i, null));
        MaterialButton materialButton2 = this.w;
        if (materialButton2 != null) {
            materialButton2.setContentDescription(this.cj ? "Mark Unwatched" : "Mark Watched");
        } else {
            cr4.n("buttonWatched");
            throw null;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:29:0x0062  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x007e  */
    @Override // androidx.fragment.app.o
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onCreate(Bundle bundle) {
        Integer numValueOf;
        Integer numValueOf2;
        Intent intent;
        Intent intent2;
        Intent intent3;
        super.onCreate(bundle);
        Bundle arguments = getArguments();
        Float f = null;
        ContentItem contentItem = (ContentItem) (arguments != null ? Build.VERSION.SDK_INT >= 33 ? (Parcelable) arguments.getParcelable("arg_content_item", ContentItem.class) : arguments.getParcelable("arg_content_item") : null);
        if (contentItem == null) {
            androidx.fragment.app.t activity = getActivity();
            Intent intent4 = activity != null ? activity.getIntent() : null;
            contentItem = (ContentItem) (intent4 != null ? Build.VERSION.SDK_INT >= 33 ? (Parcelable) intent4.getParcelableExtra("content_item", ContentItem.class) : intent4.getParcelableExtra("content_item") : null);
        }
        this.f = contentItem;
        androidx.fragment.app.t activity2 = getActivity();
        if (activity2 == null || (intent3 = activity2.getIntent()) == null) {
            numValueOf = null;
        } else {
            int intExtra = intent3.getIntExtra("continue_watching_season", -1);
            numValueOf = Integer.valueOf(intExtra);
            if (intExtra <= 0) {
            }
        }
        this.cg = numValueOf;
        androidx.fragment.app.t activity3 = getActivity();
        if (activity3 == null || (intent2 = activity3.getIntent()) == null) {
            numValueOf2 = null;
        } else {
            int intExtra2 = intent2.getIntExtra("continue_watching_episode", -1);
            numValueOf2 = Integer.valueOf(intExtra2);
            if (intExtra2 <= 0) {
            }
        }
        this.ch = numValueOf2;
        androidx.fragment.app.t activity4 = getActivity();
        if (activity4 != null && (intent = activity4.getIntent()) != null) {
            float floatExtra = intent.getFloatExtra("continue_watching_progress", -1.0f);
            Float fValueOf = Float.valueOf(floatExtra);
            if (floatExtra >= 0.0f) {
                f = fValueOf;
            }
        }
        this.ci = f;
    }

    @Override // androidx.fragment.app.o
    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        cr4.g(layoutInflater, "inflater");
        View viewInflate = layoutInflater.inflate(R.layout.fragment_details, viewGroup, false);
        cr4.f(viewInflate, "inflate(...)");
        return viewInflate;
    }

    @Override // androidx.fragment.app.o
    public final void onDestroyView() {
        super.onDestroyView();
        p09 p09Var = this.av;
        if (p09Var != null) {
            if (Looper.myLooper() != Looper.getMainLooper()) {
                throw new AndroidRuntimeException("Animations may only be canceled on the main thread");
            }
            if (p09Var.f) {
                p09Var.b(true);
            }
        }
        this.av = null;
        u24 u24Var = this.cl;
        if (u24Var == null) {
            cr4.n("heroLogoLoader");
            throw null;
        }
        u24Var.a();
        e24 e24Var = this.ck;
        if (e24Var != null) {
            e24Var.c();
        } else {
            cr4.n("heroBackgroundController");
            throw null;
        }
    }

    @Override // androidx.fragment.app.o
    public final void onResume() {
        View viewFindViewById;
        super.onResume();
        View view = getView();
        if (view != null && (viewFindViewById = view.findViewById(R.id.background_dim_overlay)) != null) {
            if (this.bj == null) {
                cr4.n("preferencesRepository");
                throw null;
            }
            viewFindViewById.setAlpha(r2.getBackgroundDimOpacity() / 100.0f);
        }
        ContentItem contentItem = this.f;
        if (contentItem != null) {
            i85 viewLifecycleOwner = getViewLifecycleOwner();
            cr4.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
            wj0.c(androidx.lifecycle.s.a(viewLifecycleOwner), null, null, new w(contentItem, this, null), 3);
        }
    }

    @Override // androidx.fragment.app.o
    public final void onViewCreated(View view, Bundle bundle) {
        String string;
        cr4.g(view, "view");
        super.onViewCreated(view, bundle);
        this.ai = (ManualScrollNestedScrollView) view.findViewById(R.id.details_scroll);
        this.j = (ImageView) view.findViewById(R.id.details_backdrop);
        this.k = (ImageView) view.findViewById(R.id.details_backdrop_incoming);
        this.l = view.findViewById(R.id.ambient_background_overlay);
        this.m = (ImageView) view.findViewById(R.id.details_logo);
        this.n = (TextView) view.findViewById(R.id.details_title);
        this.o = (TextView) view.findViewById(R.id.details_tagline);
        this.p = (TextView) view.findViewById(R.id.details_metadata);
        this.q = (TextView) view.findViewById(R.id.details_genre_text);
        this.r = (TextView) view.findViewById(R.id.details_overview);
        this.s = (TextView) view.findViewById(R.id.details_cast);
        this.t = (MaterialButton) view.findViewById(R.id.button_play);
        this.u = (MaterialButton) view.findViewById(R.id.button_shuffle);
        this.v = (MaterialButton) view.findViewById(R.id.button_trailer);
        this.w = (MaterialButton) view.findViewById(R.id.button_watched);
        this.x = (MaterialButton) view.findViewById(R.id.button_more);
        ImageView imageView = this.j;
        if (imageView == null) {
            cr4.n(ContentImageOverrideEntity.TYPE_BACKDROP);
            throw null;
        }
        ImageView imageView2 = this.k;
        if (imageView2 == null) {
            cr4.n("backdropIncoming");
            throw null;
        }
        View view2 = this.l;
        if (view2 == null) {
            cr4.n("ambientOverlay");
            throw null;
        }
        e24 e24Var = new e24(this, imageView, imageView2, view2, (ImageView) view.findViewById(R.id.hero_sidecar), view.findViewById(R.id.sidecar_scrim));
        this.ck = e24Var;
        e24Var.e(null, getResources().getDrawable(R.drawable.default_background, null), null);
        ImageView imageView3 = this.m;
        if (imageView3 == null) {
            cr4.n("logo");
            throw null;
        }
        TextView textView = this.n;
        if (textView == null) {
            cr4.n("title");
            throw null;
        }
        this.cl = new u24(this, imageView3, textView);
        this.y = (LinearLayout) view.findViewById(R.id.cast_section);
        this.z = (LinearLayout) view.findViewById(R.id.similar_section);
        this.aa = (LinearLayout) view.findViewById(R.id.collection_section);
        this.ab = (TextView) view.findViewById(R.id.collection_section_title);
        this.ac = (HorizontalGridView) view.findViewById(R.id.cast_row);
        this.ad = (HorizontalGridView) view.findViewById(R.id.similar_row);
        this.ae = (HorizontalGridView) view.findViewById(R.id.collection_row);
        this.af = (TextView) view.findViewById(R.id.cast_empty_text);
        this.ag = (TextView) view.findViewById(R.id.similar_empty_text);
        this.ah = (TextView) view.findViewById(R.id.collection_empty_text);
        this.aj = (LinearLayout) view.findViewById(R.id.tv_show_section);
        this.ak = (HorizontalGridView) view.findViewById(R.id.season_row);
        this.al = (HorizontalGridView) view.findViewById(R.id.episode_row);
        this.am = (LinearLayout) view.findViewById(R.id.rows_container);
        this.an = (LinearLayout) view.findViewById(R.id.episode_info_shelf);
        this.ao = (TextView) view.findViewById(R.id.shelf_episode_title);
        this.ap = (TextView) view.findViewById(R.id.shelf_episode_overview);
        this.aq = (LinearLayout) view.findViewById(R.id.streaming_availability_section);
        this.ar = (HorizontalGridView) view.findViewById(R.id.streaming_services_row);
        this.as = (LinearLayout) view.findViewById(R.id.details_hero_container);
        this.at = (LinearLayout) view.findViewById(R.id.details_action_container);
        HorizontalGridView horizontalGridView = this.ar;
        if (horizontalGridView == null) {
            cr4.n("streamingServicesRow");
            throw null;
        }
        horizontalGridView.setNumRows(1);
        HorizontalGridView horizontalGridView2 = this.ar;
        if (horizontalGridView2 == null) {
            cr4.n("streamingServicesRow");
            throw null;
        }
        horizontalGridView2.setItemSpacing(0);
        HorizontalGridView horizontalGridView3 = this.ar;
        if (horizontalGridView3 == null) {
            cr4.n("streamingServicesRow");
            throw null;
        }
        horizontalGridView3.setHasFixedSize(true);
        HorizontalGridView horizontalGridView4 = this.ar;
        if (horizontalGridView4 == null) {
            cr4.n("streamingServicesRow");
            throw null;
        }
        horizontalGridView4.setFocusable(false);
        ManualScrollNestedScrollView manualScrollNestedScrollView = this.ai;
        if (manualScrollNestedScrollView == null) {
            cr4.n("detailsScroll");
            throw null;
        }
        manualScrollNestedScrollView.setOnScrollChangeListener(new dj1(this, 20));
        ManualScrollNestedScrollView manualScrollNestedScrollView2 = this.ai;
        if (manualScrollNestedScrollView2 == null) {
            cr4.n("detailsScroll");
            throw null;
        }
        manualScrollNestedScrollView2.setOnDescendantFocused(new a62(this, 3));
        MaterialButton materialButton = this.t;
        if (materialButton == null) {
            cr4.n("buttonPlay");
            throw null;
        }
        materialButton.setOnClickListener(new b62(this, 2));
        MaterialButton materialButton2 = this.u;
        if (materialButton2 == null) {
            cr4.n("buttonShuffle");
            throw null;
        }
        materialButton2.setOnClickListener(new b62(this, 3));
        MaterialButton materialButton3 = this.v;
        if (materialButton3 == null) {
            cr4.n("buttonTrailer");
            throw null;
        }
        materialButton3.setOnClickListener(new b62(this, 4));
        MaterialButton materialButton4 = this.w;
        if (materialButton4 == null) {
            cr4.n("buttonWatched");
            throw null;
        }
        materialButton4.setOnClickListener(new b62(this, 0));
        MaterialButton materialButton5 = this.x;
        if (materialButton5 == null) {
            cr4.n("buttonMore");
            throw null;
        }
        materialButton5.setOnClickListener(new b62(this, 5));
        MaterialButton materialButton6 = this.t;
        if (materialButton6 == null) {
            cr4.n("buttonPlay");
            throw null;
        }
        materialButton6.setOnFocusChangeListener(new wa(3));
        MaterialButton materialButton7 = this.u;
        if (materialButton7 == null) {
            cr4.n("buttonShuffle");
            throw null;
        }
        q07 q07Var = new q07(materialButton7, "Shuffle");
        MaterialButton materialButton8 = this.v;
        if (materialButton8 == null) {
            cr4.n("buttonTrailer");
            throw null;
        }
        q07 q07Var2 = new q07(materialButton8, "Trailer");
        MaterialButton materialButton9 = this.w;
        if (materialButton9 == null) {
            cr4.n("buttonWatched");
            throw null;
        }
        q07 q07Var3 = new q07(materialButton9, this.cj ? "Unwatched" : "Watched");
        MaterialButton materialButton10 = this.x;
        if (materialButton10 == null) {
            cr4.n("buttonMore");
            throw null;
        }
        for (q07 q07Var4 : y41.an(q07Var, q07Var2, q07Var3, new q07(materialButton10, "More"))) {
            aa((MaterialButton) q07Var4.a, (String) q07Var4.b);
        }
        ae();
        MaterialButton materialButton11 = this.t;
        if (materialButton11 == null) {
            cr4.n("buttonPlay");
            throw null;
        }
        materialButton11.requestFocus();
        Context contextRequireContext = requireContext();
        cr4.f(contextRequireContext, "requireContext(...)");
        i85 viewLifecycleOwner = getViewLifecycleOwner();
        cr4.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
        androidx.lifecycle.n nVarA = androidx.lifecycle.s.a(viewLifecycleOwner);
        ContextMenuActionHandler contextMenuActionHandler = this.bc;
        if (contextMenuActionHandler == null) {
            cr4.n("contextMenuActionHandler");
            throw null;
        }
        TraktStatusProvider traktStatusProvider = this.bd;
        if (traktStatusProvider == null) {
            cr4.n("traktStatusProvider");
            throw null;
        }
        final int i = 0;
        this.bn = new com.strmr.ps.ui.contextmenu.h(contextRequireContext, nVarA, contextMenuActionHandler, traktStatusProvider, new ir3(this) { // from class: d62
            public final /* synthetic */ DetailsFragment b;

            {
                this.b = this;
            }

            @Override // defpackage.ir3
            public final Object invoke(Object obj, Object obj2, Object obj3) {
                Integer episodeNumber;
                int i2 = i;
                e6a e6aVar = e6a.a;
                switch (i2) {
                    case 0:
                        int iIntValue = ((Integer) obj).intValue();
                        ContentItem.ItemType itemType = (ContentItem.ItemType) obj2;
                        boolean zBooleanValue = ((Boolean) obj3).booleanValue();
                        int i3 = DetailsFragment.cn;
                        cr4.g(itemType, SessionDescription.ATTR_TYPE);
                        DetailsFragment detailsFragment = this.b;
                        i85 viewLifecycleOwner2 = detailsFragment.getViewLifecycleOwner();
                        cr4.f(viewLifecycleOwner2, "getViewLifecycleOwner(...)");
                        wj0.c(s.a(viewLifecycleOwner2), null, null, new u62(detailsFragment, iIntValue, itemType, zBooleanValue, null), 3);
                        break;
                    default:
                        DetailsFragment detailsFragment2 = this.b;
                        LinkedHashSet linkedHashSet = detailsFragment2.bq;
                        int iIntValue2 = ((Integer) obj).intValue();
                        int iIntValue3 = ((Integer) obj2).intValue();
                        boolean zBooleanValue2 = ((Boolean) obj3).booleanValue();
                        int i4 = DetailsFragment.cn;
                        String strI = vw2.i(iIntValue2, iIntValue3, "S", "E");
                        if (zBooleanValue2) {
                            linkedHashSet.add(strI);
                        } else {
                            linkedHashSet.remove(strI);
                        }
                        co2 co2Var = detailsFragment2.ay;
                        if (co2Var != null) {
                            LinkedHashSet linkedHashSet2 = co2Var.g;
                            String strI2 = vw2.i(iIntValue2, iIntValue3, "S", "E");
                            if (zBooleanValue2) {
                                linkedHashSet2.add(strI2);
                            } else {
                                linkedHashSet2.remove(strI2);
                            }
                            Iterator it = co2Var.a.iterator();
                            int i5 = 0;
                            while (true) {
                                if (it.hasNext()) {
                                    TMDBEpisode tMDBEpisode = (TMDBEpisode) it.next();
                                    Integer seasonNumber = tMDBEpisode.getSeasonNumber();
                                    if (seasonNumber == null || seasonNumber.intValue() != iIntValue2 || (episodeNumber = tMDBEpisode.getEpisodeNumber()) == null || episodeNumber.intValue() != iIntValue3) {
                                        i5++;
                                    }
                                } else {
                                    i5 = -1;
                                }
                            }
                            if (i5 >= 0) {
                                co2Var.notifyItemChanged(i5);
                            }
                        }
                        break;
                }
                return e6aVar;
            }
        }, null, new a62(this, 4), new a62(this, 5), null, null, null, null, 3872);
        Context contextRequireContext2 = requireContext();
        cr4.f(contextRequireContext2, "requireContext(...)");
        i85 viewLifecycleOwner2 = getViewLifecycleOwner();
        cr4.f(viewLifecycleOwner2, "getViewLifecycleOwner(...)");
        androidx.lifecycle.n nVarA2 = androidx.lifecycle.s.a(viewLifecycleOwner2);
        TraktAccountRepository traktAccountRepository = this.bh;
        if (traktAccountRepository == null) {
            cr4.n("traktAccountRepository");
            throw null;
        }
        TraktSyncRepository traktSyncRepositoryV = v();
        PlaybackStateManager playbackStateManager = this.bi;
        if (playbackStateManager == null) {
            cr4.n("playbackStateManager");
            throw null;
        }
        final int i2 = 1;
        this.bo = new uo2(contextRequireContext2, nVarA2, traktAccountRepository, traktSyncRepositoryV, playbackStateManager, new ir3(this) { // from class: d62
            public final /* synthetic */ DetailsFragment b;

            {
                this.b = this;
            }

            @Override // defpackage.ir3
            public final Object invoke(Object obj, Object obj2, Object obj3) {
                Integer episodeNumber;
                int i22 = i2;
                e6a e6aVar = e6a.a;
                switch (i22) {
                    case 0:
                        int iIntValue = ((Integer) obj).intValue();
                        ContentItem.ItemType itemType = (ContentItem.ItemType) obj2;
                        boolean zBooleanValue = ((Boolean) obj3).booleanValue();
                        int i3 = DetailsFragment.cn;
                        cr4.g(itemType, SessionDescription.ATTR_TYPE);
                        DetailsFragment detailsFragment = this.b;
                        i85 viewLifecycleOwner22 = detailsFragment.getViewLifecycleOwner();
                        cr4.f(viewLifecycleOwner22, "getViewLifecycleOwner(...)");
                        wj0.c(s.a(viewLifecycleOwner22), null, null, new u62(detailsFragment, iIntValue, itemType, zBooleanValue, null), 3);
                        break;
                    default:
                        DetailsFragment detailsFragment2 = this.b;
                        LinkedHashSet linkedHashSet = detailsFragment2.bq;
                        int iIntValue2 = ((Integer) obj).intValue();
                        int iIntValue3 = ((Integer) obj2).intValue();
                        boolean zBooleanValue2 = ((Boolean) obj3).booleanValue();
                        int i4 = DetailsFragment.cn;
                        String strI = vw2.i(iIntValue2, iIntValue3, "S", "E");
                        if (zBooleanValue2) {
                            linkedHashSet.add(strI);
                        } else {
                            linkedHashSet.remove(strI);
                        }
                        co2 co2Var = detailsFragment2.ay;
                        if (co2Var != null) {
                            LinkedHashSet linkedHashSet2 = co2Var.g;
                            String strI2 = vw2.i(iIntValue2, iIntValue3, "S", "E");
                            if (zBooleanValue2) {
                                linkedHashSet2.add(strI2);
                            } else {
                                linkedHashSet2.remove(strI2);
                            }
                            Iterator it = co2Var.a.iterator();
                            int i5 = 0;
                            while (true) {
                                if (it.hasNext()) {
                                    TMDBEpisode tMDBEpisode = (TMDBEpisode) it.next();
                                    Integer seasonNumber = tMDBEpisode.getSeasonNumber();
                                    if (seasonNumber == null || seasonNumber.intValue() != iIntValue2 || (episodeNumber = tMDBEpisode.getEpisodeNumber()) == null || episodeNumber.intValue() != iIntValue3) {
                                        i5++;
                                    }
                                } else {
                                    i5 = -1;
                                }
                            }
                            if (i5 >= 0) {
                                co2Var.notifyItemChanged(i5);
                            }
                        }
                        break;
                }
                return e6aVar;
            }
        }, new y52(this, 5), new y52(this, 6));
        i85 viewLifecycleOwner3 = getViewLifecycleOwner();
        cr4.f(viewLifecycleOwner3, "getViewLifecycleOwner(...)");
        wj0.c(androidx.lifecycle.s.a(viewLifecycleOwner3), null, null, new y(this, null), 3);
        ContentItem contentItem = this.f;
        if (contentItem == null) {
            TextView textView2 = this.n;
            if (textView2 == null) {
                cr4.n("title");
                throw null;
            }
            textView2.setText(getString(R.string.app_name));
            TextView textView3 = this.r;
            if (textView3 != null) {
                textView3.setText(getString(R.string.details_section_similar_empty));
                return;
            } else {
                cr4.n("overview");
                throw null;
            }
        }
        e24 e24Var2 = this.ck;
        if (e24Var2 == null) {
            cr4.n("heroBackgroundController");
            throw null;
        }
        e24Var2.e(contentItem.getBackdropUrl(), getResources().getDrawable(R.drawable.default_background, null), new c62(this, 0));
        TextView textView4 = this.n;
        if (textView4 == null) {
            cr4.n("title");
            throw null;
        }
        textView4.setText(contentItem.getTitle());
        contentItem.getTitle();
        String strC = x24.c(contentItem);
        if (strC == null || (string = strC.toString()) == null) {
            string = getString(R.string.details_section_similar_empty);
            cr4.f(string, "getString(...)");
        }
        this.bs = string;
        x24.b(null, contentItem);
        TextView textView5 = this.r;
        if (textView5 == null) {
            cr4.n("overview");
            throw null;
        }
        if (strC == null) {
            strC = getString(R.string.details_section_similar_empty);
            cr4.f(strC, "getString(...)");
        }
        textView5.setText(strC);
        TextView textView6 = this.r;
        if (textView6 == null) {
            cr4.n("overview");
            throw null;
        }
        textView6.setVisibility(0);
        ac(contentItem.getLogoUrl());
        TextView textView7 = this.o;
        if (textView7 == null) {
            cr4.n("detailsTagline");
            throw null;
        }
        x24.g(textView7, contentItem.getTagline());
        TextView textView8 = this.p;
        if (textView8 == null) {
            cr4.n("detailsMetadata");
            throw null;
        }
        x24.f(textView8, contentItem);
        TextView textView9 = this.q;
        if (textView9 == null) {
            cr4.n("detailsGenreText");
            throw null;
        }
        x24.e(textView9, contentItem.getGenres());
        TextView textView10 = this.s;
        if (textView10 == null) {
            cr4.n("detailsCast");
            throw null;
        }
        x24.d(textView10, contentItem.getCast());
        LinearLayout linearLayout = this.y;
        if (linearLayout == null) {
            cr4.n("castSection");
            throw null;
        }
        linearLayout.setVisibility(0);
        LinearLayout linearLayout2 = this.z;
        if (linearLayout2 == null) {
            cr4.n("similarSection");
            throw null;
        }
        linearLayout2.setVisibility(0);
        LinearLayout linearLayout3 = this.aa;
        if (linearLayout3 == null) {
            cr4.n("collectionSection");
            throw null;
        }
        linearLayout3.setVisibility(8);
        ContentItem contentItem2 = this.f;
        if (contentItem2 != null) {
            i85 viewLifecycleOwner4 = getViewLifecycleOwner();
            cr4.f(viewLifecycleOwner4, "getViewLifecycleOwner(...)");
            wj0.c(androidx.lifecycle.s.a(viewLifecycleOwner4), null, null, new d(contentItem2, this, null), 3);
        }
    }

    public final RateLimiter t() {
        RateLimiter rateLimiter = this.az;
        if (rateLimiter != null) {
            return rateLimiter;
        }
        cr4.n("rateLimiter");
        throw null;
    }

    public final TMDBApiService u() {
        TMDBApiService tMDBApiService = this.ba;
        if (tMDBApiService != null) {
            return tMDBApiService;
        }
        cr4.n("tmdbApiService");
        throw null;
    }

    public final TraktSyncRepository v() {
        TraktSyncRepository traktSyncRepository = this.bf;
        if (traktSyncRepository != null) {
            return traktSyncRepository;
        }
        cr4.n("traktSyncRepository");
        throw null;
    }

    public final void w() {
        ContentItem contentItem = this.f;
        if (contentItem != null && contentItem.getItemType() == ContentItem.ItemType.TV_SHOW) {
            int tmdbId = contentItem.getTmdbId();
            i85 viewLifecycleOwner = getViewLifecycleOwner();
            cr4.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
            wj0.c(androidx.lifecycle.s.a(viewLifecycleOwner), null, null, new r(this, tmdbId, contentItem, null), 3);
        }
    }

    public final void x(int i) {
        List list = this.cm;
        if (list == null) {
            return;
        }
        ArrayList arrayList = new ArrayList();
        for (Object obj : list) {
            z69 z69Var = (z69) obj;
            Integer numE = z69Var.getSeason();
            if ((numE != null && numE.intValue() == i) || (z69Var.getSeason() == null && i == 1)) {
                arrayList.add(obj);
            }
        }
        ArrayList arrayList2 = new ArrayList();
        Iterator it = arrayList.iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            TMDBEpisode tMDBEpisodeB = C0609lc.b((z69) it.next());
            TMDBEpisode tMDBEpisode = tMDBEpisodeB.getEpisodeNumber() != null ? tMDBEpisodeB : null;
            if (tMDBEpisode != null) {
                arrayList2.add(tMDBEpisode);
            }
        }
        List listBj = y41.bj(new p62(), arrayList2);
        co2 co2Var = new co2(listBj, pk2.a, jk2.a, false, new a62(this, 1), new a62(this, 2), null);
        this.ay = co2Var;
        HorizontalGridView horizontalGridView = this.al;
        if (horizontalGridView == null) {
            cr4.n("episodeRow");
            throw null;
        }
        horizontalGridView.setAdapter(co2Var);
        HorizontalGridView horizontalGridView2 = this.al;
        if (horizontalGridView2 == null) {
            cr4.n("episodeRow");
            throw null;
        }
        horizontalGridView2.setVisibility(!listBj.isEmpty() ? 0 : 8);
    }

    public final void y() {
        LinearLayout linearLayout = this.an;
        if (linearLayout == null) {
            cr4.n("episodeInfoShelf");
            throw null;
        }
        if (linearLayout.getVisibility() != 8) {
            AutoTransition autoTransition = new AutoTransition();
            autoTransition.setDuration(200L);
            LinearLayout linearLayout2 = this.am;
            if (linearLayout2 == null) {
                cr4.n("rowsContainer");
                throw null;
            }
            TransitionManager.beginDelayedTransition(linearLayout2, autoTransition);
            LinearLayout linearLayout3 = this.an;
            if (linearLayout3 != null) {
                linearLayout3.setVisibility(8);
            } else {
                cr4.n("episodeInfoShelf");
                throw null;
            }
        }
    }

    public final void z(View view) {
        ManualScrollNestedScrollView manualScrollNestedScrollView = this.ai;
        if (manualScrollNestedScrollView == null) {
            cr4.n("detailsScroll");
            throw null;
        }
        int scrollY = manualScrollNestedScrollView.getScrollY();
        int[] iArr = new int[2];
        view.getLocationOnScreen(iArr);
        int i = iArr[1];
        int[] iArr2 = new int[2];
        ManualScrollNestedScrollView manualScrollNestedScrollView2 = this.ai;
        if (manualScrollNestedScrollView2 == null) {
            cr4.n("detailsScroll");
            throw null;
        }
        manualScrollNestedScrollView2.getLocationOnScreen(iArr2);
        int i2 = (i - iArr2[1]) + scrollY;
        if (this.ai == null) {
            cr4.n("detailsScroll");
            throw null;
        }
        int iMax = Math.max(0, i2 - ((int) (r3.getHeight() * 0.25f)));
        if (Math.abs(scrollY - iMax) < 5) {
            return;
        }
        p09 p09Var = this.av;
        if (p09Var != null) {
            if (Looper.myLooper() != Looper.getMainLooper()) {
                throw new AndroidRuntimeException("Animations may only be canceled on the main thread");
            }
            if (p09Var.f) {
                p09Var.b(true);
            }
        }
        c43 c43Var = new c43();
        c43Var.a = scrollY;
        p09 p09Var2 = new p09(c43Var);
        p09Var2.r = null;
        p09Var2.s = Float.MAX_VALUE;
        p09Var2.t = false;
        q09 q09Var = new q09(iMax);
        q09Var.a(200.0f);
        q09Var.b = 1.0f;
        q09Var.c = false;
        p09Var2.r = q09Var;
        dh2.q qVar = new dh2.q() { // from class: g62
            @Override // dh2.q
            public final void a(float f) {
                ManualScrollNestedScrollView manualScrollNestedScrollView3 = this.a.ai;
                if (manualScrollNestedScrollView3 != null) {
                    manualScrollNestedScrollView3.scrollTo(0, (int) f);
                } else {
                    cr4.n("detailsScroll");
                    throw null;
                }
            }
        };
        if (p09Var2.f) {
            throw new UnsupportedOperationException("Error: Update listeners must be added beforethe animation.");
        }
        ArrayList arrayList = p09Var2.k;
        if (!arrayList.contains(qVar)) {
            arrayList.add(qVar);
        }
        p09Var2.f();
        this.av = p09Var2;
    }
}
