231 lines
12 KiB
Java
231 lines
12 KiB
Java
package com.discord.widgets.captcha;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.widget.TextView;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentActivity;
|
|
import androidx.fragment.app.FragmentKt;
|
|
import androidx.fragment.app.FragmentManager;
|
|
import b.a.k.b;
|
|
import b.d.b.a.a;
|
|
import com.discord.R;
|
|
import com.discord.app.AppBottomSheet;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.databinding.WidgetCaptchaBottomSheetBinding;
|
|
import com.discord.stores.StoreNotices;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.captcha.CaptchaErrorBody;
|
|
import com.discord.utilities.captcha.CaptchaHelper;
|
|
import com.discord.utilities.captcha.CaptchaService;
|
|
import com.discord.utilities.font.FontUtils;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.discord.widgets.share.WidgetIncomingShare;
|
|
import com.discord.widgets.tabs.WidgetTabsHost;
|
|
import com.google.android.material.button.MaterialButton;
|
|
import d0.e0.c;
|
|
import d0.g;
|
|
import d0.t.n;
|
|
import d0.z.d.a0;
|
|
import d0.z.d.m;
|
|
import java.util.List;
|
|
import kotlin.Lazy;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.functions.Function2;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.reflect.KProperty;
|
|
/* compiled from: WidgetCaptchaBottomSheet.kt */
|
|
public final class WidgetCaptchaBottomSheet extends AppBottomSheet {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.b0(WidgetCaptchaBottomSheet.class, "binding", "getBinding()Lcom/discord/databinding/WidgetCaptchaBottomSheetBinding;", 0)};
|
|
private static final String ARG_REQUEST_KEY = "INTENT_EXTRA_REQUEST_CODE";
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final String NOTICE_NAME = "captcha notice";
|
|
private static final String RESULT_EXTRA_CAPTCHA_RQTOKEN = "INTENT_EXTRA_CAPTCHA_RQTOKEN";
|
|
private static final String RESULT_EXTRA_CAPTCHA_TOKEN = "INTENT_EXTRA_CAPTCHA_TOKEN";
|
|
private static final List<c<? extends AppFragment>> resolvableFragments = n.listOf((Object[]) new c[]{a0.getOrCreateKotlinClass(WidgetTabsHost.class), a0.getOrCreateKotlinClass(WidgetIncomingShare.class)});
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetCaptchaBottomSheet$binding$2.INSTANCE, null, 2, null);
|
|
private final Lazy captchaErrorBody$delegate = g.lazy(new WidgetCaptchaBottomSheet$captchaErrorBody$2(this));
|
|
private boolean captchaPassed;
|
|
private Function0<Unit> onCaptchaAttemptFailed;
|
|
private final Lazy requestCode$delegate = g.lazy(new WidgetCaptchaBottomSheet$requestCode$2(this));
|
|
|
|
/* compiled from: WidgetCaptchaBottomSheet.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.captcha.WidgetCaptchaBottomSheet$Companion */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ void enqueue$default(Companion companion, String str, Function2 function2, Function0 function0, CaptchaErrorBody captchaErrorBody, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
function0 = null;
|
|
}
|
|
companion.enqueue(str, function2, function0, captchaErrorBody);
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.captcha.WidgetCaptchaBottomSheet$Companion */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ void show$default(Companion companion, FragmentManager fragmentManager, String str, CaptchaErrorBody captchaErrorBody, Function0 function0, int i, Object obj) {
|
|
if ((i & 8) != 0) {
|
|
function0 = null;
|
|
}
|
|
companion.show(fragmentManager, str, captchaErrorBody, function0);
|
|
}
|
|
|
|
public final void enqueue(String str, Function2<? super AppFragment, ? super CaptchaHelper.CaptchaPayload, Unit> function2, Function0<Unit> function0, CaptchaErrorBody captchaErrorBody) {
|
|
m.checkNotNullParameter(str, "requestKey");
|
|
m.checkNotNullParameter(function2, "onCaptchaPayloadReceived");
|
|
StoreStream.Companion.getNotices().requestToShow(new StoreNotices.Notice(WidgetCaptchaBottomSheet.NOTICE_NAME, null, 0, 0, false, WidgetCaptchaBottomSheet.access$getResolvableFragments$cp(), 0, false, 0, new WidgetCaptchaBottomSheet$Companion$enqueue$captchaNotice$1(str, captchaErrorBody, function0, function2), FontUtils.MAX_FONT_SCALING, null));
|
|
}
|
|
|
|
public final void registerForResult(AppFragment appFragment, String str, Function2<? super AppFragment, ? super CaptchaHelper.CaptchaPayload, Unit> function2) {
|
|
m.checkNotNullParameter(appFragment, "fragment");
|
|
m.checkNotNullParameter(str, "requestKey");
|
|
m.checkNotNullParameter(function2, "onCaptchaPayloadReceived");
|
|
FragmentKt.setFragmentResultListener(appFragment, str, new WidgetCaptchaBottomSheet$Companion$registerForResult$1(str, function2, appFragment));
|
|
}
|
|
|
|
public final void show(FragmentManager fragmentManager, String str, CaptchaErrorBody captchaErrorBody, Function0<Unit> function0) {
|
|
m.checkNotNullParameter(fragmentManager, "fragmentManager");
|
|
m.checkNotNullParameter(str, "requestKey");
|
|
WidgetCaptchaBottomSheet widgetCaptchaBottomSheet = new WidgetCaptchaBottomSheet();
|
|
Bundle bundle = new Bundle();
|
|
bundle.putSerializable("INTENT_EXTRA_CAPTCHA_ERROR_BODY", captchaErrorBody);
|
|
bundle.putString(WidgetCaptchaBottomSheet.ARG_REQUEST_KEY, str);
|
|
widgetCaptchaBottomSheet.setArguments(bundle);
|
|
WidgetCaptchaBottomSheet.access$setOnCaptchaAttemptFailed$p(widgetCaptchaBottomSheet, function0);
|
|
widgetCaptchaBottomSheet.show(fragmentManager, WidgetCaptchaBottomSheet.class.getName());
|
|
}
|
|
}
|
|
|
|
public WidgetCaptchaBottomSheet() {
|
|
super(false, 1, null);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$finishIfCaptchaTokenReceived(WidgetCaptchaBottomSheet widgetCaptchaBottomSheet, Activity activity) {
|
|
widgetCaptchaBottomSheet.finishIfCaptchaTokenReceived(activity);
|
|
}
|
|
|
|
public static final /* synthetic */ Bundle access$getArgumentsOrDefault$p(WidgetCaptchaBottomSheet widgetCaptchaBottomSheet) {
|
|
return widgetCaptchaBottomSheet.getArgumentsOrDefault();
|
|
}
|
|
|
|
public static final /* synthetic */ boolean access$getCaptchaPassed$p(WidgetCaptchaBottomSheet widgetCaptchaBottomSheet) {
|
|
return widgetCaptchaBottomSheet.captchaPassed;
|
|
}
|
|
|
|
public static final /* synthetic */ Function0 access$getOnCaptchaAttemptFailed$p(WidgetCaptchaBottomSheet widgetCaptchaBottomSheet) {
|
|
return widgetCaptchaBottomSheet.onCaptchaAttemptFailed;
|
|
}
|
|
|
|
public static final /* synthetic */ List access$getResolvableFragments$cp() {
|
|
return resolvableFragments;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$openCaptcha(WidgetCaptchaBottomSheet widgetCaptchaBottomSheet) {
|
|
widgetCaptchaBottomSheet.openCaptcha();
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setCaptchaPassed$p(WidgetCaptchaBottomSheet widgetCaptchaBottomSheet, boolean z2) {
|
|
widgetCaptchaBottomSheet.captchaPassed = z2;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setOnCaptchaAttemptFailed$p(WidgetCaptchaBottomSheet widgetCaptchaBottomSheet, Function0 function0) {
|
|
widgetCaptchaBottomSheet.onCaptchaAttemptFailed = function0;
|
|
}
|
|
|
|
private final void configureUI() {
|
|
TextView textView = getBinding().d;
|
|
m.checkNotNullExpressionValue(textView, "binding.captchaTitle");
|
|
b.n(textView, R.string.generic_captcha_header, new Object[0], null, 4);
|
|
TextView textView2 = getBinding().f2236b;
|
|
m.checkNotNullExpressionValue(textView2, "binding.captchaBody");
|
|
b.n(textView2, R.string.generic_captcha_description, new Object[0], null, 4);
|
|
MaterialButton materialButton = getBinding().c;
|
|
m.checkNotNullExpressionValue(materialButton, "binding.captchaButton");
|
|
b.n(materialButton, R.string.confirm, new Object[0], null, 4);
|
|
getBinding().c.setOnClickListener(new WidgetCaptchaBottomSheet$configureUI$1(this));
|
|
}
|
|
|
|
private final void finishIfCaptchaTokenReceived(Activity activity) {
|
|
CaptchaHelper captchaHelper = CaptchaHelper.INSTANCE;
|
|
String captchaToken = captchaHelper.getCaptchaToken();
|
|
if (captchaToken != null) {
|
|
String captchaRqtoken = captchaHelper.getCaptchaRqtoken();
|
|
captchaHelper.setCaptchaToken(null);
|
|
captchaHelper.setCaptchaRqtoken(null);
|
|
String requestCode = getRequestCode();
|
|
Bundle bundle = new Bundle();
|
|
bundle.putString(RESULT_EXTRA_CAPTCHA_TOKEN, captchaToken);
|
|
bundle.putString(RESULT_EXTRA_CAPTCHA_RQTOKEN, captchaRqtoken);
|
|
FragmentKt.setFragmentResult(this, requestCode, bundle);
|
|
dismiss();
|
|
}
|
|
}
|
|
|
|
private final WidgetCaptchaBottomSheetBinding getBinding() {
|
|
return (WidgetCaptchaBottomSheetBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
private final CaptchaErrorBody getCaptchaErrorBody() {
|
|
return (CaptchaErrorBody) this.captchaErrorBody$delegate.getValue();
|
|
}
|
|
|
|
private final String getRequestCode() {
|
|
return (String) this.requestCode$delegate.getValue();
|
|
}
|
|
|
|
private final void openCaptcha() {
|
|
CaptchaHelper.CaptchaRequest captchaRequest;
|
|
String captchaSitekey = getCaptchaErrorBody().getCaptchaSitekey();
|
|
CaptchaService captchaService = getCaptchaErrorBody().getCaptchaService();
|
|
String captchaRqdata = getCaptchaErrorBody().getCaptchaRqdata();
|
|
String captchaRqtoken = getCaptchaErrorBody().getCaptchaRqtoken();
|
|
CaptchaHelper captchaHelper = CaptchaHelper.INSTANCE;
|
|
captchaHelper.setCaptchaRqtoken(captchaRqtoken);
|
|
if (captchaSitekey == null || captchaService != CaptchaService.HCAPTCHA) {
|
|
FragmentActivity requireActivity = requireActivity();
|
|
m.checkNotNullExpressionValue(requireActivity, "requireActivity()");
|
|
captchaRequest = new CaptchaHelper.CaptchaRequest.ReCaptcha(requireActivity);
|
|
} else {
|
|
FragmentActivity requireActivity2 = requireActivity();
|
|
m.checkNotNullExpressionValue(requireActivity2, "requireActivity()");
|
|
captchaRequest = new CaptchaHelper.CaptchaRequest.HCaptcha(captchaSitekey, requireActivity2, captchaRqdata);
|
|
}
|
|
ObservableExtensionsKt.appSubscribe$default(captchaHelper.tryShowCaptcha(captchaRequest), WidgetCaptchaBottomSheet.class, (Context) null, (Function1) null, new WidgetCaptchaBottomSheet$openCaptcha$2(this), (Function0) null, (Function0) null, new WidgetCaptchaBottomSheet$openCaptcha$1(this), 54, (Object) null);
|
|
}
|
|
|
|
@Override // com.discord.app.AppBottomSheet
|
|
public int getContentViewResId() {
|
|
return R.layout.widget_captcha_bottom_sheet;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.DialogFragment, android.content.DialogInterface.OnDismissListener
|
|
public void onDismiss(DialogInterface dialogInterface) {
|
|
Function0<Unit> function0;
|
|
m.checkNotNullParameter(dialogInterface, "dialog");
|
|
super.onDismiss(dialogInterface);
|
|
if (!this.captchaPassed && (function0 = this.onCaptchaAttemptFailed) != null) {
|
|
function0.mo1invoke();
|
|
}
|
|
}
|
|
|
|
@Override // com.discord.app.AppBottomSheet, androidx.fragment.app.Fragment
|
|
public void onViewCreated(View view, Bundle bundle) {
|
|
m.checkNotNullParameter(view, "view");
|
|
super.onViewCreated(view, bundle);
|
|
configureUI();
|
|
}
|
|
}
|