909 lines
39 KiB
Java
909 lines
39 KiB
Java
package com.discord.utilities.icon;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.text.TextUtils;
|
|
import android.widget.ImageView;
|
|
import androidx.annotation.DimenRes;
|
|
import androidx.annotation.DrawableRes;
|
|
import c.d.b.a.a;
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.discord.BuildConfig;
|
|
import com.discord.R;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.api.role.GuildRole;
|
|
import com.discord.models.commands.Application;
|
|
import com.discord.models.commands.ApplicationKt;
|
|
import com.discord.models.guild.Guild;
|
|
import com.discord.models.member.GuildMember;
|
|
import com.discord.models.user.CoreUser;
|
|
import com.discord.models.user.User;
|
|
import com.discord.nullserializable.NullSerializable;
|
|
import com.discord.utilities.SnowflakeUtils;
|
|
import com.discord.utilities.color.ColorCompat;
|
|
import com.discord.utilities.drawable.DrawableCompat;
|
|
import com.discord.utilities.images.MGImages;
|
|
import com.discord.utilities.string.StringUtilsKt;
|
|
import com.discord.widgets.chat.input.MentionUtilsKt;
|
|
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|
import d0.g0.t;
|
|
import d0.g0.w;
|
|
import d0.t.c0;
|
|
import d0.t.k;
|
|
import d0.t.o;
|
|
import d0.z.d.m;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.NoSuchElementException;
|
|
import java.util.Objects;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.ranges.IntRange;
|
|
/* compiled from: IconUtils.kt */
|
|
public final class IconUtils {
|
|
public static final String ANIMATED_IMAGE_EXTENSION = "gif";
|
|
public static final String DEFAULT_ICON = "asset://asset/images/default_icon.jpg";
|
|
public static final String DEFAULT_ICON_BLURPLE = "asset://asset/images/default_icon_selected.jpg";
|
|
private static final List<String> GROUP_DM_DEFAULT_ICONS;
|
|
private static final int IMAGE_SIZE_ASSET_DEFAULT_PX = 160;
|
|
public static final IconUtils INSTANCE = new IconUtils();
|
|
private static final Integer[] MEDIA_PROXY_SIZES = {16, 20, 32, 40, 64, 80, 128, Integer.valueOf((int) IMAGE_SIZE_ASSET_DEFAULT_PX), 256, 320, 512, 640, 1024, 1280, 1536, 2048, 3072, 4096};
|
|
@DimenRes
|
|
private static final int UNRESTRICTED = 2131165298;
|
|
|
|
static {
|
|
IntRange intRange = new IntRange(0, 7);
|
|
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(intRange, 10));
|
|
Iterator<Integer> it = intRange.iterator();
|
|
while (it.hasNext()) {
|
|
arrayList.add("asset://asset/images/group_dm_icon_" + ((c0) it).nextInt() + ".png");
|
|
}
|
|
GROUP_DM_DEFAULT_ICONS = arrayList;
|
|
}
|
|
|
|
private IconUtils() {
|
|
}
|
|
|
|
public static final String getApplicationIcon(long j, String str, int i) {
|
|
m.checkNotNullParameter(str, "imageId");
|
|
return "https://cdn.discordapp.com/app-icons/" + j + MentionUtilsKt.SLASH_CHAR + str + '.' + StringUtilsKt.getSTATIC_IMAGE_EXTENSION() + "?size=" + i;
|
|
}
|
|
|
|
public static /* synthetic */ String getApplicationIcon$default(long j, String str, int i, int i2, Object obj) {
|
|
if ((i2 & 4) != 0) {
|
|
i = IMAGE_SIZE_ASSET_DEFAULT_PX;
|
|
}
|
|
return getApplicationIcon(j, str, i);
|
|
}
|
|
|
|
public static /* synthetic */ String getAssetImage$default(IconUtils iconUtils, Long l, String str, int i, int i2, Object obj) {
|
|
if ((i2 & 4) != 0) {
|
|
i = IMAGE_SIZE_ASSET_DEFAULT_PX;
|
|
}
|
|
return iconUtils.getAssetImage(l, str, i);
|
|
}
|
|
|
|
private final String getAssetPlatformUrl(String str, String str2) {
|
|
if (str.hashCode() == -1998723398 && str.equals("spotify")) {
|
|
return a.s("https://i.scdn.co/image/", str2);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static /* synthetic */ String getBannerForGuild$default(IconUtils iconUtils, Guild guild, Integer num, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
num = null;
|
|
}
|
|
return iconUtils.getBannerForGuild(guild, num);
|
|
}
|
|
|
|
public static /* synthetic */ String getBannerForGuild$default(IconUtils iconUtils, Long l, String str, Integer num, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
num = null;
|
|
}
|
|
return iconUtils.getBannerForGuild(l, str, num);
|
|
}
|
|
|
|
public static final String getForChannel(long j, String str, int i, boolean z2, Integer num) {
|
|
boolean z3 = false;
|
|
if (!(str == null || str.length() == 0)) {
|
|
if (BuildConfig.HOST_CDN.length() == 0) {
|
|
z3 = true;
|
|
}
|
|
if (z3) {
|
|
return "https://discord.com/api//channels/" + j + "/icons/" + str + ".jpg";
|
|
}
|
|
IconUtils iconUtils = INSTANCE;
|
|
return iconUtils.withSize("https://cdn.discordapp.com/channel-icons/" + j + MentionUtilsKt.SLASH_CHAR + str + '.' + StringUtilsKt.getSTATIC_IMAGE_EXTENSION(), num);
|
|
} else if (i == 3) {
|
|
return INSTANCE.getDefaultForGroupDM(j);
|
|
} else {
|
|
if (z2) {
|
|
return "";
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static final String getForChannel(Channel channel, Integer num) {
|
|
if (channel == null) {
|
|
return null;
|
|
}
|
|
return channel.A() == 1 ? getForUser$default(AnimatableValueParser.v0(channel), false, null, 6, null) : getForChannel(channel.h(), channel.g(), channel.A(), false, num);
|
|
}
|
|
|
|
public static /* synthetic */ String getForChannel$default(long j, String str, int i, boolean z2, Integer num, int i2, Object obj) {
|
|
if ((i2 & 16) != 0) {
|
|
num = null;
|
|
}
|
|
return getForChannel(j, str, i, z2, num);
|
|
}
|
|
|
|
public static /* synthetic */ String getForChannel$default(Channel channel, Integer num, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
num = null;
|
|
}
|
|
return getForChannel(channel, num);
|
|
}
|
|
|
|
public static final String getForGuild(Guild guild) {
|
|
return getForGuild$default(guild, null, false, null, 14, null);
|
|
}
|
|
|
|
public static final String getForGuild(Guild guild, String str) {
|
|
return getForGuild$default(guild, str, false, null, 12, null);
|
|
}
|
|
|
|
public static final String getForGuild(Guild guild, String str, boolean z2) {
|
|
return getForGuild$default(guild, str, z2, null, 8, null);
|
|
}
|
|
|
|
public static final String getForGuild(Guild guild, String str, boolean z2, Integer num) {
|
|
String str2 = null;
|
|
Long valueOf = guild != null ? Long.valueOf(guild.getId()) : null;
|
|
if (guild != null) {
|
|
str2 = guild.getIcon();
|
|
}
|
|
return getForGuild(valueOf, str2, str, z2, num);
|
|
}
|
|
|
|
public static final String getForGuild(Long l, String str) {
|
|
return getForGuild$default(l, str, null, false, null, 28, null);
|
|
}
|
|
|
|
public static final String getForGuild(Long l, String str, String str2) {
|
|
return getForGuild$default(l, str, str2, false, null, 24, null);
|
|
}
|
|
|
|
public static final String getForGuild(Long l, String str, String str2, boolean z2) {
|
|
return getForGuild$default(l, str, str2, z2, null, 16, null);
|
|
}
|
|
|
|
public static final String getForGuild(Long l, String str, String str2, boolean z2, Integer num) {
|
|
String str3;
|
|
if (TextUtils.isEmpty(str) || l == null) {
|
|
return str2;
|
|
}
|
|
String str4 = null;
|
|
Integer valueOf = num != null ? Integer.valueOf(getMediaProxySize(num.intValue())) : null;
|
|
StringBuilder sb = new StringBuilder();
|
|
if (BuildConfig.HOST_CDN.length() == 0) {
|
|
str3 = "https://discord.com/api//guilds/" + l + "/icons/" + str + ".jpg";
|
|
} else {
|
|
IconUtils iconUtils = INSTANCE;
|
|
m.checkNotNull(str);
|
|
str3 = "https://cdn.discordapp.com/icons/" + l + MentionUtilsKt.SLASH_CHAR + str + '.' + iconUtils.getImageExtension(str, z2);
|
|
}
|
|
sb.append(str3);
|
|
if (valueOf != null) {
|
|
str4 = a.j("?size=", valueOf.intValue());
|
|
}
|
|
if (str4 == null) {
|
|
str4 = "";
|
|
}
|
|
sb.append(str4);
|
|
return sb.toString();
|
|
}
|
|
|
|
public static /* synthetic */ String getForGuild$default(Guild guild, String str, boolean z2, Integer num, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
str = null;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
z2 = false;
|
|
}
|
|
if ((i & 8) != 0) {
|
|
num = null;
|
|
}
|
|
return getForGuild(guild, str, z2, num);
|
|
}
|
|
|
|
public static /* synthetic */ String getForGuild$default(Long l, String str, String str2, boolean z2, Integer num, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
str2 = null;
|
|
}
|
|
if ((i & 8) != 0) {
|
|
z2 = false;
|
|
}
|
|
if ((i & 16) != 0) {
|
|
num = null;
|
|
}
|
|
return getForGuild(l, str, str2, z2, num);
|
|
}
|
|
|
|
public static /* synthetic */ String getForGuildMember$default(IconUtils iconUtils, GuildMember guildMember, Integer num, boolean z2, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
num = null;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
z2 = false;
|
|
}
|
|
return iconUtils.getForGuildMember(guildMember, num, z2);
|
|
}
|
|
|
|
public static /* synthetic */ String getForGuildMember$default(IconUtils iconUtils, String str, long j, long j2, Integer num, boolean z2, int i, Object obj) {
|
|
return iconUtils.getForGuildMember(str, j, j2, (i & 8) != 0 ? null : num, (i & 16) != 0 ? false : z2);
|
|
}
|
|
|
|
public static /* synthetic */ String getForGuildMemberOrUser$default(IconUtils iconUtils, User user, GuildMember guildMember, Integer num, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
num = null;
|
|
}
|
|
return iconUtils.getForGuildMemberOrUser(user, guildMember, num);
|
|
}
|
|
|
|
public static final String getForUser(User user) {
|
|
return getForUser$default(user, false, null, 6, null);
|
|
}
|
|
|
|
public static final String getForUser(User user, boolean z2) {
|
|
return getForUser$default(user, z2, null, 4, null);
|
|
}
|
|
|
|
public static final String getForUser(User user, boolean z2, Integer num) {
|
|
Integer num2 = null;
|
|
Long valueOf = user != null ? Long.valueOf(user.getId()) : null;
|
|
String avatar = user != null ? user.getAvatar() : null;
|
|
if (user != null) {
|
|
num2 = Integer.valueOf(user.getDiscriminator());
|
|
}
|
|
return getForUser(valueOf, avatar, num2, z2, num);
|
|
}
|
|
|
|
public static final String getForUser(Long l, String str) {
|
|
return getForUser$default(l, str, null, false, null, 28, null);
|
|
}
|
|
|
|
public static final String getForUser(Long l, String str, Integer num) {
|
|
return getForUser$default(l, str, num, false, null, 24, null);
|
|
}
|
|
|
|
public static final String getForUser(Long l, String str, Integer num, boolean z2) {
|
|
return getForUser$default(l, str, num, z2, null, 16, null);
|
|
}
|
|
|
|
public static final String getForUser(Long l, String str, Integer num, boolean z2, Integer num2) {
|
|
int i = 0;
|
|
if (l != null) {
|
|
if (-1 == l.longValue()) {
|
|
return str;
|
|
}
|
|
if (str != null) {
|
|
if (BuildConfig.HOST_CDN.length() == 0) {
|
|
i = 1;
|
|
}
|
|
if (i != 0) {
|
|
return "https://discord.com/api//users/" + l + "/avatars/" + str + ".jpg";
|
|
}
|
|
IconUtils iconUtils = INSTANCE;
|
|
String imageExtension = iconUtils.getImageExtension(str, z2);
|
|
return iconUtils.withSize("https://cdn.discordapp.com/avatars/" + l + MentionUtilsKt.SLASH_CHAR + str + '.' + imageExtension, num2);
|
|
} else if (num != null) {
|
|
i = num.intValue() % 5;
|
|
}
|
|
}
|
|
return a.k("asset://asset/images/default_avatar_", i, ".png");
|
|
}
|
|
|
|
public static /* synthetic */ String getForUser$default(User user, boolean z2, Integer num, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
z2 = false;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
num = null;
|
|
}
|
|
return getForUser(user, z2, num);
|
|
}
|
|
|
|
public static /* synthetic */ String getForUser$default(Long l, String str, Integer num, boolean z2, Integer num2, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
num = null;
|
|
}
|
|
if ((i & 8) != 0) {
|
|
z2 = false;
|
|
}
|
|
if ((i & 16) != 0) {
|
|
num2 = null;
|
|
}
|
|
return getForUser(l, str, num, z2, num2);
|
|
}
|
|
|
|
public static /* synthetic */ String getForUserBanner$default(IconUtils iconUtils, long j, String str, Integer num, boolean z2, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
num = null;
|
|
}
|
|
return iconUtils.getForUserBanner(j, str, num, (i & 8) != 0 ? false : z2);
|
|
}
|
|
|
|
public static /* synthetic */ String getGiftSplashUrl$default(IconUtils iconUtils, long j, String str, Integer num, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
num = null;
|
|
}
|
|
return iconUtils.getGiftSplashUrl(j, str, num);
|
|
}
|
|
|
|
public static /* synthetic */ String getGuildSplashUrl$default(IconUtils iconUtils, long j, String str, Integer num, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
num = null;
|
|
}
|
|
return iconUtils.getGuildSplashUrl(j, str, num);
|
|
}
|
|
|
|
public static /* synthetic */ String getGuildSplashUrl$default(IconUtils iconUtils, Guild guild, Integer num, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
num = null;
|
|
}
|
|
return iconUtils.getGuildSplashUrl(guild, num);
|
|
}
|
|
|
|
public static final int getMediaProxySize(int i) {
|
|
Integer[] numArr = MEDIA_PROXY_SIZES;
|
|
for (Integer num : numArr) {
|
|
if (num.intValue() >= i) {
|
|
return num.intValue();
|
|
}
|
|
}
|
|
throw new NoSuchElementException("Array contains no element matching the predicate.");
|
|
}
|
|
|
|
public static /* synthetic */ String getRoleIconUrl$default(IconUtils iconUtils, long j, String str, Integer num, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
num = null;
|
|
}
|
|
return iconUtils.getRoleIconUrl(j, str, num);
|
|
}
|
|
|
|
public static final void setApplicationIcon(ImageView imageView, Application application) {
|
|
m.checkNotNullParameter(imageView, "imageView");
|
|
m.checkNotNullParameter(application, "application");
|
|
String applicationIcon = INSTANCE.getApplicationIcon(application);
|
|
if (application.getIconRes() == null || ApplicationKt.hasBotAvatar(application)) {
|
|
MGImages.setImage$default(imageView, applicationIcon, 0, 0, false, null, null, 124, null);
|
|
return;
|
|
}
|
|
int themedColor = ColorCompat.getThemedColor(imageView, (int) R.attr.colorTextMuted);
|
|
Context context = imageView.getContext();
|
|
m.checkNotNullExpressionValue(context, "imageView.context");
|
|
Drawable drawable$default = DrawableCompat.getDrawable$default(context, application.getIconRes().intValue(), themedColor, false, 4, null);
|
|
if (drawable$default != null) {
|
|
MGImages.setImage$default(MGImages.INSTANCE, imageView, drawable$default, (MGImages.ChangeDetector) null, 4, (Object) null);
|
|
} else {
|
|
MGImages.setImage$default(MGImages.INSTANCE, imageView, application.getIconRes().intValue(), (MGImages.ChangeDetector) null, 4, (Object) null);
|
|
}
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, Channel channel) {
|
|
setIcon$default(imageView, channel, 0, (MGImages.ChangeDetector) null, 12, (Object) null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, Channel channel, @DimenRes int i) {
|
|
setIcon$default(imageView, channel, i, (MGImages.ChangeDetector) null, 8, (Object) null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, Channel channel, @DimenRes int i, MGImages.ChangeDetector changeDetector) {
|
|
m.checkNotNullParameter(imageView, "imageView");
|
|
m.checkNotNullParameter(changeDetector, "changeDetector");
|
|
String str = null;
|
|
setIcon$default(imageView, getForChannel$default(channel, null, 2, null), i, (Function1) null, changeDetector, 8, (Object) null);
|
|
if (channel != null) {
|
|
str = AnimatableValueParser.y0(channel);
|
|
}
|
|
imageView.setContentDescription(str);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, GuildRole guildRole) {
|
|
setIcon$default(imageView, guildRole, 0, (MGImages.ChangeDetector) null, 12, (Object) null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, GuildRole guildRole, @DimenRes int i) {
|
|
setIcon$default(imageView, guildRole, i, (MGImages.ChangeDetector) null, 8, (Object) null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, GuildRole guildRole, @DimenRes int i, MGImages.ChangeDetector changeDetector) {
|
|
String d;
|
|
m.checkNotNullParameter(imageView, "imageView");
|
|
m.checkNotNullParameter(changeDetector, "changeDetector");
|
|
if (guildRole != null && (d = guildRole.d()) != null) {
|
|
setIcon$default(imageView, getRoleIconUrl$default(INSTANCE, guildRole.getId(), d, null, 4, null), i, (Function1) null, changeDetector, 8, (Object) null);
|
|
}
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, Guild guild) {
|
|
setIcon$default(imageView, guild, 0, (MGImages.ChangeDetector) null, false, 28, (Object) null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, Guild guild, @DimenRes int i) {
|
|
setIcon$default(imageView, guild, i, (MGImages.ChangeDetector) null, false, 24, (Object) null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, Guild guild, @DimenRes int i, MGImages.ChangeDetector changeDetector) {
|
|
setIcon$default(imageView, guild, i, changeDetector, false, 16, (Object) null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, Guild guild, @DimenRes int i, MGImages.ChangeDetector changeDetector, boolean z2) {
|
|
m.checkNotNullParameter(imageView, "imageView");
|
|
m.checkNotNullParameter(changeDetector, "changeDetector");
|
|
setIcon$default(imageView, getForGuild$default(guild, null, z2, null, 10, null), i, (Function1) null, changeDetector, 8, (Object) null);
|
|
imageView.setContentDescription(guild != null ? guild.getName() : null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, User user) {
|
|
setIcon$default(imageView, user, 0, null, null, null, 60, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, User user, @DimenRes int i) {
|
|
setIcon$default(imageView, user, i, null, null, null, 56, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, User user, @DimenRes int i, Function1<? super ImageRequestBuilder, Unit> function1) {
|
|
setIcon$default(imageView, user, i, function1, null, null, 48, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, User user, @DimenRes int i, Function1<? super ImageRequestBuilder, Unit> function1, MGImages.ChangeDetector changeDetector) {
|
|
setIcon$default(imageView, user, i, function1, changeDetector, null, 32, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, User user, @DimenRes int i, Function1<? super ImageRequestBuilder, Unit> function1, MGImages.ChangeDetector changeDetector, GuildMember guildMember) {
|
|
m.checkNotNullParameter(imageView, "imageView");
|
|
m.checkNotNullParameter(changeDetector, "changeDetector");
|
|
Integer num = null;
|
|
String username = user != null ? user.getUsername() : null;
|
|
Long valueOf = user != null ? Long.valueOf(user.getId()) : null;
|
|
String avatar = user != null ? user.getAvatar() : null;
|
|
if (user != null) {
|
|
num = Integer.valueOf(user.getDiscriminator());
|
|
}
|
|
setIcon(imageView, username, valueOf, avatar, num, i, function1, changeDetector, guildMember);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str) {
|
|
setIcon$default(imageView, str, 0, (Function1) null, (MGImages.ChangeDetector) null, 28, (Object) null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, @DimenRes int i) {
|
|
setIcon$default(imageView, str, i, (Function1) null, (MGImages.ChangeDetector) null, 24, (Object) null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, int i, int i2) {
|
|
setIcon$default(imageView, str, i, i2, false, null, null, 112, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, int i, int i2, boolean z2) {
|
|
setIcon$default(imageView, str, i, i2, z2, null, null, 96, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, int i, int i2, boolean z2, Function1<? super ImageRequestBuilder, Unit> function1) {
|
|
setIcon$default(imageView, str, i, i2, z2, function1, null, 64, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, int i, int i2, boolean z2, Function1<? super ImageRequestBuilder, Unit> function1, MGImages.ChangeDetector changeDetector) {
|
|
m.checkNotNullParameter(imageView, "imageView");
|
|
m.checkNotNullParameter(changeDetector, "changeDetector");
|
|
MGImages.setImage(imageView, str, i, i2, z2, function1, changeDetector);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, @DimenRes int i, Function1<? super ImageRequestBuilder, Unit> function1) {
|
|
setIcon$default(imageView, str, i, function1, (MGImages.ChangeDetector) null, 16, (Object) null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, @DimenRes int i, Function1<? super ImageRequestBuilder, Unit> function1, MGImages.ChangeDetector changeDetector) {
|
|
m.checkNotNullParameter(imageView, "imageView");
|
|
m.checkNotNullParameter(changeDetector, "changeDetector");
|
|
setIcon(imageView, str, imageView.getResources().getDimensionPixelSize(i), imageView.getResources().getDimensionPixelSize(i), true, function1, changeDetector);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, Long l, String str2, Integer num) {
|
|
setIcon$default(imageView, str, l, str2, num, 0, null, null, null, 480, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, Long l, String str2, Integer num, @DimenRes int i) {
|
|
setIcon$default(imageView, str, l, str2, num, i, null, null, null, 448, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, Long l, String str2, Integer num, @DimenRes int i, Function1<? super ImageRequestBuilder, Unit> function1) {
|
|
setIcon$default(imageView, str, l, str2, num, i, function1, null, null, 384, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, Long l, String str2, Integer num, @DimenRes int i, Function1<? super ImageRequestBuilder, Unit> function1, MGImages.ChangeDetector changeDetector) {
|
|
setIcon$default(imageView, str, l, str2, num, i, function1, changeDetector, null, 256, null);
|
|
}
|
|
|
|
public static final void setIcon(ImageView imageView, String str, Long l, String str2, Integer num, @DimenRes int i, Function1<? super ImageRequestBuilder, Unit> function1, MGImages.ChangeDetector changeDetector, GuildMember guildMember) {
|
|
m.checkNotNullParameter(imageView, "imageView");
|
|
m.checkNotNullParameter(changeDetector, "changeDetector");
|
|
Integer valueOf = i != R.dimen.avatar_size_unrestricted ? Integer.valueOf(imageView.getResources().getDimensionPixelSize(i)) : null;
|
|
setIcon$default(imageView, (guildMember == null || !guildMember.hasAvatar()) ? getForUser$default(l, str2, num, false, valueOf, 8, null) : getForGuildMember$default(INSTANCE, guildMember, valueOf, false, 4, null), valueOf != null ? valueOf.intValue() : 0, valueOf != null ? valueOf.intValue() : 0, false, function1, changeDetector, 16, null);
|
|
imageView.setContentDescription(str);
|
|
}
|
|
|
|
public static /* synthetic */ void setIcon$default(ImageView imageView, Channel channel, int i, MGImages.ChangeDetector changeDetector, int i2, Object obj) {
|
|
if ((i2 & 4) != 0) {
|
|
i = R.dimen.avatar_size_unrestricted;
|
|
}
|
|
if ((i2 & 8) != 0) {
|
|
changeDetector = MGImages.AlwaysUpdateChangeDetector.INSTANCE;
|
|
}
|
|
setIcon(imageView, channel, i, changeDetector);
|
|
}
|
|
|
|
public static /* synthetic */ void setIcon$default(ImageView imageView, GuildRole guildRole, int i, MGImages.ChangeDetector changeDetector, int i2, Object obj) {
|
|
if ((i2 & 4) != 0) {
|
|
i = R.dimen.avatar_size_unrestricted;
|
|
}
|
|
if ((i2 & 8) != 0) {
|
|
changeDetector = MGImages.AlwaysUpdateChangeDetector.INSTANCE;
|
|
}
|
|
setIcon(imageView, guildRole, i, changeDetector);
|
|
}
|
|
|
|
public static /* synthetic */ void setIcon$default(ImageView imageView, Guild guild, int i, MGImages.ChangeDetector changeDetector, boolean z2, int i2, Object obj) {
|
|
if ((i2 & 4) != 0) {
|
|
i = R.dimen.avatar_size_unrestricted;
|
|
}
|
|
if ((i2 & 8) != 0) {
|
|
changeDetector = MGImages.AlwaysUpdateChangeDetector.INSTANCE;
|
|
}
|
|
if ((i2 & 16) != 0) {
|
|
z2 = false;
|
|
}
|
|
setIcon(imageView, guild, i, changeDetector, z2);
|
|
}
|
|
|
|
public static /* synthetic */ void setIcon$default(ImageView imageView, User user, int i, Function1 function1, MGImages.ChangeDetector changeDetector, GuildMember guildMember, int i2, Object obj) {
|
|
int i3 = (i2 & 4) != 0 ? R.dimen.avatar_size_unrestricted : i;
|
|
Function1 function12 = (i2 & 8) != 0 ? null : function1;
|
|
if ((i2 & 16) != 0) {
|
|
changeDetector = MGImages.AlwaysUpdateChangeDetector.INSTANCE;
|
|
}
|
|
setIcon(imageView, user, i3, function12, changeDetector, (i2 & 32) != 0 ? null : guildMember);
|
|
}
|
|
|
|
public static /* synthetic */ void setIcon$default(ImageView imageView, String str, int i, int i2, boolean z2, Function1 function1, MGImages.ChangeDetector changeDetector, int i3, Object obj) {
|
|
boolean z3 = (i3 & 16) != 0 ? true : z2;
|
|
if ((i3 & 32) != 0) {
|
|
function1 = null;
|
|
}
|
|
if ((i3 & 64) != 0) {
|
|
changeDetector = MGImages.AlwaysUpdateChangeDetector.INSTANCE;
|
|
}
|
|
setIcon(imageView, str, i, i2, z3, function1, changeDetector);
|
|
}
|
|
|
|
public static /* synthetic */ void setIcon$default(ImageView imageView, String str, int i, Function1 function1, MGImages.ChangeDetector changeDetector, int i2, Object obj) {
|
|
if ((i2 & 4) != 0) {
|
|
i = R.dimen.avatar_size_unrestricted;
|
|
}
|
|
if ((i2 & 8) != 0) {
|
|
function1 = null;
|
|
}
|
|
if ((i2 & 16) != 0) {
|
|
changeDetector = MGImages.AlwaysUpdateChangeDetector.INSTANCE;
|
|
}
|
|
setIcon(imageView, str, i, function1, changeDetector);
|
|
}
|
|
|
|
public static /* synthetic */ void setIcon$default(ImageView imageView, String str, Long l, String str2, Integer num, int i, Function1 function1, MGImages.ChangeDetector changeDetector, GuildMember guildMember, int i2, Object obj) {
|
|
setIcon(imageView, str, l, str2, num, (i2 & 32) != 0 ? R.dimen.avatar_size_unrestricted : i, (i2 & 64) != 0 ? null : function1, (i2 & 128) != 0 ? MGImages.AlwaysUpdateChangeDetector.INSTANCE : changeDetector, (i2 & 256) != 0 ? null : guildMember);
|
|
}
|
|
|
|
private final String withSize(String str, Integer num) {
|
|
if (str == null || num == null || num.intValue() <= 0) {
|
|
return str;
|
|
}
|
|
StringBuilder P = a.P(str, "?size=");
|
|
P.append(getMediaProxySize(num.intValue()));
|
|
return P.toString();
|
|
}
|
|
|
|
public final String getApplicationIcon(Application application) {
|
|
m.checkNotNullParameter(application, "application");
|
|
com.discord.api.user.User bot = application.getBot();
|
|
String icon = application.getIcon();
|
|
String str = null;
|
|
if (icon == null || t.isBlank(icon)) {
|
|
icon = null;
|
|
}
|
|
CoreUser coreUser = bot != null ? new CoreUser(bot) : null;
|
|
boolean z2 = coreUser != null && (bot.a() instanceof NullSerializable.b);
|
|
int discriminator = (coreUser != null ? coreUser.getDiscriminator() : 0) % 5;
|
|
if (z2) {
|
|
str = getForUser$default(coreUser, false, null, 6, null);
|
|
} else if (icon != null) {
|
|
str = getApplicationIcon(application.getId(), icon, IMAGE_SIZE_ASSET_DEFAULT_PX);
|
|
}
|
|
return str != null ? str : a.k("asset://asset/images/default_avatar_", discriminator, ".png");
|
|
}
|
|
|
|
@SuppressLint({"DefaultLocale"})
|
|
public final String getAssetImage(Long l, String str, int i) {
|
|
m.checkNotNullParameter(str, "imageId");
|
|
if (w.contains$default((CharSequence) str, (char) MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR, false, 2, (Object) null)) {
|
|
List split$default = w.split$default((CharSequence) str, new char[]{MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR}, false, 2, 2, (Object) null);
|
|
String str2 = (String) split$default.get(0);
|
|
Objects.requireNonNull(str2, "null cannot be cast to non-null type java.lang.String");
|
|
String lowerCase = str2.toLowerCase();
|
|
m.checkNotNullExpressionValue(lowerCase, "(this as java.lang.String).toLowerCase()");
|
|
return getAssetPlatformUrl(lowerCase, (String) split$default.get(1));
|
|
} else if (l == null) {
|
|
return null;
|
|
} else {
|
|
return "https://cdn.discordapp.com/app-assets/" + l + MentionUtilsKt.SLASH_CHAR + str + ".jpg?size=" + i;
|
|
}
|
|
}
|
|
|
|
public final String getBannerForGuild(Guild guild, Integer num) {
|
|
String str = null;
|
|
Long valueOf = guild != null ? Long.valueOf(guild.getId()) : null;
|
|
if (guild != null) {
|
|
str = guild.getBanner();
|
|
}
|
|
return getBannerForGuild(valueOf, str, num);
|
|
}
|
|
|
|
public final String getBannerForGuild(Long l, String str, Integer num) {
|
|
String str2 = null;
|
|
if (l == null || str == null) {
|
|
return null;
|
|
}
|
|
Integer valueOf = num != null ? Integer.valueOf(getMediaProxySize(num.intValue())) : null;
|
|
if (BuildConfig.HOST_CDN.length() == 0) {
|
|
return "https://discord.com/api//guilds/" + l + "/banners/" + str + ".jpg";
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("https://cdn.discordapp.com/banners/");
|
|
sb.append(l);
|
|
sb.append(MentionUtilsKt.SLASH_CHAR);
|
|
sb.append(str);
|
|
sb.append(".jpg");
|
|
if (valueOf != null) {
|
|
str2 = a.j("?size=", valueOf.intValue());
|
|
}
|
|
if (str2 == null) {
|
|
str2 = "";
|
|
}
|
|
sb.append(str2);
|
|
return sb.toString();
|
|
}
|
|
|
|
public final String getDefaultForGroupDM(long j) {
|
|
long j2 = (j >>> 22) + SnowflakeUtils.DISCORD_EPOCH;
|
|
List<String> list = GROUP_DM_DEFAULT_ICONS;
|
|
return list.get((int) (j2 % ((long) list.size())));
|
|
}
|
|
|
|
public final String getForGuildMember(GuildMember guildMember, Integer num, boolean z2) {
|
|
m.checkNotNullParameter(guildMember, "guildMember");
|
|
return getForGuildMember(guildMember.getAvatarHash(), guildMember.getGuildId(), guildMember.getUserId(), num, z2);
|
|
}
|
|
|
|
public final String getForGuildMember(String str, long j, long j2, Integer num, boolean z2) {
|
|
if ((str == null || t.isBlank(str)) || j == 0 || j2 == 0) {
|
|
return null;
|
|
}
|
|
String imageExtension = getImageExtension(str, z2);
|
|
StringBuilder O = a.O("https://cdn.discordapp.com/guilds/", j, "/users/");
|
|
O.append(j2);
|
|
O.append("/avatars/");
|
|
O.append(str);
|
|
O.append('.');
|
|
O.append(imageExtension);
|
|
return withSize(O.toString(), num);
|
|
}
|
|
|
|
public final String getForGuildMemberOrUser(User user, GuildMember guildMember, Integer num) {
|
|
return (guildMember == null || !guildMember.hasAvatar()) ? getForUser$default(user, false, num, 2, null) : getForGuildMember$default(this, guildMember, num, false, 4, null);
|
|
}
|
|
|
|
public final String getForUserBanner(long j, String str, Integer num, boolean z2) {
|
|
if (str == null || t.isBlank(str)) {
|
|
return null;
|
|
}
|
|
String imageExtension = getImageExtension(str, z2);
|
|
return withSize("https://cdn.discordapp.com/banners/" + j + MentionUtilsKt.SLASH_CHAR + str + '.' + imageExtension, num);
|
|
}
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:20:0x005e, code lost:
|
|
if (r0 != null) goto L_0x0063;
|
|
*/
|
|
public final String getGiftSplashUrl(long j, String str, Integer num) {
|
|
String str2;
|
|
Integer num2 = null;
|
|
if (str == null) {
|
|
return null;
|
|
}
|
|
if (num != null) {
|
|
num.intValue();
|
|
Integer[] numArr = MEDIA_PROXY_SIZES;
|
|
int length = numArr.length;
|
|
int i = 0;
|
|
while (true) {
|
|
if (i >= length) {
|
|
break;
|
|
}
|
|
Integer num3 = numArr[i];
|
|
if (num3.intValue() > num.intValue()) {
|
|
num2 = num3;
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
num2 = Integer.valueOf(num2 != null ? num2.intValue() : ((Number) k.last(MEDIA_PROXY_SIZES)).intValue());
|
|
}
|
|
StringBuilder L = a.L("?");
|
|
if (num2 != null) {
|
|
num2.intValue();
|
|
str2 = "size=" + num2 + "&keep_aspect_ratio=true";
|
|
}
|
|
str2 = "keep_aspect_ratio=true";
|
|
L.append(str2);
|
|
return "https://cdn.discordapp.com/app-icons/" + j + MentionUtilsKt.SLASH_CHAR + str + '.' + StringUtilsKt.getSTATIC_IMAGE_EXTENSION() + L.toString();
|
|
}
|
|
|
|
public final String getGuildSplashUrl(long j, String str, Integer num) {
|
|
String str2;
|
|
m.checkNotNullParameter(str, "splashHash");
|
|
String str3 = null;
|
|
Integer valueOf = num != null ? Integer.valueOf(getMediaProxySize(num.intValue())) : null;
|
|
if (BuildConfig.HOST_CDN.length() == 0) {
|
|
str2 = "https://discord.com/api//guilds/" + j + "/splashes/" + str + ".jpg";
|
|
} else {
|
|
str2 = "https://cdn.discordapp.com/splashes/" + j + MentionUtilsKt.SLASH_CHAR + str + ".jpg";
|
|
}
|
|
StringBuilder L = a.L(str2);
|
|
if (valueOf != null) {
|
|
str3 = a.j("?size=", valueOf.intValue());
|
|
}
|
|
if (str3 == null) {
|
|
str3 = "";
|
|
}
|
|
L.append(str3);
|
|
return L.toString();
|
|
}
|
|
|
|
public final String getGuildSplashUrl(Guild guild, Integer num) {
|
|
if ((guild != null ? guild.getSplash() : null) == null) {
|
|
return null;
|
|
}
|
|
return getGuildSplashUrl(guild.getId(), guild.getSplash(), num);
|
|
}
|
|
|
|
public final String getImageExtension(String str, boolean z2) {
|
|
m.checkNotNullParameter(str, "imageHash");
|
|
return (!z2 || !isImageHashAnimated(str)) ? StringUtilsKt.getSTATIC_IMAGE_EXTENSION() : ANIMATED_IMAGE_EXTENSION;
|
|
}
|
|
|
|
public final String getRoleIconUrl(long j, String str, Integer num) {
|
|
String str2;
|
|
m.checkNotNullParameter(str, "iconHash");
|
|
String str3 = null;
|
|
Integer valueOf = num != null ? Integer.valueOf(getMediaProxySize(num.intValue())) : null;
|
|
if (BuildConfig.HOST_CDN.length() == 0) {
|
|
str2 = "https://discord.com/api//roles/" + j + "/icons/" + str + ".png";
|
|
} else {
|
|
str2 = "https://cdn.discordapp.com/role-icons/" + j + MentionUtilsKt.SLASH_CHAR + str + ".png";
|
|
}
|
|
StringBuilder L = a.L(str2);
|
|
if (valueOf != null) {
|
|
str3 = a.j("?size=", valueOf.intValue());
|
|
}
|
|
if (str3 == null) {
|
|
str3 = "";
|
|
}
|
|
L.append(str3);
|
|
return L.toString();
|
|
}
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:40:0x00b1 A[RETURN, SYNTHETIC] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:43:0x00bd A[RETURN, SYNTHETIC] */
|
|
@DrawableRes
|
|
public final int getVoiceRegionIconResourceId(String str) {
|
|
if (str != null) {
|
|
switch (str.hashCode()) {
|
|
case -1904464552:
|
|
if (str.equals("eu-central")) {
|
|
return R.drawable.icon_flag_eu;
|
|
}
|
|
break;
|
|
case -1867973154:
|
|
if (str.equals("us-south")) {
|
|
return R.drawable.icon_flag_en_us;
|
|
}
|
|
break;
|
|
case -1504353500:
|
|
if (str.equals("singapore")) {
|
|
return R.drawable.icon_flag_sg;
|
|
}
|
|
break;
|
|
case -1456593748:
|
|
if (str.equals("eu-west")) {
|
|
}
|
|
break;
|
|
case -1433771706:
|
|
if (str.equals("us-central")) {
|
|
}
|
|
break;
|
|
case -1381018772:
|
|
if (str.equals("brazil")) {
|
|
return R.drawable.icon_flag_pt_br;
|
|
}
|
|
break;
|
|
case -1097131496:
|
|
if (str.equals("london")) {
|
|
return R.drawable.icon_flag_gb;
|
|
}
|
|
break;
|
|
case -919652293:
|
|
if (str.equals("russia")) {
|
|
return R.drawable.icon_flag_ru;
|
|
}
|
|
break;
|
|
case -887780828:
|
|
if (str.equals("sydney")) {
|
|
return R.drawable.icon_flag_au;
|
|
}
|
|
break;
|
|
case -455031011:
|
|
if (str.equals("hongkong")) {
|
|
return R.drawable.icon_flag_hk;
|
|
}
|
|
break;
|
|
case -199235124:
|
|
if (str.equals("us-east")) {
|
|
}
|
|
break;
|
|
case -198695042:
|
|
if (str.equals("us-west")) {
|
|
}
|
|
break;
|
|
case -135164842:
|
|
if (str.equals("amsterdam")) {
|
|
return R.drawable.icon_flag_nl;
|
|
}
|
|
break;
|
|
case 100893702:
|
|
if (str.equals("japan")) {
|
|
return R.drawable.icon_flag_ja;
|
|
}
|
|
break;
|
|
case 579843043:
|
|
if (str.equals("frankfurt")) {
|
|
return R.drawable.icon_flag_de;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return R.drawable.icon_flag_unknown;
|
|
}
|
|
|
|
public final boolean isDataUrlForGif(String str) {
|
|
m.checkNotNullParameter(str, "dataUrl");
|
|
return t.startsWith$default(str, "data:image/gif", false, 2, null);
|
|
}
|
|
|
|
public final boolean isImageHashAnimated(String str) {
|
|
m.checkNotNullParameter(str, "imageHash");
|
|
return t.startsWith$default(str, "a_", false, 2, null);
|
|
}
|
|
}
|