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

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.Pair;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import b6.b;
import b6.c;
import b6.e;
import com.bytedance.sdk.component.utils.maa;
import com.bytedance.sdk.component.utils.mq;
import com.bytedance.sdk.openadsdk.CacheDirFactory;
import com.bytedance.sdk.openadsdk.api.nativeAd.PAGNativeAd;
import com.bytedance.sdk.openadsdk.core.fhx;
import com.bytedance.sdk.openadsdk.core.fhx.ro.lb;
import com.bytedance.sdk.openadsdk.core.gc;
import com.bytedance.sdk.openadsdk.core.gof;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.vt;
import com.bytedance.sdk.openadsdk.utils.bx;
import com.bytedance.sdk.openadsdk.utils.xgn;
import com.bytedance.sdk.openadsdk.utils.zan;
import com.bytedance.sdk.openadsdk.yz.jnr.ro.fhx;
import com.bytedance.sdk.openadsdk.yz.wsy;
import com.iab.omid.library.bytedance2.adsession.FriendlyObstructionPurpose;
import e6.a;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/* JADX INFO: loaded from: classes2.dex */
@SuppressLint({"ViewConstructor"})
public class ajl extends com.bytedance.sdk.openadsdk.core.ajl.lb implements b, mq.fm, lb.fm {
    private long ai;
    public wsy ajl;
    private ViewTreeObserver.OnGlobalLayoutListener bx;
    protected int dsz;
    protected String duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    protected ImageView f7092ef;
    protected boolean fhx;
    protected final lse fm;

    /* JADX INFO: renamed from: gc, reason: collision with root package name */
    private final String f7093gc;
    private ViewGroup gof;
    private boolean gqi;
    private boolean gzf;

    /* JADX INFO: renamed from: ha, reason: collision with root package name */
    private boolean f7094ha;
    private boolean hi;
    private String hlt;
    private boolean hxv;
    public ro irt;
    public boolean jnr;
    protected boolean ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    protected FrameLayout f7095lb;
    private final AtomicBoolean lz;
    private c mon;
    private boolean mq;
    private boolean nt;
    private final boolean ol;
    boolean onz;
    private long pkk;

    /* JADX INFO: renamed from: qf, reason: collision with root package name */
    private final ViewTreeObserver.OnScrollChangedListener f7096qf;
    private final Context qhl;
    protected lb ro;
    private String sds;
    private final Runnable tzk;
    protected ImageView vt;
    private final Handler wbw;
    private boolean wey;
    protected RelativeLayout wsy;
    protected ImageView wu;
    private View xgn;
    protected boolean yz;
    private final AtomicBoolean zan;
    private static final Integer maa = 0;
    private static final Integer lse = 1;

    public interface fm {
        void fm(View view, int i10);
    }

    public interface ro {
        void fm(boolean z10, long j10, long j11, long j12, boolean z11);
    }

    public ajl(@NonNull Context context, @NonNull lse lseVar, boolean z10, wsy wsyVar) {
        this(context, lseVar, z10, "embeded_ad", false, false, wsyVar);
    }

    private void ai() {
        if (this.ro == null || ha()) {
            return;
        }
        if ((!hi() || com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_multi_native_video_data", "key_video_is_update_flag", false)) && hi()) {
            long jEf = this.ro.ef();
            long jWsy = this.ro.wsy() + jEf;
            boolean zFm = com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_multi_native_video_data", "key_native_video_complete", false);
            long jFm = com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_multi_native_video_data", "key_video_current_play_position", 0L);
            long jFm2 = com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_multi_native_video_data", "key_video_total_play_duration", jWsy);
            long jFm3 = com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_multi_native_video_data", "key_video_duration", jEf);
            com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_multi_native_video_data", "key_video_is_update_flag", Boolean.FALSE);
            this.ro.ro(zFm);
            this.ro.ro(jFm);
            this.ro.lb(jFm2);
            this.ro.yz(jFm3);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void gof() {
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        Handler handler = this.wbw;
        if (handler == null || jElapsedRealtime - this.pkk <= 500) {
            return;
        }
        this.pkk = jElapsedRealtime;
        handler.sendEmptyMessageDelayed(1, 500L);
    }

    private void gqi() {
        this.ro = new lb(this.qhl, this.f7095lb, this.fm, this.duv, !ha(), this.nt, this.mq, this.ajl);
        wey();
        if (this.bx == null) {
            this.bx = new ViewTreeObserver.OnGlobalLayoutListener() { // from class: com.bytedance.sdk.openadsdk.core.fhx.ro.ajl.3
                @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
                public void onGlobalLayout() {
                    ajl ajlVar;
                    lb lbVar;
                    if (ajl.this.gof == null || ajl.this.gof.getViewTreeObserver() == null || (lbVar = (ajlVar = ajl.this).ro) == null) {
                        return;
                    }
                    lbVar.fm(ajlVar.gof.getWidth(), ajl.this.gof.getHeight());
                    ajl.this.gof.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    ajl.this.bx = null;
                }
            };
            this.gof.getViewTreeObserver().addOnGlobalLayoutListener(this.bx);
        }
    }

    private void gzf() {
        this.wbw.removeMessages(1);
        fhx.lb().removeCallbacks(this.tzk);
    }

    private boolean ha() {
        return this.wey;
    }

    private boolean hi() {
        lse lseVar = this.fm;
        if (lseVar == null) {
            return false;
        }
        return lseVar.zew();
    }

    private void hlt() {
        this.f7094ha = duv();
        xgn.fm(this.tzk);
    }

    private void jnr() {
        addView(fm(this.qhl));
        gqi();
        addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { // from class: com.bytedance.sdk.openadsdk.core.fhx.ro.ajl.1
            @Override // android.view.View.OnAttachStateChangeListener
            public void onViewAttachedToWindow(View view) {
                ajl.this.gof();
            }

            @Override // android.view.View.OnAttachStateChangeListener
            public void onViewDetachedFromWindow(View view) {
                ajl.this.gof();
            }
        });
    }

    private void lse() {
        if (!this.zan.get()) {
            this.zan.set(true);
            lb lbVar = this.ro;
            if (lbVar != null) {
                lbVar.fm(true, 3);
            }
        }
        this.lz.set(false);
    }

    private void maa() {
        this.irt = null;
        if ((this.ro instanceof lb) && !ha()) {
            this.ro.hxv();
        }
        ku();
        fm(false);
        lse();
    }

    private void mq() {
        if (ha() || !hi()) {
            return;
        }
        Boolean bool = Boolean.FALSE;
        com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_multi_native_video_data", "key_video_isfromvideodetailpage", bool);
        com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_multi_native_video_data", "key_video_is_from_detail_page", bool);
    }

    private boolean nt() {
        if (ha() || !hi()) {
            return false;
        }
        return com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_multi_native_video_data", "key_video_is_from_detail_page", false) || com.bytedance.sdk.openadsdk.gqi.yz.fm.fm("sp_multi_native_video_data", "key_video_isfromvideodetailpage", false);
    }

    private boolean ol() {
        return 2 == gof.yz().ro(this.fm.pg());
    }

    private void pkk() {
        zan.jnr(this.f7092ef);
        zan.jnr(this.wsy);
    }

    private void sds() {
        lb lbVar = this.ro;
        if (lbVar == null) {
            gqi();
        } else if ((lbVar instanceof lb) && !ha()) {
            this.ro.irt();
        }
        if (this.ro == null || !this.zan.get()) {
            return;
        }
        this.zan.set(false);
        ro();
        if (!wu()) {
            if (this.ro.dsz()) {
                this.ro.dsz();
                ro(true);
                return;
            } else {
                wsy();
                zan.fm((View) this.wsy, 0);
                return;
            }
        }
        zan.fm((View) this.wsy, 8);
        ImageView imageView = this.f7092ef;
        if (imageView != null) {
            zan.fm((View) imageView, 8);
        }
        lse lseVar = this.fm;
        if (lseVar == null || lseVar.ex() == null) {
            return;
        }
        com.bytedance.sdk.openadsdk.core.fhx.fm.ro roVarFm = lse.fm(((a) CacheDirFactory.getICacheDir(this.fm.il())).c(), this.fm);
        roVarFm.ro(this.fm.eo());
        roVarFm.ro(this.gof.getWidth());
        roVarFm.lb(this.gof.getHeight());
        roVarFm.lb(this.fm.gt());
        roVarFm.fm(0L);
        roVarFm.fm(ef());
        fm(roVarFm);
        this.ro.fm(roVarFm);
        this.ro.ro(false);
    }

    private boolean wbw() {
        return 5 == gof.yz().ro(this.fm.pg());
    }

    private void wey() {
        lb lbVar = this.ro;
        if (lbVar == null) {
            return;
        }
        lbVar.yz(this.gqi);
        this.ro.fm((lb.fm) this);
        this.ro.fm((b) this);
    }

    private void yz() {
        fm(0L, 0);
        this.mon = null;
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.lb.fm
    public void ajl() {
        c cVar = this.mon;
        if (cVar != null) {
            cVar.g_();
        }
    }

    public boolean dsz() {
        boolean z10 = false;
        if (com.bytedance.sdk.component.utils.gof.lb(gof.fm()) == 0) {
            return false;
        }
        if (this.ro.ku() != null && this.ro.ku().ajl()) {
            fm(false, maa.intValue());
            Handler handler = this.wbw;
            z10 = true;
            if (handler != null) {
                handler.removeMessages(1);
            }
        }
        return z10;
    }

    public boolean duv() {
        return gc.fm(this, 50, com.bytedance.sdk.openadsdk.core.vt.mq.ro(this.duv) ? 1 : 5, false);
    }

    public boolean ef() {
        return this.yz;
    }

    public void fhx() {
        if (com.bytedance.sdk.component.utils.gof.lb(gof.fm()) != 0 && duv()) {
            if (this.ro.ku() != null) {
                if (this.ro.ku().wsy()) {
                    fm(true, lse.intValue());
                    ro();
                    Handler handler = this.wbw;
                    if (handler != null) {
                        handler.sendEmptyMessageDelayed(1, 500L);
                        return;
                    }
                    return;
                }
                if (this.ro.ku().ro() && !this.fhx) {
                    vt();
                    lb lbVar = this.ro;
                    if (lbVar instanceof lb) {
                        lbVar.xgn();
                        return;
                    }
                    return;
                }
            }
            if (wu() || this.lz.get()) {
                return;
            }
            this.lz.set(true);
            pkk();
            lse lseVar = this.fm;
            if (lseVar != null && lseVar.ex() != null) {
                pkk();
                this.fm.ex();
                com.bytedance.sdk.openadsdk.core.fhx.fm.ro roVarFm = lse.fm(((a) CacheDirFactory.getICacheDir(this.fm.il())).c(), this.fm);
                roVarFm.ro(this.fm.eo());
                roVarFm.ro(this.gof.getWidth());
                roVarFm.lb(this.gof.getHeight());
                roVarFm.lb(this.fm.gt());
                roVarFm.fm(this.ai);
                roVarFm.fm(ef());
                roVarFm.fm(((a) CacheDirFactory.getICacheDir(this.fm.il())).c());
                fm(roVarFm);
                this.ro.fm(roVarFm);
            }
            Handler handler2 = this.wbw;
            if (handler2 != null) {
                handler2.sendEmptyMessageDelayed(1, 500L);
            }
            fm(false);
        }
    }

    @Override // b6.b
    public void fm() {
    }

    public double getCurrentPlayTime() {
        if (this.ro != null) {
            return (r0.ajl() * 1.0d) / 1000.0d;
        }
        return 0.0d;
    }

    public lb getNativeVideoController() {
        return this.ro;
    }

    public void irt() {
        com.bytedance.sdk.openadsdk.core.model.yz yzVarKl;
        com.bytedance.sdk.openadsdk.core.onz.yz yzVarFm;
        lse lseVar = this.fm;
        if (lseVar == null || (yzVarKl = lseVar.kl()) == null || (yzVarFm = yzVarKl.fm()) == null) {
            return;
        }
        yzVarFm.jnr(this.ai);
    }

    public void ku() {
        jnr jnrVarDuv;
        lb lbVar = this.ro;
        if (lbVar == null || (jnrVarDuv = lbVar.duv()) == null) {
            return;
        }
        jnrVarDuv.fm();
        View viewLb = jnrVarDuv.lb();
        if (viewLb != null) {
            viewLb.setVisibility(8);
            if (viewLb.getParent() != null) {
                ((ViewGroup) viewLb.getParent()).removeView(viewLb);
            }
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        sds();
        if (this.fhx) {
            getViewTreeObserver().addOnScrollChangedListener(this.f7096qf);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        maa();
        if (this.fhx) {
            ViewTreeObserver viewTreeObserver = getViewTreeObserver();
            if (viewTreeObserver.isAlive()) {
                viewTreeObserver.removeOnScrollChangedListener(this.f7096qf);
            }
            ViewGroup viewGroup = this.gof;
            if (viewGroup == null || this.bx == null) {
                return;
            }
            ViewTreeObserver viewTreeObserver2 = viewGroup.getViewTreeObserver();
            if (viewTreeObserver2.isAlive()) {
                viewTreeObserver2.removeOnGlobalLayoutListener(this.bx);
                this.bx = null;
            }
        }
    }

    @Override // android.view.View
    public void onFinishTemporaryDetach() {
        super.onFinishTemporaryDetach();
        sds();
    }

    @Override // android.view.ViewGroup
    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        ro roVar;
        lb lbVar;
        if (!this.wey && (roVar = this.irt) != null && (lbVar = this.ro) != null) {
            roVar.fm(lbVar.dsz(), this.ro.ef(), this.ro.ha(), this.ro.ajl(), this.gqi);
        }
        return super.onInterceptTouchEvent(motionEvent);
    }

    @Override // android.view.View
    public void onStartTemporaryDetach() {
        super.onStartTemporaryDetach();
        maa();
    }

    @Override // android.view.View
    public void onWindowFocusChanged(boolean z10) {
        lb lbVar;
        lb lbVar2;
        lb lbVar3;
        lb lbVar4;
        if ("open_ad".equals(this.duv)) {
            gzf();
            return;
        }
        this.hi = z10;
        super.onWindowFocusChanged(z10);
        com.bytedance.sdk.openadsdk.hi.fm.lb.fm(this.fm, z10);
        ai();
        if (this.fhx) {
            if (nt() && (lbVar4 = this.ro) != null && lbVar4.dsz()) {
                mq();
                zan.fm((View) this.wsy, 8);
                ro(true);
                yz();
                return;
            }
            ro();
            if (!ha() && wu() && (lbVar2 = this.ro) != null && !lbVar2.lse()) {
                if (this.wbw != null) {
                    if (z10 && (lbVar3 = this.ro) != null && !lbVar3.dsz()) {
                        this.wbw.obtainMessage(1).sendToTarget();
                        return;
                    } else {
                        gzf();
                        fm(false, maa.intValue());
                        return;
                    }
                }
                return;
            }
            if (wu()) {
                return;
            }
            if (!z10 && (lbVar = this.ro) != null && lbVar.ku() != null && this.ro.ku().ajl()) {
                gzf();
                fm(false, maa.intValue());
            } else if (z10) {
                this.wbw.obtainMessage(1).sendToTarget();
            }
        }
    }

    @Override // android.view.View
    public void onWindowVisibilityChanged(int i10) {
        lb lbVar;
        lse lseVar;
        lb lbVar2;
        lb lbVar3;
        super.onWindowVisibilityChanged(i10);
        ai();
        if (nt() && (lbVar3 = this.ro) != null && lbVar3.dsz()) {
            mq();
            zan.fm((View) this.wsy, 8);
            ro(true);
            yz();
            return;
        }
        ro();
        if (ha() || !wu() || (lbVar = this.ro) == null || lbVar.lse() || (lseVar = this.fm) == null) {
            return;
        }
        if (this.gzf && lseVar.ex() != null) {
            this.fm.ex();
            com.bytedance.sdk.openadsdk.core.fhx.fm.ro roVarFm = lse.fm(((a) CacheDirFactory.getICacheDir(this.fm.il())).c(), this.fm);
            roVarFm.ro(this.fm.eo());
            roVarFm.ro(this.gof.getWidth());
            roVarFm.lb(this.gof.getHeight());
            roVarFm.lb(this.fm.gt());
            roVarFm.fm(this.ai);
            roVarFm.fm(ef());
            fm(roVarFm);
            this.ro.fm(roVarFm);
            this.gzf = false;
            zan.fm((View) this.wsy, 8);
        }
        if (i10 != 0 || !this.fhx || this.wbw == null || (lbVar2 = this.ro) == null || lbVar2.dsz()) {
            return;
        }
        this.wbw.obtainMessage(1).sendToTarget();
    }

    public void onz() {
        if (getNativeVideoController() == null || !(getNativeVideoController() instanceof lb)) {
            return;
        }
        lb nativeVideoController = getNativeVideoController();
        nativeVideoController.fm(nativeVideoController.duv(), this);
    }

    @Override // b6.b
    public void ro(long j10, int i10) {
    }

    public void setAdCreativeClickListener(fm fmVar) {
        lb lbVar = this.ro;
        if (lbVar != null) {
            lbVar.fm(fmVar);
        }
    }

    public void setControllerStatusCallBack(ro roVar) {
        this.irt = roVar;
    }

    public void setIsAutoPlay(boolean z10) {
        if (this.hxv) {
            return;
        }
        int iRo = gof.yz().ro(this.fm.pg());
        if (z10 && iRo != 4 && (!com.bytedance.sdk.component.utils.gof.jnr(this.qhl) ? !(!com.bytedance.sdk.component.utils.gof.ajl(this.qhl) ? com.bytedance.sdk.component.utils.gof.yz(this.qhl) : ol() || wbw()) : !ol())) {
            z10 = false;
        }
        this.gqi = z10;
        lb lbVar = this.ro;
        if (lbVar != null) {
            lbVar.yz(z10);
        }
        if (this.gqi) {
            zan.fm((View) this.wsy, 8);
        } else {
            wsy();
            RelativeLayout relativeLayout = this.wsy;
            if (relativeLayout != null) {
                zan.fm((View) relativeLayout, 0);
                lse lseVar = this.fm;
                if (lseVar != null && lseVar.ex() != null) {
                    com.bytedance.sdk.openadsdk.wey.ro.ro().fm(this.fm.ex().f5926f, this.fm.ex().f5922b, this.fm.ex().f5921a, this.wu, this.fm);
                }
            }
        }
        this.hxv = true;
    }

    public void setNeedNativeVideoPlayBtnVisible(boolean z10) {
        this.ku = z10;
    }

    public void setNeedSelfManagerVideo(boolean z10) {
        this.fhx = z10;
    }

    public void setVideoAdClickListenerTTNativeAd(PAGNativeAd pAGNativeAd) {
        lb lbVar = this.ro;
        if (lbVar != null) {
            lbVar.fm(pAGNativeAd);
        }
    }

    public void setVideoAdInteractionListener(c cVar) {
        this.mon = cVar;
    }

    public void setVideoAdLoadListener(e eVar) {
        lb lbVar = this.ro;
        if (lbVar != null) {
            lbVar.fm(eVar);
        }
    }

    public void setVideoCacheUrl(String str) {
        this.sds = str;
    }

    public void setVideoPlayCallback(com.bytedance.sdk.openadsdk.core.fhx.ro.ro roVar) {
        lb lbVar = this.ro;
        if (lbVar != null) {
            lbVar.fm(roVar);
        }
    }

    @Override // android.view.View
    public void setVisibility(int i10) {
        super.setVisibility(i10);
        if (i10 == 4 || i10 == 8) {
            lse();
        }
    }

    public void vt() {
        lb lbVar = this.ro;
        if (lbVar != null) {
            jnr jnrVarDuv = lbVar.duv();
            if (jnrVarDuv != null) {
                jnrVarDuv.fm();
            }
            pkk();
        }
    }

    public void wsy() {
        View view;
        if (this.qhl == null || (view = this.xgn) == null || view.getParent() == null || this.fm == null || this.wsy != null) {
            return;
        }
        ViewParent parent = this.xgn.getParent();
        RelativeLayout relativeLayoutRo = ro(this.qhl);
        if (parent != null && (parent instanceof ViewGroup)) {
            fm(relativeLayoutRo, (ViewGroup) parent, this.xgn);
        }
        this.wsy = relativeLayoutRo;
        if (this.ku) {
            zan.fm((View) this.vt, 0);
        }
        if (this.fm.ex() != null && this.fm.ex().f5926f != null) {
            com.bytedance.sdk.openadsdk.wey.ro.ro().fm(this.fm.ex().f5926f, this.fm.ex().f5922b, this.fm.ex().f5921a, this.wu, this.fm);
        }
        ImageView imageView = this.vt;
        if (imageView != null) {
            imageView.setClickable(true);
            this.vt.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.core.fhx.ro.ajl.2
                @Override // android.view.View.OnClickListener
                public void onClick(View view2) {
                    ajl.this.lb();
                }
            });
        }
    }

    public boolean wu() {
        return this.gqi;
    }

    public ajl(@NonNull Context context, @NonNull lse lseVar, String str, boolean z10, boolean z11, wsy wsyVar) {
        this(context, lseVar, false, str, z10, z11, wsyVar);
    }

    public void lb() {
        if (dsz()) {
            return;
        }
        fhx();
    }

    public ajl(@NonNull Context context, @NonNull lse lseVar, wsy wsyVar) {
        this(context, lseVar, false, wsyVar);
    }

    public void ro() {
        lse lseVar = this.fm;
        if (lseVar == null) {
            return;
        }
        int iPg = lseVar.pg();
        int iRo = gof.yz().ro(iPg);
        int iLb = com.bytedance.sdk.component.utils.gof.lb(gof.fm());
        if (iRo == 1) {
            this.gqi = bx.yz(iLb);
        } else if (iRo == 2) {
            this.gqi = bx.jnr(iLb) || bx.yz(iLb) || bx.ajl(iLb);
        } else if (iRo == 3) {
            this.gqi = false;
        } else if (iRo == 4) {
            this.onz = true;
        } else if (iRo == 5) {
            this.gqi = bx.yz(iLb) || bx.ajl(iLb);
        }
        if (this.wey) {
            this.yz = false;
        } else if (!this.jnr || !com.bytedance.sdk.openadsdk.core.vt.mq.ro(this.duv)) {
            this.yz = gof.yz().lb(String.valueOf(iPg));
        }
        if ("open_ad".equals(this.duv)) {
            this.gqi = true;
            this.yz = true;
        }
        if (com.bytedance.sdk.openadsdk.core.vt.mq.ro(this.duv)) {
            this.yz = true;
        }
        lb lbVar = this.ro;
        if (lbVar != null) {
            lbVar.yz(this.gqi);
        }
        this.jnr = true;
    }

    public ajl(@NonNull Context context, @NonNull lse lseVar, boolean z10, String str, boolean z11, boolean z12, wsy wsyVar) {
        super(context);
        this.gqi = true;
        this.yz = true;
        this.wey = false;
        this.jnr = false;
        this.hi = true;
        this.nt = false;
        this.mq = true;
        this.ku = true;
        this.duv = "embeded_ad";
        this.dsz = 50;
        this.gzf = true;
        this.ol = false;
        this.wbw = new mq(fhx.ro().getLooper(), this);
        this.hxv = false;
        this.f7093gc = Build.MODEL;
        this.onz = false;
        this.fhx = true;
        this.zan = new AtomicBoolean(false);
        this.tzk = new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.fhx.ro.ajl.4
            @Override // java.lang.Runnable
            public void run() {
                ajl ajlVar = ajl.this;
                ajlVar.fm(ajlVar.f7094ha, ajl.maa.intValue());
            }
        };
        this.lz = new AtomicBoolean(false);
        this.f7096qf = new ViewTreeObserver.OnScrollChangedListener() { // from class: com.bytedance.sdk.openadsdk.core.fhx.ro.ajl.6
            @Override // android.view.ViewTreeObserver.OnScrollChangedListener
            public void onScrollChanged() {
                ajl.this.gof();
            }
        };
        try {
            if (lseVar.dh()) {
                this.hlt = ((a) CacheDirFactory.getICacheDir(0)).d();
            }
        } catch (Throwable unused) {
        }
        if (wsyVar != null) {
            this.ajl = wsyVar;
        }
        this.duv = str;
        this.qhl = context;
        this.fm = lseVar;
        this.wey = z10;
        setContentDescription("NativeVideoTsView");
        this.nt = z11;
        this.mq = z12;
        ro();
        jnr();
    }

    @Override // b6.b
    public void fm(long j10, int i10) {
        c cVar = this.mon;
        if (cVar != null) {
            cVar.j_();
        }
    }

    @Override // b6.b
    public void fm(long j10, long j11) {
        c cVar = this.mon;
        if (cVar != null) {
            cVar.fm(j10, j11);
        }
    }

    private View fm(Context context) {
        FrameLayout frameLayout = new FrameLayout(context);
        new FrameLayout.LayoutParams(-1, -1).gravity = 17;
        frameLayout.setVisibility(8);
        this.gof = frameLayout;
        FrameLayout frameLayout2 = new FrameLayout(context);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
        layoutParams.gravity = 17;
        frameLayout2.setLayoutParams(layoutParams);
        frameLayout.addView(frameLayout2);
        this.f7095lb = frameLayout2;
        View view = new View(context);
        view.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
        frameLayout.addView(view);
        this.xgn = view;
        return frameLayout;
    }

    private RelativeLayout ro(Context context) {
        com.bytedance.sdk.openadsdk.core.ajl.wsy wsyVar = new com.bytedance.sdk.openadsdk.core.ajl.wsy(context);
        wsyVar.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
        wsyVar.setVisibility(8);
        com.bytedance.sdk.openadsdk.core.ajl.yz yzVar = new com.bytedance.sdk.openadsdk.core.ajl.yz(context);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -1);
        layoutParams.addRule(13);
        yzVar.setLayoutParams(layoutParams);
        yzVar.setScaleType(ImageView.ScaleType.CENTER_CROP);
        this.wu = yzVar;
        com.bytedance.sdk.openadsdk.core.ajl.yz yzVar2 = new com.bytedance.sdk.openadsdk.core.ajl.yz(context);
        RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-2, -2);
        layoutParams2.addRule(13);
        yzVar2.setLayoutParams(layoutParams2);
        yzVar2.setVisibility(8);
        yzVar2.setBackground(maa.lb(context, "tt_new_play_video"));
        this.vt = yzVar2;
        wsyVar.addView(yzVar);
        wsyVar.addView(yzVar2);
        return wsyVar;
    }

    private void fm(View view, ViewGroup viewGroup, View view2) {
        int iIndexOfChild = viewGroup.indexOfChild(view2);
        viewGroup.removeViewInLayout(view2);
        ViewGroup.LayoutParams layoutParams = view2.getLayoutParams();
        if (layoutParams != null) {
            viewGroup.addView(view, iIndexOfChild, layoutParams);
        } else {
            viewGroup.addView(view, iIndexOfChild);
        }
    }

    public boolean fm(long j10, boolean z10, boolean z11) {
        boolean zFm = false;
        this.gof.setVisibility(0);
        this.ai = j10;
        if (!ha()) {
            return true;
        }
        this.ro.fm(false);
        lse lseVar = this.fm;
        if (lseVar != null && lseVar.ex() != null) {
            com.bytedance.sdk.openadsdk.core.fhx.fm.ro roVarFm = lse.fm(((a) CacheDirFactory.getICacheDir(this.fm.il())).c(), this.fm);
            roVarFm.ro(this.fm.eo());
            roVarFm.ro(this.gof.getWidth());
            roVarFm.lb(this.gof.getHeight());
            roVarFm.lb(this.fm.gt());
            roVarFm.fm(j10);
            roVarFm.fm(ef());
            fm(roVarFm);
            if (z11) {
                this.ro.ro(roVarFm);
                return true;
            }
            zFm = this.ro.fm(roVarFm);
        }
        if (((j10 > 0 && !z10 && !z11) || (j10 > 0 && z10)) && this.ro != null) {
            fhx.fm fmVar = new fhx.fm();
            fmVar.ro(this.ro.ajl());
            fmVar.yz(this.ro.ef());
            fmVar.lb(this.ro.wsy());
            com.bytedance.sdk.openadsdk.yz.jnr.fm.fm.ro(this.ro.duv(), fmVar);
        }
        return zFm;
    }

    public void ro(boolean z10) {
        lb lbVar = this.ro;
        if (lbVar != null) {
            lbVar.ro(z10);
            jnr jnrVarDuv = this.ro.duv();
            if (jnrVarDuv != null) {
                jnrVarDuv.ro();
                View viewLb = jnrVarDuv.lb();
                if (viewLb != null) {
                    if (viewLb.getParent() != null) {
                        ((ViewGroup) viewLb.getParent()).removeView(viewLb);
                    }
                    viewLb.setVisibility(0);
                    addView(viewLb);
                    jnrVarDuv.fm((Object) this.fm, new WeakReference(this.qhl), false);
                }
            }
        }
    }

    @Override // com.bytedance.sdk.component.utils.mq.fm
    public void fm(Message message) {
        if (message.what == 1) {
            hlt();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(boolean z10, int i10) {
        if (this.fm == null || this.ro == null) {
            return;
        }
        boolean zNt = nt();
        mq();
        if (zNt && this.ro.dsz()) {
            this.ro.dsz();
            ro(true);
            yz();
            return;
        }
        if (z10 && this.hi && !this.ro.dsz() && !this.ro.lse()) {
            if (this.ro.ku() == null || !this.ro.ku().wsy()) {
                if (this.gqi && this.ro.ku() == null) {
                    if (!this.zan.get()) {
                        this.zan.set(true);
                    }
                    this.lz.set(false);
                    sds();
                    return;
                }
                return;
            }
            if (this.gqi || i10 == 1) {
                lb lbVar = this.ro;
                if (lbVar != null) {
                    fm(lbVar.hlt(), "changeVideoStatus");
                }
                if ("ALP-AL00".equals(this.f7093gc)) {
                    this.ro.lb();
                } else {
                    if (!vt.ro().onz()) {
                        zNt = true;
                    }
                    this.ro.wsy(zNt);
                }
                fm(false);
                c cVar = this.mon;
                if (cVar != null) {
                    cVar.i_();
                    return;
                }
                return;
            }
            return;
        }
        if (this.ro.ku() == null || !this.ro.ku().ajl()) {
            return;
        }
        this.ro.ro();
        fm(true);
        c cVar2 = this.mon;
        if (cVar2 != null) {
            cVar2.h_();
        }
    }

    public void fm(boolean z10, String str) {
        if (com.bytedance.sdk.openadsdk.core.vt.mq.ro(this.duv)) {
            z10 = true;
        }
        this.yz = z10;
        lb lbVar = this.ro;
        if (lbVar != null) {
            lbVar.fm(z10, str);
        }
    }

    @Override // com.bytedance.sdk.openadsdk.core.fhx.ro.lb.fm
    public void fm(int i10) {
        ro();
    }

    public void fm(boolean z10) {
        if (this.f7092ef == null) {
            ImageView imageView = new ImageView(getContext());
            this.f7092ef = imageView;
            imageView.setImageResource(maa.yz(gof.fm(), "tt_new_play_video"));
            this.f7092ef.setScaleType(ImageView.ScaleType.FIT_XY);
            int iRo = zan.ro(getContext(), this.dsz);
            int iRo2 = zan.ro(getContext(), 10.0f);
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(iRo, iRo);
            layoutParams.gravity = 17;
            layoutParams.rightMargin = iRo2;
            layoutParams.bottomMargin = iRo2;
            this.gof.addView(this.f7092ef, layoutParams);
            this.f7092ef.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.core.fhx.ro.ajl.5
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    ajl.this.fhx();
                }
            });
        }
        if (z10) {
            this.f7092ef.setVisibility(0);
        } else {
            this.f7092ef.setVisibility(8);
        }
    }

    public com.bytedance.sdk.openadsdk.core.onz.ajl fm(List<Pair<View, FriendlyObstructionPurpose>> list) {
        lb lbVar = this.ro;
        if (lbVar instanceof lb) {
            return lbVar.fm(this, list);
        }
        return null;
    }

    private void fm(com.bykv.vk.openvk.fm.fm.fm.lb.lb lbVar) {
        try {
            if (this.fm.dh()) {
                lbVar.fm(this.hlt);
            }
        } catch (Throwable unused) {
        }
    }
}
