Skip to content

Commit

Permalink
prevent cancellation of unlock bottomsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-mh committed Aug 27, 2023
1 parent 6fdaeda commit c9c9a6a
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 93 deletions.
160 changes: 76 additions & 84 deletions AuthenticatorPro.Droid/Resources/layout/sheetUnlock.axml
Original file line number Diff line number Diff line change
Expand Up @@ -6,106 +6,98 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.bottomsheet.BottomSheetDragHandleView
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="match_parent"
android:clipToPadding="false"
android:clipChildren="false"
android:paddingTop="28dp"
android:paddingBottom="20dp"
android:paddingStart="16dp"
android:paddingEnd="16dp">

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:orientation="vertical"
<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:clipChildren="false"
android:paddingBottom="20dp"
android:paddingStart="16dp"
android:paddingEnd="16dp">
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:textAppearance="?attr/textAppearanceTitleLarge"
android:textAlignment="center"
android:id="@+id/textTitle"/>

<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="22dp"
android:textAppearance="?attr/textAppearanceSubtitle2"
android:text="@string/unlockMessage"/>

<com.google.android.material.textview.MaterialTextView
<com.google.android.material.textfield.TextInputLayout
app:hintEnabled="true"
app:errorEnabled="true"
app:errorIconDrawable="@null"
app:passwordToggleEnabled="true"
android:id="@+id/editPasswordLayout"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:textAppearance="?attr/textAppearanceTitleLarge"
android:textAlignment="center"
android:id="@+id/textTitle"/>
android:inputType="textPassword"
android:imeOptions="actionDone"
android:hint="@string/password"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="22dp"
android:textAppearance="?attr/textAppearanceSubtitle2"
android:text="@string/unlockMessage"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:orientation="horizontal"
android:layout_gravity="end"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputLayout
app:hintEnabled="true"
app:errorEnabled="true"
app:errorIconDrawable="@null"
app:passwordToggleEnabled="true"
android:id="@+id/editPasswordLayout"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:imeOptions="actionDone"
android:hint="@string/password"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/buttonUseBiometrics"
style="@style/Widget.Material3.Button.TextButton"
android:layout_marginEnd="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/useBiometrics"/>

<androidx.constraintlayout.widget.ConstraintLayout
android:orientation="horizontal"
android:layout_gravity="end"
<FrameLayout
android:id="@+id/layoutUnlockProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
android:id="@+id/buttonUseBiometrics"
style="@style/Widget.Material3.Button.TextButton"
android:layout_marginEnd="10dp"
android:layout_height="wrap_content"
<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progressIndicator"
style="@style/Widget.Material3.CircularProgressIndicator.Small"
android:visibility="invisible"
android:layout_width="wrap_content"
android:text="@string/useBiometrics"/>
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"/>

<FrameLayout
android:id="@+id/layoutUnlockProgress"
<com.google.android.material.button.MaterialButton
android:id="@+id/buttonUnlock"
style="@style/Widget.Material3.Button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progressIndicator"
style="@style/Widget.Material3.CircularProgressIndicator.Small"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"/>
android:text="@string/unlock"/>
</FrameLayout>

<com.google.android.material.button.MaterialButton
android:id="@+id/buttonUnlock"
style="@style/Widget.Material3.Button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/unlock"/>
</FrameLayout>

<androidx.constraintlayout.helper.widget.Flow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="buttonUseBiometrics,layoutUnlockProgress"
app:flow_horizontalGap="10dp"
app:flow_horizontalBias="1.0"
app:flow_wrapMode="chain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<androidx.constraintlayout.helper.widget.Flow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="buttonUseBiometrics,layoutUnlockProgress"
app:flow_horizontalGap="10dp"
app:flow_horizontalBias="1.0"
app:flow_wrapMode="chain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

</androidx.core.widget.NestedScrollView>
</LinearLayout>
27 changes: 18 additions & 9 deletions AuthenticatorPro.Droid/src/Interface/Fragment/UnlockBottomSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Views;
Expand All @@ -12,6 +13,7 @@
using AuthenticatorPro.Droid.Callback;
using AuthenticatorPro.Droid.Storage;
using AuthenticatorPro.Droid.Util;
using Google.Android.Material.BottomSheet;
using Google.Android.Material.Button;
using Google.Android.Material.ProgressIndicator;
using Google.Android.Material.TextField;
Expand All @@ -21,7 +23,6 @@ namespace AuthenticatorPro.Droid.Interface.Fragment
public class UnlockBottomSheet : BottomSheet
{
private PreferenceWrapper _preferences;
private BiometricPrompt _prompt;
private bool _canUseBiometrics;

private MaterialButton _unlockButton;
Expand All @@ -36,9 +37,23 @@ public UnlockBottomSheet() : base(Resource.Layout.sheetUnlock, Resource.String.u

public event EventHandler<string> UnlockAttempted;

public override Dialog OnCreateDialog(Bundle savedInstanceState)
{
var backPressCallback = new BackPressCallback(true);
backPressCallback.BackPressed += delegate
{
Dismiss();
};

var dialog = (BottomSheetDialog) base.OnCreateDialog(savedInstanceState);
dialog.OnBackPressedDispatcher.AddCallback(this, backPressCallback);
return dialog;
}

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = base.OnCreateView(inflater, container, savedInstanceState);
SetCancelable(false);

_preferences = new PreferenceWrapper(Context);

Expand Down Expand Up @@ -151,7 +166,7 @@ private void ShowBiometricPrompt()
FocusPasswordText();
};

_prompt = new BiometricPrompt(this, executor, callback);
var prompt = new BiometricPrompt(this, executor, callback);

var promptInfo = new BiometricPrompt.PromptInfo.Builder()
.SetTitle(GetString(Resource.String.unlock))
Expand All @@ -164,7 +179,7 @@ private void ShowBiometricPrompt()
try
{
var cipher = passwordStorage.GetDecryptionCipher();
_prompt.Authenticate(promptInfo, new BiometricPrompt.CryptoObject(cipher));
prompt.Authenticate(promptInfo, new BiometricPrompt.CryptoObject(cipher));
}
catch (Exception e)
{
Expand All @@ -174,11 +189,5 @@ private void ShowBiometricPrompt()
FocusPasswordText();
}
}

public override void Dismiss()
{
base.Dismiss();
_prompt?.CancelAuthentication();
}
}
}

0 comments on commit c9c9a6a

Please sign in to comment.