package rf;

import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.google.android.gms.common.api.internal.i0;
import ie.f5;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
import org.drive_hunter.R;
import tv.danmaku.ijk.media.player.ui.BasePlayerView;
import tv.danmaku.ijk.media.player.ui.IjkPlayerRuntime;
import tv.danmaku.ijk.media.player.ui.subtitleconverter.SubtitleView;
import xyz.netfly.ui.vod_player.view.CustomSeekView;
import xyz.stream.api.entity.PlayerSettingEntity;
import xyz.stream.api.entity.SeriesEntity;
import xyz.stream.api.entity.VideoInfoEntity;
import xyz.stream.download.DownloadFile;
import xyz.stream.utils.entity.CheckResultEntity;
import xyz.stream.utils.f0;
import xyz.stream.view.UiUtils;

/* JADX INFO: loaded from: classes3.dex */
public final class w implements tf.b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public CustomSeekView f32598a;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Activity f32600c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public ag.h f32601d;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public ImageView f32603f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public List f32604g;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public xyz.netfly.player.r f32608k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public xyz.netfly.player.n f32609l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public VideoInfoEntity f32610m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public String f32611n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public ie.s f32612o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public Double f32613p;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public View f32615r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public t f32616s;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Handler f32599b = new Handler(Looper.getMainLooper());

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f32605h = -1;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final List f32606i = Arrays.asList("0.5x", "0.75x", "1.0x(Normal)", "1.25x", "1.5x", "2.0x");

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public int f32607j = 2;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public int f32614q = 1;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public List f32618u = new ArrayList();

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public DownloadFile f32620w = null;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public boolean f32621x = false;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final i0 f32622y = new i0(this, 11);

    public static void a(w wVar, f5 f5Var) {
        wVar.getClass();
        wVar.updateSubtitleBackground(!(f0.o().p("sp_subtitle_bg_enable", 0) == 1), f5Var);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void applySubtitleSize(int i10, @Nullable f5 f5Var) {
        f0.o().v(i10, IjkPlayerRuntime.SP_SUBTITLE_SIZE);
        if (f5Var != null) {
            z(f5Var);
        }
        int iPlayerSubtitleSizePx = UiUtils.playerSubtitleSizePx(this.f32600c, i10);
        this.f32612o.f27444i.setTextSizePx(iPlayerSubtitleSizePx);
        BasePlayerView basePlayerView = this.f32602e;
        if (basePlayerView != null) {
            basePlayerView.setSubtitleSizePx(iPlayerSubtitleSizePx);
        }
    }

    public static /* synthetic */ void e(w wVar, int i10) {
        wVar.getClass();
        String strA = xyz.netfly.player.r.a(xyz.stream.api.o.f().u(wVar.f32610m.getId().intValue(), ((SeriesEntity) wVar.f32604g.get(i10)).getVideoId()));
        if (strA == null || strA.isEmpty()) {
            wVar.F(R.string.no_video_source);
            return;
        }
        wVar.f32602e.getCurrentPosition();
        wVar.f32602e.getDuration();
        wVar.f32605h = i10;
        int videoId = ((SeriesEntity) wVar.f32604g.get(i10)).getVideoId();
        wVar.C();
        ag.h hVar = wVar.f32601d;
        if (hVar != null) {
            hVar.j(videoId, ((SeriesEntity) wVar.f32604g.get(i10)).getCurrentDuration(), strA);
        }
    }

    public static void f(w wVar, View view) {
        wVar.getClass();
        kotlinx.coroutines.flow.h.d(view);
        wVar.f32615r = view;
        List list = wVar.f32604g;
        if (list == null || list.isEmpty()) {
            wVar.F(R.string.no_video_source);
            return;
        }
        wVar.s();
        int currentPosition = wVar.f32602e.getCurrentPosition();
        int duration = wVar.f32602e.getDuration();
        ((SeriesEntity) wVar.f32604g.get(wVar.f32605h)).setCurrentDuration(currentPosition);
        ((SeriesEntity) wVar.f32604g.get(wVar.f32605h)).setRuntime(duration);
        uf.r.k(wVar.f32600c, wVar.f32610m.getId().intValue(), wVar.f32618u, wVar.f32617t, wVar.f32604g, wVar.f32605h, new f0(wVar, 27));
    }

    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    public static void j(w wVar, PlayerSettingEntity playerSettingEntity) {
        wVar.getClass();
        if (playerSettingEntity.getId() == 2) {
            wVar.applySubtitleSize(playerSettingEntity.getDefaultValue().equals(wVar.f32600c.getString(R.string.small)) ? 45 : playerSettingEntity.getDefaultValue().equals(wVar.f32600c.getString(R.string.medium)) ? 50 : 55, null);
            return;
        }
        if (playerSettingEntity.getId() == 3) {
            wVar.updateSubtitleBackground(playerSettingEntity.getDefaultValue().equals(wVar.f32600c.getString(R.string.on)), null);
            return;
        }
        if (playerSettingEntity.getId() != 4) {
            if (playerSettingEntity.getId() == 1) {
                wVar.f32613p = Double.valueOf(u(playerSettingEntity.getDefaultValue()));
            }
        } else {
            boolean zEquals = playerSettingEntity.getDefaultValue().equals(wVar.f32600c.getString(R.string.on));
            wVar.f32614q = zEquals ? 1 : 0;
            ag.h hVar = wVar.f32601d;
            if (hVar != null) {
                hVar.i(zEquals ? 1 : 0);
            }
        }
    }

    public static void k(w wVar, PlayerSettingEntity playerSettingEntity, boolean z10) {
        wVar.getClass();
        if (playerSettingEntity.getId() == 1) {
            double dU = u(playerSettingEntity.getDefaultValue());
            playerSettingEntity.setDefaultValue(o(z10 ? dU + 0.1d : dU - 0.1d));
            return;
        }
        List<String> values = playerSettingEntity.getValues();
        if (values == null || values.isEmpty()) {
            return;
        }
        int iIndexOf = values.indexOf(playerSettingEntity.getDefaultValue());
        int size = 0;
        if (iIndexOf < 0) {
            iIndexOf = 0;
        }
        if (z10) {
            size = iIndexOf > 0 ? iIndexOf - 1 : values.size() - 1;
        } else if (iIndexOf < values.size() - 1) {
            size = iIndexOf + 1;
        }
        playerSettingEntity.setDefaultValue(values.get(size));
    }

    public static String o(double d10) {
        double dP = p(d10);
        return String.format(Locale.US, "%s %s s", dP > 0.0d ? "+" : dP == 0.0d ? "" : "-", Double.valueOf(Math.abs(dP)));
    }

    public static double p(double d10) {
        return Double.parseDouble(String.format(Locale.US, "%.1f", Double.valueOf(d10)));
    }

    public static LinkedHashMap r(Activity activity) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put(0, activity.getString(R.string.original));
        linkedHashMap.put(1, "16 : 9");
        linkedHashMap.put(2, "4 : 3");
        linkedHashMap.put(4, activity.getString(R.string.full));
        return linkedHashMap;
    }

    public static double u(String str) {
        if (str != null && !str.isEmpty()) {
            try {
                double d10 = Double.parseDouble(str.replace(" s", "").replace("+", "").replace("-", "").replace(",", "."));
                if (str.contains("-")) {
                    d10 = -d10;
                }
                return p(d10);
            } catch (NumberFormatException e10) {
                xyz.stream.utils.h.c(e10.getMessage());
            }
        }
        return 0.0d;
    }

    private void updateSubtitleBackground(boolean z10, @Nullable f5 f5Var) {
        f0.o().v(z10 ? 1 : 0, "sp_subtitle_bg_enable");
        SubtitleView subtitleView = this.f32612o.f27444i;
        Activity activity = this.f32600c;
        int i10 = z10 ? R.color.subtitle_bg : android.R.color.transparent;
        Object obj = g0.d.f26125a;
        subtitleView.setBackgroundColor(activity.getColor(i10));
        BasePlayerView basePlayerView = this.f32602e;
        if (basePlayerView != null) {
            basePlayerView.setSubtitleBgEnable(z10);
        }
        if (f5Var != null) {
            f5Var.f26861e.setImageResource(z10 ? R.mipmap.switch_on : R.mipmap.switch_off);
        }
    }

    public final void A(TextView textView) {
        Double d10 = this.f32613p;
        textView.setText(o(d10 == null ? 0.0d : d10.doubleValue()));
    }

    public final void B(String str, String str2) {
        this.f32598a.getTitleView().setText(str);
        if (str2 == null || str2.isEmpty()) {
            this.f32598a.getSecondTitleView().setVisibility(8);
        } else {
            this.f32598a.getSecondTitleView().setVisibility(0);
            this.f32598a.getSecondTitleView().setText(str2);
        }
    }

    public final void C() {
        if (this.f32598a == null || this.f32610m == null) {
            return;
        }
        List list = this.f32604g;
        if (list == null || list.isEmpty()) {
            w(new o(this, 3));
        } else {
            StringBuilder sb = new StringBuilder();
            int i10 = this.f32605h;
            if (i10 >= 0 && i10 < this.f32604g.size()) {
                sb.append("S");
                sb.append(((SeriesEntity) this.f32604g.get(this.f32605h)).getSeasonNumber());
                sb.append(".E");
                sb.append(this.f32605h + 1);
                sb.append(" · ");
                sb.append(((SeriesEntity) this.f32604g.get(this.f32605h)).getName() == null ? "" : ((SeriesEntity) this.f32604g.get(this.f32605h)).getName());
            }
            w(new ve.b(this, sb, 12));
        }
        String str = this.f32611n;
        CheckResultEntity checkResultEntityC = xyz.stream.utils.e.d().c();
        if (checkResultEntityC == null || checkResultEntityC.getIsPremium().intValue() == 1) {
            w(new ve.b(this, str, 13));
        } else {
            m();
        }
    }

    public final void D() {
        if (this.f32598a == null) {
            return;
        }
        x();
        this.f32598a.setVisibility(0);
        View view = this.f32615r;
        if (view == null) {
            this.f32598a.getBtnPlay().requestFocus();
        } else {
            view.requestFocus();
            this.f32615r = null;
        }
    }

    public final void E() {
        if (this.f32598a == null) {
            return;
        }
        x();
        this.f32598a.setVisibility(0);
        this.f32598a.getTimeBar().requestFocus();
    }

    public final void F(int i10) {
        if (t()) {
            return;
        }
        w(new q(this, i10, 1));
    }

    public final void G() {
        this.f32602e.start();
        this.f32603f.setImageResource(R.mipmap.pause);
        y(true);
        this.f32603f.setVisibility(8);
        x();
        if (this.f32621x) {
            return;
        }
        xyz.netfly.api.c.b().m();
    }

    public final void H() {
        CustomSeekView customSeekView = this.f32598a;
        if (customSeekView == null) {
            return;
        }
        if (customSeekView.getVisibility() == 0) {
            s();
        } else if (this.f32602e.getPlaybackState() > 0 || this.f32602e.getPlaybackState() == -1) {
            D();
        }
    }

    public final void I() {
        if (this.f32602e.getPlaybackState() <= 2) {
            return;
        }
        if (this.f32602e.isPlaying()) {
            v();
        } else {
            G();
        }
    }

    public final void J() {
        CustomSeekView customSeekView = this.f32598a;
        if (customSeekView == null || this.f32608k == null) {
            return;
        }
        customSeekView.getBtnQuality().setVisibility(this.f32608k.f35275b.size() > 1 ? 0 : 8);
        String strC = this.f32608k.c();
        if (strC != null) {
            this.f32598a.getBtnQuality().setText(strC);
        }
    }

    public final void l(int i10) {
        int iIntValue;
        x();
        List list = this.f32604g;
        if (list == null || list.isEmpty() || i10 < 0 || this.f32610m == null) {
            return;
        }
        int i11 = 0;
        if (i10 >= this.f32604g.size()) {
            if (this.f32618u.isEmpty() || this.f32617t == ((Integer) defpackage.e.c(this.f32618u, 1)).intValue()) {
                F(R.string.last_video);
            } else {
                int i12 = 0;
                while (true) {
                    if (i12 >= this.f32618u.size()) {
                        iIntValue = -1;
                        break;
                    } else {
                        if (((Integer) this.f32618u.get(i12)).intValue() == this.f32617t && i12 < this.f32618u.size() - 1) {
                            iIntValue = ((Integer) this.f32618u.get(i12 + 1)).intValue();
                            break;
                        }
                        i12++;
                    }
                }
                if (iIntValue <= 0) {
                    F(R.string.last_video);
                } else {
                    List listM = xyz.stream.api.o.f().m(this.f32610m.getId().intValue(), 0, Integer.valueOf(iIntValue));
                    if (listM == null || listM.isEmpty()) {
                        F(R.string.no_video_source);
                    } else {
                        this.f32604g = listM;
                        this.f32617t = iIntValue;
                        this.f32605h = 0;
                        i10 = 0;
                    }
                }
            }
            i10 = -1;
        }
        if (i10 < 0 || i10 >= this.f32604g.size() || this.f32619v == ((SeriesEntity) this.f32604g.get(i10)).getVideoId()) {
            return;
        }
        new Thread(new q(this, i10, i11)).start();
    }

    public final void m() {
        if (this.f32616s == null) {
            return;
        }
        Activity activity = this.f32600c;
        if (activity != null) {
            try {
                com.bumptech.glide.c.c(activity).clear(this.f32616s);
            } catch (Exception unused) {
            }
        }
        this.f32616s = null;
    }

    public final void n() {
        this.f32599b.removeCallbacks(this.f32622y);
        m();
        this.f32601d = null;
        this.f32612o = null;
        this.f32598a = null;
        this.f32609l = null;
        this.f32602e = null;
        this.f32603f = null;
        this.f32604g = null;
        this.f32610m = null;
        this.f32611n = null;
        this.f32620w = null;
        this.f32615r = null;
        this.f32618u.clear();
        this.f32600c = null;
        xyz.netfly.player.r rVar = this.f32608k;
        if (rVar != null) {
            rVar.f35277d = null;
            rVar.f35275b.clear();
            rVar.f35276c = 0;
            this.f32608k = null;
        }
    }

    public final VideoInfoEntity q(int i10, int i11) {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        AtomicReference atomicReference = new AtomicReference();
        xyz.stream.api.o.f().s(i10, i11, new xyz.netfly.mobile.player.p(this, atomicReference, countDownLatch, 1));
        try {
            countDownLatch.await();
            return (VideoInfoEntity) atomicReference.get();
        } catch (InterruptedException e10) {
            Thread.currentThread().interrupt();
            xyz.stream.utils.h.c(e10.getMessage());
            return null;
        }
    }

    public final void s() {
        if (this.f32598a == null) {
            return;
        }
        this.f32599b.removeCallbacks(this.f32622y);
        this.f32598a.setVisibility(8);
    }

    public final boolean t() {
        Activity activity = this.f32600c;
        return activity == null || activity.isDestroyed() || this.f32600c.isFinishing();
    }

    public final void v() {
        this.f32602e.pause();
        this.f32603f.setImageResource(R.mipmap.play);
        y(false);
        this.f32603f.setVisibility(0);
        this.f32599b.removeCallbacks(this.f32622y);
        if (this.f32621x) {
            return;
        }
        xyz.netfly.api.c.b().h();
    }

    public final void w(Runnable runnable) {
        if (t()) {
            return;
        }
        this.f32600c.runOnUiThread(runnable);
    }

    public final void x() {
        Handler handler = this.f32599b;
        i0 i0Var = this.f32622y;
        handler.removeCallbacks(i0Var);
        handler.postDelayed(i0Var, 5000L);
    }

    public final void y(boolean z10) {
        this.f32598a.setPlayButtonIcon(z10);
    }

    public final void z(f5 f5Var) {
        int iP = f0.o().p(IjkPlayerRuntime.SP_SUBTITLE_SIZE, 50);
        if (iP == 45) {
            f5Var.f26870n.setBackgroundResource(R.drawable.shape_circle_subtitle_select);
            f5Var.f26869m.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
            f5Var.f26868l.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
            Activity activity = this.f32600c;
            Object obj = g0.d.f26125a;
            f5Var.f26866j.setTextColor(activity.getColor(R.color.white));
            f5Var.f26865i.setTextColor(this.f32600c.getColor(R.color.black_9));
            f5Var.f26864h.setTextColor(this.f32600c.getColor(R.color.black_9));
            return;
        }
        if (iP == 50) {
            f5Var.f26870n.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
            f5Var.f26869m.setBackgroundResource(R.drawable.shape_circle_subtitle_select);
            f5Var.f26868l.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
            Activity activity2 = this.f32600c;
            Object obj2 = g0.d.f26125a;
            f5Var.f26866j.setTextColor(activity2.getColor(R.color.black_9));
            f5Var.f26865i.setTextColor(this.f32600c.getColor(R.color.white));
            f5Var.f26864h.setTextColor(this.f32600c.getColor(R.color.black_9));
            return;
        }
        f5Var.f26870n.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
        f5Var.f26869m.setBackgroundResource(R.drawable.shape_circle_subtitle_unselect);
        f5Var.f26868l.setBackgroundResource(R.drawable.shape_circle_subtitle_select);
        Activity activity3 = this.f32600c;
        Object obj3 = g0.d.f26125a;
        f5Var.f26866j.setTextColor(activity3.getColor(R.color.black_9));
        f5Var.f26865i.setTextColor(this.f32600c.getColor(R.color.black_9));
        f5Var.f26864h.setTextColor(this.f32600c.getColor(R.color.white));
    }
}
