package d3;

import D.C0135f;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import androidx.media3.common.text.Cue;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.extractor.text.ttml.TtmlNode;
import androidx.media3.ui.CaptionStyleCompat;
import androidx.media3.ui.PlayerView;
import androidx.media3.ui.SubtitleView;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/* JADX INFO: loaded from: classes.dex */
public final class P {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final F f15274a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final PlayerView f15275b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final SubtitleView f15276c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public ExoPlayer f15277d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public boolean f15278e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final String[] f15279f = {"version of mpv", "display as original", "doesn't support the subtitle format", "does not support the subtitle format", "please use mpv"};

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final O f15280g = new O(this);

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f15281h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public Bundle f15282i;

    public P(F f6, PlayerView playerView, SubtitleView subtitleView) {
        this.f15274a = f6;
        this.f15275b = playerView;
        this.f15276c = subtitleView;
        final C0135f c0135f = new C0135f(this, 29);
        subtitleView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { // from class: d3.M
            @Override // android.view.View.OnLayoutChangeListener
            public final void onLayoutChange(View view, int i6, int i7, int i8, int i9, int i10, int i11, int i12, int i13) {
                c0135f.invoke();
            }
        });
        subtitleView.post(new F1.r(c0135f, 19));
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x005b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void a(Context context, Bundle styleMap) {
        String lowerCase;
        float f6;
        int i6;
        kotlin.jvm.internal.o.h(context, "context");
        kotlin.jvm.internal.o.h(styleMap, "styleMap");
        this.f15282i = styleMap;
        SubtitleView subtitleView = this.f15276c;
        int iV0 = W.a.v0(styleMap.getString("textColor"));
        int iV02 = W.a.v0(styleMap.getString(TtmlNode.ATTR_TTS_BACKGROUND_COLOR));
        String string = styleMap.getString("outlineStyle");
        if (string != null) {
            lowerCase = string.toLowerCase(Locale.ROOT);
            kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
        } else {
            lowerCase = null;
        }
        int i7 = kotlin.jvm.internal.o.c(lowerCase, "outline") ? 1 : 2;
        if (styleMap.containsKey(TtmlNode.ATTR_TTS_FONT_SIZE)) {
            f6 = (float) styleMap.getDouble(TtmlNode.ATTR_TTS_FONT_SIZE, 20.0d);
            if (f6 <= 0.0f) {
                f6 = 20.0f;
            }
        }
        if (iV0 == 0) {
            iV0 = -1;
        }
        subtitleView.setStyle(new CaptionStyleCompat(iV0, iV02, 0, i7, -16777216, null));
        subtitleView.setFixedTextSize(2, f6);
        int i8 = 0;
        subtitleView.setPadding(0, 0, 0, 0);
        if (styleMap.containsKey("bottomOffset") && (i6 = (int) (((float) styleMap.getDouble("bottomOffset", 0.0d)) * context.getResources().getDisplayMetrics().density)) >= 0) {
            i8 = i6;
        }
        this.f15281h = i8;
        int height = subtitleView.getHeight();
        int i9 = this.f15281h;
        if (height > 0) {
            subtitleView.setBottomPaddingFraction(i9 > 0 ? L4.a.u(i9 / height, 0.0f, 1.0f) : 0.0f);
        }
    }

    public final void b(ExoPlayer exoPlayer) {
        ExoPlayer exoPlayer2 = this.f15277d;
        if (exoPlayer2 == exoPlayer) {
            this.f15275b.setPlayer(exoPlayer);
            this.f15274a.f15081b = exoPlayer;
            return;
        }
        if (exoPlayer2 != null) {
            exoPlayer2.removeListener(this.f15280g);
        }
        this.f15277d = exoPlayer;
        this.f15275b.setPlayer(exoPlayer);
        this.f15274a.f15081b = exoPlayer;
        this.f15276c.setCues(x4.y.f26065a);
        exoPlayer.addListener(this.f15280g);
    }

    public final void c() {
        ExoPlayer exoPlayer = this.f15277d;
        if (exoPlayer != null) {
            exoPlayer.removeListener(this.f15280g);
        }
        this.f15277d = null;
        this.f15275b.setPlayer(null);
        this.f15274a.f15081b = null;
        this.f15276c.setCues(x4.y.f26065a);
    }

    public final ArrayList d(List list) {
        ArrayList arrayList = new ArrayList();
        for (Object obj : list) {
            CharSequence charSequence = ((Cue) obj).text;
            String string = charSequence != null ? charSequence.toString() : null;
            if (string != null && string.length() != 0) {
                for (String str : this.f15279f) {
                    if (S4.p.D0(string, str, true)) {
                        break;
                    }
                }
            }
            arrayList.add(obj);
        }
        return arrayList;
    }
}
