package com.bytedance.sdk.openadsdk.common;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.utils.ai;
import hb.a;

/* JADX INFO: loaded from: classes2.dex */
public class duv extends com.bytedance.sdk.openadsdk.core.ajl.lb {
    private Runnable ajl;
    protected ku fm;
    private Runnable jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private int f6842lb;
    protected boolean ro;
    private boolean wsy;
    private int wu;
    private long yz;

    public duv(@NonNull Context context) {
        super(context);
        this.yz = 10L;
        this.ro = true;
        this.wsy = false;
        this.wu = 1;
        lb();
    }

    private void lb(int i10) {
        if (this.wu != i10) {
            this.wu = i10;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void ro(int i10) {
        ku kuVar = this.fm;
        if (kuVar != null) {
            kuVar.fm(i10);
        }
        if (i10 == 100 && this.ro) {
            ro();
        }
    }

    public ku getLoadingStyle() {
        return this.fm;
    }

    @Override // android.view.View
    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        lb(configuration.orientation);
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        Runnable runnable = this.jnr;
        if (runnable != null) {
            removeCallbacks(runnable);
            this.jnr = null;
        }
    }

    public void setOnlyLoading(boolean z10) {
        this.wsy = z10;
    }

    private void lb() {
        setBackgroundColor(Color.parseColor("#2E2E2E"));
        setVisibility(8);
    }

    public void fm(lse lseVar) {
        com.bytedance.sdk.openadsdk.core.model.sds sdsVarHlt;
        if (lseVar != null && (sdsVarHlt = lseVar.hlt()) != null) {
            this.yz = sdsVarHlt.fm();
        }
        ku kuVar = new ku(getContext());
        this.fm = kuVar;
        View viewFm = kuVar.fm();
        if (viewFm.getParent() instanceof ViewGroup) {
            ((ViewGroup) viewFm.getParent()).removeView(viewFm);
        }
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2);
        layoutParams.gravity = 17;
        viewFm.setLayoutParams(layoutParams);
        if (lseVar != null) {
            boolean zUg = lseVar.ug();
            com.bytedance.sdk.openadsdk.core.widget.qhl qhlVarRo = this.fm.ro();
            if (qhlVarRo != null) {
                if (!this.wsy && !zUg) {
                    com.bytedance.sdk.openadsdk.core.model.gof gofVarFf = (lseVar.ff() == null || TextUtils.isEmpty(lseVar.ff().fm())) ? null : lseVar.ff();
                    if (gofVarFf != null && !TextUtils.isEmpty(gofVarFf.fm())) {
                        try {
                            com.bytedance.sdk.openadsdk.vt.yz.fm(gofVarFf).lb(1).fm(new com.bytedance.sdk.openadsdk.vt.ro(lseVar, gofVarFf.fm(), new ai(qhlVarRo)));
                        } catch (Throwable unused) {
                            qhlVarRo.setVisibility(8);
                        }
                    } else {
                        qhlVarRo.setVisibility(8);
                    }
                } else {
                    qhlVarRo.setVisibility(8);
                }
            }
            com.bytedance.sdk.openadsdk.core.ajl.wu wuVarLb = this.fm.lb();
            if (wuVarLb != null) {
                if (!this.wsy && !zUg) {
                    if (!TextUtils.isEmpty(lseVar.qlg())) {
                        wuVarLb.setText(lseVar.qlg());
                    } else {
                        wuVarLb.setVisibility(8);
                    }
                } else {
                    wuVarLb.setText("Loading");
                }
            }
        }
        addView(viewFm);
        lb(getResources().getConfiguration().orientation);
    }

    public void ro() {
        this.f6842lb = 0;
        ku kuVar = this.fm;
        if (kuVar != null) {
            removeView(kuVar.fm);
            this.fm.yz();
        }
        setVisibility(8);
        this.fm = null;
        Runnable runnable = this.jnr;
        if (runnable != null) {
            removeCallbacks(runnable);
        }
        Runnable runnable2 = this.ajl;
        if (runnable2 != null) {
            removeCallbacks(runnable2);
        }
        this.ajl = null;
        this.jnr = null;
    }

    public void fm() {
        post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.common.duv.1
            @Override // java.lang.Runnable
            public void run() {
                duv duvVar = duv.this;
                if (duvVar.fm != null) {
                    duvVar.setVisibility(0);
                }
            }
        });
        if (this.jnr == null) {
            this.jnr = new Runnable() { // from class: com.bytedance.sdk.openadsdk.common.duv.2
                @Override // java.lang.Runnable
                public void run() {
                    duv.this.ro();
                }
            };
        }
        postDelayed(this.jnr, this.yz * 1000);
    }

    public void fm(int i10) {
        if (i10 == 100 || Math.abs(i10 - this.f6842lb) >= 7) {
            this.f6842lb = i10;
            if (a.a0()) {
                ro(this.f6842lb);
                return;
            }
            if (this.ajl == null) {
                this.ajl = new Runnable() { // from class: com.bytedance.sdk.openadsdk.common.duv.3
                    @Override // java.lang.Runnable
                    public void run() {
                        duv duvVar = duv.this;
                        duvVar.ro(duvVar.f6842lb);
                    }
                };
            }
            post(this.ajl);
        }
    }
}
