discord-jadx/app/src/main/java/com/discord/widgets/chat/list/adapter/WidgetChatListAdapterItemAt...

446 lines
23 KiB
Java

package com.discord.widgets.chat.list.adapter;
import a0.a.a.b;
import android.content.Context;
import android.content.res.Resources;
import android.text.format.Formatter;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.constraintlayout.widget.Barrier;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Guideline;
import c.d.b.a.a;
import com.discord.api.message.attachment.MessageAttachment;
import com.discord.api.message.attachment.MessageAttachmentType;
import com.discord.api.role.GuildRole;
import com.discord.databinding.WidgetChatListAdapterItemAttachmentBinding;
import com.discord.models.message.Message;
import com.discord.stores.StoreMessageState;
import com.discord.stores.StoreStream;
import com.discord.stores.StoreUserSettings;
import com.discord.utilities.embed.EmbedResourceUtils;
import com.discord.utilities.textprocessing.MessageRenderContext;
import com.discord.utilities.uri.UriHandler;
import com.discord.utilities.view.extensions.ViewExtensions;
import com.discord.widgets.chat.list.FragmentLifecycleListener;
import com.discord.widgets.chat.list.InlineMediaView;
import com.discord.widgets.chat.list.adapter.WidgetChatListAdapter;
import com.discord.widgets.chat.list.entries.AttachmentEntry;
import com.discord.widgets.chat.list.entries.ChatListEntry;
import com.discord.widgets.media.WidgetMedia;
import com.google.android.material.card.MaterialCardView;
import d0.z.d.m;
import java.util.Map;
import java.util.Set;
import kotlin.Pair;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Subscription;
/* compiled from: WidgetChatListAdapterItemAttachment.kt */
public final class WidgetChatListAdapterItemAttachment extends WidgetChatListItem implements FragmentLifecycleListener {
public static final Companion Companion = new Companion(null);
private final WidgetChatListAdapterItemAttachmentBinding binding;
private final int maxAttachmentImageWidth;
private Subscription subscription;
private final StoreUserSettings userSettings;
/* compiled from: WidgetChatListAdapterItemAttachment.kt */
public static final class Companion {
public final /* synthetic */ class WhenMappings {
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
static {
MessageAttachmentType.values();
int[] iArr = new int[3];
$EnumSwitchMapping$0 = iArr;
iArr[MessageAttachmentType.VIDEO.ordinal()] = 1;
iArr[MessageAttachmentType.IMAGE.ordinal()] = 2;
}
}
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final /* synthetic */ boolean access$isInlinedAttachment$p(Companion companion, MessageAttachment messageAttachment) {
return companion.isInlinedAttachment(messageAttachment);
}
public static final /* synthetic */ void access$navigateToAttachment(Companion companion, Context context, MessageAttachment messageAttachment) {
companion.navigateToAttachment(context, messageAttachment);
}
private final boolean isInlinedAttachment(MessageAttachment messageAttachment) {
return messageAttachment.e() != MessageAttachmentType.FILE;
}
private final void navigateToAttachment(Context context, MessageAttachment messageAttachment) {
int ordinal = messageAttachment.e().ordinal();
if (ordinal == 0 || ordinal == 1) {
WidgetMedia.Companion.launch(context, messageAttachment);
} else {
UriHandler.handleOrUntrusted$default(context, messageAttachment.f(), null, 4, null);
}
}
}
/* compiled from: WidgetChatListAdapterItemAttachment.kt */
public static final class Model {
private final AttachmentEntry attachmentEntry;
private final Map<Long, String> channelNames;
private final boolean isSpoilerHidden;
private final long myId;
private final Map<Long, GuildRole> roles;
private final Map<Long, String> userNames;
public Model(AttachmentEntry attachmentEntry, Map<Long, String> map, Map<Long, String> map2, Map<Long, GuildRole> map3, long j) {
m.checkNotNullParameter(attachmentEntry, "attachmentEntry");
this.attachmentEntry = attachmentEntry;
this.channelNames = map;
this.userNames = map2;
this.roles = map3;
this.myId = j;
this.isSpoilerHidden = attachmentEntry.getAttachment().h() && !isSpoilerEmbedRevealed(attachmentEntry);
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ Model(AttachmentEntry attachmentEntry, Map map, Map map2, Map map3, long j, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(attachmentEntry, (i & 2) != 0 ? null : map, (i & 4) != 0 ? null : map2, (i & 8) == 0 ? map3 : null, (i & 16) != 0 ? 0 : j);
}
/* JADX DEBUG: Multi-variable search result rejected for r4v0, resolved type: com.discord.widgets.chat.list.adapter.WidgetChatListAdapterItemAttachment$Model */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ Model copy$default(Model model, AttachmentEntry attachmentEntry, Map map, Map map2, Map map3, long j, int i, Object obj) {
if ((i & 1) != 0) {
attachmentEntry = model.attachmentEntry;
}
if ((i & 2) != 0) {
map = model.channelNames;
}
if ((i & 4) != 0) {
map2 = model.userNames;
}
if ((i & 8) != 0) {
map3 = model.roles;
}
if ((i & 16) != 0) {
j = model.myId;
}
return model.copy(attachmentEntry, map, map2, map3, j);
}
private final boolean isSpoilerEmbedRevealed(AttachmentEntry attachmentEntry) {
Map<Integer, Set<String>> visibleSpoilerEmbedMap;
StoreMessageState.State messageState = attachmentEntry.getMessageState();
return (messageState == null || (visibleSpoilerEmbedMap = messageState.getVisibleSpoilerEmbedMap()) == null || !visibleSpoilerEmbedMap.containsKey(Integer.valueOf(attachmentEntry.getEmbedIndex()))) ? false : true;
}
public final AttachmentEntry component1() {
return this.attachmentEntry;
}
public final Map<Long, String> component2() {
return this.channelNames;
}
public final Map<Long, String> component3() {
return this.userNames;
}
public final Map<Long, GuildRole> component4() {
return this.roles;
}
public final long component5() {
return this.myId;
}
public final Model copy(AttachmentEntry attachmentEntry, Map<Long, String> map, Map<Long, String> map2, Map<Long, GuildRole> map3, long j) {
m.checkNotNullParameter(attachmentEntry, "attachmentEntry");
return new Model(attachmentEntry, map, map2, map3, j);
}
public final MessageRenderContext createRenderContext(Context context, WidgetChatListAdapter.EventHandler eventHandler) {
m.checkNotNullParameter(context, "androidContext");
m.checkNotNullParameter(eventHandler, "eventHandler");
return new MessageRenderContext(context, this.myId, this.attachmentEntry.getAllowAnimatedEmojis(), this.userNames, this.channelNames, this.roles, 0, null, new WidgetChatListAdapterItemAttachment$Model$createRenderContext$1(eventHandler), 0, 0, null, null, null, 16064, null);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Model)) {
return false;
}
Model model = (Model) obj;
return m.areEqual(this.attachmentEntry, model.attachmentEntry) && m.areEqual(this.channelNames, model.channelNames) && m.areEqual(this.userNames, model.userNames) && m.areEqual(this.roles, model.roles) && this.myId == model.myId;
}
public final AttachmentEntry getAttachmentEntry() {
return this.attachmentEntry;
}
public final Map<Long, String> getChannelNames() {
return this.channelNames;
}
public final long getMyId() {
return this.myId;
}
public final Map<Long, GuildRole> getRoles() {
return this.roles;
}
public final Map<Long, String> getUserNames() {
return this.userNames;
}
public int hashCode() {
AttachmentEntry attachmentEntry = this.attachmentEntry;
int i = 0;
int hashCode = (attachmentEntry != null ? attachmentEntry.hashCode() : 0) * 31;
Map<Long, String> map = this.channelNames;
int hashCode2 = (hashCode + (map != null ? map.hashCode() : 0)) * 31;
Map<Long, String> map2 = this.userNames;
int hashCode3 = (hashCode2 + (map2 != null ? map2.hashCode() : 0)) * 31;
Map<Long, GuildRole> map3 = this.roles;
if (map3 != null) {
i = map3.hashCode();
}
return b.a(this.myId) + ((hashCode3 + i) * 31);
}
public final boolean isSpoilerHidden() {
return this.isSpoilerHidden;
}
public String toString() {
StringBuilder K = a.K("Model(attachmentEntry=");
K.append(this.attachmentEntry);
K.append(", channelNames=");
K.append(this.channelNames);
K.append(", userNames=");
K.append(this.userNames);
K.append(", roles=");
K.append(this.roles);
K.append(", myId=");
return a.y(K, this.myId, ")");
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public WidgetChatListAdapterItemAttachment(WidgetChatListAdapter widgetChatListAdapter) {
super(2131558935, widgetChatListAdapter);
m.checkNotNullParameter(widgetChatListAdapter, "adapter");
EmbedResourceUtils embedResourceUtils = EmbedResourceUtils.INSTANCE;
View view = this.itemView;
m.checkNotNullExpressionValue(view, "itemView");
Context context = view.getContext();
m.checkNotNullExpressionValue(context, "itemView.context");
this.maxAttachmentImageWidth = embedResourceUtils.computeMaximumImageWidthPx(context);
View view2 = this.itemView;
int i = 2131362538;
View findViewById = view2.findViewById(2131362538);
if (findViewById != null) {
i = 2131362540;
View findViewById2 = view2.findViewById(2131362540);
if (findViewById2 != null) {
i = 2131362572;
Barrier barrier = (Barrier) view2.findViewById(2131362572);
if (barrier != null) {
i = 2131362573;
MaterialCardView materialCardView = (MaterialCardView) view2.findViewById(2131362573);
if (materialCardView != null) {
i = 2131362574;
TextView textView = (TextView) view2.findViewById(2131362574);
if (textView != null) {
i = 2131362575;
ImageView imageView = (ImageView) view2.findViewById(2131362575);
if (imageView != null) {
i = 2131362576;
ImageView imageView2 = (ImageView) view2.findViewById(2131362576);
if (imageView2 != null) {
i = 2131362577;
InlineMediaView inlineMediaView = (InlineMediaView) view2.findViewById(2131362577);
if (inlineMediaView != null) {
i = 2131362578;
TextView textView2 = (TextView) view2.findViewById(2131362578);
if (textView2 != null) {
i = 2131362579;
FrameLayout frameLayout = (FrameLayout) view2.findViewById(2131362579);
if (frameLayout != null) {
i = 2131365471;
Guideline guideline = (Guideline) view2.findViewById(2131365471);
if (guideline != null) {
WidgetChatListAdapterItemAttachmentBinding widgetChatListAdapterItemAttachmentBinding = new WidgetChatListAdapterItemAttachmentBinding((ConstraintLayout) view2, findViewById, findViewById2, barrier, materialCardView, textView, imageView, imageView2, inlineMediaView, textView2, frameLayout, guideline);
m.checkNotNullExpressionValue(widgetChatListAdapterItemAttachmentBinding, "WidgetChatListAdapterIte…entBinding.bind(itemView)");
this.binding = widgetChatListAdapterItemAttachmentBinding;
this.userSettings = StoreStream.Companion.getUserSettings();
return;
}
}
}
}
}
}
}
}
}
}
}
throw new NullPointerException("Missing required view with ID: ".concat(view2.getResources().getResourceName(i)));
}
public static final /* synthetic */ WidgetChatListAdapter access$getAdapter$p(WidgetChatListAdapterItemAttachment widgetChatListAdapterItemAttachment) {
return (WidgetChatListAdapter) widgetChatListAdapterItemAttachment.adapter;
}
public static final /* synthetic */ WidgetChatListAdapterItemAttachmentBinding access$getBinding$p(WidgetChatListAdapterItemAttachment widgetChatListAdapterItemAttachment) {
return widgetChatListAdapterItemAttachment.binding;
}
private final void configureFileData(MessageAttachment messageAttachment, MessageRenderContext messageRenderContext) {
TextView textView = this.binding.i;
m.checkNotNullExpressionValue(textView, "binding.chatListItemAttachmentName");
textView.setText(messageAttachment.a());
TextView textView2 = this.binding.i;
m.checkNotNullExpressionValue(textView2, "binding.chatListItemAttachmentName");
ViewExtensions.setOnLongClickListenerConsumeClick(textView2, WidgetChatListAdapterItemAttachment$configureFileData$1.INSTANCE);
TextView textView3 = this.binding.e;
m.checkNotNullExpressionValue(textView3, "binding.chatListItemAttachmentDescription");
textView3.setText(Formatter.formatFileSize(messageRenderContext.getContext(), messageAttachment.d()));
this.binding.g.setImageResource(EmbedResourceUtils.INSTANCE.getFileDrawable(messageAttachment.a()));
ImageView imageView = this.binding.f;
m.checkNotNullExpressionValue(imageView, "binding.chatListItemAttachmentDownload");
imageView.setEnabled(true);
ImageView imageView2 = this.binding.f;
m.checkNotNullExpressionValue(imageView2, "binding.chatListItemAttachmentDownload");
imageView2.setAlpha(1.0f);
this.binding.f.setOnClickListener(new WidgetChatListAdapterItemAttachment$configureFileData$2(this, messageAttachment));
}
/* JADX WARNING: Code restructure failed: missing block: B:19:0x00b5, code lost:
if (r5.intValue() > 0) goto L_0x00b9;
*/
/* JADX WARNING: Removed duplicated region for block: B:18:0x00aa */
private final void configureUI(Model model) {
boolean z2;
AttachmentEntry attachmentEntry = model.getAttachmentEntry();
MessageAttachment attachment = attachmentEntry.getAttachment();
MessageRenderContext createRenderContext = model.createRenderContext(a.x(this.itemView, "itemView", "itemView.context"), ((WidgetChatListAdapter) this.adapter).getEventHandler());
boolean autoPlayGifs = attachmentEntry.getAutoPlayGifs();
if (model.isSpoilerHidden()) {
ViewExtensions.fadeIn$default(this.binding.j, 50, null, WidgetChatListAdapterItemAttachment$configureUI$1.INSTANCE, null, 10, null);
} else {
ViewExtensions.fadeOut$default(this.binding.j, 200, WidgetChatListAdapterItemAttachment$configureUI$2.INSTANCE, null, 4, null);
}
ConstraintLayout constraintLayout = this.binding.a;
m.checkNotNullExpressionValue(constraintLayout, "binding.root");
ViewExtensions.setOnLongClickListenerConsumeClick(constraintLayout, new WidgetChatListAdapterItemAttachment$configureUI$3(this, attachmentEntry));
this.binding.a.setOnClickListener(new WidgetChatListAdapterItemAttachment$configureUI$4(this, attachmentEntry));
this.binding.j.setOnClickListener(new WidgetChatListAdapterItemAttachment$configureUI$5(this, model, attachmentEntry));
boolean z3 = true;
boolean z4 = Companion.access$isInlinedAttachment$p(Companion, attachment) && this.userSettings.getIsAttachmentMediaInline();
if (attachment.b() != null) {
Integer b = attachment.b();
m.checkNotNull(b);
if (b.intValue() > 0) {
z2 = true;
if (attachment.g() != null) {
Integer g = attachment.g();
m.checkNotNull(g);
}
z3 = false;
if (z4 || (!z3 && !z2)) {
MaterialCardView materialCardView = this.binding.d;
m.checkNotNullExpressionValue(materialCardView, "binding.chatListItemAttachmentCard");
materialCardView.setVisibility(0);
InlineMediaView inlineMediaView = this.binding.h;
m.checkNotNullExpressionValue(inlineMediaView, "binding.chatListItemAttachmentInlineMedia");
inlineMediaView.setVisibility(8);
InlineMediaView.updateUIWithAttachment$default(this.binding.h, attachment, null, null, autoPlayGifs, 6, null);
} else {
EmbedResourceUtils embedResourceUtils = EmbedResourceUtils.INSTANCE;
Integer g2 = attachment.g();
m.checkNotNull(g2);
int intValue = g2.intValue();
Integer b2 = attachment.b();
m.checkNotNull(b2);
int intValue2 = b2.intValue();
int i = this.maxAttachmentImageWidth;
int max_image_view_height_px = embedResourceUtils.getMAX_IMAGE_VIEW_HEIGHT_PX();
InlineMediaView inlineMediaView2 = this.binding.h;
m.checkNotNullExpressionValue(inlineMediaView2, "binding.chatListItemAttachmentInlineMedia");
Resources resources = inlineMediaView2.getResources();
m.checkNotNullExpressionValue(resources, "binding.chatListItemAtta…mentInlineMedia.resources");
Pair calculateScaledSize$default = EmbedResourceUtils.calculateScaledSize$default(embedResourceUtils, intValue, intValue2, i, max_image_view_height_px, resources, 0, 32, null);
int intValue3 = ((Number) calculateScaledSize$default.component1()).intValue();
int intValue4 = ((Number) calculateScaledSize$default.component2()).intValue();
MaterialCardView materialCardView2 = this.binding.d;
m.checkNotNullExpressionValue(materialCardView2, "binding.chatListItemAttachmentCard");
materialCardView2.setVisibility(8);
InlineMediaView inlineMediaView3 = this.binding.h;
m.checkNotNullExpressionValue(inlineMediaView3, "binding.chatListItemAttachmentInlineMedia");
inlineMediaView3.setVisibility(0);
this.binding.h.updateUIWithAttachment(attachment, Integer.valueOf(intValue3), Integer.valueOf(intValue4), autoPlayGifs);
}
configureFileData(attachment, createRenderContext);
this.binding.h.setOnClickListener(new WidgetChatListAdapterItemAttachment$configureUI$6(attachment));
this.binding.d.setOnClickListener(new WidgetChatListAdapterItemAttachment$configureUI$7(attachment));
}
}
z2 = false;
if (attachment.g() != null) {
}
z3 = false;
if (z4) {
}
MaterialCardView materialCardView = this.binding.d;
m.checkNotNullExpressionValue(materialCardView, "binding.chatListItemAttachmentCard");
materialCardView.setVisibility(0);
InlineMediaView inlineMediaView = this.binding.h;
m.checkNotNullExpressionValue(inlineMediaView, "binding.chatListItemAttachmentInlineMedia");
inlineMediaView.setVisibility(8);
InlineMediaView.updateUIWithAttachment$default(this.binding.h, attachment, null, null, autoPlayGifs, 6, null);
configureFileData(attachment, createRenderContext);
this.binding.h.setOnClickListener(new WidgetChatListAdapterItemAttachment$configureUI$6(attachment));
this.binding.d.setOnClickListener(new WidgetChatListAdapterItemAttachment$configureUI$7(attachment));
}
@Override // com.discord.utilities.mg_recycler.MGRecyclerViewHolder
public Subscription getSubscription() {
return this.subscription;
}
@Override // com.discord.widgets.chat.list.adapter.WidgetChatListItem
public void onConfigure(int i, ChatListEntry chatListEntry) {
m.checkNotNullParameter(chatListEntry, "data");
super.onConfigure(i, chatListEntry);
AttachmentEntry attachmentEntry = (AttachmentEntry) chatListEntry;
Message message = attachmentEntry.getMessage();
View view = this.binding.f1733c;
m.checkNotNullExpressionValue(view, "binding.chatListAdapterItemHighlightedBg");
View view2 = this.binding.b;
m.checkNotNullExpressionValue(view2, "binding.chatListAdapterItemGutterBg");
configureCellHighlight(message, view, view2);
configureUI(new Model(attachmentEntry, null, null, null, 0, 30, null));
}
@Override // com.discord.widgets.chat.list.FragmentLifecycleListener
public void onPause() {
this.binding.h.onPause();
}
@Override // com.discord.widgets.chat.list.FragmentLifecycleListener
public void onResume() {
this.binding.h.onResume();
}
}