diff --git a/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt b/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt index 6cf4e25783..8f984c76f0 100644 --- a/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt +++ b/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt @@ -11,11 +11,11 @@ import android.os.Build import androidx.core.app.NotificationCompat import androidx.core.content.ContextCompat import androidx.core.graphics.drawable.toBitmap -import androidx.core.net.toUri import coil.executeBlocking import coil.request.ImageRequest import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage +import com.tangem.core.deeplink.DEEPLINK_KEY import com.tangem.domain.common.LogConfig import com.tangem.tap.MainActivity import com.tangem.tap.common.images.createCoilImageLoader @@ -38,7 +38,7 @@ internal class TangemPushNotificationService : FirebaseMessagingService() { val channelId = notification.channelId ?: TANGEM_CHANNEL_ID val intent = Intent(applicationContext, MainActivity::class.java).apply { - data = message.data[DEEPLINK_KEY]?.toUri() + putExtra(DEEPLINK_KEY, message.data[DEEPLINK_KEY]) putExtra(OnPushClickedIntentHandler.OPENED_FROM_GCM_PUSH, true) addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) } @@ -103,7 +103,5 @@ internal class TangemPushNotificationService : FirebaseMessagingService() { private companion object { const val TANGEM_CHANNEL_ID = "Tangem General" // General channel for notifications const val PUSH_NOTIFICATION_REQUEST_CODE = 123 - - const val DEEPLINK_KEY = "deeplink" } } \ No newline at end of file diff --git a/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt b/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt index 2f712579cc..1d3ceb8718 100644 --- a/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt +++ b/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt @@ -2,6 +2,11 @@ package com.tangem.core.deeplink import android.content.Intent +/** + * Key to pass deeplink via intent + */ +const val DEEPLINK_KEY = "deeplink" + // TODO: Add tests /** * Provides functionality to handle deep links. diff --git a/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/impl/DefaultDeepLinksRegistry.kt b/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/impl/DefaultDeepLinksRegistry.kt index da6b6acfd8..ff0c60033b 100644 --- a/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/impl/DefaultDeepLinksRegistry.kt +++ b/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/impl/DefaultDeepLinksRegistry.kt @@ -3,6 +3,7 @@ package com.tangem.core.deeplink.impl import android.content.Intent import android.net.Uri import androidx.core.net.toUri +import com.tangem.core.deeplink.DEEPLINK_KEY import com.tangem.core.deeplink.DeepLink import com.tangem.core.deeplink.DeepLinksRegistry import timber.log.Timber @@ -10,11 +11,14 @@ import timber.log.Timber internal class DefaultDeepLinksRegistry : DeepLinksRegistry { private var registries: List = emptyList() - private var lastIntent: Intent? = null + private var lastDeepLink: Uri? = null override fun launch(intent: Intent): Boolean { - lastIntent = intent - val received = intent.data ?: return false + // Try to get deeplink from data (direct deeplink flow) + // Otherwise, try to get from extras (notification deeplink flow) + val deepLinkExtras = intent.getStringExtra(DEEPLINK_KEY)?.toUri() + val received = intent.data ?: deepLinkExtras ?: return false + lastDeepLink = received var hasMatch = false Timber.i( @@ -35,7 +39,7 @@ internal class DefaultDeepLinksRegistry : DeepLinksRegistry { logMatch(hasMatch, expected, received, params) deepLink.onReceive(params) - lastIntent = null // clear intent if it was handled + lastDeepLink = null // clear deeplink if it was handled } if (!hasMatch) { @@ -100,10 +104,9 @@ internal class DefaultDeepLinksRegistry : DeepLinksRegistry { ) } - override fun triggerDelayedDeeplink() { - if (lastIntent != null) { - val intent = lastIntent - val received = intent?.data ?: return + override fun triggerDelayedDeeplink(deepLinkClass: Class) { + val received = lastDeepLink + if (received != null) { var hasMatch = false registries .filterIsInstance(deepLinkClass) @@ -121,12 +124,12 @@ internal class DefaultDeepLinksRegistry : DeepLinksRegistry { if (!hasMatch) { logMatch(hasMatch, null, received, null) } - lastIntent = null // clear intent in any case handle or not + lastDeepLink = null // clear deeplink in any case handle or not } } override fun cancelDelayedDeeplink() { - lastIntent = null + lastDeepLink = null } private fun logMatch(hasMatch: Boolean, expected: Uri?, received: Uri?, params: Map?) { diff --git a/data/promo/src/main/java/com/tangem/data/promo/DefaultPromoRepository.kt b/data/promo/src/main/java/com/tangem/data/promo/DefaultPromoRepository.kt index c80337d42b..f48446148f 100644 --- a/data/promo/src/main/java/com/tangem/data/promo/DefaultPromoRepository.kt +++ b/data/promo/src/main/java/com/tangem/data/promo/DefaultPromoRepository.kt @@ -39,7 +39,9 @@ internal class DefaultPromoRepository( default = true, ).map { shouldShow -> if (promoId == PromoId.Referral) { - !referralRepository.isReferralParticipant(userWalletId) && shouldShow + runCatching { + !referralRepository.isReferralParticipant(userWalletId) && shouldShow + }.getOrDefault(false) } else { shouldShow }