package com.bytedance.sdk.component.adexpress.jnr;

import android.app.Activity;
import android.content.Context;
import android.content.MutableContextWrapper;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.UiThread;
import com.bytedance.sdk.component.adexpress.ro.dsz;
import com.bytedance.sdk.component.adexpress.ro.ku;
import com.bytedance.sdk.component.adexpress.ro.onz;
import com.bytedance.sdk.component.adexpress.ro.wu;
import com.bytedance.sdk.component.ef.wsy;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes.dex */
public abstract class fm implements com.bytedance.sdk.component.adexpress.fm, ku, com.bytedance.sdk.component.adexpress.ro.yz<wsy> {
    private boolean dsz;
    private dsz duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private String f6537ef;
    protected JSONObject fm;
    protected wsy jnr;
    private wu ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    protected boolean f6538lb;
    private int onz;
    protected volatile com.bytedance.sdk.component.adexpress.ro.wsy ro;
    private String vt;
    private Context wu;
    protected boolean yz;
    protected int ajl = 8;
    protected AtomicBoolean wsy = new AtomicBoolean(false);
    private AtomicBoolean fhx = new AtomicBoolean(false);

    public fm(Context context, dsz dszVar) {
        this.f6538lb = false;
        this.wu = context;
        this.duv = dszVar;
        this.f6537ef = dszVar.yz();
        if (com.bytedance.sdk.component.adexpress.yz.ro()) {
            fhx();
            return;
        }
        wsy wsyVarFm = fm(this.wu, this.f6537ef);
        this.jnr = wsyVarFm;
        if (wsyVarFm != null) {
            this.f6538lb = true;
        } else if (com.bytedance.sdk.component.adexpress.yz.fm() != null) {
            this.jnr = new wsy(com.bytedance.sdk.component.adexpress.yz.fm(), wsy.lb.ADS);
        }
    }

    private void fhx() {
        if (this.wu == null && com.bytedance.sdk.component.adexpress.yz.fm() != null) {
            this.wu = com.bytedance.sdk.component.adexpress.yz.fm();
        }
        Context context = this.wu;
        if (context != null) {
            wsy wsyVarFm = fm(context, this.f6537ef);
            this.jnr = wsyVarFm;
            if (wsyVarFm == null) {
                this.jnr = new wsy(new MutableContextWrapper(this.wu.getApplicationContext()), fm());
            } else {
                this.f6538lb = true;
            }
        }
    }

    public void ajl() {
    }

    public void dsz() {
    }

    public void duv() {
    }

    public void ef() {
        if (yz() == null) {
            return;
        }
        try {
            yz().getWebView().resumeTimers();
        } catch (Exception unused) {
        }
    }

    public abstract void fm(int i10);

    public void fm(wu wuVar) {
        this.ku = wuVar;
    }

    public void ku() {
        duv();
        Activity activityFm = com.bytedance.sdk.component.utils.ro.fm(this.jnr);
        if (activityFm != null) {
            this.onz = ro(activityFm);
        }
    }

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

    public dsz onz() {
        return this.duv;
    }

    public void ro() {
        if (this.duv.lse()) {
            jnr.fm().yz(this.jnr);
        } else {
            jnr.fm().jnr(this.jnr);
        }
    }

    public abstract void vt();

    @Override // com.bytedance.sdk.component.adexpress.ro.yz
    /* JADX INFO: renamed from: wsy, reason: merged with bridge method [inline-methods] */
    public wsy jnr() {
        return yz();
    }

    public void wu() {
        if (this.wsy.get()) {
            return;
        }
        this.wsy.set(true);
        vt();
        if (this.jnr.getParent() != null) {
            ((ViewGroup) this.jnr.getParent()).removeView(this.jnr);
        }
        this.fhx.get();
        if (!this.yz || this.fhx.get()) {
            jnr.fm().ajl(this.jnr);
        } else {
            ro();
        }
    }

    public wsy yz() {
        return this.jnr;
    }

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

    public void fm(JSONObject jSONObject) {
        this.fm = jSONObject;
    }

    public void fm(boolean z10) {
        this.dsz = z10;
    }

    public boolean ro(onz onzVar) {
        return onzVar.ro();
    }

    private int ro(Activity activity) {
        return activity.hashCode();
    }

    public wsy.lb fm() {
        return this.duv.lse() ? wsy.lb.ADS_V3 : wsy.lb.ADS;
    }

    public void ro(boolean z10) {
        this.fhx.set(z10);
    }

    public wsy fm(Context context, String str) {
        if (this.duv.lse()) {
            return jnr.fm().ro(context, str);
        }
        return jnr.fm().lb(context, str);
    }

    @Override // com.bytedance.sdk.component.adexpress.ro.yz
    public void fm(com.bytedance.sdk.component.adexpress.ro.wsy wsyVar) {
        String str;
        this.ro = wsyVar;
        if (yz() != null && yz().getWebView() != null) {
            if (TextUtils.isEmpty(this.vt)) {
                this.ro.fm(102, "url is empty");
                return;
            }
            if (!this.duv.ai()) {
                if (!this.duv.lse()) {
                    if (!com.bytedance.sdk.component.adexpress.fm.ro.ro.fm(this.fm)) {
                        com.bytedance.sdk.component.adexpress.ro.wsy wsyVar2 = this.ro;
                        StringBuilder sb = new StringBuilder("data null is ");
                        sb.append(this.fm == null);
                        wsyVar2.fm(103, sb.toString());
                        return;
                    }
                } else if (lb() == 9 && !com.bytedance.sdk.component.adexpress.fm.ro.ro.ro(this.fm)) {
                    com.bytedance.sdk.component.adexpress.ro.wsy wsyVar3 = this.ro;
                    StringBuilder sb2 = new StringBuilder("data null is ");
                    sb2.append(this.fm == null);
                    wsyVar3.fm(103, sb2.toString());
                    return;
                }
            }
            this.duv.jnr().fm(this.f6538lb);
            if (this.f6538lb) {
                try {
                    int iHi = this.duv.hi();
                    if (this.duv.lse() && iHi == 1) {
                        this.duv.lb();
                        str = "javascript:window.SDK_RESET_RENDER();" + ("window.SDK_INJECT_DATA=" + this.duv.lb() + ";") + "window.SDK_TRIGGER_RENDER();";
                    } else {
                        str = "javascript:window.SDK_RESET_RENDER();window.SDK_TRIGGER_RENDER();";
                    }
                    ajl();
                    this.jnr.irt();
                    this.duv.jnr();
                    com.bytedance.sdk.component.utils.onz.fm(this.jnr.getWebView(), str);
                    return;
                } catch (Exception e10) {
                    jnr.fm().ajl(this.jnr);
                    this.ro.fm(102, "load exception is " + e10.getMessage());
                    return;
                }
            }
            wsy wsyVarYz = yz();
            wsyVarYz.irt();
            this.duv.jnr();
            wsyVarYz.a_(this.vt);
            return;
        }
        com.bytedance.sdk.component.adexpress.ro.wsy wsyVar4 = this.ro;
        StringBuilder sb3 = new StringBuilder("SSWebview null is ");
        sb3.append(yz() == null);
        sb3.append(" or Webview is null");
        wsyVar4.fm(102, sb3.toString());
    }

    @Override // com.bytedance.sdk.component.adexpress.ro.ku
    public void fm(final onz onzVar) {
        if (onzVar == null) {
            if (this.ro != null) {
                this.ro.fm(105, "renderResult is null");
                return;
            }
            return;
        }
        boolean zRo = ro(onzVar);
        final float fLb = (float) onzVar.lb();
        final float fYz = (float) onzVar.yz();
        if (lb() != 0 || (fLb > 0.0f && fYz > 0.0f)) {
            this.yz = zRo;
            if (Looper.myLooper() == Looper.getMainLooper()) {
                fm(onzVar, fLb, fYz);
                return;
            } else {
                new Handler(Looper.getMainLooper()).post(new Runnable() { // from class: com.bytedance.sdk.component.adexpress.jnr.fm.1
                    @Override // java.lang.Runnable
                    public void run() {
                        fm.this.fm(onzVar, fLb, fYz);
                    }
                });
                return;
            }
        }
        if (this.ro != null) {
            this.ro.fm(105, "width is " + fLb + "height is " + fYz);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(onz onzVar, float f10, float f11) {
        onzVar.vt();
        boolean z10 = this.yz;
        if (z10 && !this.dsz) {
            fm(f10, f11);
            fm(this.ajl);
            if (this.ro != null) {
                this.ro.fm(yz(), onzVar);
                return;
            }
            return;
        }
        if (!z10) {
            jnr.fm().ajl(this.jnr);
        }
        fm(onzVar.vt(), onzVar.ef());
    }

    @Override // com.bytedance.sdk.component.adexpress.ro.ku
    public void fm(View view, int i10, com.bytedance.sdk.component.adexpress.lb lbVar) {
        wu wuVar = this.ku;
        if (wuVar != null) {
            wuVar.fm(view, i10, lbVar);
        }
    }

    @UiThread
    private void fm(float f10, float f11) {
        this.duv.jnr().jnr();
        if (lb() != 9 && lb() != 11) {
            int iFm = (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.wu, f10);
            int iFm2 = (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.wu, f11);
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) yz().getLayoutParams();
            if (layoutParams == null) {
                layoutParams = new FrameLayout.LayoutParams(iFm, iFm2);
            }
            layoutParams.width = iFm;
            layoutParams.height = iFm2;
            yz().setLayoutParams(layoutParams);
            return;
        }
        FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) yz().getLayoutParams();
        if (layoutParams2 == null) {
            layoutParams2 = new FrameLayout.LayoutParams(-1, -1);
        }
        layoutParams2.width = -1;
        layoutParams2.height = -1;
        yz().setLayoutParams(layoutParams2);
    }

    private void fm(int i10, String str) {
        if (this.ro != null) {
            this.ro.fm(i10, str);
        }
    }

    @Override // com.bytedance.sdk.component.adexpress.fm
    public void fm(Activity activity) {
        if (this.onz == 0 || activity == null || activity.hashCode() != this.onz) {
            return;
        }
        wu();
        dsz();
    }
}
