package com.bytedance.sdk.openadsdk.component.reward.lb;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import com.bytedance.sdk.component.utils.mq;
import com.bytedance.sdk.component.utils.wey;
import com.bytedance.sdk.openadsdk.api.PAGExpressAdWrapperListener;
import com.bytedance.sdk.openadsdk.component.reward.fm.duv;
import com.bytedance.sdk.openadsdk.component.reward.fm.fhx;
import com.bytedance.sdk.openadsdk.component.reward.lb.ro.ro;
import com.bytedance.sdk.openadsdk.core.lb.lb;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.vt.hlt;
import com.bytedance.sdk.openadsdk.utils.irt;
import com.google.android.gms.measurement.internal.u1;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public abstract class ro implements mq.fm, PAGExpressAdWrapperListener, fm, com.bytedance.sdk.openadsdk.component.reward.lb.fm.jnr {
    protected String ajl;
    protected Context dsz;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    protected duv f6956ef;
    protected long fhx;
    protected String fm;
    private com.bytedance.sdk.openadsdk.component.reward.lb.ro.jnr gqi;
    private com.bytedance.sdk.openadsdk.sds.fm.fm.lb hi;
    private ViewGroup hlt;
    protected boolean irt;
    protected lse jnr;
    protected com.bytedance.sdk.openadsdk.component.reward.lb.ro.lb ku;
    private com.bytedance.sdk.openadsdk.core.ajl.lb maa;
    protected boolean qhl;
    public boolean ro;
    private com.bytedance.sdk.openadsdk.component.reward.lb.ro.fm sds;
    protected com.bytedance.sdk.openadsdk.component.reward.fm.fm vt;
    private com.bytedance.sdk.openadsdk.component.reward.lb.ro.wsy wey;
    public fhx wsy;
    protected com.bytedance.sdk.openadsdk.component.reward.lb.ro.yz wu;
    protected Activity yz;
    private final AtomicBoolean gof = new AtomicBoolean(false);

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    protected boolean f6957lb = false;
    private boolean lse = false;
    protected final mq duv = new mq(Looper.getMainLooper(), this);
    protected AtomicBoolean onz = new AtomicBoolean(false);
    private AtomicBoolean nt = new AtomicBoolean(false);
    private AtomicBoolean mq = new AtomicBoolean(false);

    public ro(Activity activity, Context context, lse lseVar, String str, ViewGroup viewGroup, String str2) {
        this.yz = activity;
        this.jnr = lseVar;
        this.ajl = str;
        this.dsz = context;
        this.hlt = viewGroup;
        this.wu = new com.bytedance.sdk.openadsdk.component.reward.lb.ro.yz(this, activity, lseVar, str);
        this.wsy = new fhx(viewGroup, lseVar, str, activity, activity.getApplicationContext(), this);
        this.f6956ef = new duv(activity, lseVar, lseVar.nnq(), false, this.ro, null);
        this.gqi = new com.bytedance.sdk.openadsdk.component.reward.lb.ro.jnr(this, activity, lseVar);
        this.wey = new com.bytedance.sdk.openadsdk.component.reward.lb.ro.wsy(lseVar);
        this.sds = new com.bytedance.sdk.openadsdk.component.reward.lb.ro.fm(viewGroup, activity);
        this.vt = new com.bytedance.sdk.openadsdk.component.reward.fm.fm(activity, lseVar, lseVar.nnq(), str);
        this.fm = str2;
        com.bytedance.sdk.openadsdk.core.ajl.lb lbVar = new com.bytedance.sdk.openadsdk.core.ajl.lb(activity);
        this.maa = lbVar;
        com.bytedance.sdk.openadsdk.component.reward.lb.ro.lb lbVar2 = new com.bytedance.sdk.openadsdk.component.reward.lb.ro.lb(activity, lseVar, lbVar, viewGroup, this.wsy);
        this.ku = lbVar2;
        lbVar2.fm(this);
        this.wu.fm(this);
        this.wsy.fm((PAGExpressAdWrapperListener) this);
        this.vt.fm(fm(lseVar));
        this.f6956ef.fm(lseVar.cpu().getDurationSlotType() == 7);
    }

    private void gof() {
        com.bytedance.sdk.openadsdk.component.reward.fm.fm fmVar = this.vt;
        if (fmVar == null) {
            return;
        }
        fmVar.fm();
        if (this.vt.ajl() != null) {
            this.hlt.addView(this.vt.ajl(), new FrameLayout.LayoutParams(-1, -1));
            this.vt.lb();
        }
    }

    private void gqi() {
        if (this.wu != null) {
            JSONObject jSONObject = new JSONObject();
            fhx fhxVar = this.wsy;
            if (fhxVar != null && fhxVar.ro() != null) {
                jSONObject = this.wsy.ro().fm(jSONObject, this.jnr);
            }
            this.fhx = System.currentTimeMillis();
            this.wu.fm(jSONObject);
        }
    }

    private void wey() {
        wey.fm("BaseManagerBundle", "removeLoadingPage: ");
        try {
            com.bytedance.sdk.openadsdk.component.reward.fm.fm fmVar = this.vt;
            if (fmVar != null) {
                fmVar.yz();
            }
        } catch (Throwable th) {
            wey.fm("BaseManagerBundle", "removeLoadingPage: ", th);
            com.bytedance.sdk.openadsdk.component.reward.fm.fm fmVar2 = this.vt;
            if (fmVar2 == null || fmVar2.ajl() == null) {
                return;
            }
            this.vt.ajl().setAlpha(0.0f);
        }
    }

    public void ajl() {
        wey.fm("BaseManagerBundle", "onPause: ");
        fhx fhxVar = this.wsy;
        if (fhxVar != null) {
            fhxVar.jnr();
        }
        com.bytedance.sdk.openadsdk.component.reward.lb.ro.fm fmVar = this.sds;
        if (fmVar != null) {
            fmVar.lb();
        }
    }

    public abstract void dsz();

    public abstract void duv();

    public void ef() {
        duv duvVar = this.f6956ef;
        if (duvVar != null) {
            duvVar.fm();
        }
    }

    public boolean fhx() {
        return this.f6957lb;
    }

    @Override // com.bytedance.sdk.component.utils.mq.fm
    public void fm(Message message) {
    }

    public abstract void fm(boolean z10, int i10, String str, int i11, String str2, int i12);

    public abstract void irt();

    public void jnr() {
        fhx fhxVar = this.wsy;
        if (fhxVar == null) {
            return;
        }
        hlt hltVarRo = fhxVar.ro();
        this.wsy.fm((fm) this);
        if (hltVarRo != null) {
            this.wey.fm(hltVarRo.getWebView());
            this.wsy.fm(this.wey);
            hltVarRo.setJsbLandingPageOpenListener(new com.bytedance.sdk.openadsdk.core.widget.jnr() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.ro.2
                @Override // com.bytedance.sdk.openadsdk.core.widget.jnr
                public void fm() {
                    ro.this.vt();
                }
            });
        }
    }

    public void ku() {
        duv();
        fhx fhxVar = this.wsy;
        if (fhxVar == null || fhxVar.ro() == null) {
            return;
        }
        this.wsy.ro().gqi();
    }

    public void lb(Bundle bundle) {
        if (bundle != null) {
            this.irt = bundle.getBoolean("enable_new_arch", false);
            return;
        }
        Activity activity = this.yz;
        if (activity == null || activity.getIntent() == null) {
            return;
        }
        this.irt = this.yz.getIntent().getBooleanExtra("enable_new_arch", false);
    }

    @Override // com.bytedance.sdk.openadsdk.api.PAGAdWrapperListener
    public void onAdClicked() {
    }

    @Override // com.bytedance.sdk.openadsdk.api.PAGExpressAdWrapperListener
    public void onAdDismissed() {
    }

    @Override // com.bytedance.sdk.openadsdk.api.PAGExpressAdWrapperListener
    public void onAdShow(View view, int i10) {
    }

    public void onRenderFail(View view, String str, int i10) {
        this.onz.set(false);
    }

    @Override // com.bytedance.sdk.openadsdk.api.PAGExpressAdWrapperListener
    public void onRenderSuccess(View view, float f10, float f11) {
        this.onz.set(true);
        if (!com.bytedance.sdk.openadsdk.core.model.wey.jnr(this.jnr)) {
            gqi();
            com.bytedance.sdk.openadsdk.component.reward.fm.fm fmVar = this.vt;
            if (fmVar != null) {
                fmVar.jnr();
                this.vt.yz();
            }
        } else if (!this.mq.get() || this.nt.get()) {
            com.bytedance.sdk.openadsdk.component.reward.fm.fm fmVar2 = this.vt;
            if (fmVar2 != null) {
                fmVar2.ro();
            }
        } else {
            this.nt.set(true);
            gqi();
            com.bytedance.sdk.openadsdk.component.reward.lb.ro.lb lbVar = this.ku;
            if (lbVar != null) {
                lbVar.fm();
            }
            com.bytedance.sdk.openadsdk.component.reward.fm.fm fmVar3 = this.vt;
            if (fmVar3 != null) {
                fmVar3.jnr();
                this.vt.yz();
            }
        }
        if (this.sds == null || !wu.wsy()) {
            return;
        }
        this.sds.fm();
        this.sds.fm(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.ro.3
            @Override // android.view.View.OnClickListener
            public void onClick(View view2) {
                ro roVar = ro.this;
                if (roVar.yz != null) {
                    fhx fhxVar = roVar.wsy;
                    if (fhxVar != null && fhxVar.ro() != null) {
                        ro.this.wsy.ro().setDirectDestroyWebView(true);
                    }
                    ro.this.onz();
                    ro.this.yz.finish();
                }
            }
        });
        this.sds.fm(new ro.fm() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.ro.4
            @Override // com.bytedance.sdk.openadsdk.component.reward.lb.ro.ro.fm
            public void fm() {
                fhx fhxVar = ro.this.wsy;
                if (fhxVar != null) {
                    fhxVar.fm();
                    wey.fm("BaseManagerBundle", "onSendHeartbeat: ");
                }
            }

            @Override // com.bytedance.sdk.openadsdk.component.reward.lb.ro.ro.fm
            public void fm(ro.EnumC0054ro enumC0054ro) {
                wey.fm("BaseManagerBundle", "onHeartbeatStatusChanged: ".concat(String.valueOf(enumC0054ro)));
                if (enumC0054ro == ro.EnumC0054ro.TIMEOUT) {
                    ro.this.sds.ro();
                    ro.this.sds.fm(ro.this.jnr);
                }
            }
        });
        this.wsy.fm(new yz() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.ro.5
            @Override // com.bytedance.sdk.openadsdk.component.reward.lb.yz
            public void fm() {
                if (ro.this.sds != null) {
                    ro.this.sds.yz();
                    wey.fm("BaseManagerBundle", "responseHeartBeat: ");
                }
            }
        });
    }

    public void onz() {
    }

    public void qhl() {
        Activity activity;
        if (com.bytedance.sdk.openadsdk.hlt.jnr.ef() && (activity = this.yz) != null && activity.isChangingConfigurations()) {
            wey.fm("BVA", "callback close is invoke by config change.");
            return;
        }
        if (this.qhl) {
            wey.fm("BVA", "invoke callback onAdClose has already been called ");
            return;
        }
        this.qhl = true;
        lse lseVar = this.jnr;
        if (lseVar != null && !lseVar.lz()) {
            long jEf = this.jnr.ef();
            if (jEf > 0) {
                long jElapsedRealtime = SystemClock.elapsedRealtime() - jEf;
                if (jElapsedRealtime > 0) {
                    this.jnr.ro(jElapsedRealtime);
                }
            }
            if (this.wu != null) {
                JSONObject jSONObject = new JSONObject();
                fhx fhxVar = this.wsy;
                if (fhxVar != null && fhxVar.ro() != null) {
                    jSONObject = this.wsy.ro().fm(jSONObject, this.jnr);
                }
                this.fhx = System.currentTimeMillis();
                this.wu.fm(jSONObject);
            }
        }
        irt();
    }

    public void ro(boolean z10) {
        this.f6957lb = z10;
    }

    public void vt() {
        wey.fm("BaseManagerBundle", "invoke callback onAdClicked, ".concat(String.valueOf(this)));
        dsz();
    }

    public void wsy() {
        com.bytedance.sdk.openadsdk.component.reward.lb.ro.lb lbVar = this.ku;
        if (lbVar != null) {
            lbVar.lb();
        }
    }

    public void wu() {
        wey();
        com.bytedance.sdk.openadsdk.component.reward.lb.ro.yz yzVar = this.wu;
        if (yzVar != null && yzVar.fm() && this.wu.ro() > 0) {
            String strValueOf = String.valueOf(SystemClock.elapsedRealtime() - this.wu.ro());
            fhx fhxVar = this.wsy;
            com.bytedance.sdk.openadsdk.yz.lb.fm(strValueOf, this.jnr, this.ajl, (fhxVar == null || fhxVar.ro() == null) ? null : this.wsy.ro().getAdShowTime());
        }
        com.bytedance.sdk.openadsdk.component.reward.lb.ro.jnr jnrVar = this.gqi;
        if (jnrVar != null) {
            jnrVar.fm();
        }
        fhx fhxVar2 = this.wsy;
        if (fhxVar2 != null) {
            fhxVar2.wsy();
        }
        irt.fm();
    }

    public void yz() {
        if (this.lse || this.jnr == null) {
            return;
        }
        this.lse = true;
        this.yz.getWindow().getDecorView().post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.ro.1
            @Override // java.lang.Runnable
            public void run() {
                int iNnq = ro.this.jnr.nnq();
                ro roVar = ro.this;
                float[] fArrFm = duv.fm(iNnq, roVar.yz, roVar.jnr, false);
                wey.fm("BaseManagerBundle", "show loading page");
                fhx fhxVar = ro.this.wsy;
                if (fhxVar != null) {
                    fhxVar.fm(fArrFm);
                    ro roVar2 = ro.this;
                    roVar2.wsy.fm(roVar2.ku);
                    ro.this.wsy.lb();
                    ro.this.jnr();
                    ro.this.wsy.ajl();
                    ro.this.wsy.fm(new com.bytedance.sdk.openadsdk.core.vt.jnr() { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.ro.1.1
                        @Override // com.bytedance.sdk.openadsdk.core.vt.jnr
                        public void fm(String str) {
                            if (ro.this.gqi != null) {
                                ro.this.gqi.fm(str);
                            }
                        }
                    });
                }
            }
        });
    }

    public void fm(@Nullable Bundle bundle) {
        irt.fm(this.jnr, this.dsz, this.ajl, this);
        gof();
        if (com.bytedance.sdk.openadsdk.core.model.wey.jnr(this.jnr)) {
            this.vt.ro();
        }
        this.hlt.addView(this.maa, new ViewGroup.LayoutParams(-1, -1));
        this.maa.setVisibility(8);
    }

    public void ro(Bundle bundle) {
        com.bytedance.sdk.openadsdk.component.reward.lb.ro.yz yzVar = this.wu;
        if (yzVar != null && yzVar.fm()) {
            this.jnr.vt(true);
        }
        if (this.gof.get()) {
            this.jnr.wu(true);
        }
    }

    public void lb() {
        yz();
        duv duvVar = this.f6956ef;
        if (duvVar != null) {
            duvVar.fm(this.duv);
        }
        com.bytedance.sdk.openadsdk.component.reward.lb.ro.lb lbVar = this.ku;
        if (lbVar != null) {
            lbVar.ro();
        }
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.lb.fm
    public void ro() {
        if (this.gof.compareAndSet(false, true)) {
            wey.fm("BVA", "invoke callback onShow, ".concat(String.valueOf(this)));
            ku();
        }
    }

    public void fm(boolean z10) {
        if (this.wu != null) {
            fhx fhxVar = this.wsy;
            this.wu.fm(z10, (fhxVar == null || fhxVar.ro() == null) ? null : this.wsy.ro().getAdShowTime());
            this.wu.fm(z10, this.jnr, this.ajl);
        }
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.lb.fm
    public void fm() {
        vt();
        this.jnr.qi();
        this.jnr.yz(true);
        if (lse.jnr(this.jnr)) {
            lse lseVar = this.jnr;
            com.bytedance.sdk.openadsdk.yz.lb.ro(lseVar, this.ajl, lseVar.cll());
        }
    }

    public com.bytedance.sdk.openadsdk.core.lb.jnr fm(lse lseVar) {
        if (this.hi == null) {
            this.hi = com.bytedance.sdk.openadsdk.sds.fm.fm.yz.fm(this.yz, this.ajl);
        }
        Activity activity = this.yz;
        String str = this.ajl;
        com.bytedance.sdk.openadsdk.core.lb.jnr jnrVar = new com.bytedance.sdk.openadsdk.core.lb.jnr(activity, lseVar, str, TextUtils.equals(str, "rewarded_video") ? 7 : 5) { // from class: com.bytedance.sdk.openadsdk.component.reward.lb.ro.6
            @Override // com.bytedance.sdk.openadsdk.core.lb.jnr
            public void fm(View view, float f10, float f11, float f12, float f13, SparseArray<lb.fm> sparseArray, int i10, int i11, int i12, boolean z10) {
                HashMap map = new HashMap();
                u1.t(0, map, "duration", 1, "click_scence");
                fm(map);
                ro.this.vt();
            }
        };
        jnrVar.fm(this.hi);
        return jnrVar;
    }

    @Override // com.bytedance.sdk.openadsdk.component.reward.lb.fm.jnr
    public void fm(String str, int i10, int i11) {
        fhx fhxVar = this.wsy;
        if (fhxVar != null) {
            fhxVar.fm(str, i10, i11);
            if (i10 == 2 || i10 == 3) {
                System.currentTimeMillis();
                this.mq.set(true);
                if (!this.onz.get() || !com.bytedance.sdk.openadsdk.core.model.wey.jnr(this.jnr) || this.nt.get()) {
                    com.bytedance.sdk.openadsdk.core.ajl.lb lbVar = this.maa;
                    if (lbVar != null) {
                        lbVar.setVisibility(0);
                    }
                    com.bytedance.sdk.openadsdk.component.reward.lb.ro.lb lbVar2 = this.ku;
                    if (lbVar2 == null || i10 != 2) {
                        return;
                    }
                    lbVar2.fm();
                    return;
                }
                this.nt.set(true);
                gqi();
                com.bytedance.sdk.openadsdk.core.ajl.lb lbVar3 = this.maa;
                if (lbVar3 != null) {
                    lbVar3.setVisibility(0);
                }
                com.bytedance.sdk.openadsdk.component.reward.lb.ro.lb lbVar4 = this.ku;
                if (lbVar4 != null && i10 == 2) {
                    lbVar4.fm();
                }
                com.bytedance.sdk.openadsdk.component.reward.fm.fm fmVar = this.vt;
                if (fmVar != null) {
                    fmVar.yz();
                    this.vt.jnr();
                }
            }
        }
    }
}
