From 454105ff755c60cbbcac7a20e9faa682cd28c5f4 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Thu, 28 Dec 2023 17:18:11 +0600 Subject: [PATCH] fixed: app purchase --- .../apps/data/playstore/utils/GPlayHttpClient.kt | 12 +++++++++--- .../e/apps/ui/purchase/AppPurchaseFragment.kt | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/playstore/utils/GPlayHttpClient.kt b/app/src/main/java/foundation/e/apps/data/playstore/utils/GPlayHttpClient.kt index a8ac6ed99..3e23c0f91 100644 --- a/app/src/main/java/foundation/e/apps/data/playstore/utils/GPlayHttpClient.kt +++ b/app/src/main/java/foundation/e/apps/data/playstore/utils/GPlayHttpClient.kt @@ -58,6 +58,7 @@ class GPlayHttpClient @Inject constructor( private const val STATUS_CODE_OK = 200 private const val STATUS_CODE_UNAUTHORIZED = 401 private const val STATUS_CODE_TOO_MANY_REQUESTS = 429 + private const val URL_SUBSTRING_PURCHASE = "purchase" const val STATUS_CODE_TIMEOUT = 408 } @@ -187,7 +188,8 @@ class GPlayHttpClient @Inject constructor( return PlayResponse().apply { isSuccessful = response.isSuccessful code = response.code - Timber.d("$TAG: Url: ${response.request.url}\nStatus: $code") + val url = response.request.url + Timber.d("$TAG: Url: $url\nStatus: $code") when (code) { STATUS_CODE_UNAUTHORIZED -> MainScope().launch { @@ -198,7 +200,7 @@ class GPlayHttpClient @Inject constructor( STATUS_CODE_TOO_MANY_REQUESTS -> MainScope().launch { cache.evictAll() - if (response.request.url.toString().contains(SEARCH_SUGGEST)) { + if (url.toString().contains(SEARCH_SUGGEST)) { return@launch } @@ -208,7 +210,11 @@ class GPlayHttpClient @Inject constructor( } } - if (code !in listOf(STATUS_CODE_OK, STATUS_CODE_UNAUTHORIZED)) { + if (!url.toString().contains(URL_SUBSTRING_PURCHASE) && code !in listOf( + STATUS_CODE_OK, + STATUS_CODE_UNAUTHORIZED + ) + ) { throw GplayHttpRequestException(code, response.message) } diff --git a/app/src/main/java/foundation/e/apps/ui/purchase/AppPurchaseFragment.kt b/app/src/main/java/foundation/e/apps/ui/purchase/AppPurchaseFragment.kt index f63db522a..1c6ab8df4 100644 --- a/app/src/main/java/foundation/e/apps/ui/purchase/AppPurchaseFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/purchase/AppPurchaseFragment.kt @@ -7,6 +7,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.webkit.CookieManager +import android.webkit.WebResourceRequest import android.webkit.WebSettings import android.webkit.WebView import android.webkit.WebViewClient @@ -28,6 +29,10 @@ class AppPurchaseFragment : Fragment() { private var isAppPurchased = false private var packageName = "" + companion object { + private const val URL_SCHEME_INTENT = "intent" + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -78,6 +83,17 @@ class AppPurchaseFragment : Fragment() { return true } + + override fun shouldOverrideUrlLoading( + view: WebView?, + request: WebResourceRequest? + ): Boolean { + if (request?.url.toString().contains(URL_SCHEME_INTENT)) { + return true + } + + return false + } } binding.playStoreWebView.apply { -- GitLab