package com.discord.utilities.embed; import android.content.Context; import android.content.res.Resources; import androidx.annotation.DrawableRes; import c.d.b.a.a; import com.discord.api.message.attachment.MessageAttachment; import com.discord.api.message.attachment.MessageAttachmentType; import com.discord.api.message.embed.EmbedImage; import com.discord.api.message.embed.EmbedProvider; import com.discord.api.message.embed.EmbedThumbnail; import com.discord.api.message.embed.EmbedType; import com.discord.api.message.embed.EmbedVideo; import com.discord.api.message.embed.MessageEmbed; import com.discord.embed.RenderableEmbedMedia; import com.discord.utilities.dimen.DimenUtils; import com.discord.utilities.display.DisplayUtils; import com.discord.utilities.string.StringUtilsKt; import d0.g0.t; import d0.g0.w; import d0.o; import d0.t.n; import d0.t.u; import d0.z.d.m; import java.util.List; import java.util.Locale; import kotlin.NoWhenBranchMatchedException; import kotlin.Pair; /* compiled from: EmbedResourceUtils.kt */ public final class EmbedResourceUtils { public static final String FILE_SCHEME = "res:///"; public static final EmbedResourceUtils INSTANCE = new EmbedResourceUtils(); public static final int MAX_IMAGE_SIZE = 1440; private static final int MAX_IMAGE_VIEW_HEIGHT_PX = DimenUtils.dpToPixels(320); private static final List PLAYABLE_EMBED_TYPES = n.listOf((Object[]) new EmbedType[]{EmbedType.VIDEO, EmbedType.GIFV}); public final /* synthetic */ class WhenMappings { public static final /* synthetic */ int[] $EnumSwitchMapping$0; public static final /* synthetic */ int[] $EnumSwitchMapping$1; public static final /* synthetic */ int[] $EnumSwitchMapping$2; public static final /* synthetic */ int[] $EnumSwitchMapping$3; public static final /* synthetic */ int[] $EnumSwitchMapping$4; public static final /* synthetic */ int[] $EnumSwitchMapping$5; static { MessageAttachmentType.values(); int[] iArr = new int[3]; $EnumSwitchMapping$0 = iArr; iArr[MessageAttachmentType.VIDEO.ordinal()] = 1; iArr[MessageAttachmentType.IMAGE.ordinal()] = 2; iArr[MessageAttachmentType.FILE.ordinal()] = 3; EmbedType.values(); int[] iArr2 = new int[11]; $EnumSwitchMapping$1 = iArr2; iArr2[EmbedType.LINK.ordinal()] = 1; iArr2[EmbedType.HTML.ordinal()] = 2; EmbedType embedType = EmbedType.VIDEO; iArr2[embedType.ordinal()] = 3; EmbedType embedType2 = EmbedType.GIFV; iArr2[embedType2.ordinal()] = 4; iArr2[EmbedType.TWEET.ordinal()] = 5; EmbedType embedType3 = EmbedType.IMAGE; iArr2[embedType3.ordinal()] = 6; iArr2[EmbedType.ARTICLE.ordinal()] = 7; EmbedType.values(); int[] iArr3 = new int[11]; $EnumSwitchMapping$2 = iArr3; iArr3[embedType2.ordinal()] = 1; iArr3[embedType3.ordinal()] = 2; iArr3[embedType.ordinal()] = 3; EmbedType.values(); int[] iArr4 = new int[11]; $EnumSwitchMapping$3 = iArr4; iArr4[embedType3.ordinal()] = 1; iArr4[embedType2.ordinal()] = 2; EmbedType.values(); int[] iArr5 = new int[11]; $EnumSwitchMapping$4 = iArr5; iArr5[embedType2.ordinal()] = 1; iArr5[embedType3.ordinal()] = 2; EmbedType.values(); int[] iArr6 = new int[11]; $EnumSwitchMapping$5 = iArr6; iArr6[EmbedType.FILE.ordinal()] = 1; iArr6[embedType.ordinal()] = 2; } } private EmbedResourceUtils() { } public static /* synthetic */ Pair calculateScaledSize$default(EmbedResourceUtils embedResourceUtils, int i, int i2, int i3, int i4, Resources resources, int i5, int i6, Object obj) { return embedResourceUtils.calculateScaledSize(i, i2, i3, i4, resources, (i6 & 32) != 0 ? 0 : i5); } private final RenderableEmbedMedia createFileRenderableMedia(String str) { StringBuilder L = a.L("res:///"); L.append(getFileDrawable(str)); return new RenderableEmbedMedia(L.toString(), 30, 40); } public static /* synthetic */ List getPreviewUrls$default(EmbedResourceUtils embedResourceUtils, String str, int i, int i2, boolean z2, int i3, Object obj) { if ((i3 & 8) != 0) { z2 = true; } return embedResourceUtils.getPreviewUrls(str, i, i2, z2); } public final Pair calculateScaledSize(int i, int i2, int i3, int i4, Resources resources, int i5) { m.checkNotNullParameter(resources, "resources"); float f = resources.getDisplayMetrics().density; float f2 = (float) i; float f3 = f * f2; float f4 = (float) i2; float f5 = f * f4; boolean z2 = false; boolean z3 = f3 > ((float) (i3 / 2)) || f5 > ((float) (i4 / 2)); boolean z4 = i5 > 0 && i < i5; float f6 = i2 > 0 ? f2 / f4 : 0.0f; if (z3) { if (i > i2) { z2 = true; } float f7 = z2 ? (float) i3 : ((float) i4) * f6; float f8 = z2 ? ((float) i3) / f6 : (float) i4; if (z2) { float f9 = (float) i4; if (f8 > f9) { f7 *= f9 / f8; f8 = f9; return o.to(Integer.valueOf(d0.a0.a.roundToInt(f7)), Integer.valueOf(d0.a0.a.roundToInt(f8))); } } if (!z2) { float f10 = (float) i3; if (f7 > f10) { f8 *= f10 / f7; f7 = f10; } } return o.to(Integer.valueOf(d0.a0.a.roundToInt(f7)), Integer.valueOf(d0.a0.a.roundToInt(f8))); } else if (!z4) { return o.to(Integer.valueOf(d0.a0.a.roundToInt(f3)), Integer.valueOf(d0.a0.a.roundToInt(f5))); } else { float f11 = (float) i5; float f12 = (f11 / f2) * f4; float f13 = (float) i4; if (f12 > f13) { z2 = true; } if (z2) { float f14 = f13 / f12; f11 *= f14; f12 *= f14; } return o.to(Integer.valueOf(d0.a0.a.roundToInt(f11)), Integer.valueOf(d0.a0.a.roundToInt(f12))); } } public final int computeMaximumImageWidthPx(Context context) { m.checkNotNullParameter(context, "context"); Resources resources = context.getResources(); return Math.min(1440, DisplayUtils.getScreenSize(context).width() - (resources.getDimensionPixelSize(2131165768) + resources.getDimensionPixelSize(2131165310))); } public final RenderableEmbedMedia createRenderableEmbedMediaFromAttachment(MessageAttachment messageAttachment) { m.checkNotNullParameter(messageAttachment, "attachment"); int ordinal = messageAttachment.e().ordinal(); if (ordinal == 0 || ordinal == 1) { return new RenderableEmbedMedia(messageAttachment.c(), messageAttachment.g(), messageAttachment.b()); } if (ordinal == 2) { return createFileRenderableMedia(messageAttachment.a()); } throw new NoWhenBranchMatchedException(); } public final String getExternalOpenUrl(MessageEmbed messageEmbed) { EmbedProvider g; m.checkNotNullParameter(messageEmbed, "$this$getExternalOpenUrl"); EmbedType k = messageEmbed.k(); if (k == null) { return null; } int ordinal = k.ordinal(); if (ordinal == 2) { EmbedVideo m = messageEmbed.m(); if (m != null) { return m.c(); } return null; } else if (ordinal == 6 && (g = messageEmbed.g()) != null) { return g.b(); } else { return null; } } @DrawableRes public final int getFileDrawable(String str) { String substringAfterLast; String str2 = ""; if (!(str == null || (substringAfterLast = w.substringAfterLast(str, '.', str2)) == null)) { str2 = substringAfterLast; } FileType fromExtension = FileType.Companion.getFromExtension(str2); if (fromExtension != null) { return fromExtension.getFileDrawable(); } return 2131231629; } public final int getMAX_IMAGE_VIEW_HEIGHT_PX() { return MAX_IMAGE_VIEW_HEIGHT_PX; } /* JADX WARNING: Code restructure failed: missing block: B:15:0x0025, code lost: if (r0 != 7) goto L_0x0027; */ public final RenderableEmbedMedia getPreviewImage(MessageEmbed messageEmbed) { m.checkNotNullParameter(messageEmbed, "$this$getPreviewImage"); EmbedType k = messageEmbed.k(); RenderableEmbedMedia renderableEmbedMedia = null; if (k != null) { int ordinal = k.ordinal(); if (!(ordinal == 0 || ordinal == 1)) { if (ordinal != 2) { if (ordinal != 3) { if (!(ordinal == 4 || ordinal == 5)) { } return renderableEmbedMedia; } } EmbedThumbnail h = messageEmbed.h(); if (h != null) { m.checkNotNullParameter(h, "$this$asRenderableEmbedMedia"); String b = h.b(); if (b == null) { b = h.c(); } renderableEmbedMedia = new RenderableEmbedMedia(b, h.d(), h.a()); } else { EmbedVideo m = messageEmbed.m(); if (m != null) { m.checkNotNullParameter(m, "$this$asRenderableEmbedMedia"); String b2 = m.b(); if (b2 == null) { b2 = m.c(); } renderableEmbedMedia = new RenderableEmbedMedia(b2, m.d(), m.a()); } } return renderableEmbedMedia; } EmbedThumbnail h2 = messageEmbed.h(); if (h2 != null) { m.checkNotNullParameter(h2, "$this$asRenderableEmbedMedia"); String b3 = h2.b(); if (b3 == null) { b3 = h2.c(); } renderableEmbedMedia = new RenderableEmbedMedia(b3, h2.d(), h2.a()); } return renderableEmbedMedia; } EmbedImage f = messageEmbed.f(); if (f != null) { m.checkNotNullParameter(f, "$this$asRenderableEmbedMedia"); String b4 = f.b(); if (b4 == null) { b4 = f.c(); } renderableEmbedMedia = new RenderableEmbedMedia(b4, f.d(), f.a()); } return renderableEmbedMedia; } public final List getPreviewUrls(String str, int i, int i2, boolean z2) { m.checkNotNullParameter(str, "originalUrl"); String str2 = str + "?width=" + i + "&height=" + i2; if (z2 && (t.startsWith$default(str, "res:///", false, 2, null) || t.endsWith$default(str, ".gif", false, 2, null))) { return d0.t.m.listOf(str2); } StringBuilder P = a.P(str2, "&format="); P.append(StringUtilsKt.getSTATIC_IMAGE_EXTENSION()); return n.listOf((Object[]) new String[]{P.toString(), str2}); } public final boolean isAnimated(EmbedType embedType, String str) { if (embedType == null) { return false; } int ordinal = embedType.ordinal(); if (ordinal != 1) { if (ordinal != 7) { return false; } } else if (str == null) { return false; } else { Locale locale = Locale.ROOT; m.checkNotNullExpressionValue(locale, "Locale.ROOT"); String lowerCase = str.toLowerCase(locale); m.checkNotNullExpressionValue(lowerCase, "(this as java.lang.String).toLowerCase(locale)"); if (lowerCase == null || !w.contains$default((CharSequence) lowerCase, (CharSequence) ".gif", false, 2, (Object) null)) { return false; } } return true; } public final boolean isAnimated(MessageEmbed messageEmbed) { m.checkNotNullParameter(messageEmbed, "$this$isAnimated"); EmbedType k = messageEmbed.k(); RenderableEmbedMedia previewImage = getPreviewImage(messageEmbed); return isAnimated(k, previewImage != null ? previewImage.a : null); } public final boolean isInlineEmbed(MessageEmbed messageEmbed) { EmbedType k; m.checkNotNullParameter(messageEmbed, "$this$isInlineEmbed"); if ((getPreviewImage(messageEmbed) == null && messageEmbed.m() == null) || (k = messageEmbed.k()) == null) { return false; } int ordinal = k.ordinal(); if (ordinal == 1 || ordinal == 2) { if (!(messageEmbed.a() == null && messageEmbed.j() == null)) { return false; } } else if (ordinal != 7) { return false; } return true; } public final boolean isPlayable(MessageEmbed messageEmbed) { m.checkNotNullParameter(messageEmbed, "$this$isPlayable"); return u.contains(PLAYABLE_EMBED_TYPES, messageEmbed.k()); } public final boolean isSimpleEmbed(MessageEmbed messageEmbed) { int ordinal; m.checkNotNullParameter(messageEmbed, "$this$isSimpleEmbed"); EmbedType k = messageEmbed.k(); if (k != null && ((ordinal = k.ordinal()) == 1 || ordinal == 7)) { return isInlineEmbed(messageEmbed); } return false; } }