discord-jadx/app/src/main/java/com/lytefast/flexinput/model/Attachment.java

237 lines
9.9 KiB
Java

package com.lytefast.flexinput.model;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import androidx.annotation.CallSuper;
import androidx.core.view.inputmethod.InputContentInfoCompat;
import com.airbnb.lottie.parser.AnimatableValueParser;
import d0.g0.w;
import d0.y.b;
import d0.z.d.m;
import java.io.File;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: Attachment.kt */
public class Attachment<T> implements Parcelable {
public static final Parcelable.Creator<Attachment<?>> CREATOR = new a();
public static final Companion Companion = new Companion(null);
private final T data;
private final String displayName;
/* renamed from: id reason: collision with root package name */
private final long f2404id;
private final Uri uri;
/* compiled from: Attachment.kt */
public static final class Companion {
public Companion() {
}
public Companion(DefaultConstructorMarker defaultConstructorMarker) {
}
/* JADX WARNING: Code restructure failed: missing block: B:26:0x0065, code lost:
r1 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:27:0x0066, code lost:
d0.y.b.closeFinally(r12, r0);
*/
/* JADX WARNING: Code restructure failed: missing block: B:28:0x0069, code lost:
throw r1;
*/
/* JADX WARNING: Removed duplicated region for block: B:39:0x00aa */
public final Attachment<Uri> a(Uri uri, ContentResolver contentResolver) {
String str;
int columnIndex;
m.checkNotNullParameter(uri, "$this$toAttachment");
m.checkNotNullParameter(contentResolver, "resolver");
m.checkNotNullParameter(uri, "$this$getFileName");
m.checkNotNullParameter(contentResolver, "contentResolver");
String scheme = uri.getScheme();
if (scheme != null) {
int hashCode = scheme.hashCode();
str = null;
if (hashCode != 3143036) {
if (hashCode == 951530617 && scheme.equals("content")) {
try {
Cursor query = contentResolver.query(uri, null, null, null, null);
if (query != null) {
if (!query.moveToFirst() || (columnIndex = query.getColumnIndex("_display_name")) < 0) {
b.closeFinally(query, null);
} else {
String string = query.getString(columnIndex);
if (string == null) {
string = uri.getLastPathSegment();
}
b.closeFinally(query, null);
str = string;
if (str == null) {
str = String.valueOf(uri.hashCode());
}
return new Attachment<>((long) uri.hashCode(), uri, str, null);
}
}
str = uri.getLastPathSegment();
} catch (NullPointerException e) {
StringBuilder K = c.d.b.a.a.K("Error getting file name for: ");
K.append(uri.getPath());
Log.e("FileUtils", K.toString(), e);
str = uri.getLastPathSegment();
}
if (str == null) {
}
return new Attachment<>((long) uri.hashCode(), uri, str, null);
}
} else if (scheme.equals("file")) {
String path = uri.getPath();
if (path != null) {
str = new File(path).getName();
}
if (str == null) {
}
return new Attachment<>((long) uri.hashCode(), uri, str, null);
}
}
str = uri.getLastPathSegment();
if (str == null) {
}
return new Attachment<>((long) uri.hashCode(), uri, str, null);
}
public final Attachment<InputContentInfoCompat> b(InputContentInfoCompat inputContentInfoCompat, ContentResolver contentResolver, boolean z2, String str) {
String str2;
m.checkNotNullParameter(inputContentInfoCompat, "$this$toAttachment");
m.checkNotNullParameter(contentResolver, "resolver");
m.checkNotNullParameter(str, "defaultName");
String queryParameter = inputContentInfoCompat.getContentUri().getQueryParameter("fileName");
if (queryParameter != null) {
str = queryParameter;
}
m.checkNotNullExpressionValue(str, "contentUri.getQueryParam…fileName\") ?: defaultName");
String substringAfterLast$default = w.substringAfterLast$default(str, File.separatorChar, null, 2, null);
if (z2) {
String mimeType = inputContentInfoCompat.getDescription().getMimeType(0);
if (mimeType == null) {
mimeType = inputContentInfoCompat.getContentUri().getQueryParameter("mimeType");
}
if (mimeType == null) {
mimeType = contentResolver.getType(inputContentInfoCompat.getContentUri());
}
if (mimeType != null) {
String str3 = substringAfterLast$default + '.' + w.substringAfterLast$default(mimeType, '/', null, 2, null);
if (str3 != null) {
str2 = str3;
Uri contentUri = inputContentInfoCompat.getContentUri();
m.checkNotNullExpressionValue(contentUri, "contentUri");
return new Attachment<>((long) inputContentInfoCompat.getContentUri().hashCode(), contentUri, str2, inputContentInfoCompat);
}
}
}
str2 = substringAfterLast$default;
Uri contentUri = inputContentInfoCompat.getContentUri();
m.checkNotNullExpressionValue(contentUri, "contentUri");
return new Attachment<>((long) inputContentInfoCompat.getContentUri().hashCode(), contentUri, str2, inputContentInfoCompat);
}
}
/* compiled from: Attachment.kt */
public static final class a implements Parcelable.Creator<Attachment<?>> {
/* Return type fixed from 'java.lang.Object' to match base method */
@Override // android.os.Parcelable.Creator
public Attachment<?> createFromParcel(Parcel parcel) {
m.checkNotNullParameter(parcel, "parcelIn");
return new Attachment<>(parcel);
}
/* Return type fixed from 'java.lang.Object[]' to match base method */
@Override // android.os.Parcelable.Creator
public Attachment<?>[] newArray(int i) {
return new Attachment[i];
}
}
public Attachment(long j, Uri uri, String str, T t) {
m.checkNotNullParameter(uri, "uri");
m.checkNotNullParameter(str, "displayName");
this.f2404id = j;
this.uri = uri;
this.displayName = str;
this.data = t;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ Attachment(long j, Uri uri, String str, Object obj, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(j, uri, str, (i & 8) != 0 ? null : obj);
}
/* JADX WARNING: Illegal instructions before constructor call */
public Attachment(Parcel parcel) {
this(r2, r0, r8, null);
m.checkNotNullParameter(parcel, "parcelIn");
long readLong = parcel.readLong();
Uri uri = (Uri) parcel.readParcelable(Uri.class.getClassLoader());
if (uri == null) {
uri = Uri.EMPTY;
m.checkNotNullExpressionValue(uri, "Uri.EMPTY");
}
String readString = parcel.readString();
readString = readString == null ? "" : readString;
m.checkNotNullExpressionValue(readString, "parcelIn.readString() ?: \"\"");
}
public static final Attachment<Uri> toAttachment(Uri uri, ContentResolver contentResolver) {
return Companion.a(uri, contentResolver);
}
public static final Attachment<InputContentInfoCompat> toAttachment(InputContentInfoCompat inputContentInfoCompat, ContentResolver contentResolver, boolean z2, String str) {
return Companion.b(inputContentInfoCompat, contentResolver, z2, str);
}
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // java.lang.Object
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof Attachment)) {
return false;
}
Attachment attachment = (Attachment) obj;
return this.f2404id == attachment.f2404id && m.areEqual(this.uri, attachment.uri);
}
public final T getData() {
return this.data;
}
public final String getDisplayName() {
return this.displayName;
}
public final long getId() {
return this.f2404id;
}
public final Uri getUri() {
return this.uri;
}
@Override // java.lang.Object
public int hashCode() {
return AnimatableValueParser.W0(Long.valueOf(this.f2404id), this.uri);
}
@Override // android.os.Parcelable
@CallSuper
public void writeToParcel(Parcel parcel, int i) {
m.checkNotNullParameter(parcel, "dest");
parcel.writeLong(this.f2404id);
parcel.writeParcelable(this.uri, i);
parcel.writeString(this.displayName);
}
}