Can delete input certificate

This commit is contained in:
Pierre HUBERT 2022-02-16 14:20:30 +01:00
parent 5b40805a8b
commit b61d7edfb9
6 changed files with 65 additions and 0 deletions

1
.idea/misc.xml generated
View File

@ -13,6 +13,7 @@
<entry key="app/src/main/res/layout/fragment_first.xml" value="0.29483695652173914" />
<entry key="app/src/main/res/layout/fragment_second.xml" value="0.29483695652173914" />
<entry key="app/src/main/res/layout/qr_entry.xml" value="0.28125" />
<entry key="app/src/main/res/menu/cert_menu.xml" value="0.3697916666666667" />
<entry key="app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml" value="0.3859375" />
</map>
</option>

View File

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

View File

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

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z"/>
</vector>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/delete_cert"
android:title="@string/delete_cert" />
</menu>

View File

@ -18,4 +18,8 @@
<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>
<string name="delete_cert">Delete certificate</string>
<string name="remove_cert">Remove certificate</string>
<string name="msg_confirm_remove_cert">Do you really want to remove this certificate from the list?</string>
<string name="no">No</string>
</resources>