package b0.a.a; import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.os.ParcelFileDescriptor; import b0.a.a.e.a; import d0.l; import d0.w.g.c; import d0.w.h.a.e; import d0.w.h.a.k; import d0.z.d.m; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import kotlin.Unit; import kotlin.coroutines.Continuation; import kotlin.jvm.functions.Function1; import kotlin.jvm.functions.Function2; import kotlinx.coroutines.CoroutineScope; /* compiled from: Compressor.kt */ @e(c = "id.zelory.compressor.Compressor$compress$6", f = "Compressor.kt", l = {}, m = "invokeSuspend") public final class b extends k implements Function2, Object> { public final /* synthetic */ Function1 $compressionPatch; public final /* synthetic */ Context $context; public final /* synthetic */ Uri $imageFileUri; public int label; private CoroutineScope p$; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public b(Function1 function1, Context context, Uri uri, Continuation continuation) { super(2, continuation); this.$compressionPatch = function1; this.$context = context; this.$imageFileUri = uri; } @Override // d0.w.h.a.a public final Continuation create(Object obj, Continuation continuation) { m.checkParameterIsNotNull(continuation, "completion"); b bVar = new b(this.$compressionPatch, this.$context, this.$imageFileUri, continuation); bVar.p$ = (CoroutineScope) obj; return bVar; } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */ @Override // kotlin.jvm.functions.Function2 public final Object invoke(CoroutineScope coroutineScope, Continuation continuation) { Continuation continuation2 = continuation; m.checkParameterIsNotNull(continuation2, "completion"); b bVar = new b(this.$compressionPatch, this.$context, this.$imageFileUri, continuation2); bVar.p$ = coroutineScope; return bVar.invokeSuspend(Unit.a); } /* JADX WARNING: Code restructure failed: missing block: B:42:0x015e, code lost: r2 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:43:0x015f, code lost: d0.y.b.closeFinally(r0, r13); */ /* JADX WARNING: Code restructure failed: missing block: B:44:0x0162, code lost: throw r2; */ /* JADX WARNING: Code restructure failed: missing block: B:47:0x0164, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:48:0x0165, code lost: d0.y.b.closeFinally(r1, r13); */ /* JADX WARNING: Code restructure failed: missing block: B:49:0x0168, code lost: throw r0; */ /* JADX WARNING: Code restructure failed: missing block: B:55:0x0182, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:56:0x0183, code lost: d0.y.b.closeFinally(r1, r13); */ /* JADX WARNING: Code restructure failed: missing block: B:57:0x0186, code lost: throw r0; */ @Override // d0.w.h.a.a public final Object invokeSuspend(Object obj) { String str; c.getCOROUTINE_SUSPENDED(); if (this.label == 0) { l.throwOnFailure(obj); a aVar = new a(); this.$compressionPatch.invoke(aVar); Context context = this.$context; Uri uri = this.$imageFileUri; String str2 = d.a; m.checkParameterIsNotNull(context, "context"); m.checkParameterIsNotNull(uri, "srcFileUri"); StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); File cacheDir = context.getCacheDir(); m.checkExpressionValueIsNotNull(cacheDir, "context.cacheDir"); sb2.append(cacheDir.getPath()); String str3 = d.a; sb2.append(str3); sb2.append("compressor"); sb2.append(str3); sb.append(sb2.toString()); m.checkParameterIsNotNull(context, "context"); m.checkParameterIsNotNull(uri, "uri"); ContentResolver contentResolver = context.getContentResolver(); Cursor query = contentResolver.query(uri, new String[]{"_display_name"}, null, null, null); if (query == null) { m.throwNpe(); } int columnIndex = query.getColumnIndex("_display_name"); if (query.moveToFirst()) { str = query.getString(columnIndex); m.checkExpressionValueIsNotNull(str, "it.getString(nameIndex)"); d0.y.b.closeFinally(query, null); } else { String str4 = "IMG_" + new SimpleDateFormat("yyyyMMdd_", Locale.getDefault()).format(new Date()) + System.nanoTime(); String type = contentResolver.getType(uri); if (m.areEqual(type, "image/jpg") || m.areEqual(type, "image/jpeg")) { str = str4 + ".jpeg"; } else if (m.areEqual(type, "image/png")) { str = str4 + ".png"; } else { throw new IllegalStateException(type + " fallback display name not supported"); } d0.y.b.closeFinally(query, null); } sb.append(str); File file = new File(sb.toString()); File parentFile = file.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } if (file.exists()) { file.delete(); } file.createNewFile(); file.deleteOnExit(); ParcelFileDescriptor.AutoCloseInputStream autoCloseInputStream = new ParcelFileDescriptor.AutoCloseInputStream(context.getContentResolver().openFileDescriptor(uri, "r")); FileOutputStream fileOutputStream = new FileOutputStream(file); d0.y.a.copyTo$default(autoCloseInputStream, fileOutputStream, 0, 2, null); d0.y.b.closeFinally(fileOutputStream, null); d0.y.b.closeFinally(autoCloseInputStream, null); for (b0.a.a.e.b bVar : aVar.a) { while (!bVar.b(file)) { file = bVar.a(file); } } return file; } throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine"); } }