From 5ef4c96ee789e757e06be2fbdb38caf44644f995 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 6 May 2019 22:49:57 -0400 Subject: [PATCH] DoOnce helper --- src/App/Pages/BaseContentPage.cs | 14 ++++++++++++++ src/App/Pages/Vault/CiphersPage.xaml.cs | 9 +++++++++ .../Vault/GroupingsPage/GroupingsPage.xaml.cs | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/src/App/Pages/BaseContentPage.cs b/src/App/Pages/BaseContentPage.cs index 73eb55ab2..0d886e5d1 100644 --- a/src/App/Pages/BaseContentPage.cs +++ b/src/App/Pages/BaseContentPage.cs @@ -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; + } } } diff --git a/src/App/Pages/Vault/CiphersPage.xaml.cs b/src/App/Pages/Vault/CiphersPage.xaml.cs index 4d01240d5..baa3881e9 100644 --- a/src/App/Pages/Vault/CiphersPage.xaml.cs +++ b/src/App/Pages/Vault/CiphersPage.xaml.cs @@ -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); diff --git a/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs b/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs index 114cf8ddf..ac4eb3420 100644 --- a/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs +++ b/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs @@ -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;