Repository: Automattic/pocket-casts-android
File: app/src/main/java/au/com/shiftyjelly/pocketcasts/ui/MainActivity.kt (Kotlin)

Code before:
                openTab(VR.id.navigation_discover)
            }

            is OnboardingFinish.DoneShowPlusPromotion -> {
                settings.setHasDoneInitialOnboarding()
                OnboardingLauncher.openOnboardingFlow(this, OnboardingFlow.Upsell(OnboardingUpgradeSource.LOGIN_PLUS_PROMOTION))
            }

            is OnboardingFinish.DoneShowWelcomeInReferralFlow -> {
                settings.showReferralWelcome.set(true, updateModifiedAt = false)
            }

            is OnboardingFinish.DoneApplySuggestedFolders, null -> {
                Timber.e("Unexpected result $result from onboarding activity")
            }
        }
    }

    private val bookmarkActivityLauncher: ActivityResultLauncher<Intent> = registerForActivityResult(
        BookmarkActivityContract(),
    ) { result ->
        showViewBookmarksSnackbar(result)
    }

    private val endOfYearActivityLauncher: ActivityResultLauncher<Intent> = registerForActivityResult(StoriesActivity.StoriesActivityContract()) { result ->
        result?.let { source ->
            val view = snackBarView()
            val action = View.OnClickListener {
                showStories(source = source)
            }
            Snackbar.make(view, getString(LR.string.end_of_year_failed_to_load_message), Snackbar.LENGTH_LONG)
                .setAction(LR.string.retry, action)
                .setTextColor(ThemeColor.primaryText01(Theme.ThemeType.DARK))
                .show()
        }
    }

    private val notificationPermissionLauncher = registerForActivityResult(
        ActivityResultContracts.RequestPermission(),
    ) {}

    private val deepLinkFactory = DeepLinkFactory()

    @SuppressLint("WrongConstant") // for custom snackbar duration constant
    private fun checkForNotificationPermission(onPermissionGranted: () -> Unit = {}) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            when {
                ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED -> {
                    onPermissionGranted()
                }


Review comment (bug):
💡 Could we make it a bit more explicit and add some flag like `isFailure` to the contract? It's rather surprising that if any result is returned it means that there was a failure.

Code after:
                openTab(VR.id.navigation_discover)
            }

            is OnboardingFinish.DoneShowPlusPromotion -> {
                settings.setHasDoneInitialOnboarding()
                OnboardingLauncher.openOnboardingFlow(this, OnboardingFlow.Upsell(OnboardingUpgradeSource.LOGIN_PLUS_PROMOTION))
            }

            is OnboardingFinish.DoneShowWelcomeInReferralFlow -> {
                settings.showReferralWelcome.set(true, updateModifiedAt = false)
            }

            is OnboardingFinish.DoneApplySuggestedFolders, null -> {
                Timber.e("Unexpected result $result from onboarding activity")
            }
        }
    }

    private val bookmarkActivityLauncher: ActivityResultLauncher<Intent> = registerForActivityResult(
        BookmarkActivityContract(),
    ) { result ->
        showViewBookmarksSnackbar(result)
    }

    private val endOfYearActivityLauncher: ActivityResultLauncher<Intent> = registerForActivityResult(StoriesActivity.StoriesActivityContract()) { result ->
        when (result) {
            is StoriesActivity.StoriesActivityContract.Result.Failure -> {
                result.source?.let { source ->
                    val view = snackBarView()
                    val action = View.OnClickListener {
                        showStories(source = source)
                    }
                    Snackbar.make(view, getString(LR.string.end_of_year_failed_to_load_message), Snackbar.LENGTH_LONG)
                        .setAction(LR.string.retry, action)
                        .setTextColor(ThemeColor.primaryText01(Theme.ThemeType.DARK))
                        .show()
                }
            }
            else -> Unit
        }
    }

    private val notificationPermissionLauncher = registerForActivityResult(
        ActivityResultContracts.RequestPermission(),
    ) {}

    private val deepLinkFactory = DeepLinkFactory()

    @SuppressLint("WrongConstant") // for custom snackbar duration constant
    private fun checkForNotificationPermission(onPermissionGranted: () -> Unit = {}) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {