package androidx.media3.exoplayer.offline;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.os.Build;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.R;
import defpackage.l18;
import defpackage.of2;
import defpackage.rq6;
import defpackage.t79;
import defpackage.wp6;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
@UnstableApi
public final class DownloadNotificationHelper {

    @t79
    private static final int NULL_STRING_ID = 0;
    private final wp6.o notificationBuilder;

    @l18
    public static final class Api31 {
        private Api31() {
        }

        @SuppressLint({"WrongConstant"})
        public static void setForegroundServiceBehavior(wp6.o oVar) {
            oVar.aa = 1;
        }
    }

    public DownloadNotificationHelper(Context context, String str) {
        this.notificationBuilder = new wp6.o(context.getApplicationContext(), str);
    }

    private Notification buildEndStateNotification(Context context, @of2 int i, @rq6 PendingIntent pendingIntent, @rq6 String str, @t79 int i2) {
        return buildNotification(context, i, pendingIntent, str, i2, 0, 0, false, false, true);
    }

    private Notification buildNotification(Context context, @of2 int i, @rq6 PendingIntent pendingIntent, @rq6 String str, @t79 int i2, int i3, int i4, boolean z, boolean z2, boolean z3) {
        wp6.o oVar = this.notificationBuilder;
        oVar.ac.icon = i;
        wp6.m mVar = null;
        oVar.e = wp6.o.b(i2 == 0 ? null : context.getResources().getString(i2));
        wp6.o oVar2 = this.notificationBuilder;
        oVar2.g = pendingIntent;
        if (str != null) {
            mVar = new wp6.m();
            mVar.a = wp6.o.b(str);
        }
        oVar2.d(mVar);
        wp6.o oVar3 = this.notificationBuilder;
        oVar3.n = i3;
        oVar3.o = i4;
        oVar3.p = z;
        oVar3.c(2, z2);
        wp6.o oVar4 = this.notificationBuilder;
        oVar4.j = z3;
        if (Build.VERSION.SDK_INT >= 31) {
            Api31.setForegroundServiceBehavior(oVar4);
        }
        return this.notificationBuilder.a();
    }

    public Notification buildDownloadCompletedNotification(Context context, @of2 int i, @rq6 PendingIntent pendingIntent, @rq6 String str) {
        return buildEndStateNotification(context, i, pendingIntent, str, R.string.exo_download_completed);
    }

    public Notification buildDownloadFailedNotification(Context context, @of2 int i, @rq6 PendingIntent pendingIntent, @rq6 String str) {
        return buildEndStateNotification(context, i, pendingIntent, str, R.string.exo_download_failed);
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0028  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x0071  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x0089  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Notification buildProgressNotification(Context context, @of2 int i, @rq6 PendingIntent pendingIntent, @rq6 String str, List<Download> list, int i2) {
        int i3;
        int i4;
        boolean z;
        int i5;
        int i6;
        boolean z2;
        float f = 0.0f;
        boolean z3 = false;
        boolean z4 = false;
        boolean z5 = false;
        boolean z6 = false;
        boolean z7 = false;
        int i7 = 0;
        boolean z8 = true;
        for (int i8 = 0; i8 < list.size(); i8++) {
            Download download = list.get(i8);
            int i9 = download.state;
            if (i9 == 0) {
                z5 = true;
            } else if (i9 == 2) {
                float percentDownloaded = download.getPercentDownloaded();
                if (percentDownloaded != -1.0f) {
                    f += percentDownloaded;
                    z8 = false;
                }
                z6 |= download.getBytesDownloaded() > 0;
                i7++;
                z4 = true;
            } else if (i9 == 5) {
                z7 = true;
            } else if (i9 != 7) {
            }
        }
        if (z4) {
            i4 = R.string.exo_download_downloading;
        } else {
            if (z5 && i2 != 0) {
                i3 = (i2 & 2) != 0 ? R.string.exo_download_paused_for_wifi : (i2 & 1) != 0 ? R.string.exo_download_paused_for_network : R.string.exo_download_paused;
                z = false;
                if (z) {
                }
                return buildNotification(context, i, pendingIntent, str, i3, i5, i6, z2, true, false);
            }
            if (!z7) {
                i3 = 0;
                z = true;
                if (z) {
                    if (z4) {
                        int i10 = (int) (f / i7);
                        if (z8 && z6) {
                            z3 = true;
                        }
                        i6 = i10;
                        z2 = z3;
                    } else {
                        i6 = 0;
                        z2 = true;
                    }
                    i5 = 100;
                } else {
                    i5 = 0;
                    i6 = 0;
                    z2 = false;
                }
                return buildNotification(context, i, pendingIntent, str, i3, i5, i6, z2, true, false);
            }
            i4 = R.string.exo_download_removing;
        }
        i3 = i4;
        z = true;
        if (z) {
        }
        return buildNotification(context, i, pendingIntent, str, i3, i5, i6, z2, true, false);
    }
}
