package com.applovin.impl; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Handler; import android.os.StrictMode; import android.text.TextUtils; import android.view.ViewGroup; import androidx.core.view.ViewCompat; import androidx.lifecycle.Lifecycle; import com.applovin.adview.AppLovinFullscreenActivity; import com.applovin.adview.AppLovinFullscreenAdViewObserver; import com.applovin.adview.AppLovinInterstitialAdDialog; import com.applovin.impl.p9; import com.applovin.impl.sdk.ad.AppLovinAdImpl; import com.applovin.impl.sdk.utils.StringUtils; import com.applovin.sdk.AppLovinAd; import com.applovin.sdk.AppLovinAdClickListener; import com.applovin.sdk.AppLovinAdDisplayListener; import com.applovin.sdk.AppLovinAdLoadListener; import com.applovin.sdk.AppLovinAdSize; import com.applovin.sdk.AppLovinAdVideoPlaybackListener; import com.applovin.sdk.AppLovinSdk; import com.applovin.sdk.AppLovinSdkUtils; import com.google.android.gms.drive.DriveFile; import java.lang.ref.WeakReference; import java.util.Collections; import java.util.HashMap; import java.util.Map; /* loaded from: classes.dex */ public class tb implements AppLovinInterstitialAdDialog { protected final com.applovin.impl.sdk.j a; private final WeakReference b; private final Map c = Collections.synchronizedMap(new HashMap()); private volatile AppLovinAdLoadListener d; private volatile AppLovinAdDisplayListener e; private volatile AppLovinAdVideoPlaybackListener f; private volatile AppLovinAdClickListener g; private volatile com.applovin.impl.sdk.ad.b h; public void a() { this.g = null; this.d = null; this.f = null; this.e = null; } public AppLovinAdClickListener b() { return this.g; } public AppLovinAdDisplayListener c() { return this.e; } public AppLovinAdVideoPlaybackListener d() { return this.f; } public com.applovin.impl.sdk.ad.b f() { return this.h; } public Map h() { return this.c; } @Override // com.applovin.adview.AppLovinInterstitialAdDialog public void setAdClickListener(AppLovinAdClickListener appLovinAdClickListener) { this.g = appLovinAdClickListener; } @Override // com.applovin.adview.AppLovinInterstitialAdDialog public void setAdDisplayListener(AppLovinAdDisplayListener appLovinAdDisplayListener) { this.e = appLovinAdDisplayListener; } @Override // com.applovin.adview.AppLovinInterstitialAdDialog public void setAdLoadListener(AppLovinAdLoadListener appLovinAdLoadListener) { this.d = appLovinAdLoadListener; } @Override // com.applovin.adview.AppLovinInterstitialAdDialog public void setAdVideoPlaybackListener(AppLovinAdVideoPlaybackListener appLovinAdVideoPlaybackListener) { this.f = appLovinAdVideoPlaybackListener; } public String toString() { return "AppLovinInterstitialAdDialog{}"; } public tb(AppLovinSdk appLovinSdk, Context context) { if (appLovinSdk == null) { throw new IllegalArgumentException("No sdk specified"); } if (context != null) { this.a = appLovinSdk.a(); this.b = new WeakReference(context); return; } throw new IllegalArgumentException("No context specified"); } public class a implements AppLovinAdLoadListener { public a() { } @Override // com.applovin.sdk.AppLovinAdLoadListener public void adReceived(AppLovinAd appLovinAd) { tb.this.b(appLovinAd); tb.this.showAndRender(appLovinAd); } @Override // com.applovin.sdk.AppLovinAdLoadListener public void failedToReceiveAd(int i) { tb.this.b(i); } } @Override // com.applovin.adview.AppLovinInterstitialAdDialog public void show() { a(new a()); } @Override // com.applovin.adview.AppLovinInterstitialAdDialog public void showAndRender(AppLovinAd appLovinAd) { AppLovinAd a2 = yp.a(appLovinAd, this.a); Context e = e(); String a3 = a(a2, appLovinAd, e); if (StringUtils.isValidString(a3)) { a(appLovinAd, a3); } else { a((com.applovin.impl.sdk.ad.b) a2, e); } } @Override // com.applovin.adview.AppLovinInterstitialAdDialog public void setExtraInfo(String str, Object obj) { if (str != null) { this.c.put(str, obj); return; } throw new IllegalArgumentException("No key specified"); } @Override // com.applovin.adview.AppLovinInterstitialAdDialog public void showAndRender(AppLovinAd appLovinAd, ViewGroup viewGroup, Lifecycle lifecycle) { if (viewGroup != null && lifecycle != null) { AppLovinAd a2 = yp.a(appLovinAd, this.a); Context e = e(); String a3 = a(a2, appLovinAd, e); if (StringUtils.isValidString(a3)) { a(appLovinAd, a3); return; } AppLovinFullscreenAdViewObserver appLovinFullscreenAdViewObserver = new AppLovinFullscreenAdViewObserver(lifecycle, this, this.a); lifecycle.addObserver(appLovinFullscreenAdViewObserver); a((com.applovin.impl.sdk.ad.b) a2, viewGroup, appLovinFullscreenAdViewObserver, e); return; } com.applovin.impl.sdk.n.h("InterstitialAdDialogWrapper", "Failed to show interstitial: attempting to show ad with null container view or lifecycle object"); a(appLovinAd, "Failed to show interstitial: attempting to show ad with null container view or lifecycle object"); } public class b implements p9.d { final /* synthetic */ Context a; final /* synthetic */ AppLovinFullscreenAdViewObserver b; final /* synthetic */ ViewGroup c; public b(Context context, AppLovinFullscreenAdViewObserver appLovinFullscreenAdViewObserver, ViewGroup viewGroup) { this.a = context; this.b = appLovinFullscreenAdViewObserver; this.c = viewGroup; } @Override // com.applovin.impl.p9.d public void a(p9 p9Var) { if (r.a((Activity) this.a)) { com.applovin.impl.sdk.n.h("InterstitialAdDialogWrapper", "Failed to show interstitial: attempting to show ad when parent activity is finishing"); tb.a(tb.this.h, tb.this.e, "Failed to show interstitial: attempting to show ad when parent activity is finishing", null, null); return; } this.b.setPresenter(p9Var); try { p9Var.a(this.c); } catch (Throwable th) { String str = "Failed to show interstitial: presenter threw exception " + th; com.applovin.impl.sdk.n.h("InterstitialAdDialogWrapper", str); tb.a(tb.this.h, tb.this.e, str, null, null); } } @Override // com.applovin.impl.p9.d public void a(String str, Throwable th) { tb.a(tb.this.h, tb.this.e, str, th, null); } } private long g() { String str = this.a.g0().getExtraParameters().get("fullscreen_ad_display_delay_enabled"); if (str == null || Boolean.parseBoolean(str)) { return Math.max(0L, ((Long) this.a.a(sj.q2)).longValue()); } return 0L; } private void i() { if (this.a.e().a() == null) { this.a.D().c(ca.r); } } private Context e() { return (Context) this.b.get(); } private void b(Context context) { Intent intent = new Intent(context, (Class) AppLovinFullscreenActivity.class); intent.putExtra("com.applovin.interstitial.sdk_key", this.a.b0()); AppLovinFullscreenActivity.parentInterstitialWrapper = this; if (this.a.e().a() == null && ((Boolean) this.a.a(sj.P2)).booleanValue()) { intent.addFlags(8388608); } StrictMode.ThreadPolicy allowThreadDiskReads = StrictMode.allowThreadDiskReads(); if (context instanceof Activity) { context.startActivity(intent); ((Activity) context).overridePendingTransition(0, 0); } else { intent.addFlags(DriveFile.MODE_READ_ONLY); context.startActivity(intent); } StrictMode.setThreadPolicy(allowThreadDiskReads); } private void a(AppLovinAd appLovinAd, String str) { if (this.e != null) { if (this.e instanceof qb) { ((qb) this.e).onAdDisplayFailed(str); } else { this.e.adHidden(appLovinAd); } } } public static void a(com.applovin.impl.sdk.ad.b bVar, AppLovinAdDisplayListener appLovinAdDisplayListener, String str, Throwable th, AppLovinFullscreenActivity appLovinFullscreenActivity) { com.applovin.impl.sdk.n.c("InterstitialAdDialogWrapper", str, th); if (appLovinAdDisplayListener instanceof qb) { gc.a(appLovinAdDisplayListener, str); } else { gc.b(appLovinAdDisplayListener, bVar); } if (appLovinFullscreenActivity != null) { appLovinFullscreenActivity.dismiss(); } } /* JADX INFO: Access modifiers changed from: private */ public void b(final AppLovinAd appLovinAd) { AppLovinSdkUtils.runOnUiThread(new Runnable() { // from class: com.applovin.impl.tb$$ExternalSyntheticLambda1 @Override // java.lang.Runnable public final void run() { tb.this.a(appLovinAd); } }); } /* JADX INFO: Access modifiers changed from: private */ public void b(final int i) { AppLovinSdkUtils.runOnUiThread(new Runnable() { // from class: com.applovin.impl.tb$$ExternalSyntheticLambda2 @Override // java.lang.Runnable public final void run() { tb.this.a(i); } }); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(AppLovinAd appLovinAd) { if (this.d != null) { this.d.adReceived(appLovinAd); } } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(int i) { if (this.d != null) { this.d.failedToReceiveAd(i); } } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(Context context) { this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("InterstitialAdDialogWrapper", "Presenting ad in a fullscreen activity"); } b(context); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(ViewGroup viewGroup, Context context, AppLovinFullscreenAdViewObserver appLovinFullscreenAdViewObserver) { this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("InterstitialAdDialogWrapper", "Presenting ad in a containerView(" + viewGroup + ")"); } viewGroup.setBackgroundColor(ViewCompat.MEASURED_STATE_MASK); p9.a(this.h, this.g, this.e, this.f, this.c, this.a, (Activity) context, new b(context, appLovinFullscreenAdViewObserver, viewGroup)); } private void a(AppLovinAdLoadListener appLovinAdLoadListener) { this.a.i().loadNextAd(AppLovinAdSize.INTERSTITIAL, appLovinAdLoadListener); } private String a(AppLovinAd appLovinAd, AppLovinAd appLovinAd2, Context context) { if (context == null) { com.applovin.impl.sdk.n.h("InterstitialAdDialogWrapper", "Failed to show interstitial: stale activity reference provided"); return "Failed to show interstitial: stale activity reference provided"; } if (appLovinAd == null) { com.applovin.impl.sdk.n.h("InterstitialAdDialogWrapper", "Unable to retrieve the loaded ad: " + appLovinAd2); return "Unable to retrieve the loaded ad"; } if (!((AppLovinAdImpl) appLovinAd).hasShown() || !((Boolean) this.a.a(sj.a2)).booleanValue()) { return null; } com.applovin.impl.sdk.n.h("InterstitialAdDialogWrapper", "Attempting to show ad again: " + appLovinAd); return "Attempting to show ad again"; } private void a(com.applovin.impl.sdk.ad.b bVar, Context context, final Runnable runnable) { if (TextUtils.isEmpty(bVar.H()) && bVar.c1() && !e4.a(context) && (context instanceof Activity)) { AlertDialog create = new AlertDialog.Builder(context).setTitle(bVar.O()).setMessage(bVar.N()).setPositiveButton(bVar.M(), (DialogInterface.OnClickListener) null).create(); create.setOnDismissListener(new DialogInterface.OnDismissListener() { // from class: com.applovin.impl.tb$$ExternalSyntheticLambda6 @Override // android.content.DialogInterface.OnDismissListener public final void onDismiss(DialogInterface dialogInterface) { runnable.run(); } }); create.show(); return; } runnable.run(); } private void a(com.applovin.impl.sdk.ad.b bVar, final Context context) { i(); this.a.f().a(bVar); this.h = bVar; final long g = g(); this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("InterstitialAdDialogWrapper", "Presenting ad with delay " + g + "ms..."); } a(bVar, context, new Runnable() { // from class: com.applovin.impl.tb$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { tb.this.a(context, g); } }); } private void a(com.applovin.impl.sdk.ad.b bVar, final ViewGroup viewGroup, final AppLovinFullscreenAdViewObserver appLovinFullscreenAdViewObserver, final Context context) { i(); this.a.f().a(bVar); this.h = bVar; final long g = g(); this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("InterstitialAdDialogWrapper", "Presenting ad with delay " + g + "ms..."); } a(bVar, context, new Runnable() { // from class: com.applovin.impl.tb$$ExternalSyntheticLambda5 @Override // java.lang.Runnable public final void run() { tb.this.a(context, viewGroup, appLovinFullscreenAdViewObserver, g); } }); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(final Context context, long j) { new Handler(context.getMainLooper()).postDelayed(new Runnable() { // from class: com.applovin.impl.tb$$ExternalSyntheticLambda3 @Override // java.lang.Runnable public final void run() { tb.this.a(context); } }, j); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(final Context context, final ViewGroup viewGroup, final AppLovinFullscreenAdViewObserver appLovinFullscreenAdViewObserver, long j) { new Handler(context.getMainLooper()).postDelayed(new Runnable() { // from class: com.applovin.impl.tb$$ExternalSyntheticLambda4 @Override // java.lang.Runnable public final void run() { tb.this.a(viewGroup, context, appLovinFullscreenAdViewObserver); } }, j); } }