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

Code before:
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsTracker
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import timber.log.Timber

@AndroidEntryPoint
class NotificationOpenReceiver : BroadcastReceiver() {
    @Inject
    lateinit var analyticsTracker: AnalyticsTracker

    override fun onReceive(context: Context?, intent: Intent?) {
        when (intent?.action) {
            ACTION_REVAMP_NOTIFICATION_OPENED -> handleRevampedNotificationOpen(intent, context)
            else -> handleRelayedNotificationOpen(intent ?: Intent(), context)
        }
    }

    private fun handleRelayedNotificationOpen(intent: Intent, context: Context?) {
        val category = intent.getStringExtra(EXTRA_CATEGORY)
        if (context == null || category == null) return

        analyticsTracker.track(
            event = AnalyticsEvent.NOTIFICATION_OPENED,
            properties = buildMap {
                put("category", category)
            },
        )

        val originalIntent = Intent().apply {
            intent.extras?.keySet()?.forEach {
                when (it) {
                    EXTRA_ORIGINAL_ACTION -> {
                        action = intent.getStringExtra(it)
                        intent.removeExtra(it)
                    }

                    EXTRA_ORIGINAL_FLAGS -> {
                        flags = intent.getIntExtra(it, 0)
                        intent.removeExtra(it)
                    }

                    EXTRA_ORIGINAL_COMPONENT -> {
                        component =
                            @Suppress("DEPRECATION")
                            intent.getParcelableExtra(it)
                        intent.removeExtra(it)
                    }

                    EXTRA_CATEGORY -> intent.removeExtra(it)
                    else -> Unit
                }

Review comment (suggestion):
```suggestion
            properties = mapOf("category" to category),
```

Code after:
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsEvent
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsTracker
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import timber.log.Timber

@AndroidEntryPoint
class NotificationOpenReceiver : BroadcastReceiver() {
    @Inject
    lateinit var analyticsTracker: AnalyticsTracker

    override fun onReceive(context: Context, intent: Intent) {
        when (intent.action) {
            ACTION_REVAMP_NOTIFICATION_OPENED -> handleRevampedNotificationOpen(intent, context)
            else -> handleRelayedNotificationOpen(intent, context)
        }
    }

    private fun handleRelayedNotificationOpen(intent: Intent, context: Context) {
        val category = intent.getStringExtra(EXTRA_CATEGORY) ?: return

        analyticsTracker.track(
            event = AnalyticsEvent.NOTIFICATION_OPENED,
            properties = mapOf(
                "category" to category,
            ),
        )

        val originalIntent = Intent().apply {
            flags = intent.flags
            action = intent.action
            IntentCompat.getParcelableExtra(intent, EXTRA_ORIGINAL_COMPONENT, ComponentName::class.java)?.let {
                component = it
            }
            putExtras(intent)
            removeExtra(EXTRA_CATEGORY)
            removeExtra(EXTRA_ORIGINAL_COMPONENT)
        }
        tryLaunchIntent(originalIntent, context)
    }

    private fun handleRevampedNotificationOpen(intent: Intent, context: Context) {
        val subCategory = intent.getStringExtra(EXTRA_REVAMPED_TYPE) ?: return

        val notificationType = NotificationType.fromSubCategory(subCategory)
        notificationType?.let {
            analyticsTracker.track(
                event = AnalyticsEvent.NOTIFICATION_OPENED,
                properties = mapOf(
                    "type" to it.analyticsType,
                    "category" to CATEGORY_DEEP_LINK,