package defpackage;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.core.content.FileProvider;
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
import com.google.android.material.button.MaterialButton;
import com.strmr.ps.R;
import com.strmr.ps.update.UpdateDownloadManager;
import com.strmr.ps.update.a;
import java.io.File;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\u000e\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\u00020\u00022\u0006\u0010\u0001\u001a\u00020\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lcom/strmr/ps/update/a;", "state", "Le6a;", "<anonymous>", "(Lcom/strmr/ps/update/a;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.ui.update.UpdateDialog$startDownload$1$1", f = "UpdateDialog.kt", i = {}, l = {}, m = "invokeSuspend", n = {}, s = {})
final class i9a extends SuspendLambda implements gr3<a, Continuation<? super e6a>, Object> {
    public /* synthetic */ Object a;
    public final /* synthetic */ k9a b;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public i9a(k9a k9aVar, Continuation continuation) {
        super(2, continuation);
        this.b = k9aVar;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        i9a i9aVar = new i9a(this.b, continuation);
        i9aVar.a = obj;
        return i9aVar;
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        i9a i9aVar = (i9a) create((a) obj, (Continuation) obj2);
        e6a e6aVar = e6a.a;
        i9aVar.invokeSuspend(e6aVar);
        return e6aVar;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Object invokeSuspend(Object obj) {
        ck1 ck1Var = ck1.a;
        s38.b(obj);
        a aVar = (a) this.a;
        boolean z = aVar instanceof a.d;
        k9a k9aVar = this.b;
        if (z) {
            TextView textView = k9aVar.l;
            if (textView == null) {
                cr4.n("progressText");
                throw null;
            }
            textView.setText(k9aVar.getContext().getString(R.string.preparing_download));
        } else if (aVar instanceof a.b) {
            ProgressBar progressBar = k9aVar.k;
            if (progressBar == null) {
                cr4.n("downloadProgress");
                throw null;
            }
            a.b bVar = (a.b) aVar;
            int i = bVar.a;
            progressBar.setProgress(zr7.c(i, 0, 100));
            long j = bVar.b;
            long j2 = ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES;
            long j3 = j / j2;
            long j4 = bVar.c / j2;
            TextView textView2 = k9aVar.l;
            if (textView2 == null) {
                cr4.n("progressText");
                throw null;
            }
            textView2.setText(i >= 0 ? k9aVar.getContext().getString(R.string.downloading_progress, Boxing.boxInt(i), Boxing.boxLong(j3), Boxing.boxLong(j4)) : k9aVar.getContext().getString(R.string.downloading_size, Boxing.boxLong(j3)));
        } else if (aVar instanceof a.C0126a) {
            TextView textView3 = k9aVar.l;
            if (textView3 == null) {
                cr4.n("progressText");
                throw null;
            }
            textView3.setText(k9aVar.getContext().getString(R.string.download_complete));
            k9aVar.o = false;
            UpdateDownloadManager updateDownloadManager = k9aVar.b;
            Context context = k9aVar.getContext();
            cr4.f(context, "getContext(...)");
            File file = ((a.C0126a) aVar).a;
            updateDownloadManager.getClass();
            file.getAbsolutePath();
            Uri uriD = FileProvider.d(context, file);
            cr4.f(uriD, "getUriForFile(...)");
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.setDataAndType(uriD, "application/vnd.android.package-archive");
            intent.setFlags(268435457);
            context.startActivity(intent);
        } else {
            if (!(aVar instanceof a.c)) {
                throw new io6();
            }
            k9aVar.o = false;
            View view = k9aVar.j;
            if (view == null) {
                cr4.n("progressSection");
                throw null;
            }
            view.setVisibility(8);
            View view2 = k9aVar.m;
            if (view2 == null) {
                cr4.n("buttonSection");
                throw null;
            }
            view2.setVisibility(0);
            MaterialButton materialButton = k9aVar.e;
            if (materialButton == null) {
                cr4.n("btnUpdate");
                throw null;
            }
            materialButton.setText(k9aVar.getContext().getString(R.string.retry_download));
            MaterialButton materialButton2 = k9aVar.e;
            if (materialButton2 == null) {
                cr4.n("btnUpdate");
                throw null;
            }
            materialButton2.setOnClickListener(new h9a(k9aVar, 3));
            TextView textView4 = k9aVar.l;
            if (textView4 == null) {
                cr4.n("progressText");
                throw null;
            }
            textView4.setVisibility(0);
            TextView textView5 = k9aVar.l;
            if (textView5 == null) {
                cr4.n("progressText");
                throw null;
            }
            textView5.setText(((a.c) aVar).a);
        }
        return e6a.a;
    }
}
