forked from Juby210/discord-jadx
258 lines
12 KiB
Java
258 lines
12 KiB
Java
package com.discord.widgets.friends;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.os.Bundle;
|
|
import android.text.SpannableStringBuilder;
|
|
import android.text.style.ForegroundColorSpan;
|
|
import android.view.View;
|
|
import android.widget.TextView;
|
|
import androidx.fragment.app.Fragment;
|
|
import c.a.d.o;
|
|
import c.a.k.b;
|
|
import c.d.b.a.a;
|
|
import c0.g0.s;
|
|
import c0.g0.t;
|
|
import c0.z.d.m;
|
|
import com.discord.R;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.databinding.WidgetFriendsAddByIdBinding;
|
|
import com.discord.models.user.MeUser;
|
|
import com.discord.models.user.User;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.analytics.AnalyticsTracker;
|
|
import com.discord.utilities.color.ColorCompat;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.user.UserUtils;
|
|
import com.discord.utilities.view.extensions.ViewExtensions;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
import java.util.List;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.reflect.KProperty;
|
|
import kotlin.text.MatchResult;
|
|
import kotlin.text.Regex;
|
|
/* compiled from: WidgetFriendsAddById.kt */
|
|
public final class WidgetFriendsAddById extends AppFragment {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.Z(WidgetFriendsAddById.class, "binding", "getBinding()Lcom/discord/databinding/WidgetFriendsAddByIdBinding;", 0)};
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final Regex PATTERN_USERNAME = new Regex("^(.*)#(\\d{4})$");
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetFriendsAddById$binding$2.INSTANCE, null, 2, null);
|
|
|
|
/* compiled from: WidgetFriendsAddById.kt */
|
|
public static final class Companion {
|
|
|
|
/* compiled from: WidgetFriendsAddById.kt */
|
|
public static final class UserNameDiscriminator {
|
|
private final Integer discriminator;
|
|
private final String username;
|
|
|
|
public UserNameDiscriminator(String str, Integer num) {
|
|
m.checkNotNullParameter(str, "username");
|
|
this.username = str;
|
|
this.discriminator = num;
|
|
}
|
|
|
|
public static /* synthetic */ UserNameDiscriminator copy$default(UserNameDiscriminator userNameDiscriminator, String str, Integer num, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
str = userNameDiscriminator.username;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
num = userNameDiscriminator.discriminator;
|
|
}
|
|
return userNameDiscriminator.copy(str, num);
|
|
}
|
|
|
|
public final String component1() {
|
|
return this.username;
|
|
}
|
|
|
|
public final Integer component2() {
|
|
return this.discriminator;
|
|
}
|
|
|
|
public final UserNameDiscriminator copy(String str, Integer num) {
|
|
m.checkNotNullParameter(str, "username");
|
|
return new UserNameDiscriminator(str, num);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof UserNameDiscriminator)) {
|
|
return false;
|
|
}
|
|
UserNameDiscriminator userNameDiscriminator = (UserNameDiscriminator) obj;
|
|
return m.areEqual(this.username, userNameDiscriminator.username) && m.areEqual(this.discriminator, userNameDiscriminator.discriminator);
|
|
}
|
|
|
|
public final Integer getDiscriminator() {
|
|
return this.discriminator;
|
|
}
|
|
|
|
public final String getUsername() {
|
|
return this.username;
|
|
}
|
|
|
|
public int hashCode() {
|
|
String str = this.username;
|
|
int i = 0;
|
|
int hashCode = (str != null ? str.hashCode() : 0) * 31;
|
|
Integer num = this.discriminator;
|
|
if (num != null) {
|
|
i = num.hashCode();
|
|
}
|
|
return hashCode + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder O = a.O("UserNameDiscriminator(username=");
|
|
O.append(this.username);
|
|
O.append(", discriminator=");
|
|
return a.D(O, this.discriminator, ")");
|
|
}
|
|
}
|
|
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public static final /* synthetic */ UserNameDiscriminator access$extractUsernameAndDiscriminator(Companion companion, CharSequence charSequence) {
|
|
return companion.extractUsernameAndDiscriminator(charSequence);
|
|
}
|
|
|
|
private final UserNameDiscriminator extractUsernameAndDiscriminator(CharSequence charSequence) {
|
|
List<String> groupValues;
|
|
MatchResult matchEntire = WidgetFriendsAddById.access$getPATTERN_USERNAME$cp().matchEntire(charSequence);
|
|
return (matchEntire == null || (groupValues = matchEntire.getGroupValues()) == null || !(groupValues.isEmpty() ^ true)) ? new UserNameDiscriminator(charSequence.toString(), null) : new UserNameDiscriminator(matchEntire.getGroupValues().get(1), s.toIntOrNull(matchEntire.getGroupValues().get(2)));
|
|
}
|
|
}
|
|
|
|
public WidgetFriendsAddById() {
|
|
super(R.layout.widget_friends_add_by_id);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$extractTargetAndSendFriendRequest(WidgetFriendsAddById widgetFriendsAddById) {
|
|
widgetFriendsAddById.extractTargetAndSendFriendRequest();
|
|
}
|
|
|
|
public static final /* synthetic */ WidgetFriendsAddByIdBinding access$getBinding$p(WidgetFriendsAddById widgetFriendsAddById) {
|
|
return widgetFriendsAddById.getBinding();
|
|
}
|
|
|
|
public static final /* synthetic */ Regex access$getPATTERN_USERNAME$cp() {
|
|
return PATTERN_USERNAME;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setInputEditError(WidgetFriendsAddById widgetFriendsAddById, CharSequence charSequence) {
|
|
widgetFriendsAddById.setInputEditError(charSequence);
|
|
}
|
|
|
|
private final void extractTargetAndSendFriendRequest() {
|
|
TextInputLayout textInputLayout = getBinding().e;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.friendsAddTextEditWrap");
|
|
String textOrEmpty = ViewExtensions.getTextOrEmpty(textInputLayout);
|
|
Companion.UserNameDiscriminator access$extractUsernameAndDiscriminator = Companion.access$extractUsernameAndDiscriminator(Companion, textOrEmpty);
|
|
if (access$extractUsernameAndDiscriminator.getDiscriminator() != null) {
|
|
sendFriendRequest(access$extractUsernameAndDiscriminator.getUsername(), access$extractUsernameAndDiscriminator.getDiscriminator().intValue());
|
|
return;
|
|
}
|
|
Context context = getContext();
|
|
CharSequence charSequence = null;
|
|
if (context != null) {
|
|
charSequence = b.h(context, R.string.add_friend_error_username_only, new Object[]{access$extractUsernameAndDiscriminator.getUsername()}, null, 4);
|
|
}
|
|
setInputEditError(charSequence);
|
|
AnalyticsTracker.INSTANCE.friendRequestFailed(textOrEmpty, access$extractUsernameAndDiscriminator.getUsername(), access$extractUsernameAndDiscriminator.getDiscriminator(), "Invalid Username");
|
|
}
|
|
|
|
private final WidgetFriendsAddByIdBinding getBinding() {
|
|
return (WidgetFriendsAddByIdBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
private final SpannableStringBuilder getUsernameIndicatorText(User user) {
|
|
Resources resources = getResources();
|
|
m.checkNotNullExpressionValue(resources, "resources");
|
|
UserUtils userUtils = UserUtils.INSTANCE;
|
|
CharSequence i = b.i(resources, R.string.self_username_indicator, new Object[]{UserUtils.getUserNameWithDiscriminator$default(userUtils, user, null, null, 3, null)}, null, 4);
|
|
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(i);
|
|
SpannableStringBuilder spannableStringBuilder2 = (SpannableStringBuilder) i;
|
|
spannableStringBuilder.setSpan(new ForegroundColorSpan(ColorCompat.getThemedColor(requireContext(), (int) R.attr.colorHeaderPrimary)), spannableStringBuilder2.length() - UserUtils.getUserNameWithDiscriminator$default(userUtils, user, null, null, 3, null).length(), spannableStringBuilder2.length(), 33);
|
|
return spannableStringBuilder;
|
|
}
|
|
|
|
private final void sendFriendRequest(String str, int i) {
|
|
ObservableExtensionsKt.ui$default(RestAPI.Companion.getApi().sendRelationshipRequest("Search - Add Friend Search", str, i), this, null, 2, null).k(o.h(new WidgetFriendsAddById$sendFriendRequest$1(this, str), getAppActivity(), new WidgetFriendsAddById$sendFriendRequest$2(this, str, i)));
|
|
}
|
|
|
|
private final void setInputEditError(CharSequence charSequence) {
|
|
TextInputLayout textInputLayout = getBinding().e;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.friendsAddTextEditWrap");
|
|
textInputLayout.setError(charSequence);
|
|
TextInputLayout textInputLayout2 = getBinding().e;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.friendsAddTextEditWrap");
|
|
textInputLayout2.setErrorEnabled(!(charSequence == null || t.isBlank(charSequence)));
|
|
}
|
|
|
|
private final void setInputText(String str) {
|
|
if (!(str == null || t.isBlank(str))) {
|
|
TextInputLayout textInputLayout = getBinding().e;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.friendsAddTextEditWrap");
|
|
ViewExtensions.setText(textInputLayout, str);
|
|
TextInputLayout textInputLayout2 = getBinding().e;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.friendsAddTextEditWrap");
|
|
ViewExtensions.setSelectionEnd(textInputLayout2);
|
|
}
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void hideKeyboard(View view) {
|
|
super.hideKeyboard(view);
|
|
getBinding().e.clearFocus();
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment, androidx.fragment.app.Fragment
|
|
public void onPause() {
|
|
super.onPause();
|
|
AppFragment.hideKeyboard$default(this, null, 1, null);
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment, androidx.fragment.app.Fragment
|
|
public void onResume() {
|
|
super.onResume();
|
|
AnalyticsTracker.INSTANCE.friendAddViewed("Id");
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBound(View view) {
|
|
m.checkNotNullParameter(view, "view");
|
|
super.onViewBound(view);
|
|
getBinding().d.setOnClickListener(new WidgetFriendsAddById$onViewBound$1(this));
|
|
TextInputLayout textInputLayout = getBinding().e;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.friendsAddTextEditWrap");
|
|
ViewExtensions.addBindedTextWatcher(textInputLayout, this, new WidgetFriendsAddById$onViewBound$2(this));
|
|
TextInputLayout textInputLayout2 = getBinding().e;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.friendsAddTextEditWrap");
|
|
String str = null;
|
|
ViewExtensions.setOnImeActionDone$default(textInputLayout2, false, new WidgetFriendsAddById$onViewBound$3(this), 1, null);
|
|
getBinding().f2233c.setOnClickListener(new WidgetFriendsAddById$onViewBound$4(this));
|
|
Bundle extras = getMostRecentIntent().getExtras();
|
|
if (extras != null) {
|
|
str = extras.getString("android.intent.extra.TEXT");
|
|
}
|
|
setInputText(str);
|
|
MeUser me2 = StoreStream.Companion.getUsers().getMe();
|
|
TextView textView = getBinding().b;
|
|
m.checkNotNullExpressionValue(textView, "binding.friendAddUsernameIndicator");
|
|
textView.setVisibility(0);
|
|
TextView textView2 = getBinding().b;
|
|
m.checkNotNullExpressionValue(textView2, "binding.friendAddUsernameIndicator");
|
|
textView2.setText(getUsernameIndicatorText(me2));
|
|
}
|
|
}
|