package com.igaworks.ssp.part.custom; import android.content.Context; import android.os.Handler; import android.os.Looper; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import com.igaworks.ssp.SSPErrorCode; import com.igaworks.ssp.common.adapter.BaseMediationAdapter; import com.igaworks.ssp.common.g; import com.igaworks.ssp.common.g.b; import com.igaworks.ssp.common.i; import com.igaworks.ssp.common.m.f; import com.igaworks.ssp.common.n.a; import com.igaworks.ssp.common.o.h; import com.igaworks.ssp.common.o.k; import com.igaworks.ssp.part.custom.listener.IReactNativeAdEventCallbackListener; import java.lang.ref.WeakReference; import java.util.concurrent.ConcurrentHashMap; import org.json.JSONObject; /* loaded from: classes2.dex */ public class AdPopcornSSPReactNativeAd extends FrameLayout { /* renamed from: a, reason: collision with root package name */ private String f6958a; /* renamed from: b, reason: collision with root package name */ private String f6959b; /* renamed from: c, reason: collision with root package name */ private WeakReference f6960c; /* renamed from: d, reason: collision with root package name */ private f f6961d; /* renamed from: e, reason: collision with root package name */ private IReactNativeAdEventCallbackListener f6962e; /* renamed from: f, reason: collision with root package name */ private boolean f6963f; /* renamed from: g, reason: collision with root package name */ private boolean f6964g; /* renamed from: h, reason: collision with root package name */ private int f6965h; /* renamed from: i, reason: collision with root package name */ private BaseMediationAdapter f6966i; /* renamed from: j, reason: collision with root package name */ private ConcurrentHashMap f6967j; /* renamed from: k, reason: collision with root package name */ private boolean f6968k; /* renamed from: l, reason: collision with root package name */ private int f6969l; /* renamed from: m, reason: collision with root package name */ private int f6970m; /* renamed from: n, reason: collision with root package name */ private com.igaworks.ssp.part.custom.listener.a f6971n; /* renamed from: o, reason: collision with root package name */ com.igaworks.ssp.common.n.c f6972o; class a extends com.igaworks.ssp.common.o.c { /* renamed from: com.igaworks.ssp.part.custom.AdPopcornSSPReactNativeAd$a$a, reason: collision with other inner class name */ class RunnableC0090a implements Runnable { RunnableC0090a() { } @Override // java.lang.Runnable public void run() { AdPopcornSSPReactNativeAd.this.f6963f = false; AdPopcornSSPReactNativeAd.this.loadAd(); } } a() { } @Override // com.igaworks.ssp.common.o.c public void a() { new Handler(Looper.getMainLooper()).post(new RunnableC0090a()); } } class b implements com.igaworks.ssp.part.custom.listener.a { b() { } @Override // com.igaworks.ssp.part.custom.listener.a public void a(int i10, int i11) { try { if (AdPopcornSSPReactNativeAd.this.f6966i != null) { com.igaworks.ssp.common.o.m.a.a(Thread.currentThread(), "Fail in adapter : " + AdPopcornSSPReactNativeAd.this.f6966i.getNetworkName() + ", internalReason : " + i11); AdPopcornSSPReactNativeAd adPopcornSSPReactNativeAd = AdPopcornSSPReactNativeAd.this; adPopcornSSPReactNativeAd.a(adPopcornSSPReactNativeAd.f6966i); } if (i11 == 3) { com.igaworks.ssp.common.o.m.a.b(Thread.currentThread(), "Native asset error : " + AdPopcornSSPReactNativeAd.this.f6966i.getNetworkName()); } if (AdPopcornSSPReactNativeAd.this.f6961d.d() == null) { AdPopcornSSPReactNativeAd.this.a(SSPErrorCode.NO_AD); return; } if (i10 >= AdPopcornSSPReactNativeAd.this.f6961d.d().a().size() - 1) { AdPopcornSSPReactNativeAd.this.a(SSPErrorCode.NO_AD); return; } AdPopcornSSPReactNativeAd.this.f6965h = i10 + 1; com.igaworks.ssp.common.b a10 = com.igaworks.ssp.common.b.a(AdPopcornSSPReactNativeAd.this.f6961d.d().a().get(AdPopcornSSPReactNativeAd.this.f6965h).a()); AdPopcornSSPReactNativeAd.this.f6968k = false; AdPopcornSSPReactNativeAd adPopcornSSPReactNativeAd2 = AdPopcornSSPReactNativeAd.this; adPopcornSSPReactNativeAd2.f6966i = adPopcornSSPReactNativeAd2.a(a10); AdPopcornSSPReactNativeAd.this.f6966i.setReactNativeMediationAdapterEventListener(this); AdPopcornSSPReactNativeAd.this.f6966i.loadReactNativeAd((Context) AdPopcornSSPReactNativeAd.this.f6960c.get(), AdPopcornSSPReactNativeAd.this.f6961d, AdPopcornSSPReactNativeAd.this.f6968k, AdPopcornSSPReactNativeAd.this.f6965h, AdPopcornSSPReactNativeAd.this); } catch (Exception e10) { com.igaworks.ssp.common.o.m.a.a(Thread.currentThread(), e10); AdPopcornSSPReactNativeAd.this.a(SSPErrorCode.EXCEPTION); } } @Override // com.igaworks.ssp.part.custom.listener.a public void onClicked() { AdPopcornSSPReactNativeAd.this.d(); } @Override // com.igaworks.ssp.part.custom.listener.a public void onImpression() { AdPopcornSSPReactNativeAd.this.e(); } @Override // com.igaworks.ssp.part.custom.listener.a public void a(int i10, int i11, int i12, int i13) { AdPopcornSSPReactNativeAd.this.f6965h = i10; AdPopcornSSPReactNativeAd.this.a(i11, i12, i13); } } class c implements com.igaworks.ssp.common.n.c { c() { } @Override // com.igaworks.ssp.common.n.c public void a(a.d dVar, String str, String str2, boolean z10) { if (dVar == a.d.NATIVE_AD) { try { if (z10) { AdPopcornSSPReactNativeAd.this.a(SSPErrorCode.SERVER_TIMEOUT); return; } if (k.b(str)) { AdPopcornSSPReactNativeAd.this.a(SSPErrorCode.UNKNOWN_SERVER_ERROR); return; } if (!h.b(((Context) AdPopcornSSPReactNativeAd.this.f6960c.get()).getApplicationContext())) { AdPopcornSSPReactNativeAd.this.a(SSPErrorCode.NETWORK_IS_NOT_ONLINE); return; } f f10 = com.igaworks.ssp.common.l.a.f(str); if (f10 != null && f10.f() != 1) { AdPopcornSSPReactNativeAd.this.a(f10.f()); return; } AdPopcornSSPReactNativeAd.this.f6961d = f10; if (AdPopcornSSPReactNativeAd.this.f6961d != null && AdPopcornSSPReactNativeAd.this.f6961d.c() != null) { i.a((Context) AdPopcornSSPReactNativeAd.this.f6960c.get(), AdPopcornSSPReactNativeAd.this.f6961d.c()); } AdPopcornSSPReactNativeAd.this.c(); } catch (Exception e10) { com.igaworks.ssp.common.o.m.a.a(Thread.currentThread(), e10); AdPopcornSSPReactNativeAd.this.a(SSPErrorCode.EXCEPTION); } } } } public AdPopcornSSPReactNativeAd(Context context) { super(context); this.f6963f = false; this.f6964g = false; this.f6965h = 0; this.f6968k = false; this.f6969l = 0; this.f6970m = 0; this.f6971n = new b(); this.f6972o = new c(); this.f6960c = new WeakReference<>(context); } private void b() { com.igaworks.ssp.common.o.m.a.c(Thread.currentThread(), "internalStopAd : " + this.f6958a); setVisibility(8); } /* JADX INFO: Access modifiers changed from: private */ public void c() { BaseMediationAdapter baseMediationAdapter; Context context; f fVar; boolean z10; try { if (com.igaworks.ssp.common.o.b.c(this.f6961d)) { com.igaworks.ssp.common.o.b.a(this.f6961d, this.f6967j); com.igaworks.ssp.common.b a10 = com.igaworks.ssp.common.b.a(this.f6961d.d().a().get(this.f6965h).a()); this.f6968k = false; BaseMediationAdapter a11 = a(a10); this.f6966i = a11; a11.setReactNativeMediationAdapterEventListener(this.f6971n); baseMediationAdapter = this.f6966i; context = this.f6960c.get(); fVar = this.f6961d; z10 = this.f6968k; } else { this.f6968k = false; if (!com.igaworks.ssp.common.o.b.a(this.f6961d)) { a(this.f6961d.f()); return; } BaseMediationAdapter a12 = a(com.igaworks.ssp.common.b.ADPOPCORN); this.f6966i = a12; a12.setReactNativeMediationAdapterEventListener(this.f6971n); baseMediationAdapter = this.f6966i; context = this.f6960c.get(); fVar = this.f6961d; z10 = this.f6968k; } baseMediationAdapter.loadReactNativeAd(context, fVar, z10, this.f6965h, this); } catch (Exception e10) { e10.printStackTrace(); a(SSPErrorCode.EXCEPTION); } } /* JADX INFO: Access modifiers changed from: private */ public void d() { IReactNativeAdEventCallbackListener iReactNativeAdEventCallbackListener = this.f6962e; if (iReactNativeAdEventCallbackListener != null) { iReactNativeAdEventCallbackListener.onClicked(); } } public void destroy() { try { com.igaworks.ssp.common.o.m.a.c(Thread.currentThread(), "ReactNativeAd destroy : " + this.f6958a); this.f6964g = false; this.f6963f = false; BaseMediationAdapter baseMediationAdapter = this.f6966i; if (baseMediationAdapter != null) { baseMediationAdapter.destroyReactNativeAd(); this.f6966i.setReactNativeMediationAdapterEventListener(null); this.f6966i = null; } if (this.f6961d != null) { this.f6961d = null; } g.e().b(this); a(); } catch (Exception e10) { com.igaworks.ssp.common.o.m.a.a(Thread.currentThread(), e10); } } public int getReactNativeHeight() { return this.f6970m; } public int getReactNativeWidth() { return this.f6969l; } public boolean isLoaded() { return this.f6964g; } public void loadAd() { try { if (!g.e().d()) { com.igaworks.ssp.common.o.m.a.a(Thread.currentThread(), this.f6958a + " : GDPR_CONSENT_UNAVAILABLE"); a(SSPErrorCode.GDPR_CONSENT_UNAVAILABLE); return; } if (this.f6963f) { com.igaworks.ssp.common.o.m.a.b(Thread.currentThread(), this.f6958a + " : ReactNativeAd In Progress!!"); return; } this.f6965h = 0; this.f6963f = true; String str = this.f6958a; if (str != null && str.length() != 0) { if (!g.e().i()) { com.igaworks.ssp.common.o.m.a.c(Thread.currentThread(), "Checking ADID..."); g.e().a(new a()); g e10 = g.e(); e10.getClass(); e10.new b(this.f6960c.get().getApplicationContext()).start(); return; } com.igaworks.ssp.common.o.m.a.c(Thread.currentThread(), "load ReactNativeAd : " + this.f6958a); if (h.b(this.f6960c.get().getApplicationContext())) { g.e().b().a(this.f6960c.get().getApplicationContext(), a.d.NATIVE_AD, this.f6958a, this.f6959b, (JSONObject) null, this.f6972o); return; } else { a(SSPErrorCode.NETWORK_IS_NOT_ONLINE); return; } } a(SSPErrorCode.INVALID_PLACEMENT_ID); } catch (Exception unused) { this.f6963f = false; } } @Override // android.view.View protected void onVisibilityChanged(View view, int i10) { super.onVisibilityChanged(view, i10); BaseMediationAdapter baseMediationAdapter = this.f6966i; if (baseMediationAdapter != null) { baseMediationAdapter.checkAdPopcornSSPNativeImpression(); } } @Override // android.view.View public void onWindowFocusChanged(boolean z10) { super.onWindowFocusChanged(z10); BaseMediationAdapter baseMediationAdapter = this.f6966i; if (baseMediationAdapter != null) { baseMediationAdapter.checkAdPopcornSSPNativeImpression(); } } public void setPlacementAppKey(String str) { this.f6959b = str; } public void setPlacementId(String str) { this.f6958a = str; g.e().a(this); } public void setReactNativeAdEventCallbackListener(IReactNativeAdEventCallbackListener iReactNativeAdEventCallbackListener) { this.f6962e = iReactNativeAdEventCallbackListener; } public void setReactNativeHeight(int i10) { this.f6970m = i10; } public void setReactNativeWidth(int i10) { this.f6969l = i10; } public AdPopcornSSPReactNativeAd(Context context, AttributeSet attributeSet) { super(context, attributeSet); this.f6963f = false; this.f6964g = false; this.f6965h = 0; this.f6968k = false; this.f6969l = 0; this.f6970m = 0; this.f6971n = new b(); this.f6972o = new c(); this.f6960c = new WeakReference<>(context); } /* JADX INFO: Access modifiers changed from: private */ public void e() { IReactNativeAdEventCallbackListener iReactNativeAdEventCallbackListener = this.f6962e; if (iReactNativeAdEventCallbackListener != null) { iReactNativeAdEventCallbackListener.onImpression(); } } public AdPopcornSSPReactNativeAd(Context context, String str) { super(context); this.f6963f = false; this.f6964g = false; this.f6965h = 0; this.f6968k = false; this.f6969l = 0; this.f6970m = 0; this.f6971n = new b(); this.f6972o = new c(); this.f6960c = new WeakReference<>(context); this.f6959b = str; } /* JADX INFO: Access modifiers changed from: private */ public BaseMediationAdapter a(com.igaworks.ssp.common.b bVar) { if (this.f6967j == null) { this.f6967j = new ConcurrentHashMap<>(); } BaseMediationAdapter baseMediationAdapter = this.f6967j.get(bVar); if (baseMediationAdapter == null && (baseMediationAdapter = bVar.d()) != null) { this.f6967j.put(bVar, baseMediationAdapter); } return baseMediationAdapter; } private void a() { ConcurrentHashMap concurrentHashMap = this.f6967j; if (concurrentHashMap != null) { concurrentHashMap.clear(); this.f6967j = null; } } /* JADX INFO: Access modifiers changed from: private */ public void a(int i10) { this.f6963f = false; this.f6964g = false; IReactNativeAdEventCallbackListener iReactNativeAdEventCallbackListener = this.f6962e; if (iReactNativeAdEventCallbackListener != null) { iReactNativeAdEventCallbackListener.onReactNativeAdLoadFailed(new SSPErrorCode(i10)); } b(); } /* JADX INFO: Access modifiers changed from: private */ public void a(int i10, int i11, int i12) { this.f6963f = false; this.f6964g = true; IReactNativeAdEventCallbackListener iReactNativeAdEventCallbackListener = this.f6962e; if (iReactNativeAdEventCallbackListener != null) { iReactNativeAdEventCallbackListener.onReactNativeAdLoadSuccess(i10, i11, i12); } } /* JADX INFO: Access modifiers changed from: private */ public void a(BaseMediationAdapter baseMediationAdapter) { if (baseMediationAdapter == null) { return; } baseMediationAdapter.setNativeMediationAdapterEventListener(null); baseMediationAdapter.destroyNativeAd(); } }