diff --git a/.idea/misc.xml b/.idea/misc.xml
index a07ad20..25577e6 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -13,6 +13,7 @@
+
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 ee6ea99..d51080e 100644
--- a/app/src/main/java/org/communiquons/dccaggregator/activities/CertsManager.kt
+++ b/app/src/main/java/org/communiquons/dccaggregator/activities/CertsManager.kt
@@ -1,7 +1,11 @@
package org.communiquons.dccaggregator.activities
+import android.app.AlertDialog
import android.os.Bundle
+import android.view.ContextMenu
import android.view.MenuItem
+import android.view.View
+import android.widget.AdapterView
import android.widget.Toast
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions
@@ -36,6 +40,7 @@ class CertsManager : BaseActivity() {
// Initialize certificates list
binding.certsList.adapter = listAdapter
+ registerForContextMenu(binding.certsList)
binding.scanCertButton.setOnClickListener {
addNewCertificate()
@@ -98,4 +103,39 @@ class CertsManager : BaseActivity() {
listAdapter.notifyDataSetChanged()
}
+
+ override fun onCreateContextMenu(
+ menu: ContextMenu?,
+ v: View?,
+ menuInfo: ContextMenu.ContextMenuInfo?
+ ) {
+ super.onCreateContextMenu(menu, v, menuInfo)
+ if (v == binding.certsList)
+ menuInflater.inflate(R.menu.cert_menu, menu)
+ }
+
+ override fun onContextItemSelected(item: MenuItem): Boolean {
+
+ if (item.itemId == R.id.delete_cert) {
+ val pos = (item.menuInfo as AdapterView.AdapterContextMenuInfo).position
+ confirmDeleteCertificate(certsList.get(pos))
+ return true
+ }
+
+ return super.onContextItemSelected(item)
+ }
+
+ private fun confirmDeleteCertificate(cert: Certificate) {
+ AlertDialog.Builder(this).apply {
+ setTitle(R.string.remove_cert)
+ setMessage(R.string.msg_confirm_remove_cert)
+ setNegativeButton(R.string.no, null)
+ setPositiveButton(R.string.delete_cert) { _, _ ->
+ certsManager.removeCertificate(cert)
+ refreshList()
+ }
+ setIcon(R.drawable.ic_warning)
+ show()
+ }
+ }
}
\ 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 c2b8976..5bdec5c 100644
--- a/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt
+++ b/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt
@@ -37,4 +37,13 @@ class CertificatesList(context: Context) {
list.add(cert.encoded)
listString = list
}
+
+ /**
+ * Remove a certificate from the list
+ */
+ fun removeCertificate(cert: Certificate) {
+ val list = HashSet(listString)
+ list.remove(cert.encoded)
+ listString = list
+ }
}
diff --git a/app/src/main/res/drawable/ic_warning.xml b/app/src/main/res/drawable/ic_warning.xml
new file mode 100644
index 0000000..3c9a4b3
--- /dev/null
+++ b/app/src/main/res/drawable/ic_warning.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/menu/cert_menu.xml b/app/src/main/res/menu/cert_menu.xml
new file mode 100644
index 0000000..4dc7c3e
--- /dev/null
+++ b/app/src/main/res/menu/cert_menu.xml
@@ -0,0 +1,6 @@
+
+
\ 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 b763e25..6e51981 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -18,4 +18,8 @@
Vaccine certificate\nDose %1$d / %2$d\nDate: %3$s\nType: %4$s
Recovery certificate\nTested positive on %1$s
Unknown certificate type
+ Delete certificate
+ Remove certificate
+ Do you really want to remove this certificate from the list?
+ No
\ No newline at end of file