package com.bytedance.sdk.openadsdk.core.fhx.fm;

import android.app.Activity;
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.os.Looper;
import android.os.Message;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import b6.b;
import b6.d;
import b6.e;
import b6.f;
import b6.g;
import com.bykv.vk.openvk.fm.fm.fm.ajl.yz;
import com.bytedance.sdk.component.utils.mq;
import com.bytedance.sdk.openadsdk.core.fhx.ro.jnr;
import com.bytedance.sdk.openadsdk.core.fhx.yz.lb;
import com.bytedance.sdk.openadsdk.core.gof;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.onz.ajl;
import com.bytedance.sdk.openadsdk.core.widget.wey;
import com.bytedance.sdk.openadsdk.yz.jnr.ro.fhx;
import com.bytedance.sdk.openadsdk.yz.wsy;
import i6.a;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes2.dex */
public abstract class fm implements f, mq.fm, com.bytedance.sdk.openadsdk.core.fhx.ro.fm {
    protected boolean ai;
    protected lb ajl;

    /* JADX INFO: renamed from: gc, reason: collision with root package name */
    private long f7083gc;
    protected ajl gzf;
    protected final ViewGroup hi;
    protected boolean hlt;
    protected boolean irt;
    protected SurfaceTexture jnr;

    @NonNull
    protected final Context ku;
    protected ro lse;
    protected b mq;
    protected WeakReference<d> nt;
    protected long pkk;
    protected boolean sds;
    protected long wbw;
    protected jnr wsy;

    @NonNull
    protected final lse wu;
    protected SurfaceHolder yz;
    protected String fm = "TTAD.VideoController";
    protected final int ro = 100;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    protected final mq f7085lb = new mq(Looper.getMainLooper(), this);

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    protected long f7082ef = 0;
    protected long vt = 0;
    protected final List<Runnable> duv = new ArrayList();
    protected boolean dsz = false;
    protected boolean onz = false;
    protected boolean fhx = true;
    protected boolean qhl = false;
    protected boolean gof = false;
    protected boolean gqi = false;
    protected AtomicBoolean wey = new AtomicBoolean(false);
    protected boolean maa = true;
    protected AtomicInteger ol = new AtomicInteger(0);

    /* JADX INFO: renamed from: ha, reason: collision with root package name */
    protected boolean f7084ha = false;
    protected Runnable hxv = new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.fhx.fm.fm.1
        @Override // java.lang.Runnable
        public void run() {
            boolean z10 = fm.this.dsz;
            fm.this.wey();
        }
    };
    private long xgn = 0;
    private boolean mon = true;
    private int bx = 1;
    private final AtomicBoolean zan = new AtomicBoolean(false);

    /* JADX INFO: renamed from: com.bytedance.sdk.openadsdk.core.fhx.fm.fm$4, reason: invalid class name */
    public static /* synthetic */ class AnonymousClass4 {
        static final /* synthetic */ int[] fm;

        static {
            int[] iArr = new int[wey.fm.values().length];
            fm = iArr;
            try {
                iArr[wey.fm.PAUSE_VIDEO.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                fm[wey.fm.RELEASE_VIDEO.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                fm[wey.fm.START_VIDEO.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    public fm(Context context, @NonNull lse lseVar, ViewGroup viewGroup) {
        this.wu = lseVar;
        this.ku = context;
        this.hi = viewGroup;
        this.fm += hashCode();
    }

    private void hxv() {
        jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.yz(0);
            this.wsy.fm(false, false);
            this.wsy.lb(false);
            this.wsy.jnr();
            this.wsy.wsy();
        }
    }

    private boolean irt() {
        jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            return jnrVar.dsz() instanceof yz;
        }
        return false;
    }

    public final void ai() {
        this.f7084ha = true;
        fhx.fm fmVar = new fhx.fm();
        fmVar.ro(ajl());
        fmVar.yz(ef() / ((long) wbw()));
        fmVar.lb(wsy());
        fmVar.fm(qhl());
        com.bytedance.sdk.openadsdk.yz.jnr.fm.fm.fm(this.wsy, fmVar);
    }

    @Override // b6.f
    public long ajl() {
        return this.f7082ef;
    }

    @Override // b6.f
    public boolean dsz() {
        return this.onz;
    }

    @Override // b6.f
    public final long ef() {
        lb lbVar = this.ajl;
        if (lbVar == null) {
            return 0L;
        }
        return lbVar.qhl();
    }

    @Override // b6.f
    public boolean fhx() {
        return true;
    }

    @Override // b6.f
    public abstract /* synthetic */ void fm();

    @Override // b6.f
    public void fm(long j10) {
        this.wbw = j10;
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public abstract /* synthetic */ void fm(g gVar, View view);

    public abstract /* synthetic */ void fm(boolean z10, int i10);

    public void gof() {
        if (this.ajl == null) {
            return;
        }
        if (irt()) {
            SurfaceTexture surfaceTexture = this.jnr;
            if (surfaceTexture == null || surfaceTexture == this.ajl.wey()) {
                return;
            }
            this.ajl.fm(this.jnr);
            return;
        }
        SurfaceHolder surfaceHolder = this.yz;
        if (surfaceHolder == null || surfaceHolder == this.ajl.gqi()) {
            return;
        }
        this.ajl.fm(this.yz);
    }

    public void gqi() {
        if (this.duv.isEmpty()) {
            return;
        }
        Iterator it = new ArrayList(this.duv).iterator();
        while (it.hasNext()) {
            ((Runnable) it.next()).run();
        }
        this.duv.clear();
    }

    public final void gzf() {
        this.f7084ha = true;
        fhx.fm fmVar = new fhx.fm();
        fmVar.ro(ajl());
        fmVar.yz(ef() / ((long) wbw()));
        fmVar.lb(wsy());
        com.bytedance.sdk.openadsdk.yz.jnr.fm.fm.ro(duv(), fmVar);
    }

    public final long ha() {
        return wsy() + ajl();
    }

    public boolean hi() {
        return this.mon;
    }

    public boolean hlt() {
        return this.irt;
    }

    @Override // b6.f
    public abstract /* synthetic */ void jnr();

    public void jnr(boolean z10) {
        this.maa = z10;
    }

    @Override // b6.f
    public v5.b ku() {
        return this.ajl;
    }

    @Override // b6.f
    public abstract /* synthetic */ void lb();

    public void lb(long j10) {
        this.xgn = j10;
    }

    public boolean lse() {
        return this.qhl;
    }

    public boolean maa() {
        return this.fhx;
    }

    public final boolean mq() {
        lb lbVar = this.ajl;
        return lbVar != null && lbVar.ajl();
    }

    public final boolean nt() {
        lb lbVar = this.ajl;
        return lbVar == null || lbVar.ro();
    }

    public final void ol() {
        this.f7084ha = true;
        com.bytedance.sdk.openadsdk.yz.jnr.fm.fm.fm(this.wu, this.wsy, this.lse);
    }

    @Override // b6.f
    public final boolean onz() {
        return this.hlt;
    }

    public final void pkk() {
        com.bytedance.sdk.openadsdk.yz.fm.ro.fm(com.bytedance.sdk.openadsdk.hi.fm.fm(this.wu.zzm(), true, this.wu), 5, this.wu.eo());
    }

    public long qhl() {
        return this.wbw;
    }

    public void ro(int i10) {
        this.bx = i10;
    }

    @Override // b6.f
    /* JADX INFO: renamed from: sds, reason: merged with bridge method [inline-methods] */
    public final jnr duv() {
        return this.wsy;
    }

    @Override // b6.f
    public final int vt() {
        return a.a(this.vt, this.pkk);
    }

    public int wbw() {
        return this.bx;
    }

    public void wey() {
        this.f7085lb.postAtFrontOfQueue(new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.fhx.fm.fm.2
            @Override // java.lang.Runnable
            public void run() {
                fm fmVar = fm.this;
                if (fmVar.ajl != null) {
                    boolean z10 = fmVar.dsz;
                    fm.this.ajl.vt();
                }
            }
        });
    }

    @Override // b6.f
    public final long wsy() {
        lb lbVar = this.ajl;
        if (lbVar == null) {
            return 0L;
        }
        return lbVar.fhx();
    }

    @Override // b6.f
    public final int wu() {
        lb lbVar = this.ajl;
        if (lbVar == null) {
            return 0;
        }
        return lbVar.irt();
    }

    @Override // b6.f
    public abstract /* synthetic */ void yz();

    public void yz(long j10) {
        this.pkk = j10;
    }

    @Override // com.bytedance.sdk.component.utils.mq.fm
    public void fm(Message message) {
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm, b6.a
    public final void jnr(g gVar, View view) {
        fm(gVar, view, false);
    }

    public void lb(boolean z10) {
        this.gqi = z10;
    }

    public final void ro(boolean z10) {
        this.onz = z10;
    }

    public final void yz(boolean z10) {
        this.mon = z10;
    }

    @Override // b6.f
    public final void fm(b bVar) {
        this.mq = bVar;
    }

    public final void jnr(long j10) {
        this.f7082ef = j10;
        this.vt = Math.max(this.vt, j10);
        jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.fm();
        }
        lb lbVar = this.ajl;
        if (lbVar != null) {
            lbVar.fm(true, this.f7082ef, this.irt);
        }
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public final void lb(g gVar, View view) {
        jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.ef();
        }
        fm(true, 3);
    }

    public void ro(long j10) {
        this.f7082ef = j10;
        this.vt = Math.max(this.vt, j10);
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public final void yz(g gVar, View view) {
        if (this.gqi) {
            lb(false);
            jnr jnrVar = this.wsy;
            if (jnrVar != null) {
                jnrVar.ro(this.hi);
            }
            fm(1);
            return;
        }
        fm(true, 3);
    }

    public void fm(e eVar) {
    }

    public void ro(Runnable runnable) {
        this.duv.add(runnable);
    }

    private boolean lb(int i10) {
        return this.wsy.ro(i10);
    }

    public void fm(g gVar, View view, boolean z10) {
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public void ro(g gVar, SurfaceHolder surfaceHolder) {
        this.dsz = false;
        this.yz = null;
        lb lbVar = this.ajl;
        if (lbVar != null) {
            lbVar.fm(false);
        }
    }

    @Override // b6.f
    public boolean fm(com.bykv.vk.openvk.fm.fm.fm.lb.lb lbVar) {
        return false;
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public void ro(g gVar, SurfaceTexture surfaceTexture) {
        this.dsz = false;
        lb lbVar = this.ajl;
        if (lbVar != null) {
            lbVar.fm(false);
        }
        this.jnr = null;
        gqi();
    }

    public void fm(Runnable runnable) {
        if (this.wsy.maa() && this.dsz) {
            runnable.run();
        } else {
            ro(runnable);
        }
    }

    public void ro(com.bykv.vk.openvk.fm.fm.fm.lb.lb lbVar) {
        ro roVar = (ro) lbVar;
        this.lse = roVar;
        this.irt = roVar.ku();
        lbVar.yz(String.valueOf(this.wu.pg()));
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public void fm(g gVar, SurfaceHolder surfaceHolder) {
        this.dsz = true;
        this.yz = surfaceHolder;
        lb lbVar = this.ajl;
        if (lbVar == null) {
            return;
        }
        lbVar.fm(surfaceHolder);
        gqi();
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public final void ro(g gVar, View view) {
        ro(gVar, view, false, false);
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public void fm(g gVar, SurfaceTexture surfaceTexture) {
        this.dsz = true;
        this.jnr = surfaceTexture;
        lb lbVar = this.ajl;
        if (lbVar != null) {
            lbVar.fm(surfaceTexture);
            this.ajl.fm(this.dsz);
        }
        gqi();
    }

    public final void ro(g gVar, View view, boolean z10, boolean z11) {
        lb(!this.gqi);
        Context context = this.ku;
        if (context != null && (context instanceof Activity)) {
            if (this.gqi) {
                fm(z10 ? 8 : 0);
                jnr jnrVar = this.wsy;
                if (jnrVar != null) {
                    jnrVar.fm(this.hi);
                    this.wsy.lb(false);
                }
            } else {
                fm(1);
                jnr jnrVar2 = this.wsy;
                if (jnrVar2 != null) {
                    jnrVar2.ro(this.hi);
                    this.wsy.lb(false);
                }
            }
            WeakReference<d> weakReference = this.nt;
            d dVar = weakReference != null ? weakReference.get() : null;
            if (dVar != null) {
                dVar.fm(this.gqi);
            }
        }
    }

    public void fm(boolean z10) {
        this.fhx = z10;
        jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.yz(z10);
        }
    }

    @Override // b6.f
    public final void fm(final boolean z10, String str) {
        this.irt = z10;
        lb lbVar = this.ajl;
        if (lbVar != null) {
            lbVar.ro(z10);
            com.bytedance.sdk.openadsdk.yz.jnr.fm.fm.fm(this.wsy, z10, str);
        }
        if (this.gzf != null) {
            if (hb.a.a0()) {
                this.gzf.fm(z10);
            } else {
                this.f7085lb.post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.fhx.fm.fm.3
                    @Override // java.lang.Runnable
                    public void run() {
                        fm.this.gzf.fm(z10);
                    }
                });
            }
        }
    }

    public final void fm(d dVar) {
        this.nt = new WeakReference<>(dVar);
    }

    public final void fm(int i10) {
        Context context = this.ku;
        if (context == null) {
            return;
        }
        boolean z10 = i10 == 0 || i10 == 8;
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            try {
                activity.setRequestedOrientation(i10);
            } catch (Throwable unused) {
            }
            if (!z10) {
                activity.getWindow().setFlags(1024, 1024);
            } else {
                activity.getWindow().clearFlags(1024);
            }
        }
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public final void ro(g gVar, int i10) {
        jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.ajl();
        }
    }

    public final void ro(wsy wsyVar) {
        this.f7084ha = true;
        fhx.fm fmVar = new fhx.fm();
        fmVar.ro(ajl());
        fmVar.yz(ef() / ((long) wbw()));
        fmVar.lb(wsy());
        fmVar.yz(wu());
        fmVar.fm(qhl());
        fmVar.lb(this.ai);
        com.bytedance.sdk.openadsdk.yz.jnr.fm.fm.ro(this.wsy, fmVar, wsyVar);
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public final void fm(g gVar, View view, boolean z10, boolean z11) {
        if (this.fhx) {
            ro();
        }
        if (z10 && !this.fhx && !nt()) {
            this.wsy.ro(!mq(), false);
            this.wsy.fm(z11, true, false);
        }
        lb lbVar = this.ajl;
        if (lbVar != null && lbVar.ajl()) {
            this.wsy.ajl();
            this.wsy.jnr();
        } else {
            this.wsy.ajl();
        }
    }

    @Override // b6.f
    public final void ro() {
        lb lbVar = this.ajl;
        if (lbVar != null) {
            lbVar.ku();
        }
        if (this.sds || !this.wey.get()) {
            return;
        }
        ai();
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public final void fm(g gVar, int i10, boolean z10) {
        if (this.ku == null) {
            return;
        }
        long j10 = (long) (((((long) i10) * r0) * 1.0f) / 100.0f);
        if (this.pkk > 0) {
            this.f7083gc = (int) j10;
        } else {
            this.f7083gc = 0L;
        }
        jnr jnrVar = this.wsy;
        if (jnrVar != null) {
            jnrVar.fm(this.f7083gc);
        }
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public final void fm(g gVar, int i10) {
        if (this.ajl == null) {
            return;
        }
        fm(this.f7083gc, lb(i10));
    }

    private void fm(long j10, boolean z10) {
        if (this.ajl == null) {
            return;
        }
        if (z10) {
            hxv();
        }
        this.ajl.fm(j10);
    }

    public final void fm(wsy wsyVar) {
        boolean z10 = false;
        if (this.wey.compareAndSet(false, true)) {
            this.f7084ha = true;
            ajl ajlVar = this.gzf;
            if (ajlVar != null) {
                ajlVar.fm(ef(), hlt());
            }
            fhx.fm fmVar = new fhx.fm();
            fmVar.fm(hi());
            fmVar.yz(ef());
            lb lbVar = this.ajl;
            if (lbVar != null && lbVar.onz()) {
                z10 = true;
            }
            fmVar.ro(z10);
            com.bytedance.sdk.openadsdk.yz.jnr.fm.fm.fm(gof.fm(), this.wsy, fmVar, wsyVar);
        }
    }

    public final void fm(com.bykv.vk.openvk.fm.fm.fm.lb.a aVar) {
        this.f7084ha = true;
        fhx.fm fmVar = new fhx.fm();
        fmVar.lb(wsy());
        fmVar.yz(ef() / ((long) wbw()));
        fmVar.ro(ajl());
        fmVar.fm(aVar);
        com.bytedance.sdk.openadsdk.yz.jnr.fm.fm.lb(duv(), fmVar);
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.fm
    public final void fm(wey.fm fmVar, String str) {
        int i10 = AnonymousClass4.fm[fmVar.ordinal()];
        if (i10 == 1) {
            ro();
            return;
        }
        if (i10 == 2) {
            yz();
        } else {
            if (i10 != 3) {
                return;
            }
            lb();
            this.qhl = false;
            this.gof = true;
        }
    }

    @Override // b6.f
    public boolean fm(float f10) {
        lb lbVar = this.ajl;
        if (lbVar != null) {
            return lbVar.fm(f10);
        }
        return false;
    }

    public void fm(long j10, long j11) {
        if (!this.zan.get() && com.bytedance.sdk.openadsdk.ajl.fm.fm().lb() && (j10 * 1.0d) / j11 > 0.3d) {
            this.zan.set(true);
            if (this.wu != null) {
                com.bytedance.sdk.openadsdk.ajl.ro.fm().fm("videoPercent30", this.wu);
            }
        }
    }

    @Override // b6.f
    public void fm(SurfaceTexture surfaceTexture) {
        this.ai = true;
        this.ol.incrementAndGet();
    }
}
