package xyz.netfly.ui.vod_player.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import ie.y4;
import me.d;
import org.drive_hunter.R;
import p000if.e;
import tf.a;
import tf.b;
import tv.danmaku.ijk.media.player.ui.BasePlayerView;
import xyz.stream.utils.f;
import xyz.stream.view.DefaultTimeBar;
import xyz.stream.view.UiUtils;
import xyz.stream.view.listener.SeekListener;
import xyz.stream.view.listener.TimeBar;

/* JADX INFO: loaded from: classes3.dex */
public class CustomSeekView extends FrameLayout implements TimeBar.OnScrubListener {

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final y4 f35735h;

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

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

    private void setFocusChangeListener(View... viewArr) {
        for (View view : viewArr) {
            view.setOnFocusChangeListener(new a(this, 1));
        }
    }

    public final void a() {
        removeCallbacks(this.f35728a);
        post(this.f35728a);
    }

    public final void b() {
        BasePlayerView basePlayerView = this.f35729b;
        if (basePlayerView == null) {
            return;
        }
        long duration = basePlayerView.getDuration();
        long currentPosition = this.f35729b.getCurrentPosition();
        long bufferedPosition = this.f35729b.getBufferedPosition();
        boolean z10 = currentPosition != this.f35731d;
        boolean z11 = duration != this.f35730c;
        this.f35730c = duration;
        this.f35731d = currentPosition;
        y4 y4Var = this.f35735h;
        if (z11) {
            y4Var.f27758s.setDuration(duration);
            y4Var.f27742c.setText(UiUtils.stringToTime(duration >= 0 ? duration : 0L));
        }
        if (z10 && !this.f35732e) {
            y4Var.f27758s.setPosition(currentPosition);
            y4Var.f27758s.setBufferedPosition(bufferedPosition);
            y4Var.f27742c.setText(String.format("%s / %s", UiUtils.stringToTime(currentPosition), UiUtils.stringToTime(duration)));
        }
        removeCallbacks(this.f35728a);
        if (this.f35729b.isPlaying()) {
            postDelayed(this.f35728a, Math.max(200L, Math.min((long) (Math.min(y4Var.f27758s.getPreferredUpdateDelay(), 1000 - (currentPosition % 1000)) / this.f35729b.getSpeed()), 1000L)));
        } else {
            postDelayed(this.f35728a, 1000L);
        }
    }

    public ConstraintLayout getBottomLayout() {
        return this.f35735h.f27741b;
    }

    public ImageView getBtnAudio() {
        return this.f35735h.f27744e;
    }

    public ImageView getBtnFeedback() {
        return this.f35735h.f27746g;
    }

    public ImageView getBtnNext() {
        return this.f35735h.f27747h;
    }

    public ImageView getBtnPlay() {
        return this.f35735h.f27745f;
    }

    public TextView getBtnQuality() {
        return this.f35735h.f27748i;
    }

    public ImageView getBtnRatio() {
        return this.f35735h.f27756q;
    }

    public ImageView getBtnSeries() {
        return this.f35735h.f27750k;
    }

    public ImageView getBtnSetting() {
        return this.f35735h.f27751l;
    }

    public ImageView getBtnSpeed() {
        return this.f35735h.f27753n;
    }

    public ImageView getBtnSubtitle() {
        return this.f35735h.f27754o;
    }

    public ImageView getBtnTvSetting() {
        return this.f35735h.f27752m;
    }

    public ImageView getIvBack() {
        return this.f35735h.f27743d;
    }

    public TextView getSecondTitleView() {
        return this.f35735h.f27749j;
    }

    public TextView getSubtitleProgressView() {
        return this.f35735h.f27757r;
    }

    public DefaultTimeBar getTimeBar() {
        return this.f35735h.f27758s;
    }

    public TextView getTitleView() {
        return this.f35735h.f27755p;
    }

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

    @Override // xyz.stream.view.listener.TimeBar.OnScrubListener
    public final void onScrubMove(TimeBar timeBar, long j10) {
        this.f35735h.f27742c.setText(String.format("%s / %s", UiUtils.stringToTime(j10), UiUtils.stringToTime(this.f35730c)));
        SeekListener seekListener = this.f35733f;
        if (seekListener != null) {
            seekListener.onSeekMove(timeBar, j10);
        }
    }

    @Override // xyz.stream.view.listener.TimeBar.OnScrubListener
    public final void onScrubStart(TimeBar timeBar, long j10) {
        this.f35732e = true;
        this.f35735h.f27742c.setText(String.format("%s / %s", UiUtils.stringToTime(j10), UiUtils.stringToTime(this.f35730c)));
        SeekListener seekListener = this.f35733f;
        if (seekListener != null) {
            seekListener.onSeekStart(timeBar, j10);
        }
    }

    @Override // xyz.stream.view.listener.TimeBar.OnScrubListener
    public final void onScrubStop(TimeBar timeBar, long j10, boolean z10) {
        this.f35732e = false;
        if (!z10 && this.f35729b != null) {
            f.p().x("seekToTimeBarPosition: positionMs = " + j10);
            this.f35729b.seekTo(j10);
            b();
        }
        SeekListener seekListener = this.f35733f;
        if (seekListener != null) {
            seekListener.onSeekStop(timeBar, j10, z10);
        }
    }

    public void setControllerListener(b bVar) {
        this.f35736i = bVar;
    }

    public void setPlayButtonIcon(boolean z10) {
        this.f35734g = z10;
        if (z10) {
            getBtnPlay().setImageDrawable(f.a.getDrawable(getContext(), getBtnPlay().isFocused() ? R.mipmap.live_pause_black : R.mipmap.live_pause_white));
        } else {
            getBtnPlay().setImageDrawable(f.a.getDrawable(getContext(), getBtnPlay().isFocused() ? R.mipmap.live_play_black : R.mipmap.live_play_white));
        }
    }

    public void setSeekListener(SeekListener seekListener) {
        this.f35733f = seekListener;
    }

    public void setVideoView(BasePlayerView basePlayerView) {
        this.f35729b = basePlayerView;
        this.f35735h.f27742c.setText(String.format("%s / %s", UiUtils.stringToTime(0L), UiUtils.stringToTime(0L)));
    }

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

    public CustomSeekView(Context context, @Nullable AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        y4 y4VarInflate = y4.inflate(LayoutInflater.from(context), null, false);
        this.f35735h = y4VarInflate;
        addView(y4VarInflate.f27740a);
        getBtnSubtitle().setImageDrawable(f.a.getDrawable(getContext(), R.mipmap.btn_subtitle_white));
        getBtnRatio().setImageDrawable(f.a.getDrawable(getContext(), R.mipmap.ratio_white));
        getBtnSeries().setImageDrawable(f.a.getDrawable(getContext(), R.mipmap.btn_series_white));
        getBtnSpeed().setImageDrawable(f.a.getDrawable(getContext(), R.mipmap.btn_speed_white));
        getBtnFeedback().setImageDrawable(f.a.getDrawable(getContext(), R.mipmap.play_feedback_white));
        getBtnNext().setImageDrawable(f.a.getDrawable(getContext(), R.mipmap.btn_next_white));
        getBtnAudio().setImageDrawable(f.a.getDrawable(getContext(), R.mipmap.btn_audio_white));
        getBtnTvSetting().setImageDrawable(f.a.getDrawable(getContext(), R.mipmap.mobile_settings));
        this.f35728a = new e(this, 10);
        DefaultTimeBar defaultTimeBar = y4VarInflate.f27758s;
        defaultTimeBar.setKeyTimeIncrement(10000L);
        getTimeBar().setOnKeyListener(new d(7));
        getTimeBar().setOnFocusChangeListener(new a(this, 0));
        setFocusChangeListener(getBtnPlay(), getBtnNext(), getBtnSeries(), getBtnSpeed(), getBtnFeedback(), getBtnSubtitle(), getBtnAudio(), getBtnRatio(), getBtnTvSetting());
        boolean z10 = xyz.stream.utils.e.d().f36119h;
        ImageView imageView = y4VarInflate.f27752m;
        ImageView imageView2 = y4VarInflate.f27751l;
        if (z10) {
            UiUtils.setUnFocusable(defaultTimeBar);
            UiUtils.setUnFocusable(y4VarInflate.f27745f);
            UiUtils.setUnFocusable(y4VarInflate.f27747h);
            UiUtils.setUnFocusable(y4VarInflate.f27746g);
            UiUtils.setUnFocusable(y4VarInflate.f27754o);
            UiUtils.setUnFocusable(y4VarInflate.f27744e);
            UiUtils.setUnFocusable(y4VarInflate.f27750k);
            UiUtils.setUnFocusable(y4VarInflate.f27748i);
            UiUtils.setUnFocusable(y4VarInflate.f27753n);
            UiUtils.setUnFocusable(y4VarInflate.f27756q);
            imageView2.setVisibility(0);
            imageView.setVisibility(8);
        } else {
            imageView2.setVisibility(8);
            imageView.setVisibility(0);
        }
        defaultTimeBar.addListener(this);
        a();
    }
}
