discord-jadx/app/src/main/java/com/discord/utilities/images/MGImagesBitmap.java

403 lines
16 KiB
Java

package com.discord.utilities.images;
import android.graphics.Bitmap;
import android.net.Uri;
import androidx.core.app.NotificationCompat;
import b.c.a.a0.d;
import b.f.j.e.h;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import d0.g0.t;
import d0.t.h0;
import d0.z.d.g0.a;
import d0.z.d.m;
import j0.l.a.q;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
/* compiled from: MGImagesBitmap.kt */
/* loaded from: classes2.dex */
public final class MGImagesBitmap {
public static final MGImagesBitmap INSTANCE = new MGImagesBitmap();
/* compiled from: MGImagesBitmap.kt */
/* loaded from: classes2.dex */
public static final class CloseableBitmaps implements Map<String, Bitmap>, Closeable, a {
private final boolean recycleBitmaps;
private final Map<String, Bitmap> underlyingMap;
public CloseableBitmaps(Map<String, Bitmap> map, boolean z2) {
m.checkNotNullParameter(map, "underlyingMap");
this.underlyingMap = map;
this.recycleBitmaps = z2;
}
public /* synthetic */ CloseableBitmaps(Map map, boolean z2, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(map, (i & 2) != 0 ? true : z2);
}
@Override // java.util.Map
public void clear() {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() {
if (this.recycleBitmaps) {
for (Map.Entry<String, Bitmap> entry : this.underlyingMap.entrySet()) {
entry.getValue().recycle();
}
}
}
/* renamed from: compute reason: avoid collision after fix types in other method */
public Bitmap compute2(String str, BiFunction<? super String, ? super Bitmap, ? extends Bitmap> biFunction) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public /* synthetic */ Bitmap compute(String str, BiFunction<? super String, ? super Bitmap, ? extends Bitmap> biFunction) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
/* renamed from: computeIfAbsent reason: avoid collision after fix types in other method */
public Bitmap computeIfAbsent2(String str, Function<? super String, ? extends Bitmap> function) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public /* synthetic */ Bitmap computeIfAbsent(String str, Function<? super String, ? extends Bitmap> function) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
/* renamed from: computeIfPresent reason: avoid collision after fix types in other method */
public Bitmap computeIfPresent2(String str, BiFunction<? super String, ? super Bitmap, ? extends Bitmap> biFunction) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public /* synthetic */ Bitmap computeIfPresent(String str, BiFunction<? super String, ? super Bitmap, ? extends Bitmap> biFunction) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public final /* bridge */ boolean containsKey(Object obj) {
if (obj instanceof String) {
return containsKey((String) obj);
}
return false;
}
public boolean containsKey(String str) {
m.checkNotNullParameter(str, "key");
return this.underlyingMap.containsKey(str);
}
public boolean containsValue(Bitmap bitmap) {
m.checkNotNullParameter(bitmap, "value");
return this.underlyingMap.containsValue(bitmap);
}
@Override // java.util.Map
public final /* bridge */ boolean containsValue(Object obj) {
if (obj instanceof Bitmap) {
return containsValue((Bitmap) obj);
}
return false;
}
@Override // java.util.Map
public final /* bridge */ Set<Map.Entry<String, Bitmap>> entrySet() {
return getEntries();
}
public Bitmap get(String str) {
m.checkNotNullParameter(str, "key");
return this.underlyingMap.get(str);
}
@Override // java.util.Map
public final /* bridge */ Bitmap get(Object obj) {
if (obj instanceof String) {
return get((String) obj);
}
return null;
}
public Set<Map.Entry<String, Bitmap>> getEntries() {
return this.underlyingMap.entrySet();
}
public Set<String> getKeys() {
return this.underlyingMap.keySet();
}
public int getSize() {
return this.underlyingMap.size();
}
public Collection<Bitmap> getValues() {
return this.underlyingMap.values();
}
@Override // java.util.Map
public boolean isEmpty() {
return this.underlyingMap.isEmpty();
}
@Override // java.util.Map
public final /* bridge */ Set<String> keySet() {
return getKeys();
}
/* renamed from: merge reason: avoid collision after fix types in other method */
public Bitmap merge2(String str, Bitmap bitmap, BiFunction<? super Bitmap, ? super Bitmap, ? extends Bitmap> biFunction) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public /* synthetic */ Bitmap merge(String str, Bitmap bitmap, BiFunction<? super Bitmap, ? super Bitmap, ? extends Bitmap> biFunction) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
public final CloseableBitmaps plus(CloseableBitmaps closeableBitmaps) {
m.checkNotNullParameter(closeableBitmaps, "other");
return new CloseableBitmaps(h0.plus(this.underlyingMap, closeableBitmaps.underlyingMap), this.recycleBitmaps && closeableBitmaps.recycleBitmaps);
}
/* renamed from: put reason: avoid collision after fix types in other method */
public Bitmap put2(String str, Bitmap bitmap) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public /* synthetic */ Bitmap put(String str, Bitmap bitmap) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public void putAll(Map<? extends String, ? extends Bitmap> map) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
/* renamed from: putIfAbsent reason: avoid collision after fix types in other method */
public Bitmap putIfAbsent2(String str, Bitmap bitmap) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public /* synthetic */ Bitmap putIfAbsent(String str, Bitmap bitmap) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public Bitmap remove(Object obj) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public boolean remove(Object obj, Object obj2) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
/* renamed from: replace reason: avoid collision after fix types in other method */
public Bitmap replace2(String str, Bitmap bitmap) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public /* synthetic */ Bitmap replace(String str, Bitmap bitmap) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public /* synthetic */ boolean replace(String str, Bitmap bitmap, Bitmap bitmap2) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
/* renamed from: replace reason: avoid collision after fix types in other method */
public boolean replace2(String str, Bitmap bitmap, Bitmap bitmap2) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public void replaceAll(BiFunction<? super String, ? super Bitmap, ? extends Bitmap> biFunction) {
throw new UnsupportedOperationException("Operation is not supported for read-only collection");
}
@Override // java.util.Map
public final /* bridge */ int size() {
return getSize();
}
@Override // java.util.Map
public final /* bridge */ Collection<Bitmap> values() {
return getValues();
}
}
/* compiled from: MGImagesBitmap.kt */
/* loaded from: classes2.dex */
public static final class DecodeException extends Exception {
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
public DecodeException(String str) {
super("Unable to decode image: " + str + '.');
m.checkNotNullParameter(str, "imageUri");
}
}
/* compiled from: MGImagesBitmap.kt */
/* loaded from: classes2.dex */
public static final class ImageNotFoundException extends Exception {
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
public ImageNotFoundException(String str) {
super("404 image not found: " + str);
m.checkNotNullParameter(str, "imageUri");
}
}
/* compiled from: MGImagesBitmap.kt */
/* loaded from: classes2.dex */
public static final class ImageRequest {
private final String imageUri;
private final boolean roundAsCircle;
public ImageRequest(String str, boolean z2) {
m.checkNotNullParameter(str, "imageUri");
this.imageUri = str;
this.roundAsCircle = z2;
}
public static /* synthetic */ ImageRequest copy$default(ImageRequest imageRequest, String str, boolean z2, int i, Object obj) {
if ((i & 1) != 0) {
str = imageRequest.imageUri;
}
if ((i & 2) != 0) {
z2 = imageRequest.roundAsCircle;
}
return imageRequest.copy(str, z2);
}
public final String component1() {
return this.imageUri;
}
public final boolean component2() {
return this.roundAsCircle;
}
public final ImageRequest copy(String str, boolean z2) {
m.checkNotNullParameter(str, "imageUri");
return new ImageRequest(str, z2);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ImageRequest)) {
return false;
}
ImageRequest imageRequest = (ImageRequest) obj;
return m.areEqual(this.imageUri, imageRequest.imageUri) && this.roundAsCircle == imageRequest.roundAsCircle;
}
public final String getImageUri() {
return this.imageUri;
}
public final boolean getRoundAsCircle() {
return this.roundAsCircle;
}
public int hashCode() {
String str = this.imageUri;
int hashCode = (str != null ? str.hashCode() : 0) * 31;
boolean z2 = this.roundAsCircle;
if (z2) {
z2 = true;
}
int i = z2 ? 1 : 0;
int i2 = z2 ? 1 : 0;
int i3 = z2 ? 1 : 0;
return hashCode + i;
}
public String toString() {
StringBuilder R = b.d.b.a.a.R("ImageRequest(imageUri=");
R.append(this.imageUri);
R.append(", roundAsCircle=");
return b.d.b.a.a.M(R, this.roundAsCircle, ")");
}
}
/* compiled from: MGImagesBitmap.kt */
/* loaded from: classes2.dex */
public static final class MissingBitmapException extends Exception {
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
public MissingBitmapException(String str) {
super("Unable to decode image as bitmap: " + str);
m.checkNotNullParameter(str, "imageUri");
}
}
private MGImagesBitmap() {
}
public static final Observable<CloseableBitmaps> getBitmaps(Set<ImageRequest> set) {
m.checkNotNullParameter(set, "imageRequests");
ArrayList arrayList = new ArrayList();
for (Object obj : set) {
if (!t.isBlank(((ImageRequest) obj).getImageUri())) {
arrayList.add(obj);
}
}
Observable<CloseableBitmaps> X = Observable.h0(new q(arrayList)).A(MGImagesBitmap$getBitmaps$1.INSTANCE).g0(MGImagesBitmap$getBitmaps$2.INSTANCE, MGImagesBitmap$getBitmaps$3.INSTANCE).G(MGImagesBitmap$getBitmaps$4.INSTANCE).X(j0.p.a.a());
m.checkNotNullExpressionValue(X, "Observable\n .from…Schedulers.computation())");
return X;
}
private final boolean isValidUri(String str) {
Uri parse = Uri.parse(str);
m.checkNotNullExpressionValue(parse, NotificationCompat.MessagingStyle.Message.KEY_DATA_URI);
String scheme = parse.getScheme();
if (scheme == null || t.isBlank(scheme)) {
return false;
}
String host = parse.getHost();
if (host == null || t.isBlank(host)) {
return false;
}
String path = parse.getPath();
return !(path == null || t.isBlank(path));
}
public final Observable<Bitmap> getBitmap(String str, boolean z2) {
m.checkNotNullParameter(str, "imageUri");
if (!isValidUri(str)) {
Observable<Bitmap> x2 = Observable.x(new IllegalArgumentException(b.d.b.a.a.v("invalid uri: ", str)));
m.checkNotNullExpressionValue(x2, "Observable.error(Illegal…invalid uri: $imageUri\"))");
return x2;
}
b.f.j.e.m mVar = b.f.j.e.m.a;
d.y(mVar, "ImagePipelineFactory was not initialized!");
if (mVar.l == null) {
mVar.l = mVar.a();
}
h hVar = mVar.l;
ImageRequestBuilder imageRequest = MGImages.getImageRequest(str, 0, 0, false);
if (z2) {
imageRequest.l = new RoundAsCirclePostprocessor(str);
}
Observable<Bitmap> h02 = Observable.h0(new MGImagesBitmap$getBitmap$1(hVar.a(imageRequest.a(), null, ImageRequest.c.FULL_FETCH, null, null), str));
m.checkNotNullExpressionValue(h02, "Observable.unsafeCreate …y emits the bitmap.\n }");
return h02;
}
}