diff --git a/.idea/misc.xml b/.idea/misc.xml
index 4f34ae0..d737463 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -16,6 +16,7 @@
+
diff --git a/app/src/main/java/org/communiquons/dccaggregator/Constants.kt b/app/src/main/java/org/communiquons/dccaggregator/Constants.kt
index 799e252..c2ab8ab 100644
--- a/app/src/main/java/org/communiquons/dccaggregator/Constants.kt
+++ b/app/src/main/java/org/communiquons/dccaggregator/Constants.kt
@@ -4,7 +4,8 @@ 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_KEY = "certs_list"
+const val GENERATED_CERT_KEY = "generated_cert"
const val RESULT_TEST_NEGATIVE = "260415000"
const val RESULT_TEST_POSITIVE = "260373001"
diff --git a/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt b/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt
index dff62fb..94b4aca 100644
--- a/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt
+++ b/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt
@@ -2,9 +2,9 @@ package org.communiquons.dccaggregator.activities
import android.content.Intent
import android.os.Bundle
-import androidx.appcompat.app.AppCompatActivity
+import android.view.Menu
+import android.view.MenuItem
import androidx.appcompat.app.AppCompatDelegate
-import org.communiquons.dccaggregator.DCCAggregator
import org.communiquons.dccaggregator.R
class MainActivity : BaseActivity() {
@@ -14,16 +14,26 @@ class MainActivity : BaseActivity() {
setContentView(R.layout.activity_main)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
- }
-
- override fun onResume() {
- super.onResume()
// On first launch, start certificates manager first
- if (!(application as DCCAggregator).certManager.hasGeneratedCertificate)
+ if (!certsManager.hasGeneratedCertificate && savedInstanceState == null)
openCertsManager()
}
+ override fun onCreateOptionsMenu(menu: Menu?): Boolean {
+ menuInflater.inflate(R.menu.main_activity_top_menu, menu)
+ return super.onCreateOptionsMenu(menu)
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ if (item.itemId == R.id.open_settings) {
+ openCertsManager()
+ return true
+ }
+
+ return super.onOptionsItemSelected(item)
+ }
+
fun openCertsManager() {
startActivity(Intent(this, CertsManager::class.java))
}
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 5255ad3..2119a48 100644
--- a/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt
+++ b/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt
@@ -2,20 +2,37 @@ package org.communiquons.dccaggregator.helper
import android.content.Context
import androidx.preference.PreferenceManager
-import org.communiquons.dccaggregator.PREF_CERTS_LIST
+import org.communiquons.dccaggregator.GENERATED_CERT_KEY
+import org.communiquons.dccaggregator.PREF_CERTS_LIST_KEY
import org.communiquons.dccaggregator.data.Certificate
class CertificatesList(context: Context) {
private val prefsManager = PreferenceManager.getDefaultSharedPreferences(context)
- val hasGeneratedCertificate get() = false
-
/**
* The list of certificates, as a strings list
*/
private var listString
- get() = prefsManager.getStringSet(PREF_CERTS_LIST, HashSet())!!
- set(v) = prefsManager.edit().putStringSet(PREF_CERTS_LIST, v).apply()
+ get() = prefsManager.getStringSet(PREF_CERTS_LIST_KEY, HashSet())!!
+ set(v) = prefsManager.edit().putStringSet(PREF_CERTS_LIST_KEY, v).apply()
+
+
+ /**
+ * Get the aggregated certificate
+ */
+ var aggregatedCertificate
+ get() = prefsManager.getString(GENERATED_CERT_KEY, null)?.let { it -> Certificate(it) }
+ set(v) {
+ if (v != null)
+ prefsManager.edit().putString(GENERATED_CERT_KEY, v.encoded).apply()
+ else
+ prefsManager.edit().remove(GENERATED_CERT_KEY).apply()
+ }
+
+ /**
+ * Check whether a certificate has already been generated or not
+ */
+ val hasGeneratedCertificate get() = prefsManager.contains(GENERATED_CERT_KEY)
/**
* The list of decoded certificates
@@ -46,4 +63,6 @@ class CertificatesList(context: Context) {
list.remove(cert.encoded)
listString = list
}
+
+
}
diff --git a/app/src/main/java/org/communiquons/dccaggregator/viewmodel/CertsManagerViewModel.kt b/app/src/main/java/org/communiquons/dccaggregator/viewmodel/CertsManagerViewModel.kt
index 6296d1c..bb3bdba 100644
--- a/app/src/main/java/org/communiquons/dccaggregator/viewmodel/CertsManagerViewModel.kt
+++ b/app/src/main/java/org/communiquons/dccaggregator/viewmodel/CertsManagerViewModel.kt
@@ -36,13 +36,13 @@ class CertsManagerViewModel() : ViewModel() {
certsManager.certsList
)
- if (res is AggregateResult.Success) {
- Log.d(TAG, res.cert.encoded)
- } else if (res is AggregateResult.Error) {
- throw Exception(res.error)
- }
-
withContext(Dispatchers.Main) {
+ if (res is AggregateResult.Success) {
+ certsManager.aggregatedCertificate = res.cert
+ } else if (res is AggregateResult.Error) {
+ throw Exception(res.error)
+ }
+
_reqStatus.value = null
}
}
diff --git a/app/src/main/res/drawable/ic_settings.xml b/app/src/main/res/drawable/ic_settings.xml
new file mode 100644
index 0000000..b240b83
--- /dev/null
+++ b/app/src/main/res/drawable/ic_settings.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/menu/main_activity_top_menu.xml b/app/src/main/res/menu/main_activity_top_menu.xml
new file mode 100644
index 0000000..1264d36
--- /dev/null
+++ b/app/src/main/res/menu/main_activity_top_menu.xml
@@ -0,0 +1,9 @@
+
+
\ 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 d435f15..3014c4d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -24,4 +24,5 @@
No
Generate certificate
Waiting for your certificate, please wait…
+ Open settings
\ No newline at end of file