package com.discord.views;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import c.a.i.v1;
import com.discord.api.message.LocalAttachment;
import com.discord.utilities.attachments.AttachmentUtilsKt;
import com.discord.utilities.drawable.DrawableCompat;
import com.discord.utilities.file.FileUtilsKt;
import com.discord.utilities.resources.StringResourceUtilsKt;
import com.discord.utilities.rest.SendUtilsKt;
import com.lytefast.flexinput.model.Attachment;
import d0.t.n;
import d0.t.o;
import d0.t.u;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: FailedUploadList.kt */
public final class FailedUploadList extends LinearLayout {
public final v1 i;
/* compiled from: FailedUploadList.kt */
public static final class a {
public final String a;
public final long b;
/* renamed from: c reason: collision with root package name */
public final String f2136c;
public a(String str, long j, String str2) {
m.checkNotNullParameter(str, "displayName");
m.checkNotNullParameter(str2, "mimeType");
this.a = str;
this.b = j;
this.f2136c = str2;
}
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) && this.b == aVar.b && m.areEqual(this.f2136c, aVar.f2136c);
}
public int hashCode() {
String str = this.a;
int i = 0;
int a = (a0.a.a.b.a(this.b) + ((str != null ? str.hashCode() : 0) * 31)) * 31;
String str2 = this.f2136c;
if (str2 != null) {
i = str2.hashCode();
}
return a + i;
}
public String toString() {
StringBuilder K = c.d.b.a.a.K("SingleFailedUpload(displayName=");
K.append(this.a);
K.append(", sizeBytes=");
K.append(this.b);
K.append(", mimeType=");
return c.d.b.a.a.C(K, this.f2136c, ")");
}
}
/* compiled from: FailedUploadList.kt */
public static abstract class b {
/* compiled from: FailedUploadList.kt */
public static final class a extends b {
public final List a;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public a(List list) {
super(null);
m.checkNotNullParameter(list, "uploads");
this.a = list;
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof a) && m.areEqual(this.a, ((a) obj).a);
}
return true;
}
public int hashCode() {
List list = this.a;
if (list != null) {
return list.hashCode();
}
return 0;
}
public String toString() {
return c.d.b.a.a.D(c.d.b.a.a.K("FewFailedUploads(uploads="), this.a, ")");
}
}
/* compiled from: FailedUploadList.kt */
/* renamed from: com.discord.views.FailedUploadList$b$b reason: collision with other inner class name */
public static final class C0183b extends b {
public final int a;
public final long b;
public C0183b(int i, long j) {
super(null);
this.a = i;
this.b = j;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof C0183b)) {
return false;
}
C0183b bVar = (C0183b) obj;
return this.a == bVar.a && this.b == bVar.b;
}
public int hashCode() {
return a0.a.a.b.a(this.b) + (this.a * 31);
}
public String toString() {
StringBuilder K = c.d.b.a.a.K("ManyFailedUploads(uploadCount=");
K.append(this.a);
K.append(", sizeBytes=");
return c.d.b.a.a.y(K, this.b, ")");
}
}
public b(DefaultConstructorMarker defaultConstructorMarker) {
}
}
public FailedUploadList(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
View inflate = LayoutInflater.from(getContext()).inflate(2131558741, (ViewGroup) this, false);
addView(inflate);
int i = 2131362624;
FailedUploadView failedUploadView = (FailedUploadView) inflate.findViewById(2131362624);
if (failedUploadView != null) {
i = 2131362625;
FailedUploadView failedUploadView2 = (FailedUploadView) inflate.findViewById(2131362625);
if (failedUploadView2 != null) {
i = 2131362626;
FailedUploadView failedUploadView3 = (FailedUploadView) inflate.findViewById(2131362626);
if (failedUploadView3 != null) {
v1 v1Var = new v1((LinearLayout) inflate, failedUploadView, failedUploadView2, failedUploadView3);
m.checkNotNullExpressionValue(v1Var, "ViewChatUploadListBindin…rom(context), this, true)");
this.i = v1Var;
return;
}
}
}
throw new NullPointerException("Missing required view with ID: ".concat(inflate.getResources().getResourceName(i)));
}
private final List getFailedUploadViews() {
FailedUploadView failedUploadView = this.i.b;
m.checkNotNullExpressionValue(failedUploadView, "binding.chatUpload1");
FailedUploadView failedUploadView2 = this.i.f174c;
m.checkNotNullExpressionValue(failedUploadView2, "binding.chatUpload2");
FailedUploadView failedUploadView3 = this.i.d;
m.checkNotNullExpressionValue(failedUploadView3, "binding.chatUpload3");
return n.listOf((Object[]) new FailedUploadView[]{failedUploadView, failedUploadView2, failedUploadView3});
}
public final void setUp(List list) {
Object obj;
m.checkNotNullParameter(list, "localAttachments");
for (FailedUploadView failedUploadView : getFailedUploadViews()) {
failedUploadView.setVisibility(8);
}
if (!list.isEmpty()) {
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(list, 10));
for (LocalAttachment localAttachment : list) {
arrayList.add(AttachmentUtilsKt.toAttachment(localAttachment));
}
if (arrayList.size() <= 3) {
ArrayList arrayList2 = new ArrayList(o.collectionSizeOrDefault(arrayList, 10));
Iterator it = arrayList.iterator();
while (it.hasNext()) {
Attachment attachment = (Attachment) it.next();
String displayName = attachment.getDisplayName();
Uri uri = attachment.getUri();
Context context = getContext();
m.checkNotNullExpressionValue(context, "context");
ContentResolver contentResolver = context.getContentResolver();
m.checkNotNullExpressionValue(contentResolver, "context.contentResolver");
long computeFileSizeBytes = SendUtilsKt.computeFileSizeBytes(uri, contentResolver);
Context context2 = getContext();
m.checkNotNullExpressionValue(context2, "context");
arrayList2.add(new a(displayName, computeFileSizeBytes, AttachmentUtilsKt.getMimeType(attachment, context2.getContentResolver())));
}
obj = new b.a(arrayList2);
} else {
long j = 0;
Iterator it2 = arrayList.iterator();
while (it2.hasNext()) {
Uri uri2 = ((Attachment) it2.next()).getUri();
Context context3 = getContext();
m.checkNotNullExpressionValue(context3, "context");
ContentResolver contentResolver2 = context3.getContentResolver();
m.checkNotNullExpressionValue(contentResolver2, "context.contentResolver");
j += SendUtilsKt.computeFileSizeBytes(uri2, contentResolver2);
}
obj = new b.C0183b(arrayList.size(), j);
}
if (obj instanceof b.a) {
List list2 = ((b.a) obj).a;
int size = list2.size();
for (int i = 0; i < size; i++) {
a aVar = list2.get(i);
FailedUploadView failedUploadView2 = getFailedUploadViews().get(i);
failedUploadView2.setVisibility(0);
String str = aVar.a;
Context context4 = failedUploadView2.getContext();
m.checkNotNullExpressionValue(context4, "context");
failedUploadView2.a(str, FileUtilsKt.getIconForFiletype(context4, aVar.f2136c), FileUtilsKt.getSizeSubtitle(aVar.b));
}
} else if (obj instanceof b.C0183b) {
b.C0183b bVar = (b.C0183b) obj;
int i2 = bVar.a;
long j2 = bVar.b;
((View) u.first((List extends Object>) getFailedUploadViews())).setVisibility(0);
FailedUploadView failedUploadView3 = (FailedUploadView) u.first((List extends Object>) getFailedUploadViews());
Resources resources = failedUploadView3.getResources();
m.checkNotNullExpressionValue(resources, "resources");
Context context5 = failedUploadView3.getContext();
m.checkNotNullExpressionValue(context5, "context");
CharSequence quantityString = StringResourceUtilsKt.getQuantityString(resources, context5, 2131755349, i2, Integer.valueOf(i2));
Context context6 = failedUploadView3.getContext();
m.checkNotNullExpressionValue(context6, "context");
failedUploadView3.a(quantityString, DrawableCompat.getThemedDrawableRes$default(context6, 2130969468, 0, 2, (Object) null), FileUtilsKt.getSizeSubtitle(j2));
}
}
}
}