From 3473f2617b6b7e804662268b2c55c9bf0d3e640e Mon Sep 17 00:00:00 2001 From: Lukasz Macionczyk Date: Wed, 28 Aug 2024 17:15:44 +0200 Subject: [PATCH] add api to check if url is PPro url --- .../duckduckgo/subscriptions/api/Subscriptions.kt | 5 +++++ .../subscriptions/impl/SubscriptionsDummy.kt | 2 ++ .../subscriptions/impl/RealSubscriptions.kt | 14 +++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/subscriptions/subscriptions-api/src/main/java/com/duckduckgo/subscriptions/api/Subscriptions.kt b/subscriptions/subscriptions-api/src/main/java/com/duckduckgo/subscriptions/api/Subscriptions.kt index f70ae0f4032e..c8e190bc0c2f 100644 --- a/subscriptions/subscriptions-api/src/main/java/com/duckduckgo/subscriptions/api/Subscriptions.kt +++ b/subscriptions/subscriptions-api/src/main/java/com/duckduckgo/subscriptions/api/Subscriptions.kt @@ -54,6 +54,11 @@ interface Subscriptions { * Launches Privacy Pro with Settings as the parent activity */ fun launchPrivacyPro(context: Context, uri: Uri?) + + /** + * @return `true` if the given URL leads to the Privacy Pro page. or `false` otherwise + */ + fun isPrivacyProUrl(url: String): Boolean } enum class Product(val value: String) { diff --git a/subscriptions/subscriptions-dummy-impl/src/main/java/com/duckduckgo/subscriptions/impl/SubscriptionsDummy.kt b/subscriptions/subscriptions-dummy-impl/src/main/java/com/duckduckgo/subscriptions/impl/SubscriptionsDummy.kt index 6b5e64641ba9..97fb40123fb0 100644 --- a/subscriptions/subscriptions-dummy-impl/src/main/java/com/duckduckgo/subscriptions/impl/SubscriptionsDummy.kt +++ b/subscriptions/subscriptions-dummy-impl/src/main/java/com/duckduckgo/subscriptions/impl/SubscriptionsDummy.kt @@ -46,4 +46,6 @@ class SubscriptionsDummy @Inject constructor() : Subscriptions { ) { // no-op } + + override fun isPrivacyProUrl(url: String): Boolean = false } diff --git a/subscriptions/subscriptions-impl/src/main/java/com/duckduckgo/subscriptions/impl/RealSubscriptions.kt b/subscriptions/subscriptions-impl/src/main/java/com/duckduckgo/subscriptions/impl/RealSubscriptions.kt index 0f8775600c72..68921212ac7e 100644 --- a/subscriptions/subscriptions-impl/src/main/java/com/duckduckgo/subscriptions/impl/RealSubscriptions.kt +++ b/subscriptions/subscriptions-impl/src/main/java/com/duckduckgo/subscriptions/impl/RealSubscriptions.kt @@ -112,11 +112,7 @@ class RealSubscriptions @Inject constructor( } override fun shouldLaunchPrivacyProForUrl(url: String): Boolean { - val uri = url.toUri() - val eTld = uri.host?.toTldPlusOne() ?: return false - val size = uri.pathSegments.size - val path = uri.pathSegments.firstOrNull() - return if (eTld == PRIVACY_PRO_ETLD && size == 1 && path == PRIVACY_PRO_PATH) { + return if (isPrivacyProUrl(url)) { runBlocking { isEligible() } @@ -124,6 +120,14 @@ class RealSubscriptions @Inject constructor( false } } + + override fun isPrivacyProUrl(url: String): Boolean { + val uri = url.toUri() + val eTld = uri.host?.toTldPlusOne() ?: return false + val size = uri.pathSegments.size + val path = uri.pathSegments.firstOrNull() + return eTld == PRIVACY_PRO_ETLD && size == 1 && path == PRIVACY_PRO_PATH + } } @ContributesRemoteFeature(