Skip to content

Commit

Permalink
Use RadioGroup to how to unlock your DiceKey
Browse files Browse the repository at this point in the history
  • Loading branch information
angelix committed Mar 31, 2021
1 parent 04c8a90 commit 02a66df
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ class SaveFragment: AbstractDiceKeyFragment<SaveFragmentBinding>(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()
Expand All @@ -38,6 +43,11 @@ class SaveFragment: AbstractDiceKeyFragment<SaveFragmentBinding>(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)
}
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/dicekey_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 28 additions & 14 deletions app/src/main/res/layout/save_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<Button
android:id="@+id/buttonSaveBiometrics"
isVisible="@{!vm.isSaved()}"
<RadioGroup
android:id="@+id/keystore_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/save_biometrics"
android:textAllCaps="false"
android:enabled="@{canUseBiometrics}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
android:layout_marginTop="8dp"
isVisible="@{!vm.isSaved()}"
android:checkedButton="@+id/radio_button_1"
app:layout_constraintTop_toBottomOf="@+id/textView3"
tools:layout_editor_absoluteX="16dp">

<RadioButton
android:id="@+id/unlock_screen_lock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/unlock_with_lock_screen" />

<RadioButton
android:id="@+id/unlock_biometrics"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:enabled="@{canUseBiometrics}"
android:text="@string/unlock_with_biometrics" />

</RadioGroup>

<Button
android:id="@+id/buttonSaveScreenLock"
android:id="@+id/buttonSave"
isVisible="@{!vm.isSaved()}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/save"
android:textAllCaps="false"
android:text="@string/save_screen_lock"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/buttonSaveBiometrics" />
app:layout_constraintTop_toBottomOf="@+id/keystore_type" />


<Button
android:id="@+id/buttonRemove"
Expand All @@ -121,6 +134,7 @@
android:layout_marginTop="16dp"
android:text="@string/forget"
android:textAllCaps="false"
tools:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<string name="complete_the_recipe">Complete the recipe above to see the output</string>
<string name="enter_dicekey_by_hand">Enter the DiceKey by Hand</string>
<string name="save_the_dicekey">Save the DiceKey</string>
<string name="save_center_die_notice">The center die will appear in the home screen.</string>
<string name="save_dice_encryption_notice">The other 24 dice will be encrypted and your Biometrics will unlock them.</string>
<string name="save_center_die_notice">Your DiceKey will be stored encrypted and identified by the center die.</string>
<string name="how_to_unlock">How would you like to unlock the other 24 dice?</string>

<string name="tap_to_show">tap to show dice</string>

<string name="save_biometrics">Save with Biometrics</string>
<string name="save_screen_lock">Save with Screen Lock</string>
<string name="unlock_with_lock_screen">Use my lock screen unlock options</string>
<string name="unlock_with_biometrics">Use only my fingerprint or other biometrics</string>

<string name="custom_recipe">Custom Recipe</string>

Expand Down

0 comments on commit 02a66df

Please sign in to comment.