1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-30 12:54:24 +01:00

fix slider history saves

This commit is contained in:
Kyle Spearrin 2019-05-31 11:13:46 -04:00
parent 32e757a873
commit 6163a6dd77
4 changed files with 12 additions and 37 deletions

View File

@ -45,6 +45,7 @@ namespace Bit.App.Pages
public async Task ClearAsync() public async Task ClearAsync()
{ {
History.ResetWithRange(new List<GeneratedPasswordHistory>()); History.ResetWithRange(new List<GeneratedPasswordHistory>());
ShowNoData = true;
await _passwordGenerationService.ClearAsync(); await _passwordGenerationService.ClearAsync();
} }

View File

@ -105,7 +105,7 @@
VerticalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"
HorizontalTextAlignment="End" /> HorizontalTextAlignment="End" />
<controls:ExtendedSlider <controls:ExtendedSlider
ValueChanged="LengthSlider_ValueChanged" DragCompleted="LengthSlider_DragCompleted"
Value="{Binding Length}" Value="{Binding Length}"
StyleClass="box-value" StyleClass="box-value"
VerticalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"

View File

@ -23,8 +23,6 @@ namespace Bit.App.Pages
} }
} }
public DateTime LastLengthSliderChange { get; set; } = DateTime.MinValue;
public async Task InitAsync() public async Task InitAsync()
{ {
await _vm.InitAsync(); await _vm.InitAsync();
@ -60,12 +58,9 @@ namespace Bit.App.Pages
await Navigation.PushModalAsync(new NavigationPage(page)); await Navigation.PushModalAsync(new NavigationPage(page));
} }
private void LengthSlider_ValueChanged(object sender, ValueChangedEventArgs e) private async void LengthSlider_DragCompleted(object sender, EventArgs e)
{ {
if(e.NewValue != e.OldValue) await _vm.SliderChangedAsync();
{
LastLengthSliderChange = DateTime.UtcNow;
}
} }
} }
} }

View File

@ -31,7 +31,6 @@ namespace Bit.App.Pages
private string _wordSeparator; private string _wordSeparator;
private int _typeSelectedIndex; private int _typeSelectedIndex;
private bool _doneIniting; private bool _doneIniting;
private CancellationTokenSource _sliderCancellationTokenSource;
public GeneratorPageViewModel() public GeneratorPageViewModel()
{ {
@ -70,7 +69,7 @@ namespace Bit.App.Pages
if(SetProperty(ref _length, value)) if(SetProperty(ref _length, value))
{ {
_options.Length = value; _options.Length = value;
var task = SaveOptionsSliderAsync(); var task = SliderInputAsync();
} }
} }
} }
@ -236,37 +235,17 @@ namespace Bit.App.Pages
} }
} }
public async Task SaveOptionsSliderAsync() public async Task SliderChangedAsync()
{ {
if(!_doneIniting) await SaveOptionsAsync(false);
{ await _passwordGenerationService.AddHistoryAsync(Password);
return;
} }
public async Task SliderInputAsync()
{
SetOptions(); SetOptions();
_passwordGenerationService.NormalizeOptions(_options); _passwordGenerationService.NormalizeOptions(_options);
LoadFromOptions();
Password = await _passwordGenerationService.GeneratePasswordAsync(_options); Password = await _passwordGenerationService.GeneratePasswordAsync(_options);
var page = Page as GeneratorPage;
var previousCts = _sliderCancellationTokenSource;
var cts = new CancellationTokenSource();
var task = Task.Run(async () =>
{
await Task.Delay(500);
if(DateTime.UtcNow - page.LastLengthSliderChange < TimeSpan.FromMilliseconds(450))
{
return;
}
else
{
previousCts?.Cancel();
}
cts.Token.ThrowIfCancellationRequested();
await _passwordGenerationService.SaveOptionsAsync(_options);
cts.Token.ThrowIfCancellationRequested();
await _passwordGenerationService.AddHistoryAsync(Password, cts.Token);
}, cts.Token);
_sliderCancellationTokenSource = cts;
} }
public async Task CopyAsync() public async Task CopyAsync()