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

Code before:
            // 3. Booster notification tile
            dccWalletInfo?.boosterNotification?.let { boosterNotification ->
                if (boosterNotification.visible) add(boosterItem(boosterNotification, personCertificates))
            }
            // 4.Vaccination state tile
            dccWalletInfo?.vaccinationState?.let { vaccinationState ->
                if (vaccinationState.visible) add(vaccinationInfoItem(vaccinationState))
            }
            // Person details tile
            add(cwaUserCard(personCertificates))
            // Certificates tiles
            personCertificates.certificates // `certificates` are already sorted by date
                // Sorting by `whether it is high prio certificate` will bring this certificate to the top
                .sortedByDescending { it.containerId == priorityCertificate.containerId }
                .forEach { cwaCert ->
                    addCardItem(
                        certificate = cwaCert,
                        priorityCertificate = priorityCertificate,
                        isLoading = isLoading
                    )
                }
        }

        return UiState(
            name = priorityCertificate.fullName,
            certificateItems = certificateItems,
            numberOfCertificates = personCertificates.certificates.size
        )
    }

    private fun MutableList<CertificateItem>.addCardItem(
        certificate: CwaCovidCertificate,
        priorityCertificate: CwaCovidCertificate,
        isLoading: Boolean
    ) {
        val isCurrentCertificate = certificate.containerId == priorityCertificate.containerId
        when (certificate) {
            is TestCertificate -> add(tcItem(certificate, isCurrentCertificate, isLoading))
            is VaccinationCertificate -> add(vcItem(certificate, isCurrentCertificate, isLoading))
            is RecoveryCertificate -> add(rcItem(certificate, isCurrentCertificate, isLoading))
        }
    }

    private suspend fun vaccinationInfoItem(
        vaccinationState: VaccinationState
    ) = VaccinationInfoCard.Item(
        titleText = format(vaccinationState.titleText),
        subtitleText = format(vaccinationState.subtitleText),
        longText = format(vaccinationState.longText),
        faqAnchor = format(vaccinationState.faqAnchor),
    )

Review comment (suggestion):
Handle the logic in the viewmodel and send an gobackEvent if the corresponding numberofCertificates is reached

Code after:
                if (division.visible) add(dccReissuanceItem(division, personCertificates))
            }
            // 3. Booster notification tile
            dccWalletInfo?.boosterNotification?.let { boosterNotification ->
                if (boosterNotification.visible) add(boosterItem(boosterNotification, personCertificates))
            }
            // 4.Vaccination state tile
            dccWalletInfo?.vaccinationState?.let { vaccinationState ->
                if (vaccinationState.visible) add(vaccinationInfoItem(vaccinationState))
            }
            // Person details tile
            add(cwaUserCard(personCertificates))
            // Certificates tiles
            personCertificates.certificates // `certificates` are already sorted by date
                // Sorting by `whether it is high prio certificate` will bring this certificate to the top
                .sortedByDescending { it.containerId == priorityCertificate.containerId }
                .forEach { cwaCert ->
                    addCardItem(
                        certificate = cwaCert,
                        priorityCertificate = priorityCertificate,
                        isLoading = isLoading
                    )
                }
        }

        return UiState(
            name = priorityCertificate.fullName,
            certificateItems = certificateItems,
            numberOfCertificates = personCertificates.certificates.size
        )
    }

    private fun MutableList<CertificateItem>.addCardItem(
        certificate: CwaCovidCertificate,
        priorityCertificate: CwaCovidCertificate,
        isLoading: Boolean
    ) {
        val isCurrentCertificate = certificate.containerId == priorityCertificate.containerId
        when (certificate) {
            is TestCertificate -> add(tcItem(certificate, isCurrentCertificate, isLoading))
            is VaccinationCertificate -> add(vcItem(certificate, isCurrentCertificate, isLoading))
            is RecoveryCertificate -> add(rcItem(certificate, isCurrentCertificate, isLoading))
        }
    }

    private suspend fun vaccinationInfoItem(
        vaccinationState: VaccinationState
    ) = VaccinationInfoCard.Item(
        titleText = format(vaccinationState.titleText),
        subtitleText = format(vaccinationState.subtitleText),
        longText = format(vaccinationState.longText),