using System; using System.Threading.Tasks; using Acr.UserDialogs; using Bit.App.Abstractions; using Bit.App.Controls; using Bit.App.Resources; using Xamarin.Forms; using XLabs.Ioc; using Plugin.Fingerprint.Abstractions; using Plugin.Settings.Abstractions; namespace Bit.App.Pages { public class LockFingerprintPage : ExtendedContentPage { private readonly IFingerprint _fingerprint; private readonly IAuthService _authService; private readonly IUserDialogs _userDialogs; private readonly ISettings _settings; private readonly bool _checkFingerprintImmediately; public LockFingerprintPage(bool checkFingerprintImmediately) { _checkFingerprintImmediately = checkFingerprintImmediately; _fingerprint = Resolver.Resolve(); _authService = Resolver.Resolve(); _userDialogs = Resolver.Resolve(); _settings = Resolver.Resolve(); Init(); } public void Init() { var fingerprintButton = new Button { Text = "Use Fingerprint to Unlock", Command = new Command(async () => await CheckFingerprintAsync()), VerticalOptions = LayoutOptions.EndAndExpand, Style = (Style)Application.Current.Resources["btn-primary"] }; var logoutButton = new Button { Text = AppResources.LogOut, Command = new Command(async () => await LogoutAsync()), VerticalOptions = LayoutOptions.End, Style = (Style)Application.Current.Resources["btn-primaryAccent"] }; var stackLayout = new StackLayout { Padding = new Thickness(30, 40), Spacing = 10 }; stackLayout.Children.Add(fingerprintButton); stackLayout.Children.Add(logoutButton); Title = "Verify Fingerprint"; Content = stackLayout; } protected override bool OnBackButtonPressed() { return false; } protected override void OnAppearing() { base.OnAppearing(); if(_checkFingerprintImmediately) { var task = CheckFingerprintAsync(); } } public async Task LogoutAsync() { if(!await _userDialogs.ConfirmAsync("Are you sure you want to log out?", null, AppResources.Yes, AppResources.Cancel)) { return; } _authService.LogOut(); await Navigation.PopModalAsync(); Application.Current.MainPage = new HomePage(); } public async Task CheckFingerprintAsync() { var result = await _fingerprint.AuthenticateAsync("Use your fingerprint to verify."); if(result.Authenticated) { await Navigation.PopModalAsync(); } } } }