package com.ironsource; import android.content.Context; import com.ironsource.mediationsdk.logger.IronLog; import com.unity3d.mediation.LevelPlayAdSize; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import kotlin.collections.CollectionsKt___CollectionsKt; import kotlin.comparisons.ComparisonsKt__ComparisonsKt; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.SourceDebugExtension; @SourceDebugExtension({"SMAP\nAdaptiveAdSizeFactory.kt\nKotlin\n*S Kotlin\n*F\n+ 1 AdaptiveAdSizeFactory.kt\ncom/unity3d/mediation/internal/AdaptiveAdSizeFactory\n+ 2 _Collections.kt\nkotlin/collections/CollectionsKt___CollectionsKt\n*L\n1#1,80:1\n1855#2,2:81\n766#2:83\n857#2,2:84\n*S KotlinDebug\n*F\n+ 1 AdaptiveAdSizeFactory.kt\ncom/unity3d/mediation/internal/AdaptiveAdSizeFactory\n*L\n33#1:81,2\n71#1:83\n71#1:84,2\n*E\n"}) /* loaded from: classes2.dex */ public final class y2 { public static final a b = new a(null); private static final int c = -1; private final h1 a; public static final class a { private a() { } public /* synthetic */ a(DefaultConstructorMarker defaultConstructorMarker) { this(); } } @SourceDebugExtension({"SMAP\nComparisons.kt\nKotlin\n*S Kotlin\n*F\n+ 1 Comparisons.kt\nkotlin/comparisons/ComparisonsKt__ComparisonsKt$compareByDescending$1\n+ 2 AdaptiveAdSizeFactory.kt\ncom/unity3d/mediation/internal/AdaptiveAdSizeFactory\n*L\n1#1,328:1\n77#2:329\n*E\n"}) public static final class b implements Comparator { /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.Comparator public final int compare(T t, T t2) { int compareValues; compareValues = ComparisonsKt__ComparisonsKt.compareValues(Integer.valueOf(((LevelPlayAdSize) t2).getWidth()), Integer.valueOf(((LevelPlayAdSize) t).getWidth())); return compareValues; } } @SourceDebugExtension({"SMAP\nComparisons.kt\nKotlin\n*S Kotlin\n*F\n+ 1 Comparisons.kt\nkotlin/comparisons/ComparisonsKt__ComparisonsKt$thenByDescending$1\n+ 2 AdaptiveAdSizeFactory.kt\ncom/unity3d/mediation/internal/AdaptiveAdSizeFactory\n*L\n1#1,328:1\n78#2:329\n*E\n"}) public static final class c implements Comparator { final /* synthetic */ Comparator a; public c(Comparator comparator) { this.a = comparator; } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.Comparator public final int compare(T t, T t2) { int compareValues; int compare = this.a.compare(t, t2); if (compare != 0) { return compare; } compareValues = ComparisonsKt__ComparisonsKt.compareValues(Integer.valueOf(((LevelPlayAdSize) t2).getHeight()), Integer.valueOf(((LevelPlayAdSize) t).getHeight())); return compareValues; } } public y2(h1 adSizeTools) { Intrinsics.checkNotNullParameter(adSizeTools, "adSizeTools"); this.a = adSizeTools; } private final int a(Integer num, Context context) { if (num != null && num.intValue() < 0) { IronLog.API.info(h1.a(this.a, "Width is invalid, screen width will be used", (String) null, 2, (Object) null)); } else if (num != null) { return num.intValue(); } return na.a.b(context); } private final List a() { List sortedWith; sortedWith = CollectionsKt___CollectionsKt.sortedWith(this.a.b(), new c(new b())); return sortedWith; } private final List a(List list, int i, int i2) { ArrayList arrayList = new ArrayList(); for (Object obj : list) { LevelPlayAdSize levelPlayAdSize = (LevelPlayAdSize) obj; if (levelPlayAdSize.getHeight() <= i && levelPlayAdSize.getWidth() <= i2) { arrayList.add(obj); } } return arrayList; } public final LevelPlayAdSize a(Context context, Integer num) { int i; LevelPlayAdSize levelPlayAdSize; Intrinsics.checkNotNullParameter(context, "context"); if (!this.a.d()) { IronLog.API.error(h1.a(this.a, "The SDK must be successfully initialized to create an Adaptive Ad Size", (String) null, 2, (Object) null)); return null; } int a2 = a(num, context); int b2 = this.a.b(context); int a3 = this.a.a(a2); List a4 = a(); for (LevelPlayAdSize levelPlayAdSize2 : a(a4, b2, a2)) { if (levelPlayAdSize2.getWidth() <= a2 && (levelPlayAdSize2.getHeight() <= a3 || a3 == -1)) { a3 = Math.max(a3, levelPlayAdSize2.getHeight()); break; } } levelPlayAdSize2 = null; if (levelPlayAdSize2 == null) { int height = ((LevelPlayAdSize) CollectionsKt___CollectionsKt.last((List) a4)).getHeight(); i = height; levelPlayAdSize = LevelPlayAdSize.Companion.createCustomSize(a2, height); } else { i = a3; levelPlayAdSize = levelPlayAdSize2; } IronLog.INTERNAL.info(h1.a(this.a, "Adaptive: " + a2 + 'x' + i + " Fallback: " + levelPlayAdSize, (String) null, 2, (Object) null)); return new LevelPlayAdSize(a2, i, com.ironsource.mediationsdk.l.f, true, levelPlayAdSize); } }