package xyz.netfly.mobile.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.SeekBar;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import ie.g5;
import java.util.Formatter;
import java.util.Locale;
import tv.danmaku.ijk.media.player.ui.BasePlayerView;
import xyz.stream.view.UiUtils;

/* JADX INFO: loaded from: classes3.dex */
public class VideoDetailControl extends FrameLayout implements SeekBar.OnSeekBarChangeListener {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final /* synthetic */ int f35130g = 0;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final xyz.netfly.ads.h f35132b;

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

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

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

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

    public VideoDetailControl(Context context) {
        this(context, null);
    }

    public static String a(long j10) {
        StringBuilder sb = new StringBuilder();
        return UiUtils.getStringForTime(sb, new Formatter(sb, Locale.US), j10);
    }

    private void setWidthHeight(View view) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.width = 80;
        layoutParams.height = 80;
        view.setPadding(15, 15, 15, 15);
        view.setLayoutParams(layoutParams);
    }

    public final void b() {
        BasePlayerView basePlayerView = this.f35133c;
        if (basePlayerView == null) {
            return;
        }
        long duration = basePlayerView.getDuration();
        long currentPosition = this.f35133c.getCurrentPosition();
        long bufferedPosition = this.f35133c.getBufferedPosition();
        boolean z10 = currentPosition != this.f35135e;
        boolean z11 = duration != this.f35134d;
        this.f35134d = duration;
        this.f35135e = currentPosition;
        g5 g5Var = this.f35131a;
        if (z11) {
            g5Var.f26903c.setText(a(duration < 0 ? 0L : duration));
            StringBuilder sb = new StringBuilder(" / ");
            sb.append(a(duration < 0 ? 0L : duration));
            g5Var.f26909i.setText(sb.toString());
        }
        int i10 = duration == 0 ? 0 : (int) ((bufferedPosition * 100) / duration);
        if (z10 && !this.f35136f) {
            SeekBar seekBar = g5Var.f26908h;
            seekBar.setProgress((int) ((((long) seekBar.getMax()) * currentPosition) / duration));
            SeekBar seekBar2 = g5Var.f26908h;
            if (i10 >= 95) {
                seekBar2.setSecondaryProgress(seekBar2.getMax());
            } else {
                seekBar2.setSecondaryProgress(i10 * 10);
            }
            g5Var.f26903c.setText(String.format("%s", a(currentPosition)));
            g5Var.f26909i.setText(" / " + String.format("%s", a(duration)));
        }
        if (this.f35135e < C.DEFAULT_SEEK_FORWARD_INCREMENT_MS) {
            g5Var.f26907g.setEnabled(false);
            g5Var.f26907g.setAlpha(0.5f);
        } else {
            g5Var.f26907g.setEnabled(true);
            g5Var.f26907g.setAlpha(1.0f);
        }
        if (this.f35135e > duration - C.DEFAULT_SEEK_FORWARD_INCREMENT_MS) {
            g5Var.f26904d.setEnabled(false);
            g5Var.f26904d.setAlpha(0.5f);
        } else {
            g5Var.f26904d.setEnabled(true);
            g5Var.f26904d.setAlpha(1.0f);
        }
        removeCallbacks(this.f35132b);
        if (this.f35133c.isPlaying()) {
            postDelayed(this.f35132b, Math.max(200L, Math.min((long) ((1000 - (currentPosition % 1000)) / this.f35133c.getSpeed()), 1000L)));
        } else {
            postDelayed(this.f35132b, 1000L);
        }
    }

    public ImageView getBtnFullScreen() {
        return this.f35131a.f26902b;
    }

    public ImageView getBtnNext() {
        return this.f35131a.f26904d;
    }

    public ImageView getBtnPlay() {
        return this.f35131a.f26905e;
    }

    public ImageView getBtnPre() {
        return this.f35131a.f26907g;
    }

    public SeekBar getSeekBar() {
        return this.f35131a.f26908h;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        removeCallbacks(this.f35132b);
    }

    @Override // android.widget.SeekBar.OnSeekBarChangeListener
    public final void onProgressChanged(SeekBar seekBar, int i10, boolean z10) {
        if (z10) {
            long duration = this.f35133c.getDuration();
            long max = (((long) i10) * duration) / ((long) seekBar.getMax());
            g5 g5Var = this.f35131a;
            g5Var.f26903c.setText(String.format("%s", a(max)));
            g5Var.f26909i.setText(" / " + String.format("%s", a(duration)));
        }
    }

    @Override // android.widget.SeekBar.OnSeekBarChangeListener
    public final void onStartTrackingTouch(SeekBar seekBar) {
        this.f35136f = true;
    }

    @Override // android.widget.SeekBar.OnSeekBarChangeListener
    public final void onStopTrackingTouch(SeekBar seekBar) {
        long duration = (((long) this.f35133c.getDuration()) * ((long) seekBar.getProgress())) / ((long) seekBar.getMax());
        this.f35136f = false;
        xyz.netfly.api.c.b().o();
        this.f35133c.seekTo(duration);
        b();
    }

    @SuppressLint({"SetTextI18n"})
    public void setVideoView(BasePlayerView basePlayerView) {
        this.f35133c = basePlayerView;
        g5 g5Var = this.f35131a;
        g5Var.f26903c.setText(String.format("%s", a(0L)));
        g5Var.f26909i.setText(" / " + String.format("%s", a(0L)));
    }

    public VideoDetailControl(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public VideoDetailControl(Context context, @Nullable AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        g5 g5VarInflate = g5.inflate(LayoutInflater.from(context), this, true);
        this.f35131a = g5VarInflate;
        this.f35132b = new xyz.netfly.ads.h(this, 7);
        g5VarInflate.f26908h.setOnSeekBarChangeListener(this);
        removeCallbacks(this.f35132b);
        post(this.f35132b);
    }
}
