From e7595892f8612a8ef4e67be1cfaea10af0af8a69 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 16 Feb 2022 12:21:59 +0100 Subject: [PATCH] Start to show certificates description --- .../adapters/CertificatesAdapter.kt | 16 +++++++++++----- .../dccaggregator/models/Certificate.kt | 18 ++++++++++++++++++ app/src/main/res/values/strings.xml | 3 +++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/communiquons/dccaggregator/adapters/CertificatesAdapter.kt b/app/src/main/java/org/communiquons/dccaggregator/adapters/CertificatesAdapter.kt index 455410d..032d665 100644 --- a/app/src/main/java/org/communiquons/dccaggregator/adapters/CertificatesAdapter.kt +++ b/app/src/main/java/org/communiquons/dccaggregator/adapters/CertificatesAdapter.kt @@ -5,10 +5,10 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter -import android.widget.ImageView import com.google.zxing.BarcodeFormat import com.journeyapps.barcodescanner.BarcodeEncoder import org.communiquons.dccaggregator.R +import org.communiquons.dccaggregator.databinding.QrEntryBinding import org.communiquons.dccaggregator.ext.toDimensSize import org.communiquons.dccaggregator.models.Certificate @@ -20,17 +20,23 @@ class CertificatesAdapter(cxt: Context, list: ArrayList) : } override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - val view = - convertView ?: LayoutInflater.from(context).inflate(R.layout.qr_entry, parent, false) + val binding = + if (convertView == null) + QrEntryBinding.inflate(LayoutInflater.from(context), parent, false) + else QrEntryBinding.bind(convertView) val cert = getItem(position) as Certificate // Generate Qr code val bitmap = BarcodeEncoder().encodeBitmap(cert.encoded, BarcodeFormat.QR_CODE, qrSize, qrSize) - view.findViewById(R.id.certQrCode).setImageBitmap(bitmap) + binding.certQrCode.setImageBitmap(bitmap) - return view + binding.userName.text = cert.fullName + binding.dateOfBirth.text = cert.dateOfBirth + binding.certificateDescription.text = cert.descText(context) + + return binding.root } } \ No newline at end of file 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 203d03b..378d324 100644 --- a/app/src/main/java/org/communiquons/dccaggregator/models/Certificate.kt +++ b/app/src/main/java/org/communiquons/dccaggregator/models/Certificate.kt @@ -1,9 +1,12 @@ package org.communiquons.dccaggregator.models +import android.content.Context import dgca.verifier.app.decoder.CertificateDecodingResult 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 org.communiquons.dccaggregator.R @OptIn(ExperimentalUnsignedTypes::class) class Certificate(val encoded: String) { @@ -29,4 +32,19 @@ class Certificate(val encoded: String) { * Get certificate id */ val id get() = decoded.getDgci() + + val dateOfBirth get() = decoded.dateOfBirth + + val recovery: RecoveryStatement? get() = decoded.recoveryStatements?.getOrNull(0) + + fun descText(ctx: Context): String { + if (recovery != null) + return ctx.resources.getString( + R.string.desc_recovery_certificate, + recovery!!.dateOfFirstPositiveTest + ) + + + return ctx.resources.getString(R.string.desc_unknown_certificate) + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dd889b4..64bd56b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,4 +6,7 @@ Import certificate The given certificate could not be decoded! Certificate QR Code + + Recovery certificate\nTested positive on %1$s + Unknown certificate type \ No newline at end of file