mirror of
https://github.com/bitwarden/android.git
synced 2024-12-18 15:21:53 +03:00
prevent rapid clicking actions that crash app
This commit is contained in:
parent
3415be4c56
commit
bc6ff3e3bc
9 changed files with 73 additions and 0 deletions
|
@ -16,6 +16,7 @@ namespace Bit.App.Pages
|
||||||
private readonly IAuthService _authService;
|
private readonly IAuthService _authService;
|
||||||
private readonly IUserDialogs _userDialogs;
|
private readonly IUserDialogs _userDialogs;
|
||||||
private readonly ISettings _settings;
|
private readonly ISettings _settings;
|
||||||
|
private DateTime? _lastAction;
|
||||||
|
|
||||||
public HomePage()
|
public HomePage()
|
||||||
: base(updateActivity: false)
|
: base(updateActivity: false)
|
||||||
|
@ -92,11 +93,23 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
public async Task LoginAsync()
|
public async Task LoginAsync()
|
||||||
{
|
{
|
||||||
|
if(_lastAction.LastActionWasRecent())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastAction = DateTime.UtcNow;
|
||||||
|
|
||||||
await Navigation.PushForDeviceAsync(new LoginPage());
|
await Navigation.PushForDeviceAsync(new LoginPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RegisterAsync()
|
public async Task RegisterAsync()
|
||||||
{
|
{
|
||||||
|
if(_lastAction.LastActionWasRecent())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastAction = DateTime.UtcNow;
|
||||||
|
|
||||||
await Navigation.PushForDeviceAsync(new RegisterPage(this));
|
await Navigation.PushForDeviceAsync(new RegisterPage(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace Bit.App.Pages
|
||||||
private readonly ISettings _settings;
|
private readonly ISettings _settings;
|
||||||
private readonly IAppSettingsService _appSettings;
|
private readonly IAppSettingsService _appSettings;
|
||||||
private readonly bool _checkFingerprintImmediately;
|
private readonly bool _checkFingerprintImmediately;
|
||||||
|
private DateTime? _lastAction;
|
||||||
|
|
||||||
public LockFingerprintPage(bool checkFingerprintImmediately)
|
public LockFingerprintPage(bool checkFingerprintImmediately)
|
||||||
{
|
{
|
||||||
|
@ -79,6 +80,12 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
public async Task CheckFingerprintAsync()
|
public async Task CheckFingerprintAsync()
|
||||||
{
|
{
|
||||||
|
if(_lastAction.LastActionWasRecent())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastAction = DateTime.UtcNow;
|
||||||
|
|
||||||
var result = await _fingerprint.AuthenticateAsync(AppResources.FingerprintDirection);
|
var result = await _fingerprint.AuthenticateAsync(AppResources.FingerprintDirection);
|
||||||
if(result.Authenticated)
|
if(result.Authenticated)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace Bit.App.Pages
|
||||||
private readonly IAuthService _authService;
|
private readonly IAuthService _authService;
|
||||||
private readonly IAppSettingsService _appSettingsService;
|
private readonly IAppSettingsService _appSettingsService;
|
||||||
private readonly ICryptoService _cryptoService;
|
private readonly ICryptoService _cryptoService;
|
||||||
|
private DateTime? _lastAction;
|
||||||
|
|
||||||
public LockPasswordPage()
|
public LockPasswordPage()
|
||||||
{
|
{
|
||||||
|
@ -111,6 +112,12 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
protected async Task CheckPasswordAsync()
|
protected async Task CheckPasswordAsync()
|
||||||
{
|
{
|
||||||
|
if(_lastAction.LastActionWasRecent())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastAction = DateTime.UtcNow;
|
||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
|
if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
|
||||||
{
|
{
|
||||||
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
|
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace Bit.App.Pages
|
||||||
private readonly IAuthService _authService;
|
private readonly IAuthService _authService;
|
||||||
private readonly IAppSettingsService _appSettingsService;
|
private readonly IAppSettingsService _appSettingsService;
|
||||||
private TapGestureRecognizer _tgr;
|
private TapGestureRecognizer _tgr;
|
||||||
|
private DateTime? _lastAction;
|
||||||
|
|
||||||
public LockPinPage()
|
public LockPinPage()
|
||||||
{
|
{
|
||||||
|
@ -91,6 +92,12 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
protected void PinEntered(object sender, EventArgs args)
|
protected void PinEntered(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
|
if(_lastAction.LastActionWasRecent())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastAction = DateTime.UtcNow;
|
||||||
|
|
||||||
if(Model.PIN == _authService.PIN)
|
if(Model.PIN == _authService.PIN)
|
||||||
{
|
{
|
||||||
_appSettingsService.Locked = false;
|
_appSettingsService.Locked = false;
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace Bit.App.Pages
|
||||||
private readonly IUserDialogs _userDialogs;
|
private readonly IUserDialogs _userDialogs;
|
||||||
private readonly IConnectivity _connectivity;
|
private readonly IConnectivity _connectivity;
|
||||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||||
|
private DateTime? _lastAction;
|
||||||
|
|
||||||
public SettingsAddFolderPage()
|
public SettingsAddFolderPage()
|
||||||
{
|
{
|
||||||
|
@ -56,6 +57,12 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||||
{
|
{
|
||||||
|
if(_lastAction.LastActionWasRecent())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastAction = DateTime.UtcNow;
|
||||||
|
|
||||||
if(!_connectivity.IsConnected)
|
if(!_connectivity.IsConnected)
|
||||||
{
|
{
|
||||||
AlertNoConnection();
|
AlertNoConnection();
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace Bit.App.Pages
|
||||||
private readonly IUserDialogs _userDialogs;
|
private readonly IUserDialogs _userDialogs;
|
||||||
private readonly IConnectivity _connectivity;
|
private readonly IConnectivity _connectivity;
|
||||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||||
|
private DateTime? _lastAction;
|
||||||
|
|
||||||
public SettingsEditFolderPage(string folderId)
|
public SettingsEditFolderPage(string folderId)
|
||||||
{
|
{
|
||||||
|
@ -73,6 +74,12 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||||
{
|
{
|
||||||
|
if(_lastAction.LastActionWasRecent())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastAction = DateTime.UtcNow;
|
||||||
|
|
||||||
if(!_connectivity.IsConnected)
|
if(!_connectivity.IsConnected)
|
||||||
{
|
{
|
||||||
AlertNoConnection();
|
AlertNoConnection();
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace Bit.App.Pages
|
||||||
private readonly string _defaultUri;
|
private readonly string _defaultUri;
|
||||||
private readonly string _defaultName;
|
private readonly string _defaultName;
|
||||||
private readonly bool _fromAutofill;
|
private readonly bool _fromAutofill;
|
||||||
|
private DateTime? _lastAction;
|
||||||
|
|
||||||
public VaultAddLoginPage(string defaultUri = null, string defaultName = null, bool fromAutofill = false)
|
public VaultAddLoginPage(string defaultUri = null, string defaultName = null, bool fromAutofill = false)
|
||||||
{
|
{
|
||||||
|
@ -135,6 +136,12 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||||
{
|
{
|
||||||
|
if(_lastAction.LastActionWasRecent())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastAction = DateTime.UtcNow;
|
||||||
|
|
||||||
if(!_connectivity.IsConnected)
|
if(!_connectivity.IsConnected)
|
||||||
{
|
{
|
||||||
AlertNoConnection();
|
AlertNoConnection();
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace Bit.App.Pages
|
||||||
private readonly IUserDialogs _userDialogs;
|
private readonly IUserDialogs _userDialogs;
|
||||||
private readonly IConnectivity _connectivity;
|
private readonly IConnectivity _connectivity;
|
||||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||||
|
private DateTime? _lastAction;
|
||||||
|
|
||||||
public VaultEditLoginPage(string loginId)
|
public VaultEditLoginPage(string loginId)
|
||||||
{
|
{
|
||||||
|
@ -146,6 +147,12 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||||
{
|
{
|
||||||
|
if(_lastAction.LastActionWasRecent())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastAction = DateTime.UtcNow;
|
||||||
|
|
||||||
if(!_connectivity.IsConnected)
|
if(!_connectivity.IsConnected)
|
||||||
{
|
{
|
||||||
AlertNoConnection();
|
AlertNoConnection();
|
||||||
|
|
|
@ -106,5 +106,16 @@ namespace Bit.App
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool LastActionWasRecent(this DateTime? lastAction, int milliseconds = 1000)
|
||||||
|
{
|
||||||
|
if(lastAction.HasValue && (DateTime.UtcNow - lastAction.Value).TotalMilliseconds < milliseconds)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine("Last action occurred recently.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue