mirror of
https://github.com/bitwarden/mobile
synced 2026-01-07 19:13:19 +00:00
redid lock pin page with pin control.
This commit is contained in:
@@ -8,6 +8,8 @@ using XLabs.Ioc;
|
||||
using Plugin.Settings.Abstractions;
|
||||
using System.Collections.Generic;
|
||||
using Bit.App.Models.Page;
|
||||
using Bit.App.Controls;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Bit.App.Pages
|
||||
{
|
||||
@@ -27,43 +29,11 @@ namespace Bit.App.Pages
|
||||
}
|
||||
|
||||
public PinPageModel Model { get; set; } = new PinPageModel();
|
||||
public PinControl PinControl { get; set; }
|
||||
|
||||
public void Init()
|
||||
{
|
||||
var label = new Label
|
||||
{
|
||||
HorizontalTextAlignment = TextAlignment.Center,
|
||||
FontSize = 40,
|
||||
TextColor = Color.FromHex("333333")
|
||||
};
|
||||
label.SetBinding<PinPageModel>(Label.TextProperty, s => s.LabelText);
|
||||
|
||||
var grid = new Grid();
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
|
||||
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
|
||||
|
||||
Action updateLabelAction = new Action(UpdateLabel);
|
||||
grid.Children.Add(new PinButton("1", this, updateLabelAction), 0, 0);
|
||||
grid.Children.Add(new PinButton("2", this, updateLabelAction), 1, 0);
|
||||
grid.Children.Add(new PinButton("3", this, updateLabelAction), 2, 0);
|
||||
|
||||
grid.Children.Add(new PinButton("4", this, updateLabelAction), 0, 1);
|
||||
grid.Children.Add(new PinButton("5", this, updateLabelAction), 1, 1);
|
||||
grid.Children.Add(new PinButton("6", this, updateLabelAction), 2, 1);
|
||||
|
||||
grid.Children.Add(new PinButton("7", this, updateLabelAction), 0, 2);
|
||||
grid.Children.Add(new PinButton("8", this, updateLabelAction), 1, 2);
|
||||
grid.Children.Add(new PinButton("9", this, updateLabelAction), 2, 2);
|
||||
|
||||
grid.Children.Add(new Label(), 0, 3);
|
||||
grid.Children.Add(new PinButton("0", this, updateLabelAction), 1, 3);
|
||||
grid.Children.Add(new DeleteButton(this, updateLabelAction), 2, 3);
|
||||
PinControl = new PinControl(PinEntered);
|
||||
|
||||
var logoutButton = new Button
|
||||
{
|
||||
@@ -76,7 +46,7 @@ namespace Bit.App.Pages
|
||||
{
|
||||
Padding = new Thickness(30, 40),
|
||||
Spacing = 10,
|
||||
Children = { label, grid, logoutButton }
|
||||
Children = { PinControl.Label, PinControl.Entry, logoutButton }
|
||||
};
|
||||
|
||||
Title = "Verify PIN";
|
||||
@@ -87,6 +57,22 @@ namespace Bit.App.Pages
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
PinControl.Entry.Focus();
|
||||
}
|
||||
|
||||
protected void PinEntered()
|
||||
{
|
||||
if(Model.PIN == "1234")
|
||||
{
|
||||
PinControl.Entry.Unfocus();
|
||||
Navigation.PopModalAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
_userDialogs.Alert("Invalid PIN. Try again.");
|
||||
Model.PIN = string.Empty;
|
||||
PinControl.Entry.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LogoutAsync()
|
||||
@@ -100,60 +86,5 @@ namespace Bit.App.Pages
|
||||
await Navigation.PopModalAsync();
|
||||
Application.Current.MainPage = new LoginNavigationPage();
|
||||
}
|
||||
|
||||
private void UpdateLabel()
|
||||
{
|
||||
var newText = string.Empty;
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
if(Model.PIN.Count <= i)
|
||||
{
|
||||
newText += "_ ";
|
||||
}
|
||||
else
|
||||
{
|
||||
newText += "* ";
|
||||
}
|
||||
}
|
||||
|
||||
Model.LabelText = newText.TrimEnd();
|
||||
}
|
||||
|
||||
public class PinButton : Button
|
||||
{
|
||||
public PinButton(string text, LockPinPage page, Action updateLabelAction)
|
||||
{
|
||||
Text = text;
|
||||
Command = new Command(() =>
|
||||
{
|
||||
if(page.Model.PIN.Count >= 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
page.Model.PIN.Add(text);
|
||||
updateLabelAction();
|
||||
});
|
||||
CommandParameter = text;
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteButton : Button
|
||||
{
|
||||
public DeleteButton(LockPinPage page, Action updateLabelAction)
|
||||
{
|
||||
Text = "Delete";
|
||||
Command = new Command(() =>
|
||||
{
|
||||
if(page.Model.PIN.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
page.Model.PIN.RemoveAt(page.Model.PIN.Count - 1);
|
||||
updateLabelAction();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user