package com.discord.widgets.chat.list.adapter; import a0.a.a.b; import android.content.Context; import android.content.res.Resources; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import c.d.b.a.a; import com.discord.app.AppLog; import com.discord.databinding.WidgetChatListAdapterItemUploadProgressBinding; import com.discord.stores.StoreMessageUploads; import com.discord.stores.StoreStream; import com.discord.stores.updates.ObservationDeck; import com.discord.stores.updates.ObservationDeckProvider; import com.discord.utilities.drawable.DrawableCompat; import com.discord.utilities.file.FileUtilsKt; import com.discord.utilities.logging.Logger; import com.discord.utilities.resources.StringResourceUtilsKt; import com.discord.utilities.rest.SendUtils; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.views.UploadProgressView; import com.discord.widgets.chat.list.entries.ChatListEntry; import com.discord.widgets.chat.list.entries.UploadProgressEntry; import d0.t.o; import d0.z.d.m; import j0.l.e.j; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Ref$LongRef; import rx.Observable; import rx.Subscription; /* compiled from: WidgetChatListAdapterItemUploadProgress.kt */ public final class WidgetChatListAdapterItemUploadProgress extends WidgetChatListItem { public static final Companion Companion = new Companion(null); private static final long MODEL_THROTTLE_MS = 100; private final WidgetChatListAdapterItemUploadProgressBinding binding; private Subscription subscription; /* compiled from: WidgetChatListAdapterItemUploadProgress.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } } /* compiled from: WidgetChatListAdapterItemUploadProgress.kt */ public static abstract class Model { public static final Companion Companion = new Companion(null); public static final int PROGRESS_INDETERMINATE = -1; public static final long SIZE_UNKNOWN = -1; /* compiled from: WidgetChatListAdapterItemUploadProgress.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } } /* compiled from: WidgetChatListAdapterItemUploadProgress.kt */ public static final class Few extends Model { private final List uploads; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Few(List list) { super(null); m.checkNotNullParameter(list, "uploads"); this.uploads = list; } /* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.chat.list.adapter.WidgetChatListAdapterItemUploadProgress$Model$Few */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ Few copy$default(Few few, List list, int i, Object obj) { if ((i & 1) != 0) { list = few.uploads; } return few.copy(list); } public final List component1() { return this.uploads; } public final Few copy(List list) { m.checkNotNullParameter(list, "uploads"); return new Few(list); } public boolean equals(Object obj) { if (this != obj) { return (obj instanceof Few) && m.areEqual(this.uploads, ((Few) obj).uploads); } return true; } public final List getUploads() { return this.uploads; } public int hashCode() { List list = this.uploads; if (list != null) { return list.hashCode(); } return 0; } public String toString() { return a.D(a.K("Few(uploads="), this.uploads, ")"); } } /* compiled from: WidgetChatListAdapterItemUploadProgress.kt */ public static final class Many extends Model { private final int numFiles; private final int progress; private final long sizeBytes; public Many(int i, long j, int i2) { super(null); this.numFiles = i; this.sizeBytes = j; this.progress = i2; } public static /* synthetic */ Many copy$default(Many many, int i, long j, int i2, int i3, Object obj) { if ((i3 & 1) != 0) { i = many.numFiles; } if ((i3 & 2) != 0) { j = many.sizeBytes; } if ((i3 & 4) != 0) { i2 = many.progress; } return many.copy(i, j, i2); } public final int component1() { return this.numFiles; } public final long component2() { return this.sizeBytes; } public final int component3() { return this.progress; } public final Many copy(int i, long j, int i2) { return new Many(i, j, i2); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Many)) { return false; } Many many = (Many) obj; return this.numFiles == many.numFiles && this.sizeBytes == many.sizeBytes && this.progress == many.progress; } public final int getNumFiles() { return this.numFiles; } public final int getProgress() { return this.progress; } public final long getSizeBytes() { return this.sizeBytes; } public int hashCode() { return ((b.a(this.sizeBytes) + (this.numFiles * 31)) * 31) + this.progress; } public String toString() { StringBuilder K = a.K("Many(numFiles="); K.append(this.numFiles); K.append(", sizeBytes="); K.append(this.sizeBytes); K.append(", progress="); return a.w(K, this.progress, ")"); } } /* compiled from: WidgetChatListAdapterItemUploadProgress.kt */ public static final class None extends Model { public static final None INSTANCE = new None(); private None() { super(null); } } /* compiled from: WidgetChatListAdapterItemUploadProgress.kt */ public static final class Preprocessing extends Model { private final String displayName; private final String mimeType; private final int numFiles; public Preprocessing(int i, String str, String str2) { super(null); this.numFiles = i; this.displayName = str; this.mimeType = str2; } public static /* synthetic */ Preprocessing copy$default(Preprocessing preprocessing, int i, String str, String str2, int i2, Object obj) { if ((i2 & 1) != 0) { i = preprocessing.numFiles; } if ((i2 & 2) != 0) { str = preprocessing.displayName; } if ((i2 & 4) != 0) { str2 = preprocessing.mimeType; } return preprocessing.copy(i, str, str2); } public final int component1() { return this.numFiles; } public final String component2() { return this.displayName; } public final String component3() { return this.mimeType; } public final Preprocessing copy(int i, String str, String str2) { return new Preprocessing(i, str, str2); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Preprocessing)) { return false; } Preprocessing preprocessing = (Preprocessing) obj; return this.numFiles == preprocessing.numFiles && m.areEqual(this.displayName, preprocessing.displayName) && m.areEqual(this.mimeType, preprocessing.mimeType); } public final String getDisplayName() { return this.displayName; } public final String getMimeType() { return this.mimeType; } public final int getNumFiles() { return this.numFiles; } public int hashCode() { int i = this.numFiles * 31; String str = this.displayName; int i2 = 0; int hashCode = (i + (str != null ? str.hashCode() : 0)) * 31; String str2 = this.mimeType; if (str2 != null) { i2 = str2.hashCode(); } return hashCode + i2; } public String toString() { StringBuilder K = a.K("Preprocessing(numFiles="); K.append(this.numFiles); K.append(", displayName="); K.append(this.displayName); K.append(", mimeType="); return a.C(K, this.mimeType, ")"); } } /* compiled from: WidgetChatListAdapterItemUploadProgress.kt */ public static final class Single extends Model { private final String mimeType; private final String name; private final int progress; private final long sizeBytes; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Single(String str, String str2, long j, int i) { super(null); m.checkNotNullParameter(str, "name"); m.checkNotNullParameter(str2, "mimeType"); this.name = str; this.mimeType = str2; this.sizeBytes = j; this.progress = i; } public static /* synthetic */ Single copy$default(Single single, String str, String str2, long j, int i, int i2, Object obj) { if ((i2 & 1) != 0) { str = single.name; } if ((i2 & 2) != 0) { str2 = single.mimeType; } if ((i2 & 4) != 0) { j = single.sizeBytes; } if ((i2 & 8) != 0) { i = single.progress; } return single.copy(str, str2, j, i); } public final String component1() { return this.name; } public final String component2() { return this.mimeType; } public final long component3() { return this.sizeBytes; } public final int component4() { return this.progress; } public final Single copy(String str, String str2, long j, int i) { m.checkNotNullParameter(str, "name"); m.checkNotNullParameter(str2, "mimeType"); return new Single(str, str2, j, i); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Single)) { return false; } Single single = (Single) obj; return m.areEqual(this.name, single.name) && m.areEqual(this.mimeType, single.mimeType) && this.sizeBytes == single.sizeBytes && this.progress == single.progress; } public final String getMimeType() { return this.mimeType; } public final String getName() { return this.name; } public final int getProgress() { return this.progress; } public final long getSizeBytes() { return this.sizeBytes; } public int hashCode() { String str = this.name; int i = 0; int hashCode = (str != null ? str.hashCode() : 0) * 31; String str2 = this.mimeType; if (str2 != null) { i = str2.hashCode(); } return ((b.a(this.sizeBytes) + ((hashCode + i) * 31)) * 31) + this.progress; } public String toString() { StringBuilder K = a.K("Single(name="); K.append(this.name); K.append(", mimeType="); K.append(this.mimeType); K.append(", sizeBytes="); K.append(this.sizeBytes); K.append(", progress="); return a.w(K, this.progress, ")"); } } private Model() { } public /* synthetic */ Model(DefaultConstructorMarker defaultConstructorMarker) { this(); } } /* compiled from: WidgetChatListAdapterItemUploadProgress.kt */ public static final class ModelProvider { public static final ModelProvider INSTANCE = new ModelProvider(); private static final int MAX_DETAILED_UPLOADS = 3; private ModelProvider() { } public static final /* synthetic */ Observable access$getFewUploadsObservable(ModelProvider modelProvider, List list, long j) { return modelProvider.getFewUploadsObservable(list, j); } public static final /* synthetic */ Observable access$getManyUploadsObservable(ModelProvider modelProvider, List list, long j) { return modelProvider.getManyUploadsObservable(list, j); } public static final /* synthetic */ int access$getPercentage(ModelProvider modelProvider, long j, long j2) { return modelProvider.getPercentage(j, j2); } public static final /* synthetic */ Observable access$getSingleUploadObservable(ModelProvider modelProvider, SendUtils.FileUpload fileUpload, long j) { return modelProvider.getSingleUploadObservable(fileUpload, j); } private final Observable getFewUploadsObservable(List list, long j) { ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(list, 10)); for (SendUtils.FileUpload fileUpload : list) { arrayList.add(INSTANCE.getSingleUploadObservable(fileUpload, j)); } Observable b = Observable.b(arrayList, WidgetChatListAdapterItemUploadProgress$ModelProvider$getFewUploadsObservable$2.INSTANCE); m.checkNotNullExpressionValue(b, "Observable\n .co…{ it as Model.Single }) }"); return b; } private final Observable getManyUploadsObservable(List list, long j) { Ref$LongRef ref$LongRef = new Ref$LongRef(); ref$LongRef.element = 0; for (SendUtils.FileUpload fileUpload : list) { if (fileUpload.getContentLength() <= 0) { ref$LongRef.element = -1; } else { ref$LongRef.element = fileUpload.getContentLength() + ref$LongRef.element; } } if (ref$LongRef.element <= 0) { j jVar = new j(new Model.Many(list.size(), -1, -1)); m.checkNotNullExpressionValue(jVar, "Observable\n .… )\n )"); return jVar; } ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(list, 10)); for (SendUtils.FileUpload fileUpload2 : list) { arrayList.add(ObservableExtensionsKt.leadingEdgeThrottle(fileUpload2.getBytesWrittenObservable(), j, TimeUnit.MILLISECONDS)); } Observable F = Observable.b(arrayList, WidgetChatListAdapterItemUploadProgress$ModelProvider$getManyUploadsObservable$3.INSTANCE).F(new WidgetChatListAdapterItemUploadProgress$ModelProvider$getManyUploadsObservable$4(ref$LongRef)).r().F(new WidgetChatListAdapterItemUploadProgress$ModelProvider$getManyUploadsObservable$5(list, ref$LongRef)); m.checkNotNullExpressionValue(F, "Observable\n .…essPercent)\n }"); return F; } private final int getPercentage(long j, long j2) { float f = (float) j; if (j2 > 0) { return (int) ((f / ((float) j2)) * ((float) 100)); } Logger.e$default(AppLog.g, "contentLengthBytes was not positive", new Exception(), null, 4, null); return 0; } private final Observable getSingleUploadObservable(SendUtils.FileUpload fileUpload, long j) { if (fileUpload.getContentLength() <= 0) { j jVar = new j(new Model.Single(fileUpload.getName(), fileUpload.getMimeType(), -1, -1)); m.checkNotNullExpressionValue(jVar, "Observable.just(\n …E\n )\n )"); return jVar; } Observable F = ObservableExtensionsKt.leadingEdgeThrottle(fileUpload.getBytesWrittenObservable(), j, TimeUnit.MILLISECONDS).F(new WidgetChatListAdapterItemUploadProgress$ModelProvider$getSingleUploadObservable$1(fileUpload)).r().F(new WidgetChatListAdapterItemUploadProgress$ModelProvider$getSingleUploadObservable$2(fileUpload)); m.checkNotNullExpressionValue(F, "upload\n .byte… )\n }"); return F; } public final Observable get(String str, long j) { m.checkNotNullParameter(str, "nonce"); StoreMessageUploads messageUploads = StoreStream.Companion.getMessageUploads(); Observable Y = ObservationDeck.connectRx$default(ObservationDeckProvider.get(), new ObservationDeck.UpdateSource[]{messageUploads}, false, null, null, new WidgetChatListAdapterItemUploadProgress$ModelProvider$get$1(messageUploads, str), 14, null).Y(new WidgetChatListAdapterItemUploadProgress$ModelProvider$get$2(j)); m.checkNotNullExpressionValue(Y, "ObservationDeckProvider.… }\n }\n }"); return Y; } } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public WidgetChatListAdapterItemUploadProgress(WidgetChatListAdapter widgetChatListAdapter) { super(2131558975, widgetChatListAdapter); m.checkNotNullParameter(widgetChatListAdapter, "adapter"); View view = this.itemView; int i = 2131364455; ImageView imageView = (ImageView) view.findViewById(2131364455); if (imageView != null) { i = 2131364456; ImageView imageView2 = (ImageView) view.findViewById(2131364456); if (imageView2 != null) { i = 2131365499; UploadProgressView uploadProgressView = (UploadProgressView) view.findViewById(2131365499); if (uploadProgressView != null) { i = 2131365500; UploadProgressView uploadProgressView2 = (UploadProgressView) view.findViewById(2131365500); if (uploadProgressView2 != null) { i = 2131365501; UploadProgressView uploadProgressView3 = (UploadProgressView) view.findViewById(2131365501); if (uploadProgressView3 != null) { WidgetChatListAdapterItemUploadProgressBinding widgetChatListAdapterItemUploadProgressBinding = new WidgetChatListAdapterItemUploadProgressBinding((LinearLayout) view, imageView, imageView2, uploadProgressView, uploadProgressView2, uploadProgressView3); m.checkNotNullExpressionValue(widgetChatListAdapterItemUploadProgressBinding, "WidgetChatListAdapterIte…essBinding.bind(itemView)"); this.binding = widgetChatListAdapterItemUploadProgressBinding; return; } } } } } throw new NullPointerException("Missing required view with ID: ".concat(view.getResources().getResourceName(i))); } public static final /* synthetic */ void access$configureUI(WidgetChatListAdapterItemUploadProgress widgetChatListAdapterItemUploadProgress, Model model) { widgetChatListAdapterItemUploadProgress.configureUI(model); } public static final /* synthetic */ Subscription access$getSubscription$p(WidgetChatListAdapterItemUploadProgress widgetChatListAdapterItemUploadProgress) { return widgetChatListAdapterItemUploadProgress.subscription; } public static final /* synthetic */ void access$setSubscription$p(WidgetChatListAdapterItemUploadProgress widgetChatListAdapterItemUploadProgress, Subscription subscription) { widgetChatListAdapterItemUploadProgress.subscription = subscription; } /* JADX WARNING: Code restructure failed: missing block: B:28:0x00db, code lost: if (r1 != false) goto L_0x00ec; */ /* JADX WARNING: Removed duplicated region for block: B:37:0x00f3 */ /* JADX WARNING: Removed duplicated region for block: B:45:0x0112 */ private final void configureUI(Model model) { boolean z2; boolean z3; boolean z4; boolean z5 = model instanceof Model.Few; int i = 8; if (!z5) { UploadProgressView uploadProgressView = this.binding.d; m.checkNotNullExpressionValue(uploadProgressView, "binding.uploadProgress1"); setUploadState(uploadProgressView, model); UploadProgressView uploadProgressView2 = this.binding.e; m.checkNotNullExpressionValue(uploadProgressView2, "binding.uploadProgress2"); uploadProgressView2.setVisibility(8); UploadProgressView uploadProgressView3 = this.binding.f; m.checkNotNullExpressionValue(uploadProgressView3, "binding.uploadProgress3"); uploadProgressView3.setVisibility(8); } else { UploadProgressView uploadProgressView4 = this.binding.d; m.checkNotNullExpressionValue(uploadProgressView4, "binding.uploadProgress1"); Model.Few few = (Model.Few) model; setUploadState(uploadProgressView4, few.getUploads().get(0)); UploadProgressView uploadProgressView5 = this.binding.e; m.checkNotNullExpressionValue(uploadProgressView5, "binding.uploadProgress2"); setUploadState(uploadProgressView5, few.getUploads().get(1)); UploadProgressView uploadProgressView6 = this.binding.f; m.checkNotNullExpressionValue(uploadProgressView6, "binding.uploadProgress3"); uploadProgressView6.setVisibility(0); if (few.getUploads().size() == 3) { UploadProgressView uploadProgressView7 = this.binding.f; m.checkNotNullExpressionValue(uploadProgressView7, "binding.uploadProgress3"); uploadProgressView7.setVisibility(0); UploadProgressView uploadProgressView8 = this.binding.f; m.checkNotNullExpressionValue(uploadProgressView8, "binding.uploadProgress3"); setUploadState(uploadProgressView8, few.getUploads().get(2)); } else { UploadProgressView uploadProgressView9 = this.binding.f; m.checkNotNullExpressionValue(uploadProgressView9, "binding.uploadProgress3"); uploadProgressView9.setVisibility(8); } } if (!(model instanceof Model.Preprocessing) && (!(model instanceof Model.Single) || ((Model.Single) model).getProgress() >= 100)) { if (z5) { List uploads = ((Model.Few) model).getUploads(); if (!(uploads instanceof Collection) || !uploads.isEmpty()) { Iterator it = uploads.iterator(); while (true) { if (!it.hasNext()) { break; } if (((Model.Single) it.next()).getProgress() < 100) { z4 = true; continue; } else { z4 = false; continue; } if (z4) { z3 = true; break; } } } z3 = false; } if (!(model instanceof Model.Many) || ((Model.Many) model).getProgress() >= 100) { z2 = false; if (!z2) { ImageView imageView = this.binding.f1757c; m.checkNotNullExpressionValue(imageView, "binding.progressCancelTop"); imageView.setVisibility(z5 ? 0 : 8); ImageView imageView2 = this.binding.b; m.checkNotNullExpressionValue(imageView2, "binding.progressCancelCentered"); if (!z5) { i = 0; } imageView2.setVisibility(i); return; } ImageView imageView3 = this.binding.f1757c; m.checkNotNullExpressionValue(imageView3, "binding.progressCancelTop"); imageView3.setVisibility(8); ImageView imageView4 = this.binding.b; m.checkNotNullExpressionValue(imageView4, "binding.progressCancelCentered"); imageView4.setVisibility(8); return; } } z2 = true; if (!z2) { } } private final void setUploadState(UploadProgressView uploadProgressView, Model model) { if (m.areEqual(model, Model.None.INSTANCE)) { CharSequence i = c.a.k.b.i(uploadProgressView, 2131894369, new Object[0], null, 4); int i2 = UploadProgressView.i; uploadProgressView.a(i, 0, null); Context context = uploadProgressView.getContext(); m.checkNotNullExpressionValue(context, "context"); uploadProgressView.setIcon(DrawableCompat.getThemedDrawableRes$default(context, 2130969467, 0, 2, (Object) null)); return; } int i3 = -1; if (model instanceof Model.Preprocessing) { Model.Preprocessing preprocessing = (Model.Preprocessing) model; CharSequence displayName = preprocessing.getDisplayName(); if (displayName == null) { Resources resources = uploadProgressView.getResources(); m.checkNotNullExpressionValue(resources, "resources"); Context context2 = uploadProgressView.getContext(); m.checkNotNullExpressionValue(context2, "context"); displayName = StringResourceUtilsKt.getQuantityString(resources, context2, 2131755345, preprocessing.getNumFiles(), Integer.valueOf(preprocessing.getNumFiles())); } int i4 = UploadProgressView.i; uploadProgressView.a(displayName, -1, null); if (preprocessing.getMimeType() != null) { Context context3 = uploadProgressView.getContext(); m.checkNotNullExpressionValue(context3, "context"); uploadProgressView.setIcon(FileUtilsKt.getIconForFiletype(context3, preprocessing.getMimeType())); return; } Context context4 = uploadProgressView.getContext(); m.checkNotNullExpressionValue(context4, "context"); uploadProgressView.setIcon(DrawableCompat.getThemedDrawableRes$default(context4, 2130969467, 0, 2, (Object) null)); } else if (model instanceof Model.Single) { Model.Single single = (Model.Single) model; String name = single.getName(); if (single.getProgress() != -1) { i3 = single.getProgress(); } uploadProgressView.a(name, i3, FileUtilsKt.getSizeSubtitle(single.getSizeBytes())); Context context5 = uploadProgressView.getContext(); m.checkNotNullExpressionValue(context5, "context"); uploadProgressView.setIcon(FileUtilsKt.getIconForFiletype(context5, single.getMimeType())); } else if (model instanceof Model.Many) { Resources resources2 = uploadProgressView.getResources(); m.checkNotNullExpressionValue(resources2, "resources"); Context context6 = uploadProgressView.getContext(); m.checkNotNullExpressionValue(context6, "context"); Model.Many many = (Model.Many) model; CharSequence quantityString = StringResourceUtilsKt.getQuantityString(resources2, context6, 2131755345, many.getNumFiles(), Integer.valueOf(many.getNumFiles())); if (many.getProgress() != -1) { i3 = many.getProgress(); } uploadProgressView.a(quantityString, i3, FileUtilsKt.getSizeSubtitle(many.getSizeBytes())); Context context7 = uploadProgressView.getContext(); m.checkNotNullExpressionValue(context7, "context"); uploadProgressView.setIcon(DrawableCompat.getThemedDrawableRes$default(context7, 2130969467, 0, 2, (Object) null)); } } @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); Observable K = ModelProvider.INSTANCE.get(((UploadProgressEntry) chatListEntry).getMessageNonce(), 100).K(); m.checkNotNullExpressionValue(K, "ModelProvider.get(data.m… .onBackpressureLatest()"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui(K), WidgetChatListAdapterItemUploadProgress.class, (Context) null, new WidgetChatListAdapterItemUploadProgress$onConfigure$2(this), (Function1) null, (Function0) null, (Function0) null, new WidgetChatListAdapterItemUploadProgress$onConfigure$1(this), 58, (Object) null); WidgetChatListAdapterItemUploadProgress$onConfigure$cancel$1 widgetChatListAdapterItemUploadProgress$onConfigure$cancel$1 = new WidgetChatListAdapterItemUploadProgress$onConfigure$cancel$1(chatListEntry); this.binding.f1757c.setOnClickListener(new WidgetChatListAdapterItemUploadProgress$onConfigure$3(widgetChatListAdapterItemUploadProgress$onConfigure$cancel$1)); this.binding.b.setOnClickListener(new WidgetChatListAdapterItemUploadProgress$onConfigure$4(widgetChatListAdapterItemUploadProgress$onConfigure$cancel$1)); } }