From b58f3a7fd8f72fb2b466d49671895b71ce58430b Mon Sep 17 00:00:00 2001 From: Alex Babrykovich Date: Wed, 5 Apr 2023 13:11:44 +0200 Subject: [PATCH] feat(sdk): reset (#104) Co-authored-by: Sergiu Danalachi --- CHANGES.md | 4 ++ .../hcaptcha/sdk/TestHCaptchaVerifier.java | 5 ++ .../com/hcaptcha/example/MainActivity.java | 8 +-- .../src/main/res/layout/activity_main.xml | 5 +- example-app/src/main/res/values/strings.xml | 2 +- sdk/build.gradle | 4 +- .../sdk/HCaptchaDialogFragmentTest.java | 11 ++++ .../sdk/HCaptchaHeadlessWebViewTest.java | 31 +++++++++ sdk/src/main/html/hcaptcha.html | 3 + .../main/java/com/hcaptcha/sdk/HCaptcha.java | 8 +++ .../hcaptcha/sdk/HCaptchaDialogFragment.java | 10 +++ .../hcaptcha/sdk/HCaptchaHeadlessWebView.java | 19 +++++- .../hcaptcha/sdk/HCaptchaWebViewHelper.java | 6 +- .../main/java/com/hcaptcha/sdk/IHCaptcha.java | 4 ++ .../com/hcaptcha/sdk/IHCaptchaVerifier.java | 4 ++ .../java/com/hcaptcha/sdk/HCaptchaTest.java | 63 +++++++++---------- 16 files changed, 142 insertions(+), 45 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 44757a3d..4c278fc0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changelog +# 3.8.0 + +- Feat: new `HCaptcha.reset` to force stop verification and release all resources. + # 3.7.0 - Feat: new `HCaptchaConfig.orientation` to set either `portrait` or `landscape` challenge orientation. diff --git a/benchmark/src/androidTest/java/com/hcaptcha/sdk/TestHCaptchaVerifier.java b/benchmark/src/androidTest/java/com/hcaptcha/sdk/TestHCaptchaVerifier.java index 8310701c..a7559a18 100644 --- a/benchmark/src/androidTest/java/com/hcaptcha/sdk/TestHCaptchaVerifier.java +++ b/benchmark/src/androidTest/java/com/hcaptcha/sdk/TestHCaptchaVerifier.java @@ -28,4 +28,9 @@ public void onOpen() { public void onSuccess(String s) { // no implementation need for performance measurement } + + @Override + public void reset() { + // no implementation need for performance measurement + } } diff --git a/example-app/src/main/java/com/hcaptcha/example/MainActivity.java b/example-app/src/main/java/com/hcaptcha/example/MainActivity.java index 7eb4280f..b13a6031 100644 --- a/example-app/src/main/java/com/hcaptcha/example/MainActivity.java +++ b/example-app/src/main/java/com/hcaptcha/example/MainActivity.java @@ -13,9 +13,6 @@ import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; import com.hcaptcha.sdk.*; -import com.hcaptcha.sdk.tasks.OnFailureListener; -import com.hcaptcha.sdk.tasks.OnOpenListener; -import com.hcaptcha.sdk.tasks.OnSuccessListener; import java.util.Arrays; @@ -82,7 +79,10 @@ private void setErrorTextView(final String error) { errorTextView.setText(error); } - public void onClickClear(final View v) { + public void onClickReset(final View view) { + if (hCaptcha != null) { + hCaptcha.reset(); + } setTokenTextView("-"); hCaptcha = null; } diff --git a/example-app/src/main/res/layout/activity_main.xml b/example-app/src/main/res/layout/activity_main.xml index 32326b6f..ae01d37a 100644 --- a/example-app/src/main/res/layout/activity_main.xml +++ b/example-app/src/main/res/layout/activity_main.xml @@ -50,8 +50,8 @@