package androidx.media3.exoplayer.offline;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import androidx.core.app.C1006m;
import androidx.core.app.C1007n;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.R;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
@UnstableApi
public final class DownloadNotificationHelper {
    private static final int NULL_STRING_ID = 0;
    private final C1007n notificationBuilder;

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

        public static void setForegroundServiceBehavior(C1007n c1007n) {
            c1007n.f11273z = 1;
        }
    }

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

    private Notification buildEndStateNotification(Context context, int i6, PendingIntent pendingIntent, String str, int i7) {
        return buildNotification(context, i6, pendingIntent, str, i7, 0, 0, false, false, true);
    }

    private Notification buildNotification(Context context, int i6, PendingIntent pendingIntent, String str, int i7, int i8, int i9, boolean z6, boolean z7, boolean z8) {
        C1007n c1007n = this.notificationBuilder;
        c1007n.f11247B.icon = i6;
        C1006m c1006m = null;
        c1007n.f11253e = C1007n.b(i7 == 0 ? null : context.getResources().getString(i7));
        C1007n c1007n2 = this.notificationBuilder;
        c1007n2.f11255g = pendingIntent;
        if (str != null) {
            c1006m = new C1006m(0);
            c1006m.f11245b = C1007n.b(str);
        }
        c1007n2.d(c1006m);
        C1007n c1007n3 = this.notificationBuilder;
        c1007n3.f11261n = i8;
        c1007n3.f11262o = i9;
        c1007n3.f11263p = z6;
        c1007n3.c(2, z7);
        C1007n c1007n4 = this.notificationBuilder;
        c1007n4.f11258j = z8;
        if (Util.SDK_INT >= 31) {
            Api31.setForegroundServiceBehavior(c1007n4);
        }
        return this.notificationBuilder.a();
    }

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

    public Notification buildDownloadFailedNotification(Context context, int i6, PendingIntent pendingIntent, String str) {
        return buildEndStateNotification(context, i6, 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, int i6, PendingIntent pendingIntent, String str, List<Download> list, int i7) {
        int i8;
        int i9;
        boolean z6;
        int i10;
        int i11;
        boolean z7;
        float f6 = 0.0f;
        boolean z8 = false;
        boolean z9 = false;
        boolean z10 = false;
        boolean z11 = false;
        boolean z12 = false;
        int i12 = 0;
        boolean z13 = true;
        for (int i13 = 0; i13 < list.size(); i13++) {
            Download download = list.get(i13);
            int i14 = download.state;
            if (i14 == 0) {
                z10 = true;
            } else if (i14 == 2) {
                float percentDownloaded = download.getPercentDownloaded();
                if (percentDownloaded != -1.0f) {
                    f6 += percentDownloaded;
                    z13 = false;
                }
                z11 |= download.getBytesDownloaded() > 0;
                i12++;
                z9 = true;
            } else if (i14 == 5) {
                z12 = true;
            } else if (i14 != 7) {
            }
        }
        if (z9) {
            i9 = R.string.exo_download_downloading;
        } else {
            if (z10 && i7 != 0) {
                i8 = (i7 & 2) != 0 ? R.string.exo_download_paused_for_wifi : (i7 & 1) != 0 ? R.string.exo_download_paused_for_network : R.string.exo_download_paused;
                z6 = false;
                if (z6) {
                }
                return buildNotification(context, i6, pendingIntent, str, i8, i10, i11, z7, true, false);
            }
            if (!z12) {
                i8 = 0;
                z6 = true;
                if (z6) {
                    if (z9) {
                        int i15 = (int) (f6 / i12);
                        if (z13 && z11) {
                            z8 = true;
                        }
                        i11 = i15;
                        z7 = z8;
                    } else {
                        i11 = 0;
                        z7 = true;
                    }
                    i10 = 100;
                } else {
                    i10 = 0;
                    i11 = 0;
                    z7 = false;
                }
                return buildNotification(context, i6, pendingIntent, str, i8, i10, i11, z7, true, false);
            }
            i9 = R.string.exo_download_removing;
        }
        i8 = i9;
        z6 = true;
        if (z6) {
        }
        return buildNotification(context, i6, pendingIntent, str, i8, i10, i11, z7, true, false);
    }
}
