Repository: corona-warn-app/cwa-app-android
File: Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentViewModel.kt (Kotlin)

Code before:
        statsData.copy(
            items = mutableListOf(
                AddStatsItem(
                    canAddItem = localStatsData.items.size < 5,
                    isInternetAvailable = isInternetAvailable
                )
            ) + localStatsData.items + statsData.items
        )
    }

    val homeItems: LiveData<List<HomeItem>> = combine(
        tracingCardItems,
        coronaTestRepository.latestPCRT,
        coronaTestRepository.latestRAT,
        combinedStatistics,
        appConfigProvider.currentConfig.map { it.coronaTestParameters }.distinctUntilChanged()
    ) { tracingItem, testPCR, testRAT, statsData, coronaTestParameters ->
        val statePCR = testPCR.toSubmissionState()
        val stateRAT = testRAT.toSubmissionState(timeStamper.nowUTC, coronaTestParameters)
        val pcrIdentifier = testPCR?.identifier ?: ""
        val ratIdentifier = testRAT?.identifier ?: ""
        mutableListOf<HomeItem>().apply {
            when {
                statePCR is SubmissionStatePCR.TestPositive || statePCR is SubmissionStatePCR.SubmissionDone -> {
                    if (testPCR != null) {
                        if (isOlderThanThreshold(
                                coronaTestParameters
                                    .coronaPCRTestParameters.hoursSinceTestRegistrationToShowRiskCard,
                                testPCR.registeredAt
                            ) || tracingItem is IncreasedRiskCard.Item
                        ) {
                            add(tracingItem)
                        }
                        // Don't show risk card
                    }
                }
                stateRAT is SubmissionStateRAT.TestPositive || stateRAT is SubmissionStateRAT.SubmissionDone -> {
                    if (testRAT != null) {
                        if (isOlderThanThreshold(
                                coronaTestParameters
                                    .coronaRapidAntigenTestParameters.hoursSinceSampleCollectionToShowRiskCard,
                                testRAT.testTakenAt
                            ) || tracingItem is IncreasedRiskCard.Item
                        ) {
                            add(tracingItem)
                        }
                    }
                    // Don't show risk card
                }
                else -> add(tracingItem)
            }

Review comment (suggestion):
I think you can combine both `if`s testRAT != null && ...

Code after:
                AddStatsItem(
                    canAddItem = localStatsData.items.size < 5,
                    isInternetAvailable = isInternetAvailable
                )
            ) + localStatsData.items + statsData.items
        )
    }

    val homeItems: LiveData<List<HomeItem>> = combine(
        tracingCardItems,
        coronaTestRepository.latestPCRT,
        coronaTestRepository.latestRAT,
        combinedStatistics,
        appConfigProvider.currentConfig.map { it.coronaTestParameters }.distinctUntilChanged()
    ) { tracingItem, testPCR, testRAT, statsData, coronaTestParameters ->
        val statePCR = testPCR.toSubmissionState()
        val stateRAT = testRAT.toSubmissionState(timeStamper.nowUTC, coronaTestParameters)
        val pcrIdentifier = testPCR?.identifier ?: ""
        val ratIdentifier = testRAT?.identifier ?: ""

        val positiveCoronaTests = listOfNotNull(testRAT, testPCR).filter { it.isPositive && it.isViewed }

        mutableListOf<HomeItem>().apply {
            when {
                // High risk is always visible regardless of test result
                tracingItem is IncreasedRiskCard.Item -> add(tracingItem)

                // No high risk card -> check corona test age against config duration
                positiveCoronaTests.isNotEmpty() -> {
                    if (positiveCoronaTests.all {
                        it.shouldShowRiskCard(coronaTestParameters, timeStamper.nowUTC)
                    }
                    ) {
                        add(tracingItem)
                    } // else -> // Don't show risk card
                }

                // Otherwise show risk card
                else -> add(tracingItem)
            }

            if (bluetoothSupport.isAdvertisingSupported == false) {
                val scanningSupported = bluetoothSupport.isScanningSupported != false
                add(
                    IncompatibleCard.Item(
                        onClickAction = { events.postValue(HomeFragmentEvents.OpenIncompatibleUrl(scanningSupported)) },
                        bluetoothSupported = scanningSupported
                    )
                )
            }