package com.fyber.inneractive.sdk.external; import android.os.Looper; import android.view.View; import android.view.ViewGroup; import com.fyber.inneractive.sdk.activities.InneractiveFullscreenAdActivity; import com.fyber.inneractive.sdk.config.e0; import com.fyber.inneractive.sdk.config.enums.UnitDisplayType; import com.fyber.inneractive.sdk.config.g0; import com.fyber.inneractive.sdk.config.x; import com.fyber.inneractive.sdk.factories.a; import com.fyber.inneractive.sdk.factories.c; import com.fyber.inneractive.sdk.flow.d0; import com.fyber.inneractive.sdk.flow.f0; import com.fyber.inneractive.sdk.flow.t; import com.fyber.inneractive.sdk.flow.w; import com.fyber.inneractive.sdk.interfaces.c; import com.fyber.inneractive.sdk.util.IAlog; import com.fyber.inneractive.sdk.util.p; import java.lang.ref.WeakReference; import java.util.HashSet; import java.util.Iterator; /* loaded from: classes2.dex */ public class InneractiveAdViewUnitController extends f0 implements t.c, InneractiveFullscreenAdActivity.FullScreenRendererProvider { public static final int DISABLED_REFRESH_INTERVAL = -1; public final HashSet a; public boolean b; public ViewGroup c; public final int d; protected int mAdContentHeight; protected int mAdContentWidth; public class a implements Runnable { public a() { } @Override // java.lang.Runnable public final void run() { InneractiveAdViewUnitController.this.a(); } } public InneractiveAdViewUnitController() { this.b = false; this.mAdContentWidth = -1; this.mAdContentHeight = -1; this.d = 0; this.a = new HashSet(); } public void bindView(ViewGroup viewGroup) { com.fyber.inneractive.sdk.interfaces.b bVar; IAlog.a("%sPPPP bindView called with parent: %s", logPrefix(), viewGroup); InneractiveAdSpot adSpot = getAdSpot(); if (adSpot == null) { IAlog.f("InneractiveFullscreenUnitController was not attached to an ad spot", new Object[0]); return; } IAlog.a("%sPPPP bindView spot is %s", logPrefix(), adSpot); Iterator it = new HashSet(this.a).iterator(); while (it.hasNext()) { InneractiveAdRenderer inneractiveAdRenderer = (InneractiveAdRenderer) it.next(); if (inneractiveAdRenderer instanceof com.fyber.inneractive.sdk.interfaces.b) { com.fyber.inneractive.sdk.interfaces.b bVar2 = (com.fyber.inneractive.sdk.interfaces.b) inneractiveAdRenderer; if (bVar2.a((View) viewGroup)) { bVar2.s(); IAlog.a("%sPPPP bindAdToRenderer returning an already attached renderer %s", logPrefix(), bVar2); return; } } } this.c = viewGroup; Iterator it2 = a.b.a.a.iterator(); while (true) { if (!it2.hasNext()) { bVar = null; break; } a.InterfaceC0069a interfaceC0069a = (a.InterfaceC0069a) it2.next(); if (interfaceC0069a.a(adSpot)) { bVar = interfaceC0069a.a(); break; } } int i = this.d; if (i != 0) { bVar.a(i); } if (bVar == null) { IAlog.f("%sCould not find a renderer for the given spot! Did you add the appropriate module to your project?", logPrefix()); return; } bVar.initialize(adSpot); selectContentController(); bVar.a(viewGroup); this.a.add(bVar); IAlog.a("%sPPPP bindView created renderer %s", logPrefix(), bVar); } @Override // com.fyber.inneractive.sdk.flow.f0 public boolean canRefreshAd() { if (!supportsRefresh()) { return false; } Iterator it = this.a.iterator(); while (it.hasNext()) { if (!((InneractiveAdRenderer) it.next()).canRefreshAd()) { return false; } } return true; } @Override // com.fyber.inneractive.sdk.flow.f0, com.fyber.inneractive.sdk.external.InneractiveUnitController public void destroy() { if (Looper.myLooper() == null || Looper.getMainLooper() != Looper.myLooper()) { p.b.post(new a()); } else { a(); } } public int getAdContentHeight() { int u; Iterator it = this.a.iterator(); while (it.hasNext()) { InneractiveAdRenderer inneractiveAdRenderer = (InneractiveAdRenderer) it.next(); if ((inneractiveAdRenderer instanceof com.fyber.inneractive.sdk.interfaces.b) && (u = ((com.fyber.inneractive.sdk.interfaces.b) inneractiveAdRenderer).u()) > 0) { return u; } } return this.mAdContentHeight; } public int getAdContentWidth() { int f; Iterator it = this.a.iterator(); while (it.hasNext()) { InneractiveAdRenderer inneractiveAdRenderer = (InneractiveAdRenderer) it.next(); if ((inneractiveAdRenderer instanceof com.fyber.inneractive.sdk.interfaces.b) && (f = ((com.fyber.inneractive.sdk.interfaces.b) inneractiveAdRenderer).f()) > 0) { return f; } } return this.mAdContentWidth; } @Override // com.fyber.inneractive.sdk.activities.InneractiveFullscreenAdActivity.FullScreenRendererProvider public c getFullscreenRenderer() { c cVar; InneractiveAdSpot inneractiveAdSpot = (InneractiveAdSpot) com.fyber.inneractive.sdk.util.t.a(this.mAdSpot); Iterator it = c.b.a.a.iterator(); while (true) { if (!it.hasNext()) { cVar = null; break; } c.a aVar = (c.a) it.next(); if (aVar.a(inneractiveAdSpot)) { cVar = aVar.b(inneractiveAdSpot); break; } } this.a.add(cVar); return cVar; } @Override // com.fyber.inneractive.sdk.flow.f0, com.fyber.inneractive.sdk.external.InneractiveUnitController public InneractiveContentController getSelectedContentController() { return this.mSelectedContentController; } @Override // com.fyber.inneractive.sdk.flow.t.c public void onAdRefreshFailed(InneractiveAdSpot inneractiveAdSpot, InneractiveErrorCode inneractiveErrorCode) { Iterator it = new HashSet(this.a).iterator(); while (it.hasNext()) { InneractiveAdRenderer inneractiveAdRenderer = (InneractiveAdRenderer) it.next(); if (inneractiveAdRenderer instanceof com.fyber.inneractive.sdk.interfaces.b) { ((com.fyber.inneractive.sdk.interfaces.b) inneractiveAdRenderer).k(); return; } } } @Override // com.fyber.inneractive.sdk.flow.t.c public void onAdRefreshed(InneractiveAdSpot inneractiveAdSpot) { com.fyber.inneractive.sdk.interfaces.b bVar; Iterator it = new HashSet(this.a).iterator(); while (true) { if (!it.hasNext()) { bVar = null; break; } InneractiveAdRenderer inneractiveAdRenderer = (InneractiveAdRenderer) it.next(); if (inneractiveAdRenderer instanceof com.fyber.inneractive.sdk.interfaces.b) { bVar = (com.fyber.inneractive.sdk.interfaces.b) inneractiveAdRenderer; if (bVar.a(inneractiveAdSpot.getAdContent())) { break; } } } if (bVar != null) { bVar.a((ViewGroup) null); } else { onAdRefreshFailed(inneractiveAdSpot, InneractiveErrorCode.SDK_INTERNAL_ERROR); } try { if (inneractiveAdSpot instanceof t) { int i = IAlog.a; ((t) inneractiveAdSpot).h.d.b(); } } catch (Exception unused) { } IAlog.a("InneractiveFullscreenUnitController onAdRefreshed called", new Object[0]); } public void refreshAd() { IAlog.a("InneractiveFullscreenUnitController refreshAd called", new Object[0]); InneractiveAdSpot inneractiveAdSpot = (InneractiveAdSpot) com.fyber.inneractive.sdk.util.t.a(this.mAdSpot); if (inneractiveAdSpot == null || !(inneractiveAdSpot instanceof d0)) { return; } ((d0) inneractiveAdSpot).a(this); } @Override // com.fyber.inneractive.sdk.flow.f0 public boolean supports(InneractiveAdSpot inneractiveAdSpot) { e0 e0Var = (e0) inneractiveAdSpot.getAdContent().d; if (e0Var.e != null) { return false; } x xVar = e0Var.c; if (xVar != null) { if (UnitDisplayType.BANNER.equals(xVar.b) || UnitDisplayType.MRECT.equals(xVar.b)) { return true; } if (UnitDisplayType.INTERSTITIAL.equals(xVar.b)) { return (inneractiveAdSpot.getCurrentProcessedRequest() == null || inneractiveAdSpot.getCurrentProcessedRequest().getAllowFullscreen()) ? false : true; } } g0 g0Var = e0Var.f; return g0Var != null && (UnitDisplayType.LANDSCAPE.equals(g0Var.j) || UnitDisplayType.SQUARE.equals(g0Var.j) || UnitDisplayType.MRECT.equals(g0Var.j)); } @Override // com.fyber.inneractive.sdk.flow.f0 public boolean supportsRefresh() { return true; } public void unbindFullscreenRenderer(com.fyber.inneractive.sdk.interfaces.c cVar) { WeakReference weakReference; IAlog.a("%sremoving full screen ad renderer %s", logPrefix(), cVar); HashSet hashSet = this.a; if (hashSet != null) { hashSet.remove(cVar); } if (this.b) { return; } Iterator it = new HashSet(this.a).iterator(); while (it.hasNext()) { InneractiveAdRenderer inneractiveAdRenderer = (InneractiveAdRenderer) it.next(); if (inneractiveAdRenderer instanceof com.fyber.inneractive.sdk.interfaces.b) { ((com.fyber.inneractive.sdk.interfaces.b) inneractiveAdRenderer).a(); if (this.mEventsListener != 0 && (weakReference = this.mAdSpot) != null && weakReference.get() != null) { ((InneractiveAdViewEventsListener) this.mEventsListener).onAdCollapsed(this.mAdSpot.get()); } } } } public final void a() { this.b = true; Iterator it = new HashSet(this.a).iterator(); while (it.hasNext()) { ((InneractiveAdRenderer) it.next()).destroy(); } this.a.clear(); this.c = null; super.destroy(); } public void unbindView(View view) { if (this.c != view) { IAlog.f("%s unbindView invoked with incorrect view, was - %s received - %s", logPrefix(), this.c, view); } else { this.c = null; } IAlog.a("%sPPPP unbindView called with %s", logPrefix(), view); IAlog.a("%sPPPP spot is %s", logPrefix(), this.mAdSpot); Iterator it = new HashSet(this.a).iterator(); while (it.hasNext()) { InneractiveAdRenderer inneractiveAdRenderer = (InneractiveAdRenderer) it.next(); if (inneractiveAdRenderer instanceof com.fyber.inneractive.sdk.interfaces.b) { com.fyber.inneractive.sdk.interfaces.b bVar = (com.fyber.inneractive.sdk.interfaces.b) inneractiveAdRenderer; if (bVar.a(view)) { IAlog.a("%sPPPP unbindView unbinding renderer %s", logPrefix(), inneractiveAdRenderer); bVar.m(); this.a.remove(bVar); return; } } } } public InneractiveAdViewUnitController(int i) { this(); if (i >= 30) { IAlog.a("InneractiveAdViewUnitController: Overriding remote config refresh interval to: %d", Integer.valueOf(i)); this.d = i; } else { IAlog.a("InneractiveAdViewUnitController: Overriding remote config refresh interval - value too low. Setting to default: %d -> %d", Integer.valueOf(i), 30); this.d = 30; } } public InneractiveAdViewUnitController(boolean z) { this(); if (z) { this.d = -1; } } }