package defpackage;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.util.Log;
import android.util.LruCache;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewPropertyAnimator;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.lifecycle.n;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import com.strmr.ps.data.local.entity.PlaybackProgress;
import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.model.tmdb.TMDBMovieDetails;
import com.strmr.ps.data.model.tmdb.TMDBShowDetails;
import com.strmr.ps.data.remote.AddonMetadataClient;
import com.strmr.ps.data.remote.api.TMDBApiService;
import java.util.concurrent.CancellationException;
import kotlin.Metadata;
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\u0010\u0000\n\u0002\b\u0003\u0018\u00002\u00020\u0001:\u0002\u0002\u0003¨\u0006\u0004"}, d2 = {"Ld34;", "", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "b", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class d34 {
    public final TMDBApiService a;
    public final AddonMetadataClient b;
    public final n c;
    public final FrameLayout d;
    public final View e;
    public final ImageView f;
    public final ImageView g;
    public long h;
    public boolean i;
    public WebView j;
    public fx4 k;
    public fx4 l;
    public fx4 m;
    public ContentItem n;
    public boolean o;
    public boolean p;
    public AnimatorSet q;
    public AnimatorSet r;
    public final float s;
    public float t;
    public float u;
    public final LruCache v;
    public final LruCache w;

    @Metadata(d1 = {"\u0000 \n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0010\t\n\u0002\b\u0005\n\u0002\u0010\u0007\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\u0006\u001a\u00020\u00058\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0006\u0010\u0007R\u0014\u0010\b\u001a\u00020\u00058\u0002X\u0082T¢\u0006\u0006\n\u0004\b\b\u0010\u0007R\u0014\u0010\t\u001a\u00020\u00058\u0002X\u0082T¢\u0006\u0006\n\u0004\b\t\u0010\u0007R\u0014\u0010\n\u001a\u00020\u00058\u0002X\u0082T¢\u0006\u0006\n\u0004\b\n\u0010\u0007R\u0014\u0010\f\u001a\u00020\u000b8\u0002X\u0082T¢\u0006\u0006\n\u0004\b\f\u0010\r¨\u0006\u000e"}, d2 = {"Ld34$a;", "", "", "TAG", "Ljava/lang/String;", "", "TRAILER_LOAD_TIMEOUT_MS", "J", "FADE_IN_DURATION", "FADE_OUT_DURATION", "INFO_SETTLE_DURATION", "", "INFO_SETTLE_TRANSLATION_DP", "F", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a {
    }

    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0082\u0004\u0018\u00002\u00020\u0001J\u000f\u0010\u0003\u001a\u00020\u0002H\u0007¢\u0006\u0004\b\u0003\u0010\u0004J\u000f\u0010\u0005\u001a\u00020\u0002H\u0007¢\u0006\u0004\b\u0005\u0010\u0004J\u000f\u0010\u0006\u001a\u00020\u0002H\u0007¢\u0006\u0004\b\u0006\u0010\u0004¨\u0006\u0007"}, d2 = {"Ld34$b;", "", "Le6a;", "onVideoPlaying", "()V", "onVideoError", "onVideoEnded", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public final class b {
        public b() {
        }

        @JavascriptInterface
        public final void onVideoEnded() {
            d34 d34Var = d34.this;
            d34Var.d.post(new e34(d34Var, 1));
        }

        @JavascriptInterface
        public final void onVideoError() {
            d34 d34Var = d34.this;
            d34Var.d.post(new e34(d34Var, 0));
        }

        @JavascriptInterface
        public final void onVideoPlaying() {
            d34 d34Var = d34.this;
            d34Var.d.post(new e34(d34Var, 2));
        }
    }

    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public /* synthetic */ class c {
        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;
        }
    }

    public d34(TMDBApiService tMDBApiService, AddonMetadataClient addonMetadataClient, n nVar, FrameLayout frameLayout, View view, ImageView imageView, ImageView imageView2) {
        cr4.g(view, "heroInfoContainer");
        cr4.g(imageView, "backdropView");
        cr4.g(imageView2, "backdropIncomingView");
        this.a = tMDBApiService;
        this.b = addonMetadataClient;
        this.c = nVar;
        this.d = frameLayout;
        this.e = view;
        this.f = imageView;
        this.g = imageView2;
        this.h = 5000L;
        this.s = view.getTranslationY();
        this.t = 1.0f;
        this.v = new LruCache(50);
        this.w = new LruCache(50);
    }

    /* JADX WARN: Removed duplicated region for block: B:60:0x00fa  */
    /* JADX WARN: Removed duplicated region for block: B:66:? A[RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0016  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object a(d34 d34Var, ContentItem contentItem, ContinuationImpl continuationImpl) throws Throwable {
        j34 j34Var;
        String trailerKey;
        TMDBApiService tMDBApiService = d34Var.a;
        if (continuationImpl instanceof j34) {
            j34Var = (j34) continuationImpl;
            int i = j34Var.e;
            if ((i & Integer.MIN_VALUE) != 0) {
                j34Var.e = i - Integer.MIN_VALUE;
            } else {
                j34Var = new j34(d34Var, continuationImpl);
            }
        }
        j34 j34Var2 = j34Var;
        Object movieDetails$default = j34Var2.c;
        ck1 ck1Var = ck1.a;
        int i2 = j34Var2.e;
        try {
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e2) {
            Boxing.boxInt(Log.w("HeroTrailerController", "TMDB trailer fetch failed for " + contentItem.getTitle(), e2));
        }
        if (i2 == 0) {
            s38.b(movieDetails$default);
            if (contentItem.getTmdbId() > 0) {
                String str = (String) d34Var.v.get(Boxing.boxInt(contentItem.getTmdbId()));
                if (str != null) {
                    if (str.length() == 0) {
                        return null;
                    }
                    return str;
                }
                int i3 = c.a[contentItem.getItemType().ordinal()];
                if (i3 == 1) {
                    int tmdbId = contentItem.getTmdbId();
                    j34Var2.a = d34Var;
                    j34Var2.b = contentItem;
                    j34Var2.e = 1;
                    movieDetails$default = TMDBApiService.DefaultImpls.getMovieDetails$default(tMDBApiService, tmdbId, null, j34Var2, 2, null);
                    if (movieDetails$default == ck1Var) {
                        return ck1Var;
                    }
                    trailerKey = ((TMDBMovieDetails) movieDetails$default).getTrailerKey();
                } else if (i3 != 2) {
                    trailerKey = null;
                } else {
                    int tmdbId2 = contentItem.getTmdbId();
                    j34Var2.a = d34Var;
                    j34Var2.b = contentItem;
                    j34Var2.e = 2;
                    movieDetails$default = TMDBApiService.DefaultImpls.getShowDetails$default(tMDBApiService, tmdbId2, null, j34Var2, 2, null);
                    if (movieDetails$default == ck1Var) {
                        return ck1Var;
                    }
                    trailerKey = ((TMDBShowDetails) movieDetails$default).getTrailerKey();
                }
            }
            j34Var2.a = null;
            j34Var2.b = null;
            j34Var2.e = 3;
            Object objG = d34Var.g(contentItem, j34Var2);
            return objG != ck1Var ? ck1Var : objG;
        }
        if (i2 == 1) {
            contentItem = j34Var2.b;
            d34Var = j34Var2.a;
            s38.b(movieDetails$default);
            trailerKey = ((TMDBMovieDetails) movieDetails$default).getTrailerKey();
        } else {
            if (i2 != 2) {
                if (i2 != 3) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(movieDetails$default);
                return movieDetails$default;
            }
            contentItem = j34Var2.b;
            d34Var = j34Var2.a;
            s38.b(movieDetails$default);
            trailerKey = ((TMDBShowDetails) movieDetails$default).getTrailerKey();
        }
        d34Var.v.put(Boxing.boxInt(contentItem.getTmdbId()), trailerKey == null ? "" : trailerKey);
        if (trailerKey != null) {
            return trailerKey;
        }
        j34Var2.a = null;
        j34Var2.b = null;
        j34Var2.e = 3;
        Object objG2 = d34Var.g(contentItem, j34Var2);
        if (objG2 != ck1Var) {
        }
    }

    public final void b(qq3 qq3Var) {
        AnimatorSet animatorSet = this.q;
        if (animatorSet != null) {
            animatorSet.cancel();
        }
        AnimatorSet animatorSet2 = this.r;
        if (animatorSet2 != null) {
            animatorSet2.cancel();
        }
        boolean z = this.o;
        float f = this.s;
        View view = this.e;
        if (!z) {
            this.o = false;
            view.setTranslationY(f);
            qq3Var.invoke();
            return;
        }
        Property property = View.ALPHA;
        FrameLayout frameLayout = this.d;
        ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat(frameLayout, (Property<FrameLayout, Float>) property, frameLayout.getAlpha(), 0.0f);
        ImageView imageView = this.f;
        ObjectAnimator objectAnimatorOfFloat2 = ObjectAnimator.ofFloat(imageView, (Property<ImageView, Float>) property, imageView.getAlpha(), this.t);
        ImageView imageView2 = this.g;
        ObjectAnimator objectAnimatorOfFloat3 = ObjectAnimator.ofFloat(imageView2, (Property<ImageView, Float>) property, imageView2.getAlpha(), this.u);
        ObjectAnimator objectAnimatorOfFloat4 = ObjectAnimator.ofFloat(view, (Property<View, Float>) View.TRANSLATION_Y, view.getTranslationY(), f);
        objectAnimatorOfFloat4.setInterpolator(new DecelerateInterpolator());
        AnimatorSet animatorSet3 = new AnimatorSet();
        animatorSet3.playTogether(objectAnimatorOfFloat, objectAnimatorOfFloat2, objectAnimatorOfFloat3, objectAnimatorOfFloat4);
        animatorSet3.setDuration(300L);
        animatorSet3.setInterpolator(new AccelerateDecelerateInterpolator());
        animatorSet3.addListener(new f34(this, qq3Var));
        animatorSet3.start();
        this.r = animatorSet3;
    }

    public final void c() {
        WebView webView = this.j;
        if (webView != null) {
            webView.loadUrl("about:blank");
        }
        FrameLayout frameLayout = this.d;
        frameLayout.setVisibility(8);
        frameLayout.setAlpha(0.0f);
    }

    public final void d() {
        this.p = true;
        fx4 fx4Var = this.k;
        if (fx4Var != null) {
            ((rx4) fx4Var).h(null);
        }
        fx4 fx4Var2 = this.l;
        if (fx4Var2 != null) {
            ((rx4) fx4Var2).h(null);
        }
        fx4 fx4Var3 = this.m;
        if (fx4Var3 != null) {
            ((rx4) fx4Var3).h(null);
        }
        AnimatorSet animatorSet = this.q;
        if (animatorSet != null) {
            animatorSet.cancel();
        }
        AnimatorSet animatorSet2 = this.r;
        if (animatorSet2 != null) {
            animatorSet2.cancel();
        }
        if (this.o) {
            this.f.setAlpha(this.t);
            this.g.setAlpha(this.u);
        }
        this.o = false;
        this.e.setTranslationY(this.s);
        this.n = null;
        e();
    }

    public final void e() {
        WebView webView = this.j;
        if (webView != null) {
            ViewPropertyAnimator viewPropertyAnimatorAnimate = webView.animate();
            if (viewPropertyAnimatorAnimate != null) {
                viewPropertyAnimatorAnimate.cancel();
            }
            webView.onPause();
            webView.removeJavascriptInterface("AndroidBridge");
            webView.loadUrl("about:blank");
            ViewParent parent = webView.getParent();
            ViewGroup viewGroup = parent instanceof ViewGroup ? (ViewGroup) parent : null;
            if (viewGroup != null) {
                viewGroup.removeView(webView);
            }
            webView.stopLoading();
            webView.destroy();
        }
        this.j = null;
        FrameLayout frameLayout = this.d;
        frameLayout.removeAllViews();
        frameLayout.setVisibility(8);
        frameLayout.setAlpha(0.0f);
    }

    public final void f() {
        fx4 fx4Var = this.k;
        if (fx4Var != null) {
            ((rx4) fx4Var).h(null);
        }
        fx4 fx4Var2 = this.l;
        if (fx4Var2 != null) {
            ((rx4) fx4Var2).h(null);
        }
        fx4 fx4Var3 = this.m;
        if (fx4Var3 != null) {
            ((rx4) fx4Var3).h(null);
        }
        if (this.o) {
            b(new c34(this, 0));
        } else {
            c();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object g(ContentItem contentItem, ContinuationImpl continuationImpl) throws Throwable {
        h34 h34Var;
        String stremioId;
        ContentItem contentItem2;
        Exception exc;
        d34 d34Var;
        String str;
        if (continuationImpl instanceof h34) {
            h34Var = (h34) continuationImpl;
            int i = h34Var.f;
            if ((i & Integer.MIN_VALUE) != 0) {
                h34Var.f = i - Integer.MIN_VALUE;
            } else {
                h34Var = new h34(this, continuationImpl);
            }
        }
        Object objF = h34Var.d;
        ck1 ck1Var = ck1.a;
        int i2 = h34Var.f;
        try {
            if (i2 == 0) {
                s38.b(objF);
                AddonMetadataClient addonMetadataClient = this.b;
                String sourceAddonUrl = contentItem.getSourceAddonUrl();
                if (sourceAddonUrl != null && (stremioId = contentItem.getStremioId()) != null) {
                    String str2 = (String) this.w.get(stremioId);
                    if (str2 == null) {
                        String stremioType = contentItem.getStremioType();
                        if (stremioType == null) {
                            stremioType = contentItem.getItemType() == ContentItem.ItemType.TV_SHOW ? "series" : PlaybackProgress.TYPE_MOVIE;
                        }
                        String str3 = stremioType;
                        try {
                            m12 m12Var = sc2.a;
                            m02 m02Var = m02.c;
                            i34 i34Var = new i34(addonMetadataClient, sourceAddonUrl, str3, stremioId, null);
                            h34Var.a = this;
                            h34Var.b = contentItem;
                            h34Var.c = stremioId;
                            h34Var.f = 1;
                            objF = wj0.f(m02Var, i34Var, h34Var);
                            if (objF == ck1Var) {
                                return ck1Var;
                            }
                            d34Var = this;
                            contentItem2 = contentItem;
                            str = stremioId;
                        } catch (Exception e) {
                            contentItem2 = contentItem;
                            exc = e;
                            Log.w("HeroTrailerController", "Addon trailer fetch failed for " + contentItem2.getTitle(), exc);
                            return null;
                        }
                    } else if (str2.length() != 0) {
                        return str2;
                    }
                }
                return null;
            }
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            str = h34Var.c;
            contentItem2 = h34Var.b;
            d34Var = h34Var.a;
            try {
                s38.b(objF);
            } catch (Exception e2) {
                exc = e2;
                Log.w("HeroTrailerController", "Addon trailer fetch failed for " + contentItem2.getTitle(), exc);
                return null;
            }
            u69 u69Var = (u69) objF;
            String strA = u69Var != null ? C0609lc.a(u69Var) : null;
            d34Var.w.put(str, strA == null ? "" : strA);
            return strA;
        } catch (CancellationException e3) {
            throw e3;
        }
    }

    public final void h(ContentItem contentItem) {
        cr4.g(contentItem, "item");
        if (this.p) {
            return;
        }
        fx4 fx4Var = this.k;
        if (fx4Var != null) {
            ((rx4) fx4Var).h(null);
        }
        fx4 fx4Var2 = this.l;
        if (fx4Var2 != null) {
            ((rx4) fx4Var2).h(null);
        }
        fx4 fx4Var3 = this.m;
        if (fx4Var3 != null) {
            ((rx4) fx4Var3).h(null);
        }
        if (this.o) {
            b(new c34(this, 1));
        } else {
            c();
        }
        this.n = contentItem;
        this.k = wj0.c(this.c, null, null, new n34(this, contentItem, null), 3);
    }

    public final void i() {
        this.p = true;
        fx4 fx4Var = this.k;
        if (fx4Var != null) {
            ((rx4) fx4Var).h(null);
        }
        fx4 fx4Var2 = this.l;
        if (fx4Var2 != null) {
            ((rx4) fx4Var2).h(null);
        }
        fx4 fx4Var3 = this.m;
        if (fx4Var3 != null) {
            ((rx4) fx4Var3).h(null);
        }
        AnimatorSet animatorSet = this.q;
        if (animatorSet != null) {
            animatorSet.cancel();
        }
        AnimatorSet animatorSet2 = this.r;
        if (animatorSet2 != null) {
            animatorSet2.cancel();
        }
        if (this.o) {
            this.f.setAlpha(this.t);
            this.g.setAlpha(this.u);
        }
        this.o = false;
        this.e.setTranslationY(this.s);
        e();
    }

    public final void j() {
        this.p = false;
        ContentItem contentItem = this.n;
        if (contentItem != null) {
            this.n = contentItem;
            this.k = wj0.c(this.c, null, null, new n34(this, contentItem, null), 3);
        }
    }
}
