package com.bytedance.sdk.openadsdk.core.vt;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.bytedance.sdk.openadsdk.TTDislikeDialogAbstract;
import com.bytedance.sdk.openadsdk.activity.single.IABLandingPageActivity;
import com.bytedance.sdk.openadsdk.activity.single.TTWebsiteActivity;
import com.bytedance.sdk.openadsdk.api.PAGExpressAdWrapperListener;
import com.bytedance.sdk.openadsdk.core.ol;
import com.bytedance.sdk.openadsdk.core.vt.ajl;
import com.bytedance.sdk.openadsdk.core.widget.PAGLogoView;
import com.bytedance.sdk.openadsdk.utils.xgn;
import com.bytedance.sdk.openadsdk.utils.zan;
import com.iab.omid.library.bytedance2.adsession.FriendlyObstructionPurpose;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/* JADX INFO: loaded from: classes2.dex */
public class lb {
    private int ajl;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private int f7306ef;
    com.bytedance.sdk.openadsdk.core.model.lse fm;
    private sds jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private fm f7307lb;
    private final Context ro;
    private int wsy;
    private ScheduledFuture<?> wu;
    private com.bytedance.sdk.component.adexpress.ro.fhx yz;

    public static class fm implements com.bytedance.sdk.component.adexpress.ro.yz<View>, ajl.ro {
        private final int ajl;
        private int dsz;
        private ajl duv;

        /* JADX INFO: renamed from: ef, reason: collision with root package name */
        private com.bytedance.sdk.openadsdk.core.model.lse f7308ef;
        private PAGExpressAdWrapperListener fhx;
        AtomicBoolean fm = new AtomicBoolean(false);
        private final Context jnr;
        private String ku;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        private TTDislikeDialogAbstract f7309lb;
        private com.bytedance.sdk.component.adexpress.ro.wsy onz;
        private com.bytedance.sdk.openadsdk.lb.lb ro;
        private final int vt;
        private final int wsy;
        private FrameLayout wu;
        private String yz;

        public fm(Context context, com.bytedance.sdk.openadsdk.core.model.lse lseVar, int i10, int i11, String str, int i12) {
            this.ku = str;
            if (lseVar != null && lseVar.bq()) {
                this.ku = "fullscreen_interstitial_ad";
            }
            this.jnr = context;
            this.ajl = i10;
            this.wsy = i11;
            this.f7308ef = lseVar;
            this.vt = zan.ro(context, 3.0f);
            this.dsz = i12;
            ajl();
        }

        private void ajl() {
            FrameLayout frameLayout = new FrameLayout(this.jnr);
            this.wu = frameLayout;
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) frameLayout.getLayoutParams();
            if (layoutParams == null) {
                layoutParams = new FrameLayout.LayoutParams(this.ajl, this.wsy);
            }
            layoutParams.width = this.ajl;
            layoutParams.height = this.wsy;
            layoutParams.gravity = 17;
            this.wu.setLayoutParams(layoutParams);
            ajl ajlVarWu = wu();
            this.wu.addView(ajlVarWu);
            View viewWsy = wsy();
            this.wu.addView(viewWsy);
            com.bytedance.sdk.openadsdk.core.model.lse lseVar = this.f7308ef;
            if (lseVar != null && lseVar.bq()) {
                ajlVarWu.setBackgroundColor(-16777216);
                ajlVarWu.fm(((Activity) this.jnr).findViewById(com.bytedance.sdk.openadsdk.utils.qhl.op), FriendlyObstructionPurpose.OTHER);
            }
            FriendlyObstructionPurpose friendlyObstructionPurpose = FriendlyObstructionPurpose.OTHER;
            ajlVarWu.fm(viewWsy, friendlyObstructionPurpose);
            Context context = this.jnr;
            if (context == null || !(context instanceof Activity)) {
                return;
            }
            View viewFindViewById = ((Activity) context).findViewById(com.bytedance.sdk.openadsdk.utils.qhl.kw);
            if (viewFindViewById != null) {
                ajlVarWu.fm(viewFindViewById, friendlyObstructionPurpose);
            }
            View viewFindViewById2 = ((Activity) this.jnr).findViewById(com.bytedance.sdk.openadsdk.utils.qhl.nss);
            if (viewFindViewById2 != null) {
                ajlVarWu.fm(viewFindViewById2, friendlyObstructionPurpose);
            }
        }

        private View wsy() {
            PAGLogoView pAGLogoViewCreatePAGLogoViewByMaterial = PAGLogoView.createPAGLogoViewByMaterial(this.jnr, this.f7308ef);
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2);
            com.bytedance.sdk.openadsdk.core.model.lse lseVar = this.f7308ef;
            if (lseVar == null || !lseVar.bq()) {
                int i10 = this.vt;
                layoutParams.topMargin = i10;
                layoutParams.leftMargin = i10;
            } else {
                layoutParams.leftMargin = zan.ro(this.jnr, 20.0f);
                layoutParams.bottomMargin = zan.ro(this.jnr, 20.0f);
                layoutParams.gravity = 8388691;
            }
            pAGLogoViewCreatePAGLogoViewByMaterial.setLayoutParams(layoutParams);
            pAGLogoViewCreatePAGLogoViewByMaterial.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.core.vt.lb.fm.1
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    if (com.bytedance.sdk.openadsdk.utils.ro.jnr() && com.bytedance.sdk.openadsdk.core.gof.yz().ai()) {
                        IABLandingPageActivity.fm(fm.this.jnr, fm.this.f7308ef, fm.this.ku);
                    } else {
                        TTWebsiteActivity.fm(fm.this.jnr, fm.this.f7308ef, fm.this.ku);
                    }
                }
            });
            return pAGLogoViewCreatePAGLogoViewByMaterial;
        }

        @SuppressLint({"ClickableViewAccessibility"})
        private ajl wu() {
            ajl ajlVarRo = yz.fm().ro();
            this.duv = ajlVarRo;
            if (ajlVarRo == null) {
                this.duv = new ajl(this.jnr);
            }
            yz.fm().lb(this.duv);
            this.duv.fm(this.f7308ef, this, this.ku);
            this.duv.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
            return this.duv;
        }

        public void fm(PAGExpressAdWrapperListener pAGExpressAdWrapperListener) {
            this.fhx = pAGExpressAdWrapperListener;
        }

        @Override // com.bytedance.sdk.component.adexpress.ro.yz
        public View jnr() {
            return this.wu;
        }

        @Override // com.bytedance.sdk.component.adexpress.ro.yz
        public int lb() {
            return 5;
        }

        public void fm(String str) {
            this.yz = str;
        }

        @Override // com.bytedance.sdk.openadsdk.core.vt.ajl.ro
        @SuppressLint({"ClickableViewAccessibility"})
        public void ro() {
            if (this.onz != null) {
                com.bytedance.sdk.component.adexpress.ro.onz onzVar = new com.bytedance.sdk.component.adexpress.ro.onz();
                onzVar.fm(true);
                onzVar.fm(zan.lb(this.jnr, this.ajl));
                onzVar.ro(zan.lb(this.jnr, this.wsy));
                this.onz.fm(this.wu, onzVar);
            }
        }

        public void yz() {
            this.wu = null;
            this.ro = null;
            this.f7309lb = null;
            this.onz = null;
            this.f7308ef = null;
            ajl ajlVar = this.duv;
            if (ajlVar != null) {
                ajlVar.fhx();
                yz.fm().fm(this.duv);
            }
            this.fm.set(true);
        }

        @Override // com.bytedance.sdk.component.adexpress.ro.yz
        public void fm(com.bytedance.sdk.component.adexpress.ro.wsy wsyVar) {
            com.bytedance.sdk.openadsdk.core.model.lse lseVar;
            if (this.fm.get()) {
                return;
            }
            if (this.jnr != null && (lseVar = this.f7308ef) != null) {
                this.onz = wsyVar;
                if (TextUtils.isEmpty(lseVar.mzr())) {
                    wsyVar.fm(106, "dsp data is null");
                    return;
                } else {
                    this.duv.gqi();
                    return;
                }
            }
            wsyVar.fm(106, "material null");
        }

        public void fm(ol olVar) {
            if (olVar instanceof com.bytedance.sdk.openadsdk.lb.lb) {
                this.ro = (com.bytedance.sdk.openadsdk.lb.lb) olVar;
            }
        }

        public void fm(TTDislikeDialogAbstract tTDislikeDialogAbstract) {
            com.bytedance.sdk.openadsdk.core.model.lse lseVar;
            if (tTDislikeDialogAbstract != null && (lseVar = this.f7308ef) != null) {
                tTDislikeDialogAbstract.setMaterialMeta(lseVar.gt(), this.f7308ef.ew());
            }
            this.f7309lb = tTDislikeDialogAbstract;
        }

        @Override // com.bytedance.sdk.openadsdk.core.vt.ajl.ro
        public View fm() {
            FrameLayout frameLayout = this.wu;
            if (frameLayout == null) {
                return null;
            }
            return (View) frameLayout.getParent();
        }

        @Override // com.bytedance.sdk.openadsdk.core.vt.ajl.ro
        public void fm(View view, int i10) {
            PAGExpressAdWrapperListener pAGExpressAdWrapperListener = this.fhx;
            if (pAGExpressAdWrapperListener != null) {
                pAGExpressAdWrapperListener.onAdClicked();
            }
        }

        @Override // com.bytedance.sdk.openadsdk.core.vt.ajl.ro
        public void fm(int i10, int i11) {
            com.bytedance.sdk.component.adexpress.ro.wsy wsyVar = this.onz;
            if (wsyVar != null) {
                wsyVar.fm(i10, "render fail");
            }
        }
    }

    /* JADX INFO: renamed from: com.bytedance.sdk.openadsdk.core.vt.lb$lb, reason: collision with other inner class name */
    public interface InterfaceC0085lb {
        void fm();

        void fm(int i10, int i11);

        void fm(String str);

        void ro(String str);
    }

    public static class ro implements Runnable {
        InterfaceC0085lb fm;

        public ro(InterfaceC0085lb interfaceC0085lb) {
            this.fm = interfaceC0085lb;
        }

        @Override // java.lang.Runnable
        public void run() {
            InterfaceC0085lb interfaceC0085lb = this.fm;
            if (interfaceC0085lb != null) {
                interfaceC0085lb.fm(107, 107);
            }
        }
    }

    public lb(Context context, sds sdsVar, com.bytedance.sdk.openadsdk.core.model.lse lseVar, String str) {
        this.fm = lseVar;
        this.ro = context;
        this.jnr = sdsVar;
        fm(sdsVar);
        this.f7307lb = new fm(context, lseVar, this.ajl, this.wsy, str, this.f7306ef);
    }

    public void fm(com.bytedance.sdk.component.adexpress.ro.fhx fhxVar) {
        this.yz = fhxVar;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void lb() {
        try {
            ScheduledFuture<?> scheduledFuture = this.wu;
            if (scheduledFuture == null || scheduledFuture.isCancelled()) {
                return;
            }
            this.wu.cancel(false);
            this.wu = null;
        } catch (Throwable unused) {
        }
    }

    public void ro() {
        fm fmVar = this.f7307lb;
        if (fmVar != null) {
            fmVar.yz();
            this.f7307lb = null;
        }
        lb();
        this.yz = null;
        this.jnr = null;
    }

    private void fm(sds sdsVar) {
        com.bytedance.sdk.openadsdk.core.model.lse lseVar = this.fm;
        if (lseVar != null && lseVar.bq()) {
            this.ajl = -1;
            this.wsy = -1;
            return;
        }
        gqi gqiVarFm = com.bytedance.sdk.openadsdk.core.yz.ro.fm(sdsVar.getExpectExpressWidth(), sdsVar.getExpectExpressHeight());
        this.f7306ef = gqiVarFm.fm;
        if (sdsVar.getExpectExpressWidth() > 0 && sdsVar.getExpectExpressHeight() > 0) {
            this.ajl = zan.ro(this.ro, sdsVar.getExpectExpressWidth());
            this.wsy = zan.ro(this.ro, sdsVar.getExpectExpressHeight());
        } else {
            int iLb = zan.lb(this.ro);
            this.ajl = iLb;
            this.wsy = Float.valueOf(iLb / gqiVarFm.ro).intValue();
        }
        int i10 = this.ajl;
        if (i10 <= 0 || i10 <= zan.lb(this.ro)) {
            return;
        }
        this.ajl = zan.lb(this.ro);
        this.wsy = Float.valueOf(this.wsy * (zan.lb(this.ro) / this.ajl)).intValue();
    }

    public void fm() {
        com.bytedance.sdk.openadsdk.core.model.lse lseVar = this.fm;
        if (lseVar != null && lseVar.bq()) {
            this.wu = xgn.fm().schedule(new ro(this.f7307lb.duv), com.bytedance.sdk.openadsdk.core.gof.yz().pkk(), TimeUnit.MILLISECONDS);
        }
        fm fmVar = this.f7307lb;
        if (fmVar == null) {
            com.bytedance.sdk.component.adexpress.ro.fhx fhxVar = this.yz;
            if (fhxVar != null) {
                fhxVar.a_(106);
                return;
            }
            return;
        }
        fmVar.fm(new com.bytedance.sdk.component.adexpress.ro.wsy() { // from class: com.bytedance.sdk.openadsdk.core.vt.lb.1
            @Override // com.bytedance.sdk.component.adexpress.ro.wsy
            public void fm(View view, com.bytedance.sdk.component.adexpress.ro.onz onzVar) {
                if (lb.this.jnr == null || view == null) {
                    if (lb.this.yz != null) {
                        lb.this.yz.a_(106);
                    }
                } else if (lb.this.yz != null) {
                    lb.this.yz.fm(lb.this.f7307lb, onzVar);
                }
                lb.this.lb();
            }

            @Override // com.bytedance.sdk.component.adexpress.ro.wsy
            public void fm(int i10, String str) {
                if (lb.this.yz != null) {
                    lb.this.yz.a_(106);
                }
                lb.this.lb();
            }
        });
        View viewJnr = this.f7307lb.jnr();
        this.jnr.removeView(viewJnr);
        if (viewJnr.getParent() != null) {
            ((ViewGroup) viewJnr.getParent()).removeView(viewJnr);
        }
        this.jnr.addView(viewJnr, new ViewGroup.LayoutParams(-1, -1));
    }

    public void fm(ol olVar) {
        fm fmVar = this.f7307lb;
        if (fmVar != null) {
            fmVar.fm(olVar);
        }
    }

    public void fm(TTDislikeDialogAbstract tTDislikeDialogAbstract) {
        fm fmVar = this.f7307lb;
        if (fmVar != null) {
            fmVar.fm(tTDislikeDialogAbstract);
        }
    }

    public void fm(String str) {
        fm fmVar = this.f7307lb;
        if (fmVar != null) {
            fmVar.fm(str);
        }
    }

    public void fm(PAGExpressAdWrapperListener pAGExpressAdWrapperListener) {
        fm fmVar = this.f7307lb;
        if (fmVar != null) {
            fmVar.fm(pAGExpressAdWrapperListener);
        }
    }
}
