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

Code before:
    internal fun startReissuance() = launch {
        runCatching {
            event.postValue(ReissuanceInProgress)
            dccReissuer.startReissuance(reissuanceData.first()!!)
        }.onFailure { e ->
            Timber.d(e, "startReissuance() failed")
            event.postValue(ReissuanceError(e))
        }.onSuccess {
            Timber.d("startReissuance() succeeded")
            event.postValue(ReissuanceSuccess)
        }
    }

    fun navigateBack() = event.postValue(Back)

    private suspend fun CertificateReissuance?.toState(): State {
        val certificates = mutableListOf<DccReissuanceItem>()
        if (this?.certificates != null) {
            this.certificates.forEach { dccCertificate ->
                var certificateToReissue: DccV1.MetaData
                dccCertificate.certificateToReissue.certificateRef.barcodeData.let {
                    certificateToReissue = dccQrCodeExtractor.extract(
                        it,
                        DccV1Parser.Mode.CERT_SINGLE_STRICT
                    ).data.certificate
                }
                certificates.add(
                    DccReissuanceConsentCard.Item(
                        certificateToReissue
                    )
                )
            }
        }
        return State(
            certificateList = certificates,
            divisionVisible = this?.reissuanceDivision?.visible ?: false,
            listItemsTitle = format(this?.reissuanceDivision?.listTitleText),
            title = format(this?.reissuanceDivision?.titleText),
            subtitle = format(this?.reissuanceDivision?.consentSubtitleText),
            content = format(this?.reissuanceDivision?.longText),
            url = format(this?.reissuanceDivision?.faqAnchor)
        )
    }

    fun openPrivacyScreen() = event.postValue(OpenPrivacyScreen)

    internal data class State(
        val certificateList: List<DccReissuanceItem>,
        val divisionVisible: Boolean = false,
        val listItemsTitle: String?,
        val title: String?,

Review comment (refactor):
```suggestion
          
                    val certificateToReissue = dccQrCodeExtractor.extract(
                        dccCertificate.certificateToReissue.certificateRef.barcodeData,
                        DccV1Parser.Mode.CERT_SINGLE_STRICT
                    ).data.certificate
               
```

Code after:
        runCatching {
            event.postValue(ReissuanceInProgress)
            dccReissuer.startReissuance(reissuanceData.first()!!)
        }.onFailure { e ->
            Timber.d(e, "startReissuance() failed")
            event.postValue(ReissuanceError(e))
        }.onSuccess {
            Timber.d("startReissuance() succeeded")
            event.postValue(ReissuanceSuccess)
        }
    }

    fun navigateBack() = event.postValue(Back)

    private suspend fun CertificateReissuance?.toState(): State {
        val certificates = mutableListOf<DccReissuanceItem>()
        if (this?.certificates != null) {
            this.certificates.forEach { dccCertificate ->

                val certificateToReissue = dccQrCodeExtractor.extract(
                    dccCertificate.certificateToReissue.certificateRef.barcodeData,
                    DccV1Parser.Mode.CERT_SINGLE_STRICT
                ).data.certificate

                certificates.add(
                    DccReissuanceConsentCard.Item(
                        certificateToReissue
                    )
                )
            }
        }
        return State(
            certificateList = certificates,
            divisionVisible = this?.reissuanceDivision?.visible ?: false,
            listItemsTitle = format(this?.reissuanceDivision?.listTitleText),
            title = format(this?.reissuanceDivision?.titleText),
            subtitle = format(this?.reissuanceDivision?.consentSubtitleText),
            content = format(this?.reissuanceDivision?.longText),
            url = format(this?.reissuanceDivision?.faqAnchor)
        )
    }

    fun openPrivacyScreen() = event.postValue(OpenPrivacyScreen)

    internal data class State(
        val certificateList: List<DccReissuanceItem>,
        val divisionVisible: Boolean = false,
        val listItemsTitle: String?,
        val title: String?,
        val subtitle: String?,
        val content: String?,