43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using Avalonia.Controls;
|
||
using Avalonia.Interactivity;
|
||
using Avalonia.Threading;
|
||
using Млаумчерб.Клиент.сеть;
|
||
|
||
namespace Млаумчерб.Клиент.видимое;
|
||
|
||
public partial class DownloadTaskView : UserControl
|
||
{
|
||
private readonly NetworkTask _task;
|
||
private readonly Action<DownloadTaskView> _removeFromList;
|
||
|
||
|
||
public DownloadTaskView()
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
public DownloadTaskView(NetworkTask task, Action<DownloadTaskView> removeFromList)
|
||
{
|
||
_task = task;
|
||
_removeFromList = removeFromList;
|
||
InitializeComponent();
|
||
NameText.Text = task.Name;
|
||
task.OnProgress += ReportProgress;
|
||
}
|
||
|
||
|
||
void ReportProgress(DownloadProgress progress)
|
||
{
|
||
Dispatcher.UIThread.Invoke(() =>
|
||
{
|
||
DownloadedProgressText.Text = progress.ToString();
|
||
});
|
||
}
|
||
|
||
private void RemoveFromList(object? sender, RoutedEventArgs e)
|
||
{
|
||
_task.Cancel();
|
||
Dispatcher.UIThread.Invoke(() => _removeFromList.Invoke(this));
|
||
}
|
||
}
|