Repository: Automattic/pocket-casts-android
File: modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/notification/NotificationOpenReceiver.kt (Kotlin)

Code before:
                event = AnalyticsEvent.NOTIFICATION_OPENED,
                properties = mapOf(
                    "type" to it.analyticsType,
                    "category" to CATEGORY_DEEP_LINK,
                ),
            )
            val target = it.toIntent(context)
            tryLaunchIntent(target, context)
        }
    }

    private fun tryLaunchIntent(intent: Intent, context: Context) {
        try {
            context.startActivity(intent.apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK })
        } catch (t: Throwable) {
            Timber.w("Failed to launch activity for intent $intent")
        }
    }

    companion object {
        private const val ACTION_REVAMP_NOTIFICATION_OPENED = "au.com.shiftyjelly.pocketcasts.ACTION_REVAMPED_NOTIFICATION_OPENED"
        private const val EXTRA_REVAMPED_TYPE = "extras.revamped.notification.type"
        private const val EXTRA_CATEGORY = "extras.notification.category"
        private const val EXTRA_ORIGINAL_COMPONENT = "extras.notification.component"
        private const val EXTRA_ORIGINAL_FLAGS = "extras.notification.flags"
        private const val EXTRA_ORIGINAL_ACTION = "extras.notification.action"
        private const val CATEGORY_DEEP_LINK = "DEEP_LINK"
        private const val CATEGORY_EPISODE = "ep"
        private const val CATEGORY_PODCAST = "po"

        fun NotificationType.toBroadcast(context: Context) = Intent(context, NotificationOpenReceiver::class.java).apply {
            action = ACTION_REVAMP_NOTIFICATION_OPENED
            putExtra(EXTRA_REVAMPED_TYPE, this@toBroadcast.subcategory)
        }

        fun toEpisodeIntentRelay(context: Context, intent: Intent) = Intent(context, NotificationOpenReceiver::class.java).apply {
            putExtras(intent)
            putExtra(EXTRA_CATEGORY, CATEGORY_EPISODE)
            putExtra(EXTRA_ORIGINAL_FLAGS, intent.flags)
            intent.component?.let {
                putExtra(EXTRA_ORIGINAL_COMPONENT, it)
            }
            intent.action?.let {
                putExtra(EXTRA_ORIGINAL_ACTION, it)
            }
        }

        fun toPodcastIntentRelay(context: Context, intent: Intent) = Intent(context, NotificationOpenReceiver::class.java).apply {
            putExtras(intent)
            putExtra(EXTRA_CATEGORY, CATEGORY_PODCAST)
            putExtra(EXTRA_ORIGINAL_FLAGS, intent.flags)

Review comment (bug):
❓ Could you prefix those with our package name? Just to avoid any potential namespace conflicts and make it easier to debug in the future when inspecting intents.

Code after:
    }

    companion object {
        private const val ACTION_REVAMP_NOTIFICATION_OPENED = "au.com.shiftyjelly.pocketcasts.ACTION_REVAMPED_NOTIFICATION_OPENED"
        private const val EXTRA_REVAMPED_TYPE = "au.com.shiftyjelly.pocketcasts.extras.revamped.notification.type"
        private const val EXTRA_CATEGORY = "au.com.shiftyjelly.pocketcasts.extras.notification.category"
        private const val EXTRA_ORIGINAL_COMPONENT = "au.com.shiftyjelly.pocketcasts.extras.notification.component"
        private const val CATEGORY_DEEP_LINK = "DEEP_LINK"
        private const val CATEGORY_EPISODE = "ep"
        private const val CATEGORY_PODCAST = "po"

        fun NotificationType.toBroadcast(context: Context) = Intent(context, NotificationOpenReceiver::class.java).apply {
            action = ACTION_REVAMP_NOTIFICATION_OPENED
            putExtra(EXTRA_REVAMPED_TYPE, this@toBroadcast.subcategory)
        }

        fun toEpisodeIntentRelay(context: Context, intent: Intent) = Intent(context, NotificationOpenReceiver::class.java).copyCommonIntentProps(intent, CATEGORY_EPISODE)

        fun toPodcastIntentRelay(context: Context, intent: Intent) = Intent(context, NotificationOpenReceiver::class.java).copyCommonIntentProps(intent, CATEGORY_PODCAST)

        fun toDeeplinkIntentRelay(context: Context, intent: Intent) = Intent(context, NotificationOpenReceiver::class.java).copyCommonIntentProps(intent, CATEGORY_DEEP_LINK)

        private fun Intent.copyCommonIntentProps(source: Intent, category: String): Intent {
            flags = source.flags
            action = source.action
            putExtras(source)
            source.component?.let {
                putExtra(EXTRA_ORIGINAL_COMPONENT, it)
            }
            putExtra(EXTRA_CATEGORY, category)
            return this
        }
    }
}