package com.discord.widgets.chat.input; import android.text.Editable; import android.text.TextUtils; import android.view.View; import android.widget.TextView; import androidx.recyclerview.widget.RecyclerView; import com.discord.app.AppFragment; import com.discord.databinding.WidgetChatInputApplicationCommandsBinding; import com.discord.widgets.chat.MessageContent; import com.discord.widgets.chat.input.MessageDraftsRepo; import com.discord.widgets.chat.input.autocomplete.Autocompletable; import com.discord.widgets.chat.input.models.ApplicationCommandData; import com.lytefast.flexinput.widget.FlexEditText; import d0.t.n; import d0.z.d.m; import d0.z.d.o; import java.util.List; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.subjects.BehaviorSubject; import rx.subjects.Subject; /* compiled from: WidgetChatInputEditText.kt */ public final class WidgetChatInputEditText { public static final Companion Companion = new Companion(null); private long channelId; private final WidgetChatInputAutocomplete chatInputCommands; private final FlexEditText editText; private final Subject emptyTextSubject; private long lastTypingEmissionMillis; private final MessageDraftsRepo messageDraftsRepo; private Function0 onSendListener; /* compiled from: WidgetChatInputEditText.kt */ /* renamed from: com.discord.widgets.chat.input.WidgetChatInputEditText$1 reason: invalid class name */ public static final class AnonymousClass1 extends o implements Function1 { public static final AnonymousClass1 INSTANCE = new AnonymousClass1(); public AnonymousClass1() { super(1); } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Boolean invoke(Autocompletable autocompletable) { return Boolean.valueOf(invoke(autocompletable)); } public final boolean invoke(Autocompletable autocompletable) { m.checkNotNullParameter(autocompletable, "it"); return false; } } /* compiled from: WidgetChatInputEditText.kt */ /* renamed from: com.discord.widgets.chat.input.WidgetChatInputEditText$2 reason: invalid class name */ public static final class AnonymousClass2 extends o implements Function1, Unit> { public static final AnonymousClass2 INSTANCE = new AnonymousClass2(); public AnonymousClass2() { super(1); } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Unit invoke(List list) { invoke(list); return Unit.a; } public final void invoke(List list) { m.checkNotNullParameter(list, ""); } } /* compiled from: WidgetChatInputEditText.kt */ /* renamed from: com.discord.widgets.chat.input.WidgetChatInputEditText$3 reason: invalid class name */ public static final class AnonymousClass3 extends o implements Function0 { public static final AnonymousClass3 INSTANCE = new AnonymousClass3(); public AnonymousClass3() { super(0); } @Override // kotlin.jvm.functions.Function0 /* renamed from: invoke */ public final void mo1invoke() { } } /* compiled from: WidgetChatInputEditText.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } private final int getCursorPosition(FlexEditText flexEditText) { return flexEditText.getSelectionEnd() >= 0 ? flexEditText.getSelectionEnd() : toStringSafe(flexEditText).length(); } public final void insert(Editable editable, CharSequence charSequence, int i, int i2) { m.checkNotNullParameter(editable, "editable"); m.checkNotNullParameter(charSequence, "charSequence"); int min = Math.min(i, i2); editable.replace(Math.max(0, min), Math.max(i, i2), charSequence, 0, charSequence.length()); } public final void insertMention(FlexEditText flexEditText, String str, String str2) { m.checkNotNullParameter(flexEditText, "editText"); m.checkNotNullParameter(str, "mention"); Editable text = flexEditText.getText(); if (text != null) { m.checkNotNullExpressionValue(text, "editText.text ?: return"); int cursorPosition = getCursorPosition(flexEditText); if (str2 != null) { int length = cursorPosition - str2.length(); insert(text, str + ' ', length, cursorPosition); flexEditText.setSelection(str.length() + length + 1); } } } public final String toStringSafe(TextView textView) { m.checkNotNullParameter(textView, "textView"); try { return textView.getText().toString(); } catch (Exception unused) { return ""; } } } public WidgetChatInputEditText(FlexEditText flexEditText, RecyclerView recyclerView, View view, TextView textView, TextView textView2, RecyclerView recyclerView2, RecyclerView recyclerView3, WidgetChatInputApplicationCommandsBinding widgetChatInputApplicationCommandsBinding, Function1 function1, Function1, Unit> function12, Function0 function0, MessageDraftsRepo messageDraftsRepo) { m.checkNotNullParameter(flexEditText, "editText"); m.checkNotNullParameter(recyclerView, "stickersRecycler"); m.checkNotNullParameter(view, "stickersContainer"); m.checkNotNullParameter(textView, "stickersHeader"); m.checkNotNullParameter(textView2, "emojiHeader"); m.checkNotNullParameter(recyclerView2, "mentionsRecycler"); m.checkNotNullParameter(recyclerView3, "categoriesRecycler"); m.checkNotNullParameter(widgetChatInputApplicationCommandsBinding, "binding"); m.checkNotNullParameter(function1, "handleAutocompleteItemClicked"); m.checkNotNullParameter(function12, "onScrollVisibleMentions"); m.checkNotNullParameter(function0, "onAutocompletionsUpdated"); m.checkNotNullParameter(messageDraftsRepo, "messageDraftsRepo"); this.editText = flexEditText; this.messageDraftsRepo = messageDraftsRepo; BehaviorSubject l0 = BehaviorSubject.l0(Boolean.TRUE); m.checkNotNullExpressionValue(l0, "BehaviorSubject.create(true)"); this.emptyTextSubject = l0; this.chatInputCommands = new WidgetChatInputAutocomplete(flexEditText, recyclerView, view, textView, textView2, recyclerView2, recyclerView3, widgetChatInputApplicationCommandsBinding, function1, function12, function0); setOnSelectionChangedListener(); setOnTextChangedListener(); setSoftwareKeyboardSendBehavior(); setHardwareKeyboardSendBehavior(); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ WidgetChatInputEditText(FlexEditText flexEditText, RecyclerView recyclerView, View view, TextView textView, TextView textView2, RecyclerView recyclerView2, RecyclerView recyclerView3, WidgetChatInputApplicationCommandsBinding widgetChatInputApplicationCommandsBinding, Function1 function1, Function1 function12, Function0 function0, MessageDraftsRepo messageDraftsRepo, int i, DefaultConstructorMarker defaultConstructorMarker) { this(flexEditText, recyclerView, view, textView, textView2, recyclerView2, recyclerView3, widgetChatInputApplicationCommandsBinding, (i & 256) != 0 ? AnonymousClass1.INSTANCE : function1, (i & 512) != 0 ? AnonymousClass2.INSTANCE : function12, (i & 1024) != 0 ? AnonymousClass3.INSTANCE : function0, (i & 2048) != 0 ? MessageDraftsRepo.Provider.INSTANCE.get() : messageDraftsRepo); } public static final /* synthetic */ WidgetChatInputAutocomplete access$getChatInputCommands$p(WidgetChatInputEditText widgetChatInputEditText) { return widgetChatInputEditText.chatInputCommands; } public static final /* synthetic */ Subject access$getEmptyTextSubject$p(WidgetChatInputEditText widgetChatInputEditText) { return widgetChatInputEditText.emptyTextSubject; } public static final /* synthetic */ long access$getLastTypingEmissionMillis$p(WidgetChatInputEditText widgetChatInputEditText) { return widgetChatInputEditText.lastTypingEmissionMillis; } public static final /* synthetic */ void access$setLastTypingEmissionMillis$p(WidgetChatInputEditText widgetChatInputEditText, long j) { widgetChatInputEditText.lastTypingEmissionMillis = j; } private final void setHardwareKeyboardSendBehavior() { this.editText.setOnKeyListener(new WidgetChatInputEditText$setHardwareKeyboardSendBehavior$1(this)); } private final void setOnSelectionChangedListener() { this.editText.setOnSelectionChangedListener(new WidgetChatInputEditText$setOnSelectionChangedListener$1(this)); } private final void setOnTextChangedListener() { this.editText.addTextChangedListener(new WidgetChatInputEditText$setOnTextChangedListener$1(this)); } private final void setSoftwareKeyboardSendBehavior() { this.editText.setOnEditorActionListener(new WidgetChatInputEditText$setSoftwareKeyboardSendBehavior$1(this)); } public final void clearLastTypingEmission() { this.lastTypingEmissionMillis = 0; } public final void configureMentionsDataSubscriptions(AppFragment appFragment) { m.checkNotNullParameter(appFragment, "fragment"); this.chatInputCommands.configureDataSubscriptions(appFragment, this.emptyTextSubject); } public final ApplicationCommandData getApplicationCommandData() { return this.chatInputCommands.getApplicationCommandData(); } public final long getChannelId() { return this.channelId; } public final MessageContent getMatchedContentWithMetaData() { Companion companion = Companion; String stringSafe = companion.toStringSafe(this.editText); String stringSafe2 = companion.toStringSafe(this.editText); int length = stringSafe2.length() - 1; int i = 0; boolean z2 = false; while (i <= length) { boolean z3 = m.compare(stringSafe2.charAt(!z2 ? i : length), 32) <= 0; if (!z2) { if (!z3) { z2 = true; } else { i++; } } else if (!z3) { break; } else { length--; } } String obj = stringSafe2.subSequence(i, length + 1).toString(); return !TextUtils.isEmpty(obj) ? this.chatInputCommands.replaceAutocompletableDataWithServerValues(stringSafe) : new MessageContent(obj, n.emptyList()); } public final Function0 getOnSendListener() { return this.onSendListener; } public final void onCommandInputsSendError() { this.chatInputCommands.onApplicationCommandSendError(); } public final void saveText() { this.messageDraftsRepo.setTextChannelInput(this.channelId, this.editText.getText()); } public final void setChannelId(long j) { this.channelId = j; } public final void setChannelId(long j, boolean z2) { if (z2) { saveText(); } this.channelId = j; } public final void setOnSendListener(Function0 function0) { this.onSendListener = function0; } }