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()
{
History.ResetWithRange(new List<GeneratedPasswordHistory>());
ShowNoData = true;
await _passwordGenerationService.ClearAsync();
}

View File

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

View File

@ -23,8 +23,6 @@ namespace Bit.App.Pages
}
}
public DateTime LastLengthSliderChange { get; set; } = DateTime.MinValue;
public async Task InitAsync()
{
await _vm.InitAsync();
@ -60,12 +58,9 @@ namespace Bit.App.Pages
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)
{
LastLengthSliderChange = DateTime.UtcNow;
}
await _vm.SliderChangedAsync();
}
}
}

View File

@ -31,7 +31,6 @@ namespace Bit.App.Pages
private string _wordSeparator;
private int _typeSelectedIndex;
private bool _doneIniting;
private CancellationTokenSource _sliderCancellationTokenSource;
public GeneratorPageViewModel()
{
@ -70,7 +69,7 @@ namespace Bit.App.Pages
if(SetProperty(ref _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)
{
return;
await SaveOptionsAsync(false);
await _passwordGenerationService.AddHistoryAsync(Password);
}
public async Task SliderInputAsync()
{
SetOptions();
_passwordGenerationService.NormalizeOptions(_options);
LoadFromOptions();
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()