mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
DoOnce helper
This commit is contained in:
parent
4ed12a859b
commit
5ef4c96ee7
3 changed files with 28 additions and 0 deletions
|
@ -9,6 +9,8 @@ namespace Bit.App.Pages
|
|||
protected int AndroidShowModalAnimationDelay = 400;
|
||||
protected int AndroidShowPageAnimationDelay = 100;
|
||||
|
||||
public DateTime? LastPageAction { get; set; }
|
||||
|
||||
protected void SetActivityIndicator()
|
||||
{
|
||||
Content = new ActivityIndicator
|
||||
|
@ -54,5 +56,17 @@ namespace Bit.App.Pages
|
|||
Device.BeginInvokeOnMainThread(() => input.Focus());
|
||||
});
|
||||
}
|
||||
|
||||
protected bool DoOnce(Action action = null, int milliseconds = 1000)
|
||||
{
|
||||
if(LastPageAction.HasValue && (DateTime.UtcNow - LastPageAction.Value).TotalMilliseconds < milliseconds)
|
||||
{
|
||||
// Last action occurred recently.
|
||||
return false;
|
||||
}
|
||||
LastPageAction = DateTime.UtcNow;
|
||||
action?.Invoke();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,12 +76,21 @@ namespace Bit.App.Pages
|
|||
|
||||
private void GoBack()
|
||||
{
|
||||
if(!DoOnce())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Navigation.PopModalAsync(false);
|
||||
}
|
||||
|
||||
private async void RowSelected(object sender, SelectedItemChangedEventArgs e)
|
||||
{
|
||||
((ListView)sender).SelectedItem = null;
|
||||
if(!DoOnce())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(e.SelectedItem is CipherView cipher)
|
||||
{
|
||||
await _vm.SelectCipherAsync(cipher);
|
||||
|
|
|
@ -74,6 +74,11 @@ namespace Bit.App.Pages
|
|||
private async void RowSelected(object sender, SelectedItemChangedEventArgs e)
|
||||
{
|
||||
((ListView)sender).SelectedItem = null;
|
||||
if(!DoOnce())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(e.SelectedItem is GroupingsPageListItem item))
|
||||
{
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue