-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sprite download progress bar and cancellation
- Loading branch information
1 parent
185cc8f
commit 7ce052c
Showing
8 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/TrackerCouncil.Smz3.Data/Services/SpriteDownloadUpdateEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace TrackerCouncil.Smz3.Data.Services; | ||
|
||
public class SpriteDownloadUpdateEventArgs(int completed, int total) : EventArgs | ||
{ | ||
public int Completed => completed; | ||
public int Total => total; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/TrackerCouncil.Smz3.UI/Services/SpriteDownloadWindowService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using AvaloniaControls.ControlServices; | ||
using TrackerCouncil.Smz3.Data.Services; | ||
using TrackerCouncil.Smz3.UI.ViewModels; | ||
|
||
namespace TrackerCouncil.Smz3.UI.Services; | ||
|
||
public class SpriteDownloadWindowService(IGitHubSpriteDownloaderService gitHubSpriteDownloaderService) : ControlService | ||
{ | ||
private SpriteDownloadWindowViewModel _model = new(); | ||
|
||
public SpriteDownloadWindowViewModel InitializeModel() | ||
{ | ||
gitHubSpriteDownloaderService.SpriteDownloadUpdate += (sender, args) => | ||
{ | ||
_model.NumTotal = args.Total; | ||
_model.NumCompleted = args.Completed; | ||
}; | ||
|
||
return _model; | ||
} | ||
|
||
public void CancelDownload() | ||
{ | ||
gitHubSpriteDownloaderService.CancelDownload(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/TrackerCouncil.Smz3.UI/ViewModels/SpriteDownloadWindowViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using ReactiveUI.Fody.Helpers; | ||
|
||
namespace TrackerCouncil.Smz3.UI.ViewModels; | ||
|
||
public class SpriteDownloadWindowViewModel : ViewModelBase | ||
{ | ||
[Reactive] public int NumCompleted { get; set; } | ||
[Reactive] public int NumTotal { get; set; } = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/TrackerCouncil.Smz3.UI/Views/SpriteDownloadWindow.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,41 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Interactivity; | ||
using AvaloniaControls.Extensions; | ||
using TrackerCouncil.Smz3.UI.Services; | ||
using TrackerCouncil.Smz3.UI.ViewModels; | ||
|
||
namespace TrackerCouncil.Smz3.UI.Views; | ||
|
||
public partial class SpriteDownloadWindow : Window | ||
{ | ||
private SpriteDownloadWindowService? _service; | ||
|
||
public SpriteDownloadWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
if (Design.IsDesignMode) | ||
{ | ||
DataContext = new SpriteDownloadWindowViewModel | ||
{ | ||
NumCompleted = 5, NumTotal = 10 | ||
}; | ||
} | ||
else | ||
{ | ||
_service = this.GetControlService<SpriteDownloadWindowService>(); | ||
DataContext = _service?.InitializeModel() ?? new SpriteDownloadWindowViewModel(); | ||
} | ||
} | ||
|
||
private void Window_OnClosing(object? sender, WindowClosingEventArgs e) | ||
{ | ||
_service?.CancelDownload(); | ||
} | ||
|
||
private void Button_OnClick(object? sender, RoutedEventArgs e) | ||
{ | ||
Close(); | ||
} | ||
} | ||
|