167 lines
9.8 KiB
Java
167 lines
9.8 KiB
Java
package com.discord.widgets.settings.account;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.text.Editable;
|
|
import android.text.Selection;
|
|
import android.view.View;
|
|
import android.widget.EditText;
|
|
import androidx.activity.result.ActivityResultLauncher;
|
|
import androidx.fragment.app.Fragment;
|
|
import b.a.d.j;
|
|
import b.d.b.a.a;
|
|
import com.discord.R;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.databinding.WidgetSettingsAccountEditBinding;
|
|
import com.discord.models.user.MeUser;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.StoreUser;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.stateful.StatefulViews;
|
|
import com.discord.utilities.user.UserUtils;
|
|
import com.discord.utilities.view.extensions.ViewExtensions;
|
|
import com.discord.utilities.view.validators.ValidationManager;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.discord.widgets.user.WidgetUserPasswordVerify;
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
import d0.g;
|
|
import d0.z.d.m;
|
|
import java.util.Arrays;
|
|
import kotlin.Lazy;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.reflect.KProperty;
|
|
/* compiled from: WidgetSettingsAccountUsernameEdit.kt */
|
|
/* loaded from: classes2.dex */
|
|
public final class WidgetSettingsAccountUsernameEdit extends AppFragment {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.b0(WidgetSettingsAccountUsernameEdit.class, "binding", "getBinding()Lcom/discord/databinding/WidgetSettingsAccountEditBinding;", 0)};
|
|
public static final Companion Companion = new Companion(null);
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetSettingsAccountUsernameEdit$binding$2.INSTANCE, null, 2, null);
|
|
private final ActivityResultLauncher<Intent> passwordVerifyLauncher = WidgetUserPasswordVerify.Companion.registerForResult(this, new WidgetSettingsAccountUsernameEdit$passwordVerifyLauncher$1(this));
|
|
private final StatefulViews state = new StatefulViews(R.id.edit_account_username_wrap, R.id.edit_account_discriminator_wrap);
|
|
private final Lazy validationManager$delegate = g.lazy(new WidgetSettingsAccountUsernameEdit$validationManager$2(this));
|
|
|
|
/* compiled from: WidgetSettingsAccountUsernameEdit.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final void launch(Context context) {
|
|
m.checkNotNullParameter(context, "context");
|
|
j.e(context, WidgetSettingsAccountUsernameEdit.class, null, 4);
|
|
}
|
|
}
|
|
|
|
public WidgetSettingsAccountUsernameEdit() {
|
|
super(R.layout.widget_settings_account_edit);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$configureUI(WidgetSettingsAccountUsernameEdit widgetSettingsAccountUsernameEdit, MeUser meUser) {
|
|
widgetSettingsAccountUsernameEdit.configureUI(meUser);
|
|
}
|
|
|
|
public static final /* synthetic */ WidgetSettingsAccountEditBinding access$getBinding$p(WidgetSettingsAccountUsernameEdit widgetSettingsAccountUsernameEdit) {
|
|
return widgetSettingsAccountUsernameEdit.getBinding();
|
|
}
|
|
|
|
public static final /* synthetic */ StatefulViews access$getState$p(WidgetSettingsAccountUsernameEdit widgetSettingsAccountUsernameEdit) {
|
|
return widgetSettingsAccountUsernameEdit.state;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$showPasswordVerification(WidgetSettingsAccountUsernameEdit widgetSettingsAccountUsernameEdit) {
|
|
widgetSettingsAccountUsernameEdit.showPasswordVerification();
|
|
}
|
|
|
|
private final void configureUI(MeUser meUser) {
|
|
TextInputLayout textInputLayout = getBinding().c;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.editAccountUsernameWrap");
|
|
StatefulViews statefulViews = this.state;
|
|
TextInputLayout textInputLayout2 = getBinding().c;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.editAccountUsernameWrap");
|
|
ViewExtensions.setText(textInputLayout, (CharSequence) statefulViews.get(textInputLayout2.getId(), meUser.getUsername()));
|
|
TextInputLayout textInputLayout3 = getBinding().f2580b;
|
|
m.checkNotNullExpressionValue(textInputLayout3, "binding.editAccountDiscriminatorWrap");
|
|
StatefulViews statefulViews2 = this.state;
|
|
TextInputLayout textInputLayout4 = getBinding().f2580b;
|
|
m.checkNotNullExpressionValue(textInputLayout4, "binding.editAccountDiscriminatorWrap");
|
|
int id2 = textInputLayout4.getId();
|
|
String format = String.format("%04d", Arrays.copyOf(new Object[]{Integer.valueOf(meUser.getDiscriminator())}, 1));
|
|
m.checkNotNullExpressionValue(format, "java.lang.String.format(format, *args)");
|
|
ViewExtensions.setText(textInputLayout3, (CharSequence) statefulViews2.get(id2, format));
|
|
TextInputLayout textInputLayout5 = getBinding().c;
|
|
m.checkNotNullExpressionValue(textInputLayout5, "binding.editAccountUsernameWrap");
|
|
EditText editText = textInputLayout5.getEditText();
|
|
Editable text = editText != null ? editText.getText() : null;
|
|
TextInputLayout textInputLayout6 = getBinding().c;
|
|
m.checkNotNullExpressionValue(textInputLayout6, "binding.editAccountUsernameWrap");
|
|
Selection.setSelection(text, ViewExtensions.getTextOrEmpty(textInputLayout6).length());
|
|
TextInputLayout textInputLayout7 = getBinding().f2580b;
|
|
m.checkNotNullExpressionValue(textInputLayout7, "binding.editAccountDiscriminatorWrap");
|
|
UserUtils userUtils = UserUtils.INSTANCE;
|
|
textInputLayout7.setLongClickable(userUtils.isPremium(meUser));
|
|
if (!userUtils.isPremium(meUser)) {
|
|
TextInputLayout textInputLayout8 = getBinding().f2580b;
|
|
m.checkNotNullExpressionValue(textInputLayout8, "binding.editAccountDiscriminatorWrap");
|
|
ViewExtensions.setOnEditTextFocusChangeListener(textInputLayout8, new WidgetSettingsAccountUsernameEdit$configureUI$1(this));
|
|
}
|
|
}
|
|
|
|
private final WidgetSettingsAccountEditBinding getBinding() {
|
|
return (WidgetSettingsAccountEditBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
private final ValidationManager getValidationManager() {
|
|
return (ValidationManager) this.validationManager$delegate.getValue();
|
|
}
|
|
|
|
private final void showPasswordVerification() {
|
|
if (ValidationManager.validate$default(getValidationManager(), false, 1, null)) {
|
|
WidgetUserPasswordVerify.Companion companion = WidgetUserPasswordVerify.Companion;
|
|
Context requireContext = requireContext();
|
|
ActivityResultLauncher<Intent> activityResultLauncher = this.passwordVerifyLauncher;
|
|
TextInputLayout textInputLayout = getBinding().c;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.editAccountUsernameWrap");
|
|
String textOrEmpty = ViewExtensions.getTextOrEmpty(textInputLayout);
|
|
TextInputLayout textInputLayout2 = getBinding().f2580b;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.editAccountDiscriminatorWrap");
|
|
WidgetUserPasswordVerify.Companion.launchUpdateAccountSettings$default(companion, requireContext, activityResultLauncher, null, textOrEmpty, ViewExtensions.getTextOrEmpty(textInputLayout2), null, 36, null);
|
|
}
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBound(View view) {
|
|
m.checkNotNullParameter(view, "view");
|
|
super.onViewBound(view);
|
|
setActionBarSubtitle(R.string.user_settings);
|
|
setActionBarTitle(R.string.user_settings_account_change_username_title);
|
|
AppFragment.setActionBarDisplayHomeAsUpEnabled$default(this, false, 1, null);
|
|
TextInputLayout textInputLayout = getBinding().f2580b;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.editAccountDiscriminatorWrap");
|
|
ViewExtensions.addBindedTextWatcher(textInputLayout, this, new WidgetSettingsAccountUsernameEdit$onViewBound$1(this));
|
|
TextInputLayout textInputLayout2 = getBinding().f2580b;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.editAccountDiscriminatorWrap");
|
|
ViewExtensions.setOnImeActionDone$default(textInputLayout2, false, new WidgetSettingsAccountUsernameEdit$onViewBound$2(this), 1, null);
|
|
getBinding().d.setOnClickListener(new WidgetSettingsAccountUsernameEdit$onViewBound$3(this));
|
|
StatefulViews statefulViews = this.state;
|
|
FloatingActionButton floatingActionButton = getBinding().d;
|
|
TextInputLayout textInputLayout3 = getBinding().c;
|
|
m.checkNotNullExpressionValue(textInputLayout3, "binding.editAccountUsernameWrap");
|
|
TextInputLayout textInputLayout4 = getBinding().f2580b;
|
|
m.checkNotNullExpressionValue(textInputLayout4, "binding.editAccountDiscriminatorWrap");
|
|
statefulViews.setupTextWatcherWithSaveAction(this, floatingActionButton, textInputLayout3, textInputLayout4);
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBoundOrOnResume() {
|
|
super.onViewBoundOrOnResume();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(StoreUser.observeMe$default(StoreStream.Companion.getUsers(), false, 1, null), this, null, 2, null), WidgetSettingsAccountUsernameEdit.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetSettingsAccountUsernameEdit$onViewBoundOrOnResume$1(this), 62, (Object) null);
|
|
}
|
|
}
|