package com.bytedance.sdk.openadsdk.component;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.media3.exoplayer.upstream.CmcdData;
import com.bytedance.sdk.component.utils.wey;
import com.bytedance.sdk.openadsdk.activity.single.IABLandingPageActivity;
import com.bytedance.sdk.openadsdk.activity.single.TTAppOpenAdTransActivity;
import com.bytedance.sdk.openadsdk.activity.single.TTWebsiteActivity;
import com.bytedance.sdk.openadsdk.component.ajl;
import com.bytedance.sdk.openadsdk.component.ef.jnr;
import com.bytedance.sdk.openadsdk.core.ajl.wu;
import com.bytedance.sdk.openadsdk.core.lb.ro;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.widget.PAGLogoView;
import com.bytedance.sdk.openadsdk.core.widget.irt;
import com.bytedance.sdk.openadsdk.core.widget.qhl;
import com.bytedance.sdk.openadsdk.utils.gof;
import com.bytedance.sdk.openadsdk.utils.zan;
import j4.a;
import java.io.File;
import java.lang.ref.WeakReference;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class lb {
    protected final int ajl;
    private RelativeLayout dsz;
    protected final com.bytedance.sdk.openadsdk.component.wu.fm duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    protected View f6883ef;
    private PAGLogoView fhx;
    protected final Activity fm;
    private qhl gof;
    private wu gqi;
    private View gzf;
    private wu hi;
    private com.bytedance.sdk.openadsdk.component.wu.lb hlt;
    private wu irt;
    protected final com.bytedance.sdk.openadsdk.component.fm jnr;
    protected wu ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    protected final boolean f6884lb;

    @NonNull
    private final com.bytedance.sdk.openadsdk.component.ef.wu lse = new com.bytedance.sdk.openadsdk.component.ef.wu();
    private float maa;
    private irt mq;
    private com.bytedance.sdk.openadsdk.core.ajl.yz nt;
    private ImageView onz;
    private ImageView qhl;
    protected final lse ro;
    private float sds;
    protected com.bytedance.sdk.openadsdk.core.ajl.yz vt;
    private wu wey;
    protected int wsy;
    protected FrameLayout wu;
    protected final FrameLayout yz;

    public static class fm implements ajl.lb {
        WeakReference<Activity> fm;
        private final WeakReference<lb> ro;

        public fm(Activity activity, lb lbVar) {
            this.fm = new WeakReference<>(activity);
            this.ro = new WeakReference<>(lbVar);
        }

        @Override // com.bytedance.sdk.openadsdk.component.ajl.lb
        public void fm(Object obj) {
            lb lbVar;
            if (this.fm.get() == null || this.fm.get().isFinishing() || (lbVar = this.ro.get()) == null) {
                return;
            }
            lbVar.fm(obj);
        }
    }

    public static class ro implements gof.fm {
        private final WeakReference<lb> fm;

        public ro(lb lbVar) {
            this.fm = new WeakReference<>(lbVar);
        }

        @Override // com.bytedance.sdk.openadsdk.utils.gof.fm
        public void fm() {
        }

        @Override // com.bytedance.sdk.openadsdk.utils.gof.fm
        public void fm(com.bytedance.sdk.openadsdk.wey.fm.ro roVar) {
            lb lbVar;
            if (!roVar.jnr() || (lbVar = this.fm.get()) == null) {
                return;
            }
            lbVar.fm(roVar);
            if (roVar.ro() != null) {
                lbVar.fm(roVar.fm());
            }
        }
    }

    public lb(Activity activity, lse lseVar, FrameLayout frameLayout, com.bytedance.sdk.openadsdk.component.fm fmVar, int i10, boolean z10, com.bytedance.sdk.openadsdk.component.wu.fm fmVar2) {
        this.fm = activity;
        this.ro = lseVar;
        this.yz = frameLayout;
        this.wsy = i10;
        this.f6884lb = z10;
        this.jnr = fmVar;
        this.ajl = lseVar.pg();
        this.duv = fmVar2;
    }

    private void ef() {
        if (this.gqi != null) {
            if (this.ro.iat() != null && !TextUtils.isEmpty(this.ro.iat().ro())) {
                this.gqi.setText(this.ro.iat().ro());
            } else if (TextUtils.isEmpty(this.ro.wjb())) {
                this.gqi.setVisibility(8);
            } else {
                this.gqi.setText(this.ro.wjb());
            }
        }
        if (this.wey != null) {
            if (TextUtils.isEmpty(this.ro.qlg())) {
                this.wey.setVisibility(8);
            } else {
                this.wey.setText(this.ro.qlg());
            }
        }
        if (this.gof != null && this.ro.ff() != null && !TextUtils.isEmpty(this.ro.ff().fm())) {
            com.bytedance.sdk.openadsdk.wey.ro.ro().fm(this.ro.ff().fm(), this.ro.ff().ro(), this.ro.ff().lb(), this.gof, this.ro);
        }
        this.jnr.lb();
    }

    private void vt() {
        com.bytedance.sdk.openadsdk.core.model.gof gofVar = this.ro.pyj().get(0);
        String strFm = TextUtils.isEmpty(gofVar.wsy()) ? com.bytedance.sdk.component.utils.jnr.fm(gofVar.fm()) : gofVar.wsy();
        if (TextUtils.isEmpty(strFm) || strFm.contains("../") || strFm.contains("/") || strFm.contains("..")) {
            return;
        }
        File fileRo = com.bytedance.sdk.openadsdk.component.wsy.fm.ro(strFm);
        gof.fm(new com.bytedance.sdk.openadsdk.wey.fm(gofVar.fm(), gofVar.wsy()), gofVar.ro(), gofVar.lb(), new ro(this), fileRo != null ? fileRo.getParent() : null, 25);
    }

    private void wu() {
        boolean z10;
        this.lse.fm();
        this.irt.setText(this.ro.eys());
        if (this.ro.ol()) {
            ef();
            return;
        }
        if (this.f6884lb) {
            ro(0);
            fm(8);
            if (fm(this.wu)) {
                this.jnr.lb();
            } else {
                this.jnr.yz();
            }
            ajl.fm(this.ro, new fm(this.fm, this), 25);
        } else {
            ro(8);
            fm(0);
            vt();
            this.jnr.lb();
        }
        boolean z11 = true;
        if (this.hi == null) {
            z10 = false;
        } else {
            if (TextUtils.isEmpty(this.ro.wjb())) {
                if (this.ro.iat() != null) {
                    this.hi.setText(this.ro.iat().ro());
                }
                z10 = false;
            } else {
                this.hi.setText(this.ro.wjb());
            }
            z10 = true;
        }
        if (this.nt != null) {
            com.bytedance.sdk.openadsdk.wey.ro.ro().fm(this.ro.ff(), this.nt, this.ro);
        }
        irt irtVar = this.mq;
        if (irtVar != null) {
            zan.fm((TextView) null, irtVar, this.ro);
            if (this.ro.iat() == null || this.ro.iat().yz() < 0.0d) {
                this.mq.setVisibility(8);
                z11 = z10;
            }
        } else {
            z11 = z10;
        }
        View view = this.gzf;
        if (view != null) {
            view.setVisibility(z11 ? 0 : 8);
        }
    }

    public void ajl() {
        View view = this.f6883ef;
        if (view == null || this.vt == null) {
            return;
        }
        view.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.component.lb.4
            @Override // android.view.View.OnClickListener
            public void onClick(View view2) {
                com.bytedance.sdk.openadsdk.component.fm fmVar = lb.this.jnr;
                if (fmVar != null) {
                    fmVar.ro(view2);
                }
            }
        });
        this.vt.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.component.lb.5
            @Override // android.view.View.OnClickListener
            public void onClick(View view2) {
                com.bytedance.sdk.openadsdk.component.fm fmVar = lb.this.jnr;
                if (fmVar != null) {
                    fmVar.fm(view2);
                }
            }
        });
    }

    public JSONObject fm(JSONObject jSONObject) {
        return null;
    }

    public void jnr() {
    }

    public void lb() {
        com.bytedance.sdk.openadsdk.component.wu.lb lbVar = this.hlt;
        if (lbVar != null) {
            lbVar.duv();
        }
    }

    public void ro() {
        Window window;
        if (this.ro.yur()) {
            this.jnr.lb();
        } else {
            wu();
        }
        Activity activity = this.fm;
        if (!(activity instanceof TTAppOpenAdTransActivity) || (window = activity.getWindow()) == null) {
            return;
        }
        window.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#1E1E1E")));
    }

    public com.bytedance.sdk.openadsdk.component.wu.lb wsy() {
        return this.hlt;
    }

    public int yz() {
        return -1;
    }

    public void fm(float f10, float f11) {
        this.maa = f10;
        this.sds = f11;
    }

    public void fm(ViewGroup viewGroup) {
        com.bytedance.sdk.openadsdk.component.ef.lb yzVar = new com.bytedance.sdk.openadsdk.component.ef.yz(this.fm, this.ro);
        int iMj = this.ro.mj();
        if (iMj == 5) {
            yzVar = new com.bytedance.sdk.openadsdk.component.ef.ajl(this.fm, this.ro);
        } else if (iMj == 4) {
            yzVar = new com.bytedance.sdk.openadsdk.component.ef.jnr(this.fm, this.ro);
        }
        this.dsz = yzVar;
        viewGroup.addView(yzVar);
        this.qhl = yzVar.getBackImage();
        this.wu = yzVar.getVideoContainer();
        this.onz = yzVar.getImageView();
        this.irt = yzVar.getClickButton();
        this.fhx = yzVar.getAdLogo();
        this.hi = yzVar.getAdTitleTextView();
        this.nt = yzVar.getAdIconView();
        this.mq = yzVar.getScoreBar();
        this.gzf = yzVar.getOverlayLayout();
        if (this.ro.ol()) {
            this.gof = yzVar.getIconOnlyView();
            this.gqi = yzVar.getTitle();
            this.wey = yzVar.getContent();
        }
        if (yzVar.getDspAdChoice() != null) {
            yzVar.getDspAdChoice().fm(14, this.ro);
        }
        if (!this.ro.yur()) {
            this.lse.fm(yzVar, this.ro, this.maa, this.sds, this.f6884lb);
        }
        this.f6883ef = yzVar.getTopDisLike();
        this.vt = yzVar.getTopSkip();
        this.ku = yzVar.getTopCountDown();
        if (yzVar instanceof com.bytedance.sdk.openadsdk.component.ef.jnr) {
            ((com.bytedance.sdk.openadsdk.component.ef.jnr) yzVar).setRenderListener(new jnr.fm() { // from class: com.bytedance.sdk.openadsdk.component.lb.1
                @Override // com.bytedance.sdk.openadsdk.component.ef.jnr.fm
                public void fm(View view, int i10) {
                    lb.this.jnr.jnr();
                }
            });
        }
    }

    private void ro(int i10) {
        zan.fm((View) this.wu, i10);
    }

    @SuppressLint({"ClickableViewAccessibility"})
    public void fm() {
        this.fhx.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.component.lb.2
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                try {
                    if (com.bytedance.sdk.openadsdk.utils.ro.jnr() && com.bytedance.sdk.openadsdk.core.gof.yz().ai()) {
                        lb lbVar = lb.this;
                        IABLandingPageActivity.fm(lbVar.fm, lbVar.ro, "open_ad");
                    } else {
                        lb lbVar2 = lb.this;
                        TTWebsiteActivity.fm(lbVar2.fm, lbVar2.ro, "open_ad");
                    }
                } catch (Throwable th) {
                    wey.lb("AppOpenAdNativeManager", th.getMessage());
                }
            }
        });
        ajl();
        if (this.ro.yur()) {
            return;
        }
        com.bytedance.sdk.openadsdk.component.fm.fm fmVarFm = com.bytedance.sdk.openadsdk.component.fm.ro.fm(this.ro, this.fm, this.duv);
        fmVarFm.fm(new ro.fm() { // from class: com.bytedance.sdk.openadsdk.component.lb.3
            @Override // com.bytedance.sdk.openadsdk.core.lb.ro.fm
            public void fm(View view, int i10) {
                lb.this.jnr.jnr();
            }
        });
        fmVarFm.fm(this.hlt);
        if (this.ro.vvj() == 1) {
            this.dsz.setOnClickListener(fmVarFm);
            this.dsz.setOnTouchListener(fmVarFm);
        }
        this.irt.setOnClickListener(fmVarFm);
        this.irt.setOnTouchListener(fmVarFm);
    }

    public boolean fm(FrameLayout frameLayout) {
        com.bytedance.sdk.openadsdk.component.wu.lb lbVar = new com.bytedance.sdk.openadsdk.component.wu.lb(this.fm);
        this.hlt = lbVar;
        return lbVar.fm(frameLayout, this.jnr, this.ro);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(Object obj) {
        try {
            if (obj instanceof Bitmap) {
                this.qhl.setImageDrawable(new BitmapDrawable(com.bytedance.sdk.openadsdk.core.gof.fm().getResources(), (Bitmap) obj));
            }
        } catch (Throwable unused) {
            wey.lb("AppOpenAdNativeManager", "open_ad", "bindBackGroundImage error");
        }
    }

    public void fm(com.bytedance.sdk.openadsdk.wey.fm.ro roVar) {
        if (this.onz == null) {
            return;
        }
        if (roVar.ro() != null) {
            this.onz.setImageBitmap(roVar.ro());
            return;
        }
        Drawable drawableYz = roVar.yz();
        if (drawableYz != null) {
            this.onz.setScaleType(ImageView.ScaleType.FIT_CENTER);
            if (Build.VERSION.SDK_INT >= 28 && a.x(drawableYz)) {
                a.f(drawableYz).start();
            }
            this.onz.setImageDrawable(drawableYz);
            return;
        }
        if (this.ro.pyj() == null || this.ro.pyj().get(0) == null) {
            return;
        }
        Drawable drawableFm = gof.fm(roVar.lb(), this.ro.pyj().get(0).ro());
        this.onz.setScaleType(ImageView.ScaleType.FIT_CENTER);
        this.onz.setImageDrawable(drawableFm);
    }

    public void fm(int i10) {
        zan.fm((View) this.onz, i10);
    }

    public void fm(int i10, boolean z10) {
        wu wuVar;
        if (this.vt == null || (wuVar = this.ku) == null) {
            return;
        }
        if (z10) {
            if (wuVar.getVisibility() != 8) {
                this.ku.setVisibility(8);
            }
            if (this.vt.getVisibility() != 0) {
                this.vt.setVisibility(0);
                return;
            }
            return;
        }
        this.ku.setText(i10 + CmcdData.STREAMING_FORMAT_SS);
        if (this.ku.getVisibility() != 0) {
            this.ku.setVisibility(0);
        }
    }
}
