package com.mbridge.msdk.advanced.b; 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.c.h; import com.mbridge.msdk.c.j; import com.mbridge.msdk.c.k; import com.mbridge.msdk.foundation.entity.CampaignEx; import com.mbridge.msdk.foundation.tools.ab; import com.mbridge.msdk.foundation.tools.af; import com.mbridge.msdk.foundation.tools.as; import com.mbridge.msdk.mbsignalcommon.windvane.g; import com.mbridge.msdk.out.MBridgeIds; import com.mbridge.msdk.out.NativeAdvancedAdListener; import org.json.JSONObject; /* loaded from: classes4.dex */ public final class c { private static String b = "NativeAdvancedProvider"; private MBOutNativeAdvancedViewGroup B; private boolean C; private boolean D; private boolean E; private String c; private String d; private MBridgeIds e; private com.mbridge.msdk.advanced.a.b f; private com.mbridge.msdk.advanced.a.c g; private b h; private NativeAdvancedAdListener i; private d j; private MBNativeAdvancedView k; private MBNativeAdvancedWebview l; private com.mbridge.msdk.advanced.view.a m; private k n; private boolean o; private j p; private JSONObject z; private int q = -1; private boolean r = false; private int s = 0; private boolean t = false; private int u = 0; private boolean v = false; private int w = 0; private int x = 0; private Object y = new Object(); private boolean A = false; private boolean F = true; public boolean a = false; private ViewTreeObserver.OnScrollChangedListener G = new ViewTreeObserver.OnScrollChangedListener() { // from class: com.mbridge.msdk.advanced.b.c.1 @Override // android.view.ViewTreeObserver.OnScrollChangedListener public final void onScrollChanged() { if (c.this.F) { c.this.F = false; if (c.this.B != null) { c.this.B.postDelayed(new Runnable() { // from class: com.mbridge.msdk.advanced.b.c.1.1 @Override // java.lang.Runnable public final void run() { c.this.F = true; } }, 1000L); } try { c.this.i(); } catch (Exception e) { af.b(c.b, e.getMessage()); } } } }; public final void a(NativeAdvancedAdListener nativeAdvancedAdListener) { this.i = nativeAdvancedAdListener; } public final void a(boolean z) { this.o = z; } public final boolean a() { return this.o; } public final MBOutNativeAdvancedViewGroup b() { return this.B; } public final int c() { return this.q; } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r4v27, types: [android.content.Context] */ public c(String str, String str2, Activity activity) { com.mbridge.msdk.advanced.view.a aVar; ViewGroup.LayoutParams layoutParams; this.d = TextUtils.isEmpty(str) ? "" : str; this.c = str2; this.e = new MBridgeIds(str, str2); if (this.g == null) { com.mbridge.msdk.advanced.a.c cVar = new com.mbridge.msdk.advanced.a.c(com.mbridge.msdk.foundation.controller.c.m().c(), this.d, this.c); this.g = cVar; cVar.a(this); } if (this.l == null) { try { this.l = new MBNativeAdvancedWebview(com.mbridge.msdk.foundation.controller.c.m().c()); } catch (Exception e) { af.b(b, e.getMessage()); } if (this.m == null) { try { this.m = new com.mbridge.msdk.advanced.view.a(this.c, this.g.c(), this); } catch (Exception e2) { af.b(b, e2.getMessage()); } } MBNativeAdvancedWebview mBNativeAdvancedWebview = this.l; if (mBNativeAdvancedWebview != null && (aVar = this.m) != null) { mBNativeAdvancedWebview.setWebViewClient(aVar); } } if (this.k == null) { MBNativeAdvancedView mBNativeAdvancedView = new MBNativeAdvancedView(activity == null ? com.mbridge.msdk.foundation.controller.c.m().c() : activity); this.k = mBNativeAdvancedView; mBNativeAdvancedView.setAdvancedNativeWebview(this.l); MBNativeAdvancedWebview mBNativeAdvancedWebview2 = this.l; if (mBNativeAdvancedWebview2 != null && mBNativeAdvancedWebview2.getParent() == null) { this.k.addView(this.l, new ViewGroup.LayoutParams(-1, -1)); } } if (this.B == null) { this.B = new MBOutNativeAdvancedViewGroup(com.mbridge.msdk.foundation.controller.c.m().c()); if (this.w == 0 || this.x == 0) { layoutParams = new ViewGroup.LayoutParams(-1, -1); } else { layoutParams = new ViewGroup.LayoutParams(this.w, this.x); } this.B.setLayoutParams(layoutParams); this.B.setProvider(this); this.B.addView(this.k); this.B.getViewTreeObserver().addOnScrollChangedListener(this.G); } if (this.p == null) { this.p = new j(); } this.p.a(com.mbridge.msdk.foundation.controller.c.m().c(), com.mbridge.msdk.foundation.controller.c.m().k(), com.mbridge.msdk.foundation.controller.c.m().b(), this.c); } public final void a(JSONObject jSONObject) { this.A = true; b(jSONObject); } private void b(JSONObject jSONObject) { if (this.A) { this.z = jSONObject; MBNativeAdvancedWebview mBNativeAdvancedWebview = this.l; if (mBNativeAdvancedWebview == null || mBNativeAdvancedWebview.isDestoryed()) { return; } com.mbridge.msdk.advanced.signal.a.a(this.l, "setStyleList", "", jSONObject); } } private void f(int i) { MBNativeAdvancedWebview mBNativeAdvancedWebview = this.l; if (mBNativeAdvancedWebview == null || mBNativeAdvancedWebview.isDestoryed()) { return; } try { if (this.l != null) { JSONObject jSONObject = new JSONObject(); jSONObject.put("netstat", i); g.a().a((WebView) this.l, "onNetstatChanged", Base64.encodeToString(jSONObject.toString().getBytes(), 2)); } } catch (Throwable th) { af.a(b, th.getMessage()); } } public final void a(String str) { if (!TextUtils.isEmpty(str)) { b(str); return; } NativeAdvancedAdListener nativeAdvancedAdListener = this.i; if (nativeAdvancedAdListener != null) { nativeAdvancedAdListener.onLoadFailed(this.e, "bid token is null or empty"); } } public final void b(String str) { b bVar = new b(this, this.e); this.h = bVar; bVar.a(this.i); this.h.a(str); a(str, 2); } public final boolean c(String str) { return (this.B == null || com.mbridge.msdk.advanced.a.d.a(this.k, this.d, this.c, str, this.q, false, true) == null) ? false : true; } public final void a(int i) { this.r = true; g(i); } private void g(int i) { if (this.r) { this.q = i; MBNativeAdvancedWebview mBNativeAdvancedWebview = this.l; if (mBNativeAdvancedWebview == null || mBNativeAdvancedWebview.isDestoryed()) { return; } int i2 = this.q; if (i2 == 1) { this.g.a(true); com.mbridge.msdk.advanced.signal.a.a(this.l, "showCloseButton", "", null); } else if (i2 == 0) { this.g.a(false); com.mbridge.msdk.advanced.signal.a.a(this.l, "hideCloseButton", "", null); } } } public final void b(int i) { this.t = true; h(i); } private void h(int i) { if (this.t) { this.s = i; MBNativeAdvancedWebview mBNativeAdvancedWebview = this.l; if (mBNativeAdvancedWebview == null || mBNativeAdvancedWebview.isDestoryed()) { return; } com.mbridge.msdk.advanced.signal.a.a(this.l, "setVolume", CampaignEx.JSON_NATIVE_VIDEO_MUTE, Integer.valueOf(i)); } } public final void c(int i) { this.v = true; i(i); } private void i(int i) { if (this.v) { this.u = i; MBNativeAdvancedWebview mBNativeAdvancedWebview = this.l; if (mBNativeAdvancedWebview == null || mBNativeAdvancedWebview.isDestoryed()) { return; } com.mbridge.msdk.advanced.signal.a.a(this.l, "setVideoPlayMode", "autoPlay", Integer.valueOf(i)); } } private void a(CampaignEx campaignEx) { if (campaignEx != null) { if (this.n == null) { this.n = h.a().a(com.mbridge.msdk.foundation.controller.c.m().k(), this.c); } this.j = new d(this, this.i, campaignEx); af.a(b, "show start"); if (this.w != 0 && this.x != 0) { a(campaignEx, false); return; } d dVar = this.j; if (dVar != null) { dVar.a(this.e, "width or height is 0 or width or height is too small"); } } } public final void a(CampaignEx campaignEx, boolean z) { h(); MBOutNativeAdvancedViewGroup mBOutNativeAdvancedViewGroup = this.B; if (mBOutNativeAdvancedViewGroup == null || mBOutNativeAdvancedViewGroup.getParent() == null) { return; } if (campaignEx != null && z) { if (this.n == null) { this.n = h.a().a(com.mbridge.msdk.foundation.controller.c.m().k(), this.c); } this.j = new d(this, this.i, campaignEx); } if (this.g == null) { com.mbridge.msdk.advanced.a.c cVar = new com.mbridge.msdk.advanced.a.c(com.mbridge.msdk.foundation.controller.c.m().c(), this.d, this.c); this.g = cVar; cVar.a(this); } b(campaignEx); } public final String d() { if (this.a) { com.mbridge.msdk.advanced.a.c cVar = this.g; return cVar != null ? cVar.a() : ""; } com.mbridge.msdk.advanced.a.b bVar = this.f; return bVar != null ? bVar.a() : ""; } public final String e() { if (this.a) { com.mbridge.msdk.advanced.a.c cVar = this.g; return cVar != null ? cVar.b() : ""; } com.mbridge.msdk.advanced.a.b bVar = this.f; return bVar != null ? bVar.b() : ""; } private void b(CampaignEx campaignEx) { if (com.mbridge.msdk.advanced.a.d.a(this.k, campaignEx, this.d, this.c)) { this.g.a(this.j); af.b(b, "start show process"); this.g.a(campaignEx, this.k, true); } } private void h() { g(this.q); h(this.s); i(this.u); b(this.z); f(ab.m(com.mbridge.msdk.foundation.controller.c.m().c())); } private void a(String str, int i) { this.F = true; synchronized (this.y) { try { if (this.o) { if (this.h != null) { this.h.a(new com.mbridge.msdk.foundation.c.b(880016, "current unit is loading"), i); this.o = true; } return; } this.o = true; if (this.w == 0 || this.x == 0) { if (this.h != null) { this.h.a(new com.mbridge.msdk.foundation.c.b(880028), i); return; } return; } if (this.k == null) { if (this.h != null) { this.h.a(new com.mbridge.msdk.foundation.c.b(880030), i); return; } return; } try { if (com.mbridge.msdk.mbsignalcommon.webEnvCheck.a.a(com.mbridge.msdk.foundation.controller.c.m().c())) { this.k.clearResStateAndRemoveClose(); k b2 = h.a().b(com.mbridge.msdk.foundation.controller.c.m().k(), this.c); this.n = b2; if (b2 == null) { this.n = k.f(this.c); } if (this.f == null) { this.f = new com.mbridge.msdk.advanced.a.b(this.d, this.c, 0L); } b bVar = this.h; if (bVar != null) { bVar.a(str); this.f.a(this.h); } this.k.resetLoadState(); this.f.a(this.k); this.f.a(this.n); this.f.a(this.w, this.x); this.f.a(this.q); this.f.a(str, i); return; } } catch (Exception e) { af.b(b, e.getMessage()); } if (this.h != null) { this.h.a(new com.mbridge.msdk.foundation.c.b(880029), i); } } catch (Throwable th) { throw th; } } } public final String d(String str) { com.mbridge.msdk.advanced.a.b bVar = this.f; return bVar != null ? bVar.a(str) : ""; } public final void d(int i) { if (i == 1) { this.C = true; } else if (i == 2) { this.D = true; } else if (i == 3) { this.E = true; } try { i(); } catch (Exception e) { af.b(b, e.getMessage()); } } /* JADX INFO: Access modifiers changed from: private */ public void i() { if (this.C && this.D && this.E) { CampaignEx a = com.mbridge.msdk.advanced.a.d.a(this.k, this.d, this.c, "", this.q, true, true); if (a != null) { a.getImpReportType(); } if (as.a(this.k.getAdvancedNativeWebview(), 0) || this.B.getAlpha() < 0.5f || this.B.getVisibility() != 0) { return; } com.mbridge.msdk.advanced.a.c cVar = this.g; if (cVar != null) { cVar.e(); } a(a); } } public final void f() { if (this.i != null) { this.i = null; } if (this.h != null) { this.h = null; } if (this.j != null) { this.j = null; } com.mbridge.msdk.advanced.a.b bVar = this.f; if (bVar != null) { bVar.a((MBNativeAdvancedView) null); this.f.c(); } com.mbridge.msdk.advanced.a.c cVar = this.g; if (cVar != null) { cVar.d(); } MBNativeAdvancedView mBNativeAdvancedView = this.k; if (mBNativeAdvancedView != null) { mBNativeAdvancedView.destroy(); } com.mbridge.msdk.advanced.common.c.b(this.d + this.c + d()); com.mbridge.msdk.advanced.view.a aVar = this.m; if (aVar != null) { aVar.a(); } MBOutNativeAdvancedViewGroup mBOutNativeAdvancedViewGroup = this.B; if (mBOutNativeAdvancedViewGroup != null) { mBOutNativeAdvancedViewGroup.getViewTreeObserver().removeOnScrollChangedListener(this.G); this.B.removeAllViews(); this.B = null; } } public final void a(int i, int i2) { if (i <= 0 || i2 <= 0) { return; } this.x = i; this.w = i2; this.B.setLayoutParams(new ViewGroup.LayoutParams(i2, i)); } public final void e(int i) { if (i == 1) { this.C = false; } else if (i == 2) { this.D = false; } else if (i == 3) { this.E = false; } com.mbridge.msdk.advanced.a.c cVar = this.g; if (cVar != null) { cVar.f(); } } }