package D;

import android.app.Notification;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import androidx.core.graphics.drawable.IconCompat;
import java.util.ArrayList;

/* JADX INFO: loaded from: classes.dex */
public final class I extends K {

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f313h;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public IconCompat f314j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public IconCompat f315k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public IconCompat f316l;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public ArrayList f310e = new ArrayList();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public ArrayList f311f = new ArrayList();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f312g = 0;
    public boolean i = true;

    public static IconCompat e(Parcelable parcelable) {
        if (parcelable == null) {
            return null;
        }
        if (parcelable instanceof Icon) {
            return IconCompat.b((Icon) parcelable);
        }
        if (parcelable instanceof Bitmap) {
            return IconCompat.d((Bitmap) parcelable);
        }
        return null;
    }

    @Override // D.K
    public final void a(Bundle bundle) {
        super.a(bundle);
        if (Build.VERSION.SDK_INT < 36) {
            ArrayList arrayList = this.f310e;
            ArrayList<? extends Parcelable> arrayList2 = new ArrayList<>();
            if (arrayList != null && !arrayList.isEmpty()) {
                for (int i = 0; i < arrayList.size(); i++) {
                    H h3 = (H) arrayList.get(i);
                    if (h3.f307a > 0) {
                        Bundle bundle2 = new Bundle();
                        bundle2.putInt("length", h3.f307a);
                        bundle2.putInt("id", h3.f308b);
                        bundle2.putInt("colorInt", h3.f309c);
                        arrayList2.add(bundle2);
                    }
                }
            }
            bundle.putParcelableArrayList("android.progressSegments", arrayList2);
            ArrayList arrayList3 = this.f311f;
            ArrayList<? extends Parcelable> arrayList4 = new ArrayList<>();
            if (arrayList3 != null && !arrayList3.isEmpty()) {
                for (int i5 = 0; i5 < arrayList3.size(); i5++) {
                    G g5 = (G) arrayList3.get(i5);
                    if (g5.f304a >= 0) {
                        Bundle bundle3 = new Bundle();
                        bundle3.putInt("position", g5.f304a);
                        bundle3.putInt("id", g5.f305b);
                        bundle3.putInt("colorInt", g5.f306c);
                        arrayList4.add(bundle3);
                    }
                }
            }
            bundle.putParcelableArrayList("android.progressPoints", arrayList4);
            bundle.putInt("android.progress", this.f312g);
            bundle.putBoolean("android.progressIndeterminate", this.f313h);
            bundle.putInt("android.progressMax", f());
            bundle.putBoolean("android.styledByProgress", this.i);
            C0044o c0044o = this.f317a;
            Context context = c0044o != null ? c0044o.f392a : null;
            if (context != null) {
                IconCompat iconCompat = this.f314j;
                if (iconCompat != null) {
                    bundle.putParcelable("android.progressTrackerIcon", iconCompat.h(context));
                } else {
                    bundle.remove("android.progressTrackerIcon");
                }
                IconCompat iconCompat2 = this.f315k;
                if (iconCompat2 != null) {
                    bundle.putParcelable("android.progressStartIcon", iconCompat2.h(context));
                } else {
                    bundle.remove("android.progressStartIcon");
                }
                IconCompat iconCompat3 = this.f316l;
                if (iconCompat3 != null) {
                    bundle.putParcelable("android.progressEndIcon", iconCompat3.h(context));
                } else {
                    bundle.remove("android.progressEndIcon");
                }
            }
        }
    }

    @Override // D.K
    public final void b(P p) {
        Notification.Builder builder = p.f322b;
        if (Build.VERSION.SDK_INT < 36) {
            int iF = f();
            builder.setProgress(iF, Math.min(this.f312g, iF), this.f313h);
            return;
        }
        Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
        F.h(progressStyle, this.i);
        F.a(progressStyle, this.f312g);
        F.c(progressStyle, this.f313h);
        IconCompat iconCompat = this.f315k;
        Context context = p.f321a;
        F.f(progressStyle, iconCompat != null ? iconCompat.h(context) : null);
        IconCompat iconCompat2 = this.f316l;
        F.b(progressStyle, iconCompat2 != null ? iconCompat2.h(context) : null);
        IconCompat iconCompat3 = this.f314j;
        F.g(progressStyle, iconCompat3 != null ? iconCompat3.h(context) : null);
        F.d(progressStyle, this.f311f);
        F.e(progressStyle, this.f310e);
        builder.setStyle(progressStyle);
    }

    @Override // D.K
    public final String c() {
        return "androidx.core.app.NotificationCompat$ProgressStyle";
    }

    @Override // D.K
    public final void d(Bundle bundle) {
        super.d(bundle);
        ArrayList arrayListB = Build.VERSION.SDK_INT >= 34 ? L.b.b(bundle, "android.progressSegments") : bundle.getParcelableArrayList("android.progressSegments");
        ArrayList arrayList = new ArrayList();
        if (arrayListB != null && !arrayListB.isEmpty()) {
            for (int i = 0; i < arrayListB.size(); i++) {
                Bundle bundle2 = (Bundle) arrayListB.get(i);
                int i5 = bundle2.getInt("length");
                if (i5 > 0) {
                    int i6 = bundle2.getInt("id");
                    int i7 = bundle2.getInt("colorInt", 0);
                    H h3 = new H();
                    h3.f307a = i5;
                    h3.f308b = i6;
                    h3.f309c = i7;
                    arrayList.add(h3);
                }
            }
        }
        this.f310e = arrayList;
        this.f312g = bundle.getInt("android.progress", 0);
        this.f313h = bundle.getBoolean("android.progressIndeterminate", false);
        this.i = bundle.getBoolean("android.styledByProgress", true);
        ArrayList arrayListB2 = Build.VERSION.SDK_INT >= 34 ? L.b.b(bundle, "android.progressPoints") : bundle.getParcelableArrayList("android.progressPoints");
        ArrayList arrayList2 = new ArrayList();
        if (arrayListB2 != null && !arrayListB2.isEmpty()) {
            for (int i8 = 0; i8 < arrayListB2.size(); i8++) {
                Bundle bundle3 = (Bundle) arrayListB2.get(i8);
                int i9 = bundle3.getInt("position");
                if (i9 >= 0) {
                    int i10 = bundle3.getInt("id");
                    int i11 = bundle3.getInt("colorInt", 0);
                    G g5 = new G();
                    g5.f304a = i9;
                    g5.f305b = i10;
                    g5.f306c = i11;
                    arrayList2.add(g5);
                }
            }
        }
        this.f311f = arrayList2;
        this.f314j = e((Parcelable) b5.a.s(bundle, "android.progressTrackerIcon", Icon.class));
        this.f315k = e((Parcelable) b5.a.s(bundle, "android.progressStartIcon", Icon.class));
        this.f316l = e((Parcelable) b5.a.s(bundle, "android.progressEndIcon", Icon.class));
    }

    public final int f() {
        ArrayList arrayList = this.f310e;
        if (arrayList == null || arrayList.isEmpty()) {
            return 100;
        }
        int i = 0;
        int iAddExact = 0;
        for (int i5 = 0; i5 < arrayList.size(); i5++) {
            int i6 = ((H) arrayList.get(i5)).f307a;
            if (i6 > 0) {
                try {
                    iAddExact = Math.addExact(iAddExact, i6);
                    i++;
                } catch (ArithmeticException unused) {
                    return 100;
                }
            }
        }
        if (i == 0) {
            return 100;
        }
        return iAddExact;
    }
}
