Add a message explaining the reason for the captcha to the captcha dialog (#2459)

This commit is contained in:
Mikołaj Pich 2024-03-02 19:49:08 +01:00 committed by GitHub
parent b319bb03cd
commit 3bab883a56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 51 additions and 17 deletions

View File

@ -38,13 +38,16 @@ internal class DataModule {
@Singleton
@Provides
fun provideSdk(chuckerInterceptor: ChuckerInterceptor, remoteConfig: RemoteConfigHelper) =
Sdk().apply {
fun provideSdk(
chuckerInterceptor: ChuckerInterceptor,
remoteConfig: RemoteConfigHelper,
webkitCookieManagerProxy: WebkitCookieManagerProxy,
) = Sdk().apply {
androidVersion = android.os.Build.VERSION.RELEASE
buildTag = android.os.Build.MODEL
userAgentTemplate = remoteConfig.userAgentTemplate
setSimpleHttpLogger { Timber.d(it) }
setAdditionalCookieManager(WebkitCookieManagerProxy())
setAdditionalCookieManager(webkitCookieManagerProxy)
// for debug only
addInterceptor(chuckerInterceptor, network = true)

View File

@ -13,6 +13,7 @@ import io.github.wulkanowy.R
import io.github.wulkanowy.databinding.DialogCaptchaBinding
import io.github.wulkanowy.sdk.Sdk
import io.github.wulkanowy.ui.base.BaseDialogFragment
import io.github.wulkanowy.utils.WebkitCookieManagerProxy
import timber.log.Timber
import javax.inject.Inject
@ -22,6 +23,9 @@ class CaptchaDialog : BaseDialogFragment<DialogCaptchaBinding>() {
@Inject
lateinit var sdk: Sdk
@Inject
lateinit var webkitCookieManagerProxy: WebkitCookieManagerProxy
private var webView: WebView? = null
companion object {
@ -80,6 +84,7 @@ class CaptchaDialog : BaseDialogFragment<DialogCaptchaBinding>() {
}
override fun onDestroy() {
webkitCookieManagerProxy.webkitCookieManager?.flush()
webView?.destroy()
super.onDestroy()
}

View File

@ -5,17 +5,21 @@ import java.net.CookiePolicy
import java.net.CookieStore
import java.net.HttpCookie
import java.net.URI
import javax.inject.Inject
import javax.inject.Singleton
import android.webkit.CookieManager as WebkitCookieManager
import java.net.CookieManager as JavaCookieManager
class WebkitCookieManagerProxy : JavaCookieManager(null, CookiePolicy.ACCEPT_ALL) {
@Singleton
class WebkitCookieManagerProxy @Inject constructor() :
JavaCookieManager(null, CookiePolicy.ACCEPT_ALL) {
private val webkitCookieManager: WebkitCookieManager? = getWebkitCookieManager()
val webkitCookieManager: WebkitCookieManager? = getCookieManager()
/**
* @see [https://stackoverflow.com/a/70354583/6695449]
*/
private fun getWebkitCookieManager(): WebkitCookieManager? {
private fun getCookieManager(): WebkitCookieManager? {
return try {
WebkitCookieManager.getInstance()
} catch (e: AndroidRuntimeException) {

View File

@ -7,15 +7,18 @@
tools:context=".ui.modules.captcha.CaptchaDialog">
<TextView
android:id="@+id/captcha_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:gravity="center_vertical"
android:paddingVertical="10dp"
android:text="@string/captcha_dialog_title"
app:layout_constraintBottom_toBottomOf="@id/captcha_close"
app:layout_constraintEnd_toStartOf="@id/captcha_refresh"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0" />
<com.google.android.material.button.MaterialButton
android:id="@+id/captcha_refresh"
@ -41,11 +44,29 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/captcha_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="captcha_title,captcha_close,captcha_refresh" />
<WebView
android:id="@+id/captcha_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/captcha_description"
app:layout_constraintDimensionRatio="1"
app:layout_constraintTop_toBottomOf="@id/captcha_toolbar" />
<TextView
android:id="@+id/captcha_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="20dp"
android:paddingVertical="10dp"
android:text="@string/captcha_dialog_description"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/captcha_close" />
app:layout_constraintTop_toBottomOf="@id/captcha_webview" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -848,7 +848,8 @@
<!--Captcha-->
<string name="captcha_dialog_title">Verification is in progress. Wait…</string>
<string name="captcha_dialog_title">VULCAN\'s website requires verification</string>
<string name="captcha_dialog_description"><b>Why am I seeing this?</b>\nThe register website from which Wulkanowy downloads data displays the same screen as above, so Wulkanowy must also show it to be able to download data from this website. There\'s no way around it</string>
<string name="captcha_verified_message">Verified successfully</string>