Improve navigation in application

This commit is contained in:
Pierre HUBERT 2022-02-17 10:29:30 +01:00
parent b2d9bd3edb
commit 01e0cb96aa
8 changed files with 65 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

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="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
</vector>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/open_settings"
android:icon="@drawable/ic_settings"
android:title="@string/action_settings"
app:showAsAction="always" />
</menu>

View File

@ -24,4 +24,5 @@
<string name="no">No</string>
<string name="generate_certificate">Generate certificate</string>
<string name="generating_certificate">Waiting for your certificate, please wait…</string>
<string name="action_settings">Open settings</string>
</resources>