Display correctly all kind of certificates

This commit is contained in:
Pierre HUBERT 2022-02-16 13:57:14 +01:00
parent e7595892f8
commit 5b40805a8b
5 changed files with 55 additions and 2 deletions

View File

@ -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"
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"

View File

@ -93,6 +93,9 @@ class CertsManager : BaseActivity() {
}
private fun refreshList() {
certsList.clear()
certsList.addAll(certsManager.certsList)
listAdapter.notifyDataSetChanged()
}
}

View File

@ -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
}
}

View File

@ -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)
}

View File

@ -7,6 +7,15 @@
<string name="invalid_certificate">The given certificate could not be decoded!</string>
<string name="certificate_qr_code">Certificate QR Code</string>
<string name="positive">positive</string>
<string name="negative">negative</string>
<string name="pcr">PCR</string>
<string name="antigenic">Antigenic</string>
<string name="unkown_test_type">Unknown test type</string>
<string name="desc_test_certificate">Test certificate\nTested %1$s\nDate: %2$s\nTest type: %3$s</string>
<string name="desc_vaccine_certificate">Vaccine certificate\nDose %1$d / %2$d\nDate: %3$s\nType: %4$s</string>
<string name="desc_recovery_certificate">Recovery certificate\nTested positive on %1$s</string>
<string name="desc_unknown_certificate">Unknown certificate type</string>
</resources>