119 lines
4.2 KiB
Java
119 lines
4.2 KiB
Java
package c.j.a;
|
|
|
|
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;
|
|
import android.webkit.WebSettings;
|
|
import android.webkit.WebView;
|
|
import android.widget.LinearLayout;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.fragment.app.DialogFragment;
|
|
import c.j.a.f.b;
|
|
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;
|
|
public class c extends DialogFragment implements b, c.j.a.f.c<HCaptchaTokenResponse>, c.j.a.f.a {
|
|
public static final String i = c.class.getSimpleName();
|
|
public final Handler j = new Handler(Looper.getMainLooper());
|
|
public e k;
|
|
public HCaptchaDialogListener l;
|
|
public View m;
|
|
public WebView n;
|
|
public LinearLayout o;
|
|
|
|
public class a implements Runnable {
|
|
public final /* synthetic */ HCaptchaException i;
|
|
|
|
public a(HCaptchaException hCaptchaException) {
|
|
this.i = hCaptchaException;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
c.this.l.a(this.i);
|
|
}
|
|
}
|
|
|
|
@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 {
|
|
this.l = (HCaptchaDialogListener) getArguments().getParcelable("hCaptchaDialogListener");
|
|
this.k = new e((HCaptchaConfig) getArguments().getSerializable("hCaptchaConfig"), this, this, this);
|
|
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);
|
|
this.m = inflate;
|
|
this.o = (LinearLayout) inflate.findViewById(R.a.loadingContainer);
|
|
WebView webView = (WebView) this.m.findViewById(R.a.webView);
|
|
this.n = webView;
|
|
WebSettings settings = webView.getSettings();
|
|
settings.setJavaScriptEnabled(true);
|
|
settings.setLoadWithOverviewMode(true);
|
|
webView.setBackgroundColor(0);
|
|
webView.setLayerType(1, null);
|
|
webView.addJavascriptInterface(this.k, "JSInterface");
|
|
webView.loadUrl("file:///android_asset/hcaptcha-form.html");
|
|
return this.m;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
WebView webView = this.n;
|
|
if (webView != null) {
|
|
webView.removeJavascriptInterface("JSInterface");
|
|
((ViewGroup) this.m).removeAllViews();
|
|
this.n.destroy();
|
|
this.n = null;
|
|
}
|
|
}
|
|
|
|
@Override // c.j.a.f.a
|
|
public void onFailure(@NonNull HCaptchaException hCaptchaException) {
|
|
if (isAdded()) {
|
|
dismiss();
|
|
}
|
|
this.j.post(new a(hCaptchaException));
|
|
}
|
|
|
|
@Override // androidx.fragment.app.DialogFragment, androidx.fragment.app.Fragment
|
|
public void onStart() {
|
|
super.onStart();
|
|
if (getDialog() != null) {
|
|
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0));
|
|
}
|
|
}
|
|
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
|
@Override // c.j.a.f.c
|
|
public void onSuccess(HCaptchaTokenResponse hCaptchaTokenResponse) {
|
|
HCaptchaTokenResponse hCaptchaTokenResponse2 = hCaptchaTokenResponse;
|
|
if (isAdded()) {
|
|
dismiss();
|
|
}
|
|
this.j.post(new d(this, hCaptchaTokenResponse2));
|
|
}
|
|
}
|