2021-12-21 23:37:30 +00:00
|
|
|
package b.j.a;
|
2021-06-27 20:44:35 +00:00
|
|
|
|
2022-01-11 22:19:46 +00:00
|
|
|
import android.app.Dialog;
|
2021-06-27 20:44:35 +00:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.graphics.drawable.ColorDrawable;
|
|
|
|
import android.os.BadParcelableException;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2022-01-11 22:19:46 +00:00
|
|
|
import android.view.Window;
|
2021-06-27 20:44:35 +00:00
|
|
|
import android.webkit.WebSettings;
|
|
|
|
import android.webkit.WebView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.fragment.app.DialogFragment;
|
2021-12-21 23:37:30 +00:00
|
|
|
import b.j.a.f.b;
|
2021-06-27 20:44:35 +00:00
|
|
|
import com.hcaptcha.sdk.HCaptchaConfig;
|
|
|
|
import com.hcaptcha.sdk.HCaptchaDialogListener;
|
|
|
|
import com.hcaptcha.sdk.HCaptchaError;
|
|
|
|
import com.hcaptcha.sdk.HCaptchaException;
|
|
|
|
import com.hcaptcha.sdk.HCaptchaTokenResponse;
|
|
|
|
import com.hcaptcha.sdk.R;
|
2021-12-21 23:37:30 +00:00
|
|
|
public class c extends DialogFragment implements b, b.j.a.f.c<HCaptchaTokenResponse>, b.j.a.f.a {
|
2021-12-17 22:03:14 +00:00
|
|
|
public static final String j = c.class.getSimpleName();
|
|
|
|
public final Handler k = new Handler(Looper.getMainLooper());
|
|
|
|
public e l;
|
2022-01-11 22:19:46 +00:00
|
|
|
public boolean m;
|
|
|
|
public HCaptchaDialogListener n;
|
|
|
|
public View o;
|
|
|
|
public WebView p;
|
|
|
|
public LinearLayout q;
|
2021-06-27 20:44:35 +00:00
|
|
|
|
|
|
|
public class a implements Runnable {
|
2021-12-17 22:03:14 +00:00
|
|
|
public final /* synthetic */ HCaptchaException j;
|
2021-06-27 20:44:35 +00:00
|
|
|
|
|
|
|
public a(HCaptchaException hCaptchaException) {
|
2021-12-17 22:03:14 +00:00
|
|
|
this.j = hCaptchaException;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override // java.lang.Runnable
|
|
|
|
public void run() {
|
2022-01-11 22:19:46 +00:00
|
|
|
c.this.n.a(this.j);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // androidx.fragment.app.DialogFragment, android.content.DialogInterface.OnCancelListener
|
|
|
|
public void onCancel(@NonNull DialogInterface dialogInterface) {
|
|
|
|
super.onCancel(dialogInterface);
|
|
|
|
onFailure(new HCaptchaException(HCaptchaError.CHALLENGE_CLOSED));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // androidx.fragment.app.DialogFragment, androidx.fragment.app.Fragment
|
|
|
|
public void onCreate(Bundle bundle) {
|
|
|
|
super.onCreate(bundle);
|
|
|
|
try {
|
2022-01-11 22:19:46 +00:00
|
|
|
this.n = (HCaptchaDialogListener) getArguments().getParcelable("hCaptchaDialogListener");
|
|
|
|
HCaptchaConfig hCaptchaConfig = (HCaptchaConfig) getArguments().getSerializable("hCaptchaConfig");
|
|
|
|
this.l = new e(hCaptchaConfig, this, this, this);
|
|
|
|
this.m = hCaptchaConfig.getLoading().booleanValue();
|
2021-06-27 20:44:35 +00:00
|
|
|
setStyle(2, R.c.HCaptchaDialogTheme);
|
|
|
|
} catch (BadParcelableException unused) {
|
|
|
|
dismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
|
|
public View onCreateView(@NonNull LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
|
|
|
View inflate = layoutInflater.inflate(R.b.hcaptcha_fragment, viewGroup, false);
|
2022-01-11 22:19:46 +00:00
|
|
|
this.o = inflate;
|
|
|
|
LinearLayout linearLayout = (LinearLayout) inflate.findViewById(R.a.loadingContainer);
|
|
|
|
this.q = linearLayout;
|
|
|
|
linearLayout.setVisibility(this.m ? 0 : 8);
|
|
|
|
WebView webView = (WebView) this.o.findViewById(R.a.webView);
|
|
|
|
this.p = webView;
|
2021-06-27 20:44:35 +00:00
|
|
|
WebSettings settings = webView.getSettings();
|
|
|
|
settings.setJavaScriptEnabled(true);
|
|
|
|
settings.setLoadWithOverviewMode(true);
|
|
|
|
webView.setBackgroundColor(0);
|
|
|
|
webView.setLayerType(1, null);
|
2021-12-17 22:03:14 +00:00
|
|
|
webView.addJavascriptInterface(this.l, "JSInterface");
|
2021-06-27 20:44:35 +00:00
|
|
|
webView.loadUrl("file:///android_asset/hcaptcha-form.html");
|
2022-01-11 22:19:46 +00:00
|
|
|
return this.o;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
2022-01-11 22:19:46 +00:00
|
|
|
WebView webView = this.p;
|
2021-06-27 20:44:35 +00:00
|
|
|
if (webView != null) {
|
|
|
|
webView.removeJavascriptInterface("JSInterface");
|
2022-01-11 22:19:46 +00:00
|
|
|
((ViewGroup) this.o).removeAllViews();
|
|
|
|
this.p.destroy();
|
|
|
|
this.p = null;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-21 23:37:30 +00:00
|
|
|
@Override // b.j.a.f.a
|
2021-06-27 20:44:35 +00:00
|
|
|
public void onFailure(@NonNull HCaptchaException hCaptchaException) {
|
|
|
|
if (isAdded()) {
|
|
|
|
dismiss();
|
|
|
|
}
|
2021-12-17 22:03:14 +00:00
|
|
|
this.k.post(new a(hCaptchaException));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override // androidx.fragment.app.DialogFragment, androidx.fragment.app.Fragment
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
2022-01-11 22:19:46 +00:00
|
|
|
Dialog dialog = getDialog();
|
|
|
|
if (dialog != null) {
|
|
|
|
Window window = dialog.getWindow();
|
|
|
|
window.setBackgroundDrawable(new ColorDrawable(0));
|
|
|
|
if (!this.m) {
|
|
|
|
window.clearFlags(2);
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
2021-12-21 23:37:30 +00:00
|
|
|
@Override // b.j.a.f.c
|
2021-06-27 20:44:35 +00:00
|
|
|
public void onSuccess(HCaptchaTokenResponse hCaptchaTokenResponse) {
|
|
|
|
HCaptchaTokenResponse hCaptchaTokenResponse2 = hCaptchaTokenResponse;
|
|
|
|
if (isAdded()) {
|
|
|
|
dismiss();
|
|
|
|
}
|
2021-12-17 22:03:14 +00:00
|
|
|
this.k.post(new d(this, hCaptchaTokenResponse2));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|