package androidx.core.app;

import android.app.Notification;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Iterator;

/* JADX INFO: loaded from: classes.dex */
public final class i1 extends j1 {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public z1 f1582c;

    @Nullable
    private CharSequence mConversationTitle;

    @Nullable
    private Boolean mIsGroupConversation;

    @Nullable
    public static i1 extractMessagingStyleFromNotification(@NonNull Notification notification) {
        j1 j1VarExtractStyleFromNotification = j1.extractStyleFromNotification(notification);
        if (j1VarExtractStyleFromNotification instanceof i1) {
            return (i1) j1VarExtractStyleFromNotification;
        }
        return null;
    }

    @Nullable
    private h1 findLatestIncomingMessage() {
        ArrayList arrayList = this.f1580a;
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            h1 h1Var = (h1) arrayList.get(size);
            if (h1Var.getPerson() != null && !TextUtils.isEmpty(h1Var.getPerson().getName())) {
                return h1Var;
            }
        }
        if (arrayList.isEmpty()) {
            return null;
        }
        return (h1) com.google.android.gms.measurement.internal.u1.e(arrayList, 1);
    }

    @Override // androidx.core.app.j1
    public final void addCompatExtras(Bundle bundle) {
        super.addCompatExtras(bundle);
        bundle.putCharSequence("android.selfDisplayName", this.f1582c.getName());
        bundle.putBundle("android.messagingStyleUser", this.f1582c.b());
        bundle.putCharSequence("android.hiddenConversationTitle", this.mConversationTitle);
        if (this.mConversationTitle != null && this.mIsGroupConversation.booleanValue()) {
            bundle.putCharSequence("android.conversationTitle", this.mConversationTitle);
        }
        ArrayList arrayList = this.f1580a;
        if (!arrayList.isEmpty()) {
            bundle.putParcelableArray("android.messages", h1.a(arrayList));
        }
        ArrayList arrayList2 = this.f1581b;
        if (!arrayList2.isEmpty()) {
            bundle.putParcelableArray("android.messages.historic", h1.a(arrayList2));
        }
        Boolean bool = this.mIsGroupConversation;
        if (bool != null) {
            bundle.putBoolean("android.isGroupConversation", bool.booleanValue());
        }
    }

    @NonNull
    public i1 addHistoricMessage(@Nullable h1 h1Var) {
        if (h1Var != null) {
            ArrayList arrayList = this.f1581b;
            arrayList.add(h1Var);
            if (arrayList.size() > 25) {
                arrayList.remove(0);
            }
        }
        return this;
    }

    @NonNull
    @Deprecated
    public i1 addMessage(@Nullable CharSequence charSequence, long j10, @Nullable CharSequence charSequence2) {
        ArrayList arrayList = this.f1580a;
        arrayList.add(new h1(charSequence, j10, new y1().setName(charSequence2).a()));
        if (arrayList.size() > 25) {
            arrayList.remove(0);
        }
        return this;
    }

    @Override // androidx.core.app.j1
    public final void apply(z zVar) {
        Notification.MessagingStyle messagingStyleB;
        s0 s0Var = this.mBuilder;
        boolean zBooleanValue = false;
        if (s0Var == null || s0Var.f1646a.getApplicationInfo().targetSdkVersion >= 28 || this.mIsGroupConversation != null) {
            Boolean bool = this.mIsGroupConversation;
            if (bool != null) {
                zBooleanValue = bool.booleanValue();
            }
        } else if (this.mConversationTitle != null) {
            zBooleanValue = true;
        }
        this.mIsGroupConversation = Boolean.valueOf(zBooleanValue);
        if (Build.VERSION.SDK_INT >= 28) {
            z1 z1Var = this.f1582c;
            z1Var.getClass();
            messagingStyleB = e1.a(m.d.y(z1Var));
        } else {
            messagingStyleB = c1.b(this.f1582c.getName());
        }
        Iterator it = this.f1580a.iterator();
        while (it.hasNext()) {
            c1.a(messagingStyleB, ((h1) it.next()).c());
        }
        if (Build.VERSION.SDK_INT >= 26) {
            Iterator it2 = this.f1581b.iterator();
            while (it2.hasNext()) {
                d1.a(messagingStyleB, ((h1) it2.next()).c());
            }
        }
        if (this.mIsGroupConversation.booleanValue() || Build.VERSION.SDK_INT >= 28) {
            c1.c(messagingStyleB, this.mConversationTitle);
        }
        if (Build.VERSION.SDK_INT >= 28) {
            e1.b(messagingStyleB, this.mIsGroupConversation.booleanValue());
        }
        messagingStyleB.setBuilder(((l1) zVar).f1598b);
    }

    @Override // androidx.core.app.j1
    public final void clearCompatExtraKeys(Bundle bundle) {
        super.clearCompatExtraKeys(bundle);
        bundle.remove("android.messagingStyleUser");
        bundle.remove("android.selfDisplayName");
        bundle.remove("android.conversationTitle");
        bundle.remove("android.hiddenConversationTitle");
        bundle.remove("android.messages");
        bundle.remove("android.messages.historic");
        bundle.remove("android.isGroupConversation");
    }

    @Override // androidx.core.app.j1
    public final String getClassName() {
        return "androidx.core.app.NotificationCompat$MessagingStyle";
    }

    @Nullable
    public CharSequence getConversationTitle() {
        return this.mConversationTitle;
    }

    @Nullable
    @Deprecated
    public CharSequence getUserDisplayName() {
        return this.f1582c.getName();
    }

    @Override // androidx.core.app.j1
    public final void restoreFromCompatExtras(Bundle bundle) {
        super.restoreFromCompatExtras(bundle);
        ArrayList arrayList = this.f1580a;
        arrayList.clear();
        if (bundle.containsKey("android.messagingStyleUser")) {
            this.f1582c = z1.a(bundle.getBundle("android.messagingStyleUser"));
        } else {
            this.f1582c = new y1().setName(bundle.getString("android.selfDisplayName")).a();
        }
        CharSequence charSequence = bundle.getCharSequence("android.conversationTitle");
        this.mConversationTitle = charSequence;
        if (charSequence == null) {
            this.mConversationTitle = bundle.getCharSequence("android.hiddenConversationTitle");
        }
        Parcelable[] parcelableArray = bundle.getParcelableArray("android.messages");
        if (parcelableArray != null) {
            arrayList.addAll(h1.b(parcelableArray));
        }
        Parcelable[] parcelableArray2 = bundle.getParcelableArray("android.messages.historic");
        if (parcelableArray2 != null) {
            this.f1581b.addAll(h1.b(parcelableArray2));
        }
        if (bundle.containsKey("android.isGroupConversation")) {
            this.mIsGroupConversation = Boolean.valueOf(bundle.getBoolean("android.isGroupConversation"));
        }
    }

    @NonNull
    public i1 setConversationTitle(@Nullable CharSequence charSequence) {
        this.mConversationTitle = charSequence;
        return this;
    }

    @NonNull
    public i1 addMessage(@Nullable CharSequence charSequence, long j10, @Nullable z1 z1Var) {
        addMessage(new h1(charSequence, j10, z1Var));
        return this;
    }

    @NonNull
    public i1 addMessage(@Nullable h1 h1Var) {
        if (h1Var != null) {
            ArrayList arrayList = this.f1580a;
            arrayList.add(h1Var);
            if (arrayList.size() > 25) {
                arrayList.remove(0);
            }
        }
        return this;
    }
}
