362 lines
16 KiB
Java
362 lines
16 KiB
Java
package com.discord.views.user;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Bitmap;
|
|
import android.util.AttributeSet;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.ImageView;
|
|
import android.widget.RelativeLayout;
|
|
import androidx.annotation.ColorInt;
|
|
import c.a.i.o1;
|
|
import com.discord.R;
|
|
import com.discord.models.member.GuildMember;
|
|
import com.discord.models.presence.Presence;
|
|
import com.discord.models.user.User;
|
|
import com.discord.utilities.accessibility.AccessibilityUtils;
|
|
import com.discord.utilities.color.ColorCompat;
|
|
import com.discord.utilities.color.ColorCompatKt;
|
|
import com.discord.utilities.icon.IconUtils;
|
|
import com.discord.utilities.images.MGImages;
|
|
import com.discord.utilities.streams.StreamContext;
|
|
import com.discord.views.StatusView;
|
|
import com.facebook.drawee.view.SimpleDraweeView;
|
|
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|
import d0.g0.t;
|
|
import d0.z.d.m;
|
|
import d0.z.d.o;
|
|
import kotlin.TypeCastException;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function1;
|
|
/* compiled from: UserAvatarPresenceView.kt */
|
|
public final class UserAvatarPresenceView extends RelativeLayout {
|
|
public final o1 i;
|
|
public final MGImages.DistinctChangeDetector j;
|
|
public int k;
|
|
public Function1<? super Bitmap, Unit> l;
|
|
|
|
/* compiled from: UserAvatarPresenceView.kt */
|
|
public static final class a {
|
|
public final User a;
|
|
public final Presence b;
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
|
public final StreamContext f2149c;
|
|
public final boolean d;
|
|
public final GuildMember e;
|
|
|
|
public a(User user, Presence presence, StreamContext streamContext, boolean z2, GuildMember guildMember) {
|
|
m.checkNotNullParameter(user, "user");
|
|
this.a = user;
|
|
this.b = presence;
|
|
this.f2149c = streamContext;
|
|
this.d = z2;
|
|
this.e = guildMember;
|
|
}
|
|
|
|
public a(User user, Presence presence, StreamContext streamContext, boolean z2, GuildMember guildMember, int i) {
|
|
int i2 = i & 16;
|
|
m.checkNotNullParameter(user, "user");
|
|
this.a = user;
|
|
this.b = presence;
|
|
this.f2149c = streamContext;
|
|
this.d = z2;
|
|
this.e = null;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof a)) {
|
|
return false;
|
|
}
|
|
a aVar = (a) obj;
|
|
return m.areEqual(this.a, aVar.a) && m.areEqual(this.b, aVar.b) && m.areEqual(this.f2149c, aVar.f2149c) && this.d == aVar.d && m.areEqual(this.e, aVar.e);
|
|
}
|
|
|
|
public int hashCode() {
|
|
User user = this.a;
|
|
int i = 0;
|
|
int hashCode = (user != null ? user.hashCode() : 0) * 31;
|
|
Presence presence = this.b;
|
|
int hashCode2 = (hashCode + (presence != null ? presence.hashCode() : 0)) * 31;
|
|
StreamContext streamContext = this.f2149c;
|
|
int hashCode3 = (hashCode2 + (streamContext != null ? streamContext.hashCode() : 0)) * 31;
|
|
boolean z2 = this.d;
|
|
if (z2) {
|
|
z2 = true;
|
|
}
|
|
int i2 = z2 ? 1 : 0;
|
|
int i3 = z2 ? 1 : 0;
|
|
int i4 = z2 ? 1 : 0;
|
|
int i5 = (hashCode3 + i2) * 31;
|
|
GuildMember guildMember = this.e;
|
|
if (guildMember != null) {
|
|
i = guildMember.hashCode();
|
|
}
|
|
return i5 + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder K = c.d.b.a.a.K("ViewState(user=");
|
|
K.append(this.a);
|
|
K.append(", presence=");
|
|
K.append(this.b);
|
|
K.append(", streamContext=");
|
|
K.append(this.f2149c);
|
|
K.append(", showPresence=");
|
|
K.append(this.d);
|
|
K.append(", guildMember=");
|
|
K.append(this.e);
|
|
K.append(")");
|
|
return K.toString();
|
|
}
|
|
}
|
|
|
|
/* compiled from: UserAvatarPresenceView.kt */
|
|
public static final class b extends o implements Function1<Bitmap, Unit> {
|
|
public static final b i = new b();
|
|
|
|
public b() {
|
|
super(1);
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public Unit invoke(Bitmap bitmap) {
|
|
m.checkNotNullParameter(bitmap, "it");
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
/* compiled from: UserAvatarPresenceView.kt */
|
|
public static final class c extends o implements Function1<ImageRequestBuilder, Unit> {
|
|
public final /* synthetic */ UserAvatarPresenceView this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public c(UserAvatarPresenceView userAvatarPresenceView) {
|
|
super(1);
|
|
this.this$0 = userAvatarPresenceView;
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public Unit invoke(ImageRequestBuilder imageRequestBuilder) {
|
|
ImageRequestBuilder imageRequestBuilder2 = imageRequestBuilder;
|
|
m.checkNotNullParameter(imageRequestBuilder2, "imageRequestBuilder");
|
|
imageRequestBuilder2.j = new c.a.y.q0.a(this);
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
/* compiled from: UserAvatarPresenceView.kt */
|
|
public static final class d extends o implements Function1<ImageRequestBuilder, Unit> {
|
|
public final /* synthetic */ UserAvatarPresenceView this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public d(UserAvatarPresenceView userAvatarPresenceView) {
|
|
super(1);
|
|
this.this$0 = userAvatarPresenceView;
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public Unit invoke(ImageRequestBuilder imageRequestBuilder) {
|
|
ImageRequestBuilder imageRequestBuilder2 = imageRequestBuilder;
|
|
m.checkNotNullParameter(imageRequestBuilder2, "imageRequestBuilder");
|
|
imageRequestBuilder2.j = new c.a.y.q0.b(this);
|
|
return Unit.a;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public UserAvatarPresenceView(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(attributeSet, "attrs");
|
|
View inflate = LayoutInflater.from(context).inflate(2131558717, (ViewGroup) this, false);
|
|
addView(inflate);
|
|
int i = 2131362081;
|
|
SimpleDraweeView simpleDraweeView = (SimpleDraweeView) inflate.findViewById(2131362081);
|
|
if (simpleDraweeView != null) {
|
|
i = 2131362082;
|
|
FrameLayout frameLayout = (FrameLayout) inflate.findViewById(2131362082);
|
|
if (frameLayout != null) {
|
|
i = 2131362083;
|
|
ImageView imageView = (ImageView) inflate.findViewById(2131362083);
|
|
if (imageView != null) {
|
|
i = 2131365201;
|
|
SimpleDraweeView simpleDraweeView2 = (SimpleDraweeView) inflate.findViewById(2131365201);
|
|
if (simpleDraweeView2 != null) {
|
|
RelativeLayout relativeLayout = (RelativeLayout) inflate;
|
|
i = 2131365539;
|
|
StatusView statusView = (StatusView) inflate.findViewById(2131365539);
|
|
if (statusView != null) {
|
|
o1 o1Var = new o1(relativeLayout, simpleDraweeView, frameLayout, imageView, simpleDraweeView2, relativeLayout, statusView);
|
|
m.checkNotNullExpressionValue(o1Var, "UserAvatarPresenceViewBi…rom(context), this, true)");
|
|
this.i = o1Var;
|
|
this.j = new MGImages.DistinctChangeDetector();
|
|
this.l = b.i;
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.a.UserAvatarPresenceView);
|
|
m.checkNotNullExpressionValue(obtainStyledAttributes, "context.obtainStyledAttr…e.UserAvatarPresenceView)");
|
|
int color = obtainStyledAttributes.getColor(0, ColorCompat.getThemedColor(this, 2130969900));
|
|
this.k = obtainStyledAttributes.getDimensionPixelSize(1, 0);
|
|
obtainStyledAttributes.recycle();
|
|
setAvatarBackgroundColor(color);
|
|
m.checkNotNullExpressionValue(simpleDraweeView, "binding.avatar");
|
|
simpleDraweeView.setClipToOutline(true);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw new NullPointerException("Missing required view with ID: ".concat(inflate.getResources().getResourceName(i)));
|
|
}
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:37:0x00a2 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:45:0x00e1 */
|
|
public final void a(a aVar) {
|
|
String str;
|
|
boolean z2;
|
|
String str2;
|
|
m.checkNotNullParameter(aVar, "viewState");
|
|
GuildMember guildMember = aVar.e;
|
|
User user = aVar.a;
|
|
boolean z3 = !AccessibilityUtils.INSTANCE.isReducedMotionEnabled();
|
|
int i = 0;
|
|
if (guildMember == null || !guildMember.hasAvatar()) {
|
|
String avatar = user.getAvatar();
|
|
if (avatar == null || !t.startsWith$default(avatar, "data:", false, 2, null)) {
|
|
String avatar2 = user.getAvatar();
|
|
if (avatar2 != null) {
|
|
z2 = z3 && IconUtils.INSTANCE.isImageHashAnimated(avatar2);
|
|
} else {
|
|
z2 = false;
|
|
}
|
|
str2 = IconUtils.getForUser$default(aVar.a, z3, null, 4, null);
|
|
} else {
|
|
String avatar3 = user.getAvatar();
|
|
if (avatar3 == null || !IconUtils.INSTANCE.isDataUrlForGif(avatar3)) {
|
|
str = avatar3;
|
|
z2 = false;
|
|
} else {
|
|
str = avatar3;
|
|
z2 = true;
|
|
}
|
|
SimpleDraweeView simpleDraweeView = this.i.b;
|
|
m.checkNotNullExpressionValue(simpleDraweeView, "binding.avatar");
|
|
IconUtils.setIcon$default(simpleDraweeView, str, 0, new c(this), this.j, 4, (Object) null);
|
|
if (z2) {
|
|
String forUser$default = (guildMember == null || !guildMember.hasAvatar()) ? IconUtils.getForUser$default(aVar.a, false, null, 4, null) : IconUtils.getForGuildMember$default(IconUtils.INSTANCE, guildMember, null, false, 2, null);
|
|
SimpleDraweeView simpleDraweeView2 = this.i.d;
|
|
m.checkNotNullExpressionValue(simpleDraweeView2, "binding.staticAvatar");
|
|
IconUtils.setIcon$default(simpleDraweeView2, forUser$default, 0, new d(this), this.j, 4, (Object) null);
|
|
}
|
|
StatusView statusView = this.i.e;
|
|
m.checkNotNullExpressionValue(statusView, "binding.userAvatarPresenceStatus");
|
|
if (!aVar.d) {
|
|
i = 8;
|
|
}
|
|
statusView.setVisibility(i);
|
|
this.i.e.setPresence(aVar.b);
|
|
}
|
|
} else {
|
|
String avatarHash = guildMember.getAvatarHash();
|
|
if (avatarHash != null) {
|
|
z2 = z3 && IconUtils.INSTANCE.isImageHashAnimated(avatarHash);
|
|
} else {
|
|
z2 = false;
|
|
}
|
|
str2 = IconUtils.getForGuildMember$default(IconUtils.INSTANCE, guildMember, null, z3, 2, null);
|
|
}
|
|
str = str2;
|
|
SimpleDraweeView simpleDraweeView = this.i.b;
|
|
m.checkNotNullExpressionValue(simpleDraweeView, "binding.avatar");
|
|
IconUtils.setIcon$default(simpleDraweeView, str, 0, new c(this), this.j, 4, (Object) null);
|
|
if (z2) {
|
|
}
|
|
StatusView statusView = this.i.e;
|
|
m.checkNotNullExpressionValue(statusView, "binding.userAvatarPresenceStatus");
|
|
if (!aVar.d) {
|
|
}
|
|
statusView.setVisibility(i);
|
|
this.i.e.setPresence(aVar.b);
|
|
}
|
|
|
|
@Override // android.widget.RelativeLayout, android.view.View
|
|
public void onMeasure(int i, int i2) {
|
|
super.onMeasure(i, i2);
|
|
int size = View.MeasureSpec.getSize(i);
|
|
ImageView imageView = this.i.f133c;
|
|
m.checkNotNullExpressionValue(imageView, "binding.avatarCutout");
|
|
ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
|
|
if (layoutParams != null) {
|
|
layoutParams.width = size;
|
|
layoutParams.height = size;
|
|
imageView.setLayoutParams(layoutParams);
|
|
int i3 = size - (this.k * 2);
|
|
SimpleDraweeView simpleDraweeView = this.i.b;
|
|
m.checkNotNullExpressionValue(simpleDraweeView, "binding.avatar");
|
|
ViewGroup.LayoutParams layoutParams2 = simpleDraweeView.getLayoutParams();
|
|
if (layoutParams2 != null) {
|
|
layoutParams2.width = i3;
|
|
layoutParams2.height = i3;
|
|
simpleDraweeView.setLayoutParams(layoutParams2);
|
|
float f = (float) size;
|
|
float f2 = 0.3375f * f;
|
|
float f3 = 0.0375f * f;
|
|
float f4 = f * 0.05f;
|
|
Resources resources = getResources();
|
|
m.checkNotNullExpressionValue(resources, "resources");
|
|
float f5 = resources.getDisplayMetrics().density;
|
|
float f6 = ((float) 12) * f5;
|
|
if (f2 < f6) {
|
|
float f7 = f6 / f2;
|
|
f2 *= f7;
|
|
f3 *= f7;
|
|
f4 *= f7;
|
|
}
|
|
float max = Math.max(f3, f5 * ((float) 2));
|
|
StatusView statusView = this.i.e;
|
|
m.checkNotNullExpressionValue(statusView, "binding.userAvatarPresenceStatus");
|
|
ViewGroup.LayoutParams layoutParams3 = statusView.getLayoutParams();
|
|
layoutParams3.width = (int) f2;
|
|
StatusView statusView2 = this.i.e;
|
|
m.checkNotNullExpressionValue(statusView2, "binding.userAvatarPresenceStatus");
|
|
statusView2.setLayoutParams(layoutParams3);
|
|
StatusView statusView3 = this.i.e;
|
|
m.checkNotNullExpressionValue(statusView3, "binding.userAvatarPresenceStatus");
|
|
statusView3.setTranslationX(f3 - ((float) this.k));
|
|
StatusView statusView4 = this.i.e;
|
|
m.checkNotNullExpressionValue(statusView4, "binding.userAvatarPresenceStatus");
|
|
statusView4.setTranslationY(f3 - ((float) this.k));
|
|
this.i.e.setBorderWidth((int) max);
|
|
this.i.e.setCornerRadius(f4);
|
|
return;
|
|
}
|
|
throw new TypeCastException("null cannot be cast to non-null type android.view.ViewGroup.LayoutParams");
|
|
}
|
|
throw new TypeCastException("null cannot be cast to non-null type android.view.ViewGroup.LayoutParams");
|
|
}
|
|
|
|
public final void setAvatarBackgroundColor(@ColorInt int i) {
|
|
this.i.e.setBackgroundColor(i);
|
|
ImageView imageView = this.i.f133c;
|
|
m.checkNotNullExpressionValue(imageView, "binding.avatarCutout");
|
|
ColorCompatKt.tintWithColor(imageView, i);
|
|
}
|
|
|
|
public final void setOnAvatarBitmapLoadedListener(Function1<? super Bitmap, Unit> function1) {
|
|
m.checkNotNullParameter(function1, "onAvatarBitmapLoadedListener");
|
|
this.l = function1;
|
|
}
|
|
}
|