From 02a66df1a006e2ebc227a1d4091e59a76d38c297 Mon Sep 17 00:00:00 2001 From: Angelos Veglektsis Date: Wed, 31 Mar 2021 13:28:38 +0300 Subject: [PATCH] Use RadioGroup to how to unlock your DiceKey --- .../app/fragments/dicekey/SaveFragment.kt | 22 +++++++--- app/src/main/res/layout/dicekey_fragment.xml | 2 +- app/src/main/res/layout/save_fragment.xml | 42 ++++++++++++------- app/src/main/res/values/strings.xml | 8 ++-- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/org/dicekeys/app/fragments/dicekey/SaveFragment.kt b/app/src/main/java/org/dicekeys/app/fragments/dicekey/SaveFragment.kt index 0806c0a7..abf8da90 100644 --- a/app/src/main/java/org/dicekeys/app/fragments/dicekey/SaveFragment.kt +++ b/app/src/main/java/org/dicekeys/app/fragments/dicekey/SaveFragment.kt @@ -22,13 +22,18 @@ class SaveFragment: AbstractDiceKeyFragment(R.layout.save_f binding.vm = viewModel - binding.buttonSaveBiometrics.setOnClickListener{ - biometricsHelper.encrypt(viewModel.diceKey.value!!, AppKeystore.KeystoreType.BIOMETRIC, this) + binding.buttonSave.setOnClickListener { + when(binding.keystoreType.checkedRadioButtonId){ + R.id.unlock_biometrics -> { + biometricsHelper.encrypt(viewModel.diceKey.value!!, AppKeystore.KeystoreType.BIOMETRIC, this) + } + R.id.unlock_screen_lock -> { + biometricsHelper.encrypt(viewModel.diceKey.value!!, AppKeystore.KeystoreType.AUTHENTICATION, this) + } + } } - binding.buttonSaveScreenLock.setOnClickListener { - biometricsHelper.encrypt(viewModel.diceKey.value!!, AppKeystore.KeystoreType.AUTHENTICATION, this) - } + binding.keystoreType.check(if(biometricsHelper.canUseBiometrics(requireContext())) R.id.unlock_biometrics else R.id.unlock_screen_lock ) binding.buttonRemove.setOnClickListener{ viewModel.remove() @@ -38,6 +43,11 @@ class SaveFragment: AbstractDiceKeyFragment(R.layout.save_f override fun onResume() { super.onResume() - binding.canUseBiometrics = biometricsHelper.canUseBiometrics(requireContext()) + binding.canUseBiometrics = biometricsHelper.canUseBiometrics(requireContext()).also { canUseBiometrics -> + // Change selection if the checked selection is not longer available + if(!canUseBiometrics && binding.keystoreType.checkedRadioButtonId == R.id.unlock_biometrics){ + binding.keystoreType.check(R.id.unlock_screen_lock) + } + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/dicekey_fragment.xml b/app/src/main/res/layout/dicekey_fragment.xml index ca9d6638..6fe84ad3 100644 --- a/app/src/main/res/layout/dicekey_fragment.xml +++ b/app/src/main/res/layout/dicekey_fragment.xml @@ -98,7 +98,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" - android:text="@string/save_dice_encryption_notice" + android:text="@string/how_to_unlock" android:textAppearance="?attr/textAppearanceBody2" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout/save_fragment.xml b/app/src/main/res/layout/save_fragment.xml index 4584416f..543b56a5 100644 --- a/app/src/main/res/layout/save_fragment.xml +++ b/app/src/main/res/layout/save_fragment.xml @@ -81,36 +81,49 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" - android:text="@string/save_dice_encryption_notice" + android:text="@string/how_to_unlock" android:textAppearance="?attr/textAppearanceBody1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView2" /> -