Add download speed limit

This commit is contained in:
Michael Bucari-Tovo 2023-01-02 02:46:46 -07:00
parent 0ed5062683
commit 9ec877999e
11 changed files with 280 additions and 21 deletions

View file

@ -1,11 +1,13 @@
using ApplicationServices;
using ApplicationServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data.Converters;
using Avalonia.Markup.Xaml;
using DataLayer;
using LibationAvalonia.ViewModels;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace LibationAvalonia.Views
@ -86,6 +88,11 @@ namespace LibationAvalonia.Views
#endregion
}
public void NumericUpDown_KeyDown(object sender, Avalonia.Input.KeyEventArgs e)
{
if (e.Key == Avalonia.Input.Key.Enter && sender is Avalonia.Input.IInputElement input) input.Focus();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
@ -148,4 +155,41 @@ namespace LibationAvalonia.Views
#endregion
}
public class DecimalConverter : IValueConverter
{
public static readonly DecimalConverter Instance = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string sourceText && targetType.IsAssignableTo(typeof(decimal?)))
{
if (sourceText == "∞") return 0;
for (int i = sourceText.Length; i > 0; i--)
{
if (decimal.TryParse(sourceText[..i], out var val))
return val;
}
return 0;
}
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is decimal val)
{
return
val == 0 ? "∞"
: (
val >= 10 ? ((long)val).ToString()
: val >= 1 ? val.ToString("F1")
: val.ToString("F2")
) + " MB/s";
}
return value.ToString();
}
}
}