From 5b40805a8b05770d8143f78b6a9a3ced48d61319 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 16 Feb 2022 13:57:14 +0100 Subject: [PATCH] Display correctly all kind of certificates --- .../communiquons/dccaggregator/Constants.kt | 8 ++++- .../dccaggregator/activities/CertsManager.kt | 3 ++ .../dccaggregator/helper/CertificatesList.kt | 4 ++- .../dccaggregator/models/Certificate.kt | 33 +++++++++++++++++++ app/src/main/res/values/strings.xml | 9 +++++ 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/communiquons/dccaggregator/Constants.kt b/app/src/main/java/org/communiquons/dccaggregator/Constants.kt index 6bd7607..f0f5cd2 100644 --- a/app/src/main/java/org/communiquons/dccaggregator/Constants.kt +++ b/app/src/main/java/org/communiquons/dccaggregator/Constants.kt @@ -4,4 +4,10 @@ package org.communiquons.dccaggregator const val WALLET_URL = "https://bonjour.tousanticovid.gouv.fr/app/walletdcc#" // Name of the preferences file holding certificates list -const val PREF_CERTS_LIST = "certs_list" \ No newline at end of file +const val PREF_CERTS_LIST = "certs_list" + +const val RESULT_TEST_NEGATIVE = "260415000" +const val RESULT_TEST_POSITIVE = "260373001" + +const val TEST_PCR = "LP6464-4" +const val TEST_ANTIGENIC = "LP217198-3" \ No newline at end of file diff --git a/app/src/main/java/org/communiquons/dccaggregator/activities/CertsManager.kt b/app/src/main/java/org/communiquons/dccaggregator/activities/CertsManager.kt index f03130d..ee6ea99 100644 --- a/app/src/main/java/org/communiquons/dccaggregator/activities/CertsManager.kt +++ b/app/src/main/java/org/communiquons/dccaggregator/activities/CertsManager.kt @@ -93,6 +93,9 @@ class CertsManager : BaseActivity() { } private fun refreshList() { + certsList.clear() + certsList.addAll(certsManager.certsList) + listAdapter.notifyDataSetChanged() } } \ No newline at end of file diff --git a/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt b/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt index 78d354a..c2b8976 100644 --- a/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt +++ b/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt @@ -33,6 +33,8 @@ class CertificatesList(context: Context) { * Add a certificate to the list */ fun addCertificate(cert: Certificate) { - listString = listString.apply { add(cert.encoded) } + val list = HashSet(listString) + list.add(cert.encoded) + listString = list } } diff --git a/app/src/main/java/org/communiquons/dccaggregator/models/Certificate.kt b/app/src/main/java/org/communiquons/dccaggregator/models/Certificate.kt index 378d324..55ff6af 100644 --- a/app/src/main/java/org/communiquons/dccaggregator/models/Certificate.kt +++ b/app/src/main/java/org/communiquons/dccaggregator/models/Certificate.kt @@ -6,7 +6,11 @@ import dgca.verifier.app.decoder.DefaultCertificateDecoder import dgca.verifier.app.decoder.base45.Base45Decoder import dgca.verifier.app.decoder.model.GreenCertificate import dgca.verifier.app.decoder.model.RecoveryStatement +import dgca.verifier.app.decoder.model.Vaccination import org.communiquons.dccaggregator.R +import org.communiquons.dccaggregator.RESULT_TEST_POSITIVE +import org.communiquons.dccaggregator.TEST_ANTIGENIC +import org.communiquons.dccaggregator.TEST_PCR @OptIn(ExperimentalUnsignedTypes::class) class Certificate(val encoded: String) { @@ -35,15 +39,44 @@ class Certificate(val encoded: String) { val dateOfBirth get() = decoded.dateOfBirth + val test get() = decoded.tests?.getOrNull(0) + + val vaccination: Vaccination? get() = decoded.vaccinations?.getOrNull(0) + val recovery: RecoveryStatement? get() = decoded.recoveryStatements?.getOrNull(0) fun descText(ctx: Context): String { + if (vaccination != null) + return ctx.resources.getString( + R.string.desc_vaccine_certificate, + vaccination!!.doseNumber, + vaccination!!.totalSeriesOfDoses, + vaccination!!.dateOfVaccination, + vaccination!!.vaccine + ) + if (recovery != null) return ctx.resources.getString( R.string.desc_recovery_certificate, recovery!!.dateOfFirstPositiveTest ) + if (test != null) + return ctx.resources.getString( + R.string.desc_test_certificate, + ctx.resources.getString( + if (test!!.testResult == RESULT_TEST_POSITIVE) + R.string.positive + else + R.string.negative + ).uppercase(), + test!!.dateTimeOfCollection, + ctx.resources.getString(when(test!!.typeOfTest) { + TEST_ANTIGENIC -> R.string.antigenic + TEST_PCR -> R.string.pcr + else -> R.string.unkown_test_type + }) + ) return ctx.resources.getString(R.string.desc_unknown_certificate) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 64bd56b..b763e25 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -7,6 +7,15 @@ The given certificate could not be decoded! Certificate QR Code + positive + negative + + PCR + Antigenic + Unknown test type + + Test certificate\nTested %1$s\nDate: %2$s\nTest type: %3$s + Vaccine certificate\nDose %1$d / %2$d\nDate: %3$s\nType: %4$s Recovery certificate\nTested positive on %1$s Unknown certificate type \ No newline at end of file