package com.bytedance.sdk.openadsdk.onz;

import android.content.Context;
import android.content.MutableContextWrapper;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.bytedance.sdk.component.ef.wsy;
import com.bytedance.sdk.component.utils.gzf;
import com.bytedance.sdk.openadsdk.activity.single.IABLandingPageActivity;
import com.bytedance.sdk.openadsdk.common.ef;
import com.bytedance.sdk.openadsdk.common.maa;
import com.bytedance.sdk.openadsdk.core.ajl.ajl;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.widget.fm.wsy;
import com.bytedance.sdk.openadsdk.utils.qhl;
import com.bytedance.sdk.openadsdk.utils.zan;

/* JADX INFO: loaded from: classes2.dex */
public class ro {
    private wsy ajl;
    private com.bytedance.sdk.openadsdk.onz.fm dsz;
    private wsy duv = null;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private boolean f7520ef;
    private final lse fm;
    private final Context jnr;
    private ajl ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private View f7521lb;
    private fm ro;
    private int vt;
    private ImageView wsy;
    private maa wu;
    private RelativeLayout yz;

    public interface fm {
        void fm(wsy wsyVar);
    }

    public ro(Context context, lse lseVar, int i10) {
        this.f7520ef = false;
        this.jnr = context;
        this.fm = lseVar;
        this.f7520ef = i10 == 1;
        this.vt = i10;
        ef();
    }

    private void ef() {
        com.bytedance.sdk.openadsdk.core.ajl.lb lbVarFm = fm(this.jnr, this.f7520ef);
        this.f7521lb = lbVarFm;
        this.ajl = (wsy) lbVarFm.findViewById(qhl.f7557ib);
        this.yz = (RelativeLayout) this.f7521lb.findViewById(qhl.xca);
        maa maaVar = new maa(this.jnr, this.yz, this.fm, this.ajl, "iab_".concat(String.valueOf(fm(this.vt))), this.f7520ef);
        this.wu = maaVar;
        this.wsy = maaVar.jnr();
        this.ku = this.wu.yz();
        com.bytedance.sdk.openadsdk.onz.fm fmVar = this.dsz;
        if (fmVar != null) {
            fmVar.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.onz.ro.2
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    ro.this.wu.yz("onSelectPrivacy");
                    IABLandingPageActivity.fm(ro.this.jnr, ro.this.fm, ro.this.fm.jnr());
                }
            });
        }
    }

    public View ajl() {
        if (this.f7521lb == null) {
            ef();
        }
        return this.f7521lb;
    }

    public RelativeLayout fm() {
        return this.yz;
    }

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

    public void wsy() {
        wsy wsyVar = this.ajl;
        if (wsyVar != null) {
            wsyVar.duv();
        }
    }

    public void wu() {
        wsy wsyVar = this.ajl;
        if (wsyVar != null) {
            gzf.fm(wsyVar);
            this.ajl = null;
        }
        this.wu = null;
    }

    public ajl yz() {
        return this.ku;
    }

    private String fm(int i10) {
        return (i10 < 0 || i10 > 2) ? "null" : i10 != 0 ? i10 != 1 ? i10 != 2 ? "null" : "history_landing_page" : "private_browser" : "landing_page";
    }

    public void lb() {
        maa maaVar = this.wu;
        if (maaVar != null) {
            maaVar.lb();
        }
    }

    public void ro() {
        maa maaVar = this.wu;
        if (maaVar != null) {
            maaVar.ro();
        }
    }

    public void fm(wsy wsyVar) {
        this.duv = wsyVar;
    }

    public void ro(String str) {
        this.wu.ro(str);
    }

    public void fm(fm fmVar) {
        this.ro = fmVar;
        wsy wsyVar = this.ajl;
        if (wsyVar != null && wsyVar.isAttachedToWindow()) {
            fmVar.fm(this.ajl);
            return;
        }
        wsy wsyVar2 = this.ajl;
        if (wsyVar2 != null) {
            wsyVar2.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { // from class: com.bytedance.sdk.openadsdk.onz.ro.1
                @Override // android.view.View.OnAttachStateChangeListener
                public void onViewAttachedToWindow(View view) {
                    if (ro.this.ro != null) {
                        ro.this.ro.fm(ro.this.ajl);
                    }
                    ro.this.ajl.removeOnAttachStateChangeListener(this);
                }

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

    private com.bytedance.sdk.openadsdk.core.ajl.lb fm(Context context, boolean z10) {
        wsy wsyVarFm;
        lse lseVar;
        com.bytedance.sdk.openadsdk.core.model.ro roVarDwu;
        com.bytedance.sdk.openadsdk.core.ajl.lb lbVar = new com.bytedance.sdk.openadsdk.core.ajl.lb(context);
        lbVar.setBackgroundColor(-1);
        RelativeLayout relativeLayout = new RelativeLayout(context);
        lbVar.addView(relativeLayout, new FrameLayout.LayoutParams(-1, -2));
        ef efVar = new ef(context);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -2);
        efVar.setId(qhl.xca);
        relativeLayout.addView(efVar, layoutParams);
        MutableContextWrapper mutableContextWrapper = new MutableContextWrapper(this.jnr.getApplicationContext());
        if (z10) {
            wsyVarFm = new wsy(mutableContextWrapper, wsy.lb.PRIVACY);
        } else {
            wsyVarFm = fm(mutableContextWrapper);
        }
        wsyVarFm.setId(qhl.f7557ib);
        FrameLayout.LayoutParams layoutParams2 = new FrameLayout.LayoutParams(-1, -1);
        layoutParams2.topMargin = zan.ro(mutableContextWrapper, 44.0f);
        lbVar.addView(wsyVarFm, layoutParams2);
        if (!z10 && (lseVar = this.fm) != null && (roVarDwu = lseVar.dwu()) != null) {
            String strYz = roVarDwu.yz();
            if (!TextUtils.isEmpty(strYz)) {
                com.bytedance.sdk.openadsdk.onz.fm fmVar = new com.bytedance.sdk.openadsdk.onz.fm(mutableContextWrapper);
                this.dsz = fmVar;
                fmVar.setId(qhl.zow);
                FrameLayout.LayoutParams layoutParams3 = new FrameLayout.LayoutParams(-1, -2);
                this.dsz.setPadding(zan.ro(this.jnr, 16.0f), zan.ro(this.jnr, 16.0f), zan.ro(this.jnr, 16.0f), zan.ro(this.jnr, 16.0f));
                this.dsz.setPrivacyText(strYz);
                layoutParams3.gravity = 80;
                lbVar.addView(this.dsz, layoutParams3);
            }
        }
        return lbVar;
    }

    private wsy fm(Context context) {
        wsy wsyVar = this.duv;
        if (wsyVar == null) {
            return new wsy(context, wsy.lb.LANDING_PAGE);
        }
        this.duv = null;
        return wsyVar;
    }

    public void fm(WebView webView, wsy.fm fmVar) {
        maa maaVar = this.wu;
        if (maaVar == null || webView == null) {
            return;
        }
        maaVar.fm(webView, fmVar);
    }

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

    public void fm(Bundle bundle) {
        if (bundle == null) {
            return;
        }
        boolean z10 = bundle.getBoolean("titleBarVisible", true);
        "restoreTitleBarState - visible: ".concat(String.valueOf(z10));
        if (z10) {
            ro();
        } else {
            lb();
        }
        if (this.wu != null) {
            String string = bundle.getString("mainTitle");
            String string2 = bundle.getString("subTitle");
            if (!TextUtils.isEmpty(string)) {
                fm(string);
            }
            if (TextUtils.isEmpty(string2)) {
                return;
            }
            ro(string2);
        }
    }
}
