package o;

import android.R;
import android.app.ActivityOptions;
import android.app.PendingIntent;
import android.app.RemoteAction;
import android.content.Context;
import android.os.Build;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.textclassifier.TextClassification;
import java.util.Objects;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.w5, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2780w5 {
    public final C2875x5 a;
    public final C2495t5 b;
    public final C2495t5 c;
    public final View d;

    public C2780w5(C2875x5 c2875x5, C2495t5 c2495t5, C2495t5 c2495t52, View view) {
        this.a = c2875x5;
        this.b = c2495t5;
        this.c = c2495t52;
        this.d = view;
    }

    /* JADX WARN: Type inference failed for: r2v3, types: [java.lang.Object, java.util.Collection, java.util.List] */
    public final boolean a(Menu menu) {
        int i;
        C1495id0 c1495id0 = (C1495id0) this.b.a();
        int i2 = 0;
        if (F3.c(c1495id0, null)) {
            return false;
        }
        menu.clear();
        ?? r2 = c1495id0.a;
        int size = r2.size();
        int i3 = 0;
        int i4 = 1;
        int i5 = 1;
        while (i3 < size) {
            AbstractC1399hd0 abstractC1399hd0 = (AbstractC1399hd0) r2.get(i3);
            if (abstractC1399hd0 instanceof C2064od0) {
                i = i4 + 1;
                final C2064od0 c2064od0 = (C2064od0) abstractC1399hd0;
                MenuItem menuItemAdd = menu.add(i5, i4, i4, c2064od0.b);
                menuItemAdd.setShowAsAction(2);
                final int i6 = 0;
                menuItemAdd.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { // from class: o.v5
                    @Override // android.view.MenuItem.OnMenuItemClickListener
                    public final boolean onMenuItemClick(MenuItem menuItem) throws PendingIntent.CanceledException {
                        switch (i6) {
                            case 0:
                                ((C2064od0) c2064od0).d.g(((C2780w5) this).a);
                                break;
                            default:
                                Context context = (Context) c2064od0;
                                TextClassification textClassification = (TextClassification) this;
                                String text = textClassification.getText();
                                PendingIntent activity = PendingIntent.getActivity(context, text != null ? text.hashCode() : 0, textClassification.getIntent(), 201326592);
                                if (Build.VERSION.SDK_INT < 34) {
                                    activity.send();
                                    break;
                                } else {
                                    try {
                                        activity.send(ActivityOptions.makeBasic().setPendingIntentBackgroundActivityStartMode(1).toBundle());
                                        break;
                                    } catch (PendingIntent.CanceledException e) {
                                        Objects.toString(activity);
                                        e.toString();
                                        return true;
                                    }
                                }
                        }
                        return true;
                    }
                });
            } else {
                if (abstractC1399hd0 instanceof C2633ud0) {
                    if (Build.VERSION.SDK_INT >= 28) {
                        i = i4 + 1;
                        final Context context = this.d.getContext();
                        C2633ud0 c2633ud0 = (C2633ud0) abstractC1399hd0;
                        final TextClassification textClassification = c2633ud0.b;
                        int i7 = c2633ud0.c;
                        if (i7 < 0) {
                            MenuItem menuItemAdd2 = menu.add(R.id.textAssist, R.id.textAssist, i4, textClassification.getLabel());
                            menuItemAdd2.setShowAsAction(2);
                            menuItemAdd2.setIcon(textClassification.getIcon());
                            final int i8 = 1;
                            menuItemAdd2.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { // from class: o.v5
                                @Override // android.view.MenuItem.OnMenuItemClickListener
                                public final boolean onMenuItemClick(MenuItem menuItem) throws PendingIntent.CanceledException {
                                    switch (i8) {
                                        case 0:
                                            ((C2064od0) context).d.g(((C2780w5) textClassification).a);
                                            break;
                                        default:
                                            Context context2 = (Context) context;
                                            TextClassification textClassification2 = (TextClassification) textClassification;
                                            String text = textClassification2.getText();
                                            PendingIntent activity = PendingIntent.getActivity(context2, text != null ? text.hashCode() : 0, textClassification2.getIntent(), 201326592);
                                            if (Build.VERSION.SDK_INT < 34) {
                                                activity.send();
                                                break;
                                            } else {
                                                try {
                                                    activity.send(ActivityOptions.makeBasic().setPendingIntentBackgroundActivityStartMode(1).toBundle());
                                                    break;
                                                } catch (PendingIntent.CanceledException e) {
                                                    Objects.toString(activity);
                                                    e.toString();
                                                    return true;
                                                }
                                            }
                                    }
                                    return true;
                                }
                            });
                        } else {
                            int i9 = i7 == 0 ? 1 : i2;
                            final RemoteAction remoteActionD = AbstractC0719aX.d(textClassification.getActions().get(i7));
                            MenuItem menuItemAdd3 = menu.add(R.id.textAssist, i9 != 0 ? 16908353 : i2, i4, remoteActionD.getTitle());
                            menuItemAdd3.setShowAsAction(i9 == 0 ? 0 : 2);
                            if (i9 != 0 || remoteActionD.shouldShowIcon()) {
                                menuItemAdd3.setIcon(remoteActionD.getIcon().loadDrawable(context));
                            }
                            menuItemAdd3.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { // from class: o.cf0
                                @Override // android.view.MenuItem.OnMenuItemClickListener
                                public final boolean onMenuItemClick(MenuItem menuItem) throws PendingIntent.CanceledException {
                                    PendingIntent actionIntent = remoteActionD.getActionIntent();
                                    if (Build.VERSION.SDK_INT < 34) {
                                        actionIntent.send();
                                        return true;
                                    }
                                    try {
                                        actionIntent.send(ActivityOptions.makeBasic().setPendingIntentBackgroundActivityStartMode(1).toBundle());
                                    } catch (PendingIntent.CanceledException e) {
                                        Objects.toString(actionIntent);
                                        e.toString();
                                    }
                                    return true;
                                }
                            });
                        }
                    }
                } else if (abstractC1399hd0 instanceof C2443sd0) {
                    i5++;
                }
                i3++;
                i2 = 0;
            }
            i4 = i;
            i3++;
            i2 = 0;
        }
        return true;
    }
}
