c.java 源代码


package com.mbridge.msdk.advanced.c;

import android.app.Activity;
import android.text.TextUtils;
import android.util.Base64;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.webkit.WebView;
import com.mbridge.msdk.advanced.view.MBNativeAdvancedView;
import com.mbridge.msdk.advanced.view.MBNativeAdvancedWebview;
import com.mbridge.msdk.advanced.view.MBOutNativeAdvancedViewGroup;
import com.mbridge.msdk.foundation.entity.CampaignEx;
import com.mbridge.msdk.foundation.tools.m;
import com.mbridge.msdk.foundation.tools.q;
import com.mbridge.msdk.foundation.tools.z;
import com.mbridge.msdk.mbsignalcommon.windvane.g;
import com.mbridge.msdk.out.MBridgeIds;
import com.mbridge.msdk.out.NativeAdvancedAdListener;
import org.json.JSONObject;

public final class c {

    private static String f16226b = "NativeAdvancedProvider";
    private MBOutNativeAdvancedViewGroup B;
    private boolean C;
    private boolean D;
    private boolean E;

    private String f16228c;

    private String f16229d;

    private MBridgeIds f16230e;

    private com.mbridge.msdk.advanced.b.a f16231f;

    private com.mbridge.msdk.advanced.b.b f16232g;

    private b f16233h;

    private NativeAdvancedAdListener f16234i;

    private d f16235j;

    private MBNativeAdvancedView f16236k;

    private MBNativeAdvancedWebview f16237l;

    private com.mbridge.msdk.advanced.view.a f16238m;

    private com.mbridge.msdk.b.d f16239n;

    private boolean f16240o;

    private com.mbridge.msdk.b.c f16241p;

    private JSONObject f16251z;

    public boolean f16227a = false;

    private int f16242q = -1;

    private boolean f16243r = false;

    private int f16244s = 0;

    private boolean f16245t = false;

    private int f16246u = 0;

    private boolean f16247v = false;

    private int f16248w = 0;

    private int f16249x = 0;

    private Object f16250y = new Object();
    private boolean A = false;
    private boolean F = true;
    private ViewTreeObserver.OnScrollChangedListener G = new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public final void onScrollChanged() {
            if (c.this.F) {
                c.this.F = false;
                if (c.this.B != null) {
                    c.this.B.postDelayed(new Runnable() {
                        @Override
                        public final void run() {
                            c.this.F = true;
                        }
                    }, 1000L);
                }
                c.this.h();
            }
        }
    };

    public c(String str, String str2, Activity activity) {
        ViewGroup.LayoutParams layoutParams;
        this.f16229d = str;
        this.f16228c = str2;
        this.f16230e = new MBridgeIds(str, str2);
        if (this.f16232g == null) {
            com.mbridge.msdk.advanced.b.b bVar = new com.mbridge.msdk.advanced.b.b(com.mbridge.msdk.foundation.controller.a.e().g(), this.f16229d, this.f16228c);
            this.f16232g = bVar;
            bVar.a(this);
        }
        if (this.f16237l == null) {
            this.f16237l = new MBNativeAdvancedWebview(com.mbridge.msdk.foundation.controller.a.e().g());
            if (this.f16238m == null) {
                this.f16238m = new com.mbridge.msdk.advanced.view.a(this.f16228c, this.f16232g.b(), this);
            }
            this.f16237l.setWebViewClient(this.f16238m);
        }
        if (this.f16236k == null) {
            MBNativeAdvancedView mBNativeAdvancedView = new MBNativeAdvancedView(activity == null ? com.mbridge.msdk.foundation.controller.a.e().g() : activity);
            this.f16236k = mBNativeAdvancedView;
            mBNativeAdvancedView.setAdvancedNativeWebview(this.f16237l);
            MBNativeAdvancedWebview mBNativeAdvancedWebview = this.f16237l;
            if (mBNativeAdvancedWebview != null && mBNativeAdvancedWebview.getParent() == null) {
                this.f16236k.addView(this.f16237l, new ViewGroup.LayoutParams(-1, -1));
            }
        }
        if (this.B == null) {
            this.B = new MBOutNativeAdvancedViewGroup(com.mbridge.msdk.foundation.controller.a.e().g());
            if (this.f16248w != 0 && this.f16249x != 0) {
                layoutParams = new ViewGroup.LayoutParams(this.f16248w, this.f16249x);
            } else {
                layoutParams = new ViewGroup.LayoutParams(-1, -1);
            }
            this.B.setLayoutParams(layoutParams);
            this.B.setProvider(this);
            this.B.addView(this.f16236k);
            this.B.getViewTreeObserver().addOnScrollChangedListener(this.G);
        }
        if (this.f16241p == null) {
            this.f16241p = new com.mbridge.msdk.b.c();
        }
        this.f16241p.a(com.mbridge.msdk.foundation.controller.a.e().g(), com.mbridge.msdk.foundation.controller.a.e().h(), com.mbridge.msdk.foundation.controller.a.e().i(), this.f16228c);
        com.mbridge.msdk.advanced.common.b.a();
    }

    private void f(int i6) {
        MBNativeAdvancedWebview mBNativeAdvancedWebview = this.f16237l;
        if (mBNativeAdvancedWebview == null || mBNativeAdvancedWebview.isDestoryed()) {
            return;
        }
        try {
            if (this.f16237l != null) {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("netstat", i6);
                g.a().a((WebView) this.f16237l, "onNetstatChanged", Base64.encodeToString(jSONObject.toString().getBytes(), 2));
            }
        } catch (Throwable th) {
            q.a(f16226b, th.getMessage());
        }
    }

    private void g(int i6) {
        if (this.f16243r) {
            this.f16242q = i6;
            MBNativeAdvancedWebview mBNativeAdvancedWebview = this.f16237l;
            if (mBNativeAdvancedWebview == null || mBNativeAdvancedWebview.isDestoryed()) {
                return;
            }
            int i7 = this.f16242q;
            if (i7 == 1) {
                this.f16232g.a(true);
                com.mbridge.msdk.advanced.js.a.a(this.f16237l, "showCloseButton", "", null);
            } else if (i7 == 0) {
                this.f16232g.a(false);
                com.mbridge.msdk.advanced.js.a.a(this.f16237l, "hideCloseButton", "", null);
            }
        }
    }

    private void h(int i6) {
        if (this.f16245t) {
            this.f16244s = i6;
            MBNativeAdvancedWebview mBNativeAdvancedWebview = this.f16237l;
            if (mBNativeAdvancedWebview == null || mBNativeAdvancedWebview.isDestoryed()) {
                return;
            }
            com.mbridge.msdk.advanced.js.a.a(this.f16237l, "setVolume", "mute", Integer.valueOf(i6));
        }
    }

    private void i(int i6) {
        if (this.f16247v) {
            this.f16246u = i6;
            MBNativeAdvancedWebview mBNativeAdvancedWebview = this.f16237l;
            if (mBNativeAdvancedWebview != null && !mBNativeAdvancedWebview.isDestoryed()) {
                com.mbridge.msdk.advanced.js.a.a(this.f16237l, "setVideoPlayMode", "autoPlay", Integer.valueOf(i6));
            }
        }
    }

    public final String d() {
        if (this.f16227a) {
            com.mbridge.msdk.advanced.b.b bVar = this.f16232g;
            return bVar != null ? bVar.a() : "";
        }
        com.mbridge.msdk.advanced.b.a aVar = this.f16231f;
        return aVar != null ? aVar.a() : "";
    }

    public final void e(int i6) {
        if (i6 == 1) {
            this.C = false;
        } else if (i6 == 2) {
            this.D = false;
        } else if (i6 == 3) {
            this.E = false;
        }
        com.mbridge.msdk.advanced.b.b bVar = this.f16232g;
        if (bVar != null) {
            bVar.e();
        }
    }

    public final MBOutNativeAdvancedViewGroup b() {
        return this.B;
    }

    public final int c() {
        return this.f16242q;
    }

    private void b(JSONObject jSONObject) {
        if (this.A) {
            this.f16251z = jSONObject;
            MBNativeAdvancedWebview mBNativeAdvancedWebview = this.f16237l;
            if (mBNativeAdvancedWebview == null || mBNativeAdvancedWebview.isDestoryed()) {
                return;
            }
            com.mbridge.msdk.advanced.js.a.a(this.f16237l, "setStyleList", "", jSONObject);
        }
    }

    public final boolean a() {
        return this.f16240o;
    }

    public final boolean c(String str) {
        return (this.B == null || com.mbridge.msdk.advanced.b.c.a(this.f16236k, this.f16229d, this.f16228c, str, this.f16242q, false, true) == null) ? false : true;
    }

    public final void a(boolean z6) {
        this.f16240o = z6;
    }

    public final void c(int i6) {
        this.f16247v = true;
        i(i6);
    }

    public void h() {
        if (this.C && this.D && this.E && !z.a(this.f16236k.getAdvancedNativeWebview()) && this.B.getAlpha() >= 0.5f && this.B.getVisibility() == 0) {
            com.mbridge.msdk.advanced.b.b bVar = this.f16232g;
            if (bVar != null) {
                bVar.d();
            }
            f();
        }
    }

    public final void a(JSONObject jSONObject) {
        this.A = true;
        b(jSONObject);
    }

    public final String d(String str) {
        com.mbridge.msdk.advanced.b.a aVar = this.f16231f;
        return aVar != null ? aVar.a(str) : "";
    }

    public final void e() {
        if (this.f16234i != null) {
            this.f16234i = null;
        }
        if (this.f16233h != null) {
            this.f16233h = null;
        }
        if (this.f16235j != null) {
            this.f16235j = null;
        }
        com.mbridge.msdk.advanced.b.a aVar = this.f16231f;
        if (aVar != null) {
            aVar.a((MBNativeAdvancedView) null);
            this.f16231f.b();
        }
        com.mbridge.msdk.advanced.b.b bVar = this.f16232g;
        if (bVar != null) {
            bVar.c();
        }
        MBNativeAdvancedView mBNativeAdvancedView = this.f16236k;
        if (mBNativeAdvancedView != null) {
            mBNativeAdvancedView.destroy();
        }
        com.mbridge.msdk.advanced.common.b.a();
        com.mbridge.msdk.advanced.view.a aVar2 = this.f16238m;
        if (aVar2 != null) {
            aVar2.a();
        }
        MBOutNativeAdvancedViewGroup mBOutNativeAdvancedViewGroup = this.B;
        if (mBOutNativeAdvancedViewGroup != null) {
            mBOutNativeAdvancedViewGroup.getViewTreeObserver().removeOnScrollChangedListener(this.G);
            this.B.removeAllViews();
            this.B = null;
        }
    }

    private void f() {
        CampaignEx a7 = com.mbridge.msdk.advanced.b.c.a(this.f16236k, this.f16229d, this.f16228c, "", this.f16242q, true, true);
        if (a7 != null) {
            if (this.f16239n == null) {
                this.f16239n = com.mbridge.msdk.b.b.a().d(com.mbridge.msdk.foundation.controller.a.e().h(), this.f16228c);
            }
            d dVar = new d(this, this.f16234i, a7);
            this.f16235j = dVar;
            if (this.f16248w != 0 && this.f16249x != 0) {
                a(a7, false);
            } else {
                dVar.a(this.f16230e, "width or height is 0  or width or height is too small");
            }
        }
    }

    public final void a(NativeAdvancedAdListener nativeAdvancedAdListener) {
        this.f16234i = nativeAdvancedAdListener;
    }

    public final void b(String str) {
        b bVar = new b(this, this.f16230e);
        this.f16233h = bVar;
        bVar.a(this.f16234i);
        this.f16233h.a(str);
        a(str, 2);
    }

    public final void a(String str) {
        if (TextUtils.isEmpty(str)) {
            NativeAdvancedAdListener nativeAdvancedAdListener = this.f16234i;
            if (nativeAdvancedAdListener != null) {
                nativeAdvancedAdListener.onLoadFailed(this.f16230e, "bid  token is null or empty");
                return;
            }
            return;
        }
        b(str);
    }

    public final void d(int i6) {
        if (i6 == 1) {
            this.C = true;
        } else if (i6 == 2) {
            this.D = true;
        } else if (i6 == 3) {
            this.E = true;
        }
        h();
    }

    private void g() {
        g(this.f16242q);
        h(this.f16244s);
        i(this.f16246u);
        b(this.f16251z);
        f(m.n(com.mbridge.msdk.foundation.controller.a.e().g()));
    }

    public final void b(int i6) {
        this.f16245t = true;
        h(i6);
    }

    public final void a(int i6) {
        this.f16243r = true;
        g(i6);
    }

    public final void a(CampaignEx campaignEx, boolean z6) {
        g();
        MBOutNativeAdvancedViewGroup mBOutNativeAdvancedViewGroup = this.B;
        if (mBOutNativeAdvancedViewGroup == null || mBOutNativeAdvancedViewGroup.getParent() == null) {
            return;
        }
        if (campaignEx != null && z6) {
            if (this.f16239n == null) {
                this.f16239n = com.mbridge.msdk.b.b.a().d(com.mbridge.msdk.foundation.controller.a.e().h(), this.f16228c);
            }
            this.f16235j = new d(this, this.f16234i, campaignEx);
        }
        if (this.f16232g == null) {
            com.mbridge.msdk.advanced.b.b bVar = new com.mbridge.msdk.advanced.b.b(com.mbridge.msdk.foundation.controller.a.e().g(), this.f16229d, this.f16228c);
            this.f16232g = bVar;
            bVar.a(this);
        }
        a(campaignEx);
    }

    private void a(CampaignEx campaignEx) {
        if (com.mbridge.msdk.advanced.b.c.a(this.f16236k, campaignEx, this.f16229d, this.f16228c)) {
            this.f16232g.a(this.f16235j);
            this.f16232g.a(campaignEx, this.f16236k, true);
        }
    }

    private void a(String str, int i6) {
        this.F = true;
        synchronized (this.f16250y) {
            if (this.f16240o) {
                b bVar = this.f16233h;
                if (bVar != null) {
                    bVar.a("current unit is loading", i6);
                    this.f16240o = true;
                }
                return;
            }
            this.f16240o = true;
            if (this.f16248w != 0 && this.f16249x != 0) {
                MBNativeAdvancedView mBNativeAdvancedView = this.f16236k;
                if (mBNativeAdvancedView == null) {
                    b bVar2 = this.f16233h;
                    if (bVar2 != null) {
                        bVar2.a("view is not ready", i6);
                        return;
                    }
                    return;
                }
                mBNativeAdvancedView.clearResStateAndRemoveClose();
                com.mbridge.msdk.b.d f6 = com.mbridge.msdk.b.b.a().f(com.mbridge.msdk.foundation.controller.a.e().h(), this.f16228c);
                this.f16239n = f6;
                if (f6 == null) {
                    this.f16239n = com.mbridge.msdk.b.d.c(this.f16228c);
                }
                if (this.f16231f == null) {
                    this.f16231f = new com.mbridge.msdk.advanced.b.a(this.f16229d, this.f16228c, 0L);
                }
                b bVar3 = this.f16233h;
                if (bVar3 != null) {
                    bVar3.a(str);
                    this.f16231f.a(this.f16233h);
                }
                this.f16236k.resetLoadState();
                this.f16231f.a(this.f16236k);
                this.f16231f.a(this.f16239n);
                this.f16231f.a(this.f16248w, this.f16249x);
                this.f16231f.a(this.f16242q);
                this.f16231f.a(str, i6);
                return;
            }
            b bVar4 = this.f16233h;
            if (bVar4 != null) {
                bVar4.a("width or height is 0  or width or height is too small", i6);
            }
        }
    }

    public final void a(int i6, int i7) {
        if (i6 <= 0 || i7 <= 0) {
            return;
        }
        this.f16249x = i6;
        this.f16248w = i7;
        this.B.setLayoutParams(new ViewGroup.LayoutParams(i7, i6));
    }
}