package p032k0;

import android.content.ClipData;
import android.content.Context;
import android.text.Editable;
import android.text.Selection;
import android.text.Spanned;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import p023h0.C0784c;
import p023h0.InterfaceC0779b1;

/* renamed from: k0.y0 */
/* loaded from: classes.dex */
public final class C1344y0 implements InterfaceC0779b1 {

    /* renamed from: k0.y0$a */
    /* loaded from: classes.dex */
    public static final class C1345a {
        /* renamed from: a */
        public static CharSequence m1586a(Context context, ClipData.Item item, int i) {
            if ((i & 1) != 0) {
                CharSequence coerceToText = item.coerceToText(context);
                return coerceToText instanceof Spanned ? coerceToText.toString() : coerceToText;
            }
            return item.coerceToStyledText(context);
        }
    }

    /* renamed from: b */
    public static CharSequence m1588b(Context context, ClipData.Item item, int i) {
        return C1345a.m1586a(context, item, i);
    }

    /* renamed from: c */
    public static void m1587c(Editable editable, CharSequence charSequence) {
        int selectionStart = Selection.getSelectionStart(editable);
        int selectionEnd = Selection.getSelectionEnd(editable);
        int max = Math.max(0, Math.min(selectionStart, selectionEnd));
        int max2 = Math.max(0, Math.max(selectionStart, selectionEnd));
        Selection.setSelection(editable, max2);
        editable.replace(max, max2, charSequence);
    }

    @Override // p023h0.InterfaceC0779b1
    /* renamed from: a */
    public C0784c mo1589a(View view, C0784c c0784c) {
        if (Log.isLoggable("ReceiveContent", 3)) {
            Log.d("ReceiveContent", "onReceive: " + c0784c);
        }
        if (c0784c.m2922d() == 2) {
            return c0784c;
        }
        ClipData m2924b = c0784c.m2924b();
        int m2923c = c0784c.m2923c();
        TextView textView = (TextView) view;
        Editable editable = (Editable) textView.getText();
        Context context = textView.getContext();
        boolean z = false;
        for (int i = 0; i < m2924b.getItemCount(); i++) {
            CharSequence m1588b = m1588b(context, m2924b.getItemAt(i), m2923c);
            if (m1588b != null) {
                if (z) {
                    editable.insert(Selection.getSelectionEnd(editable), "\n");
                    editable.insert(Selection.getSelectionEnd(editable), m1588b);
                } else {
                    m1587c(editable, m1588b);
                    z = true;
                }
            }
        }
        return null;
    }
}