diff --git a/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/detail/CertificateDetailFragment.kt b/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/detail/CertificateDetailFragment.kt index 9ae94088..3b3444a8 100644 --- a/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/detail/CertificateDetailFragment.kt +++ b/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/detail/CertificateDetailFragment.kt @@ -216,10 +216,10 @@ class CertificateDetailFragment : Fragment() { binding.certificateDetailButtonReverify.showAnimated() } - val isSuccessState = it.state is VerificationState.SUCCESS - val isOnlyNationalRulesInvalid = it.state.isOnlyNationalRulesInvalid() - binding.certificateForeignValidityButton.isVisible = - currentConfig?.foreignRulesCheckEnabled == true && (isSuccessState || isOnlyNationalRulesInvalid) + val isFeatureEnabled = currentConfig?.foreignRulesCheckEnabled == true + val isNotInvalid = it.state is VerificationState.SUCCESS || it.state.isOnlyNationalRulesInvalid() + val isValidOnlyInSwitzerland = it.state.isValidOnlyInSwitzerland() + binding.certificateForeignValidityButton.isVisible = isFeatureEnabled && isNotInvalid && !isValidOnlyInSwitzerland updateStatusInfo(it.state) } diff --git a/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/util/VerificationStateUtil.kt b/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/util/VerificationStateUtil.kt index 37e43922..571fca41 100644 --- a/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/util/VerificationStateUtil.kt +++ b/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/util/VerificationStateUtil.kt @@ -16,10 +16,7 @@ import androidx.annotation.ColorRes import ch.admin.bag.covidcertificate.common.util.addBoldDate import ch.admin.bag.covidcertificate.common.util.makeSubStringBold import ch.admin.bag.covidcertificate.sdk.core.data.ErrorCodes -import ch.admin.bag.covidcertificate.sdk.core.models.state.CheckNationalRulesState -import ch.admin.bag.covidcertificate.sdk.core.models.state.CheckRevocationState -import ch.admin.bag.covidcertificate.sdk.core.models.state.CheckSignatureState -import ch.admin.bag.covidcertificate.sdk.core.models.state.VerificationState +import ch.admin.bag.covidcertificate.sdk.core.models.state.* import ch.admin.bag.covidcertificate.wallet.R const val DATE_REPLACEMENT_STRING = "{DATE}" @@ -69,6 +66,19 @@ fun VerificationState.getNameDobColor(): Int { } } +/** + * @return True if this is a successful (wallet) verification state and the certificate is only valid in switzerland + */ +fun VerificationState.isValidOnlyInSwitzerland(): Boolean { + return when (this) { + is VerificationState.SUCCESS -> { + val walletSuccessState = this.successState as? SuccessState.WalletSuccessState + walletSuccessState?.isValidOnlyInSwitzerland ?: false + } + else -> false + } +} + /** * @return True if this is an invalid verification state and only the national rules check failed (signature and revocation must be valid) */