239 lines
13 KiB
Java
239 lines
13 KiB
Java
|
package com.discord.widgets.user;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
import android.os.Bundle;
|
||
|
import android.view.View;
|
||
|
import androidx.activity.result.ActivityResultLauncher;
|
||
|
import androidx.activity.result.contract.ActivityResultContracts;
|
||
|
import androidx.fragment.app.Fragment;
|
||
|
import androidx.fragment.app.FragmentActivity;
|
||
|
import c.a.d.l;
|
||
|
import c.a.d.o;
|
||
|
import c.a.d.q;
|
||
|
import c.d.b.a.a;
|
||
|
import com.discord.app.AppFragment;
|
||
|
import com.discord.databinding.WidgetUserPasswordVerifyBinding;
|
||
|
import com.discord.restapi.RestAPIParams;
|
||
|
import com.discord.stores.StoreStream;
|
||
|
import com.discord.utilities.analytics.AnalyticsTracker;
|
||
|
import com.discord.utilities.error.Error;
|
||
|
import com.discord.utilities.rest.RestAPI;
|
||
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
||
|
import com.discord.utilities.stateful.StatefulViews;
|
||
|
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.google.android.material.floatingactionbutton.FloatingActionButton;
|
||
|
import com.google.android.material.textfield.TextInputLayout;
|
||
|
import d0.g;
|
||
|
import d0.z.d.m;
|
||
|
import java.io.Serializable;
|
||
|
import java.util.List;
|
||
|
import java.util.Map;
|
||
|
import java.util.Objects;
|
||
|
import kotlin.Lazy;
|
||
|
import kotlin.Unit;
|
||
|
import kotlin.jvm.functions.Function0;
|
||
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
||
|
import kotlin.reflect.KProperty;
|
||
|
/* compiled from: WidgetUserPasswordVerify.kt */
|
||
|
public final class WidgetUserPasswordVerify extends AppFragment {
|
||
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.V(WidgetUserPasswordVerify.class, "binding", "getBinding()Lcom/discord/databinding/WidgetUserPasswordVerifyBinding;", 0)};
|
||
|
public static final Companion Companion = new Companion(null);
|
||
|
private static final String INTENT_EXTRA_ACTION = "INTENT_EXTRA_ACTION";
|
||
|
private static final String INTENT_EXTRA_DISCRIMINATOR = "INTENT_EXTRA_DISCRIMINATOR";
|
||
|
private static final String INTENT_EXTRA_EMAIL = "INTENT_EXTRA_EMAIL";
|
||
|
private static final String INTENT_EXTRA_PHONE_TOKEN = "INTENT_EXTRA_PHONE_TOKEN";
|
||
|
private static final String INTENT_EXTRA_USERNAME = "INTENT_EXTRA_USERNAME";
|
||
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetUserPasswordVerify$binding$2.INSTANCE, null, 2, null);
|
||
|
private final StatefulViews state = new StatefulViews(2131363018);
|
||
|
private final Lazy validationManager$delegate = g.lazy(new WidgetUserPasswordVerify$validationManager$2(this));
|
||
|
|
||
|
/* compiled from: WidgetUserPasswordVerify.kt */
|
||
|
public static final class Companion {
|
||
|
|
||
|
/* compiled from: WidgetUserPasswordVerify.kt */
|
||
|
public enum Action {
|
||
|
UpdateAccountInfo,
|
||
|
RemovePhoneNumber,
|
||
|
UpdatePhoneNumber
|
||
|
}
|
||
|
|
||
|
private Companion() {
|
||
|
}
|
||
|
|
||
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
||
|
this();
|
||
|
}
|
||
|
|
||
|
private final void launch(Context context, ActivityResultLauncher<Intent> activityResultLauncher, Bundle bundle) {
|
||
|
AnalyticsTracker.openModal$default("Account Settings Password Verification", "", null, 4, null);
|
||
|
l.g.f(context, activityResultLauncher, WidgetUserPasswordVerify.class, new Intent().putExtras(bundle));
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ void launchUpdateAccountSettings$default(Companion companion, Context context, ActivityResultLauncher activityResultLauncher, String str, String str2, String str3, int i, Object obj) {
|
||
|
companion.launchUpdateAccountSettings(context, activityResultLauncher, (i & 4) != 0 ? null : str, (i & 8) != 0 ? null : str2, (i & 16) != 0 ? null : str3);
|
||
|
}
|
||
|
|
||
|
public final void launchRemovePhoneNumber(Context context, ActivityResultLauncher<Intent> activityResultLauncher) {
|
||
|
m.checkNotNullParameter(context, "context");
|
||
|
m.checkNotNullParameter(activityResultLauncher, "launcher");
|
||
|
Bundle bundle = new Bundle();
|
||
|
bundle.putSerializable("INTENT_EXTRA_ACTION", Action.RemovePhoneNumber);
|
||
|
launch(context, activityResultLauncher, bundle);
|
||
|
}
|
||
|
|
||
|
public final void launchUpdateAccountSettings(Context context, ActivityResultLauncher<Intent> activityResultLauncher, String str, String str2, String str3) {
|
||
|
m.checkNotNullParameter(context, "context");
|
||
|
m.checkNotNullParameter(activityResultLauncher, "launcher");
|
||
|
Bundle bundle = new Bundle();
|
||
|
bundle.putSerializable("INTENT_EXTRA_ACTION", Action.UpdateAccountInfo);
|
||
|
bundle.putString("INTENT_EXTRA_EMAIL", str);
|
||
|
bundle.putString("INTENT_EXTRA_USERNAME", str2);
|
||
|
bundle.putString("INTENT_EXTRA_DISCRIMINATOR", str3);
|
||
|
launch(context, activityResultLauncher, bundle);
|
||
|
}
|
||
|
|
||
|
public final void launchUpdatePhoneNumber(Context context, ActivityResultLauncher<Intent> activityResultLauncher, String str) {
|
||
|
m.checkNotNullParameter(context, "context");
|
||
|
m.checkNotNullParameter(activityResultLauncher, "launcher");
|
||
|
m.checkNotNullParameter(str, "phoneToken");
|
||
|
Bundle bundle = new Bundle();
|
||
|
bundle.putSerializable("INTENT_EXTRA_ACTION", Action.UpdatePhoneNumber);
|
||
|
bundle.putString("INTENT_EXTRA_PHONE_TOKEN", str);
|
||
|
launch(context, activityResultLauncher, bundle);
|
||
|
}
|
||
|
|
||
|
public final ActivityResultLauncher<Intent> registerForResult(AppFragment appFragment, Function0<Unit> function0) {
|
||
|
m.checkNotNullParameter(appFragment, "fragment");
|
||
|
m.checkNotNullParameter(function0, "callback");
|
||
|
ActivityResultLauncher<Intent> registerForActivityResult = appFragment.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new WidgetUserPasswordVerify$Companion$registerForResult$1(function0));
|
||
|
m.checkNotNullExpressionValue(registerForActivityResult, "fragment.registerForActi…k()\n }\n }");
|
||
|
return registerForActivityResult;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final /* synthetic */ class WhenMappings {
|
||
|
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
|
||
|
|
||
|
static {
|
||
|
Companion.Action.values();
|
||
|
int[] iArr = new int[3];
|
||
|
$EnumSwitchMapping$0 = iArr;
|
||
|
iArr[Companion.Action.UpdateAccountInfo.ordinal()] = 1;
|
||
|
iArr[Companion.Action.RemovePhoneNumber.ordinal()] = 2;
|
||
|
iArr[Companion.Action.UpdatePhoneNumber.ordinal()] = 3;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public WidgetUserPasswordVerify() {
|
||
|
super(2131559297);
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$finishWithSuccess(WidgetUserPasswordVerify widgetUserPasswordVerify) {
|
||
|
widgetUserPasswordVerify.finishWithSuccess();
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ WidgetUserPasswordVerifyBinding access$getBinding$p(WidgetUserPasswordVerify widgetUserPasswordVerify) {
|
||
|
return widgetUserPasswordVerify.getBinding();
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ boolean access$maybeHandleApiError(WidgetUserPasswordVerify widgetUserPasswordVerify, Error error) {
|
||
|
return widgetUserPasswordVerify.maybeHandleApiError(error);
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$saveInfo(WidgetUserPasswordVerify widgetUserPasswordVerify) {
|
||
|
widgetUserPasswordVerify.saveInfo();
|
||
|
}
|
||
|
|
||
|
private final void finishWithSuccess() {
|
||
|
StatefulViews.clear$default(this.state, false, 1, null);
|
||
|
o.i(this, 2131893150, 0, 4);
|
||
|
FragmentActivity activity = getActivity();
|
||
|
if (activity != null) {
|
||
|
activity.setResult(-1);
|
||
|
}
|
||
|
FragmentActivity activity2 = getActivity();
|
||
|
if (activity2 != null) {
|
||
|
activity2.onBackPressed();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private final WidgetUserPasswordVerifyBinding getBinding() {
|
||
|
return (WidgetUserPasswordVerifyBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
||
|
}
|
||
|
|
||
|
private final ValidationManager getValidationManager() {
|
||
|
return (ValidationManager) this.validationManager$delegate.getValue();
|
||
|
}
|
||
|
|
||
|
private final boolean maybeHandleApiError(Error error) {
|
||
|
if (error.getType() != Error.Type.DISCORD_BAD_REQUEST) {
|
||
|
return false;
|
||
|
}
|
||
|
ValidationManager validationManager = getValidationManager();
|
||
|
Error.Response response = error.getResponse();
|
||
|
m.checkNotNullExpressionValue(response, "error.response");
|
||
|
Map<String, List<String>> messages = response.getMessages();
|
||
|
m.checkNotNullExpressionValue(messages, "error.response.messages");
|
||
|
return validationManager.setErrors(messages).isEmpty();
|
||
|
}
|
||
|
|
||
|
private final void removePhoneNumber(String str) {
|
||
|
ObservableExtensionsKt.withDimmer$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().userPhoneDelete(new RestAPIParams.DeletePhone(str)), false, 1, null), this, null, 2, null), getBinding().b, 0, 2, null).k(q.h(new WidgetUserPasswordVerify$removePhoneNumber$1(this), getContext(), new WidgetUserPasswordVerify$removePhoneNumber$2(this)));
|
||
|
}
|
||
|
|
||
|
private final void saveInfo() {
|
||
|
if (ValidationManager.validate$default(getValidationManager(), false, 1, null)) {
|
||
|
AppFragment.hideKeyboard$default(this, null, 1, null);
|
||
|
TextInputLayout textInputLayout = getBinding().f2008c;
|
||
|
m.checkNotNullExpressionValue(textInputLayout, "binding.editAccountPasswordWrap");
|
||
|
String textOrEmpty = ViewExtensions.getTextOrEmpty(textInputLayout);
|
||
|
Serializable serializableExtra = getMostRecentIntent().getSerializableExtra("INTENT_EXTRA_ACTION");
|
||
|
Objects.requireNonNull(serializableExtra, "null cannot be cast to non-null type com.discord.widgets.user.WidgetUserPasswordVerify.Companion.Action");
|
||
|
int ordinal = ((Companion.Action) serializableExtra).ordinal();
|
||
|
if (ordinal == 0) {
|
||
|
updateAccountInfo(textOrEmpty);
|
||
|
} else if (ordinal == 1) {
|
||
|
removePhoneNumber(textOrEmpty);
|
||
|
} else if (ordinal == 2) {
|
||
|
updatePhoneNumber(textOrEmpty);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private final void updateAccountInfo(String str) {
|
||
|
String stringExtra = getMostRecentIntent().getStringExtra("INTENT_EXTRA_USERNAME");
|
||
|
String stringExtra2 = getMostRecentIntent().getStringExtra("INTENT_EXTRA_DISCRIMINATOR");
|
||
|
String stringExtra3 = getMostRecentIntent().getStringExtra("INTENT_EXTRA_EMAIL");
|
||
|
ObservableExtensionsKt.withDimmer$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().patchUser(new RestAPIParams.UserInfo(null, stringExtra3, str, null, stringExtra, StoreStream.Companion.getNotifications().getPushToken(), null, stringExtra2, null, null, 841, null)), false, 1, null), this, null, 2, null), getBinding().b, 0, 2, null).k(q.h(new WidgetUserPasswordVerify$updateAccountInfo$1(this, stringExtra3, str), getContext(), new WidgetUserPasswordVerify$updateAccountInfo$2(this)));
|
||
|
}
|
||
|
|
||
|
private final void updatePhoneNumber(String str) {
|
||
|
String stringExtra = getMostRecentIntent().getStringExtra("INTENT_EXTRA_PHONE_TOKEN");
|
||
|
m.checkNotNull(stringExtra);
|
||
|
m.checkNotNullExpressionValue(stringExtra, "mostRecentIntent.getStri…TENT_EXTRA_PHONE_TOKEN)!!");
|
||
|
ObservableExtensionsKt.withDimmer$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().userPhoneWithToken(new RestAPIParams.VerificationPhoneCode(stringExtra, str)), false, 1, null), this, null, 2, null), getBinding().b, 0, 2, null).k(q.h(new WidgetUserPasswordVerify$updatePhoneNumber$1(this), getContext(), new WidgetUserPasswordVerify$updatePhoneNumber$2(this)));
|
||
|
}
|
||
|
|
||
|
@Override // com.discord.app.AppFragment
|
||
|
public void onViewBound(View view) {
|
||
|
m.checkNotNullParameter(view, "view");
|
||
|
super.onViewBound(view);
|
||
|
setActionBarSubtitle(2131894487);
|
||
|
setActionBarTitle(2131894512);
|
||
|
AppFragment.setActionBarDisplayHomeAsUpEnabled$default(this, false, 1, null);
|
||
|
StatefulViews statefulViews = this.state;
|
||
|
FloatingActionButton floatingActionButton = getBinding().d;
|
||
|
TextInputLayout textInputLayout = getBinding().f2008c;
|
||
|
m.checkNotNullExpressionValue(textInputLayout, "binding.editAccountPasswordWrap");
|
||
|
statefulViews.setupTextWatcherWithSaveAction(this, floatingActionButton, textInputLayout);
|
||
|
TextInputLayout textInputLayout2 = getBinding().f2008c;
|
||
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.editAccountPasswordWrap");
|
||
|
ViewExtensions.setOnImeActionDone$default(textInputLayout2, false, new WidgetUserPasswordVerify$onViewBound$1(this), 1, null);
|
||
|
getBinding().d.setOnClickListener(new WidgetUserPasswordVerify$onViewBound$2(this));
|
||
|
}
|
||
|
}
|