-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2250 from erri120/collection-download
Download external collection files
- Loading branch information
Showing
11 changed files
with
282 additions
and
58 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
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
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
84 changes: 84 additions & 0 deletions
84
src/NexusMods.App.UI/Pages/CollectionDownload/ExternalDownloadItemModel.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,84 @@ | ||
using NexusMods.Abstractions.Jobs; | ||
using NexusMods.Abstractions.NexusModsLibrary.Models; | ||
using NexusMods.App.UI.Controls; | ||
using NexusMods.App.UI.Extensions; | ||
using NexusMods.App.UI.Pages.LibraryPage; | ||
using NexusMods.MnemonicDB.Abstractions; | ||
using NexusMods.Paths; | ||
using R3; | ||
|
||
namespace NexusMods.App.UI.Pages.CollectionDownload; | ||
|
||
public class ExternalDownloadItemModel : TreeDataGridItemModel<ILibraryItemModel, EntityId>, | ||
ILibraryItemWithName, | ||
ILibraryItemWithSize, | ||
ILibraryItemWithDownloadAction | ||
{ | ||
public ExternalDownloadItemModel(CollectionDownloadExternal.ReadOnly externalDownload) | ||
{ | ||
DownloadableItem = new DownloadableItem(externalDownload); | ||
FormattedSize = ItemSize.ToFormattedProperty(); | ||
DownloadItemCommand = ILibraryItemWithDownloadAction.CreateCommand(this); | ||
|
||
// ReSharper disable once NotDisposedResource | ||
var modelActivationDisposable = this.WhenActivated(static (self, disposables) => | ||
{ | ||
self.IsInLibraryObservable.CombineLatest( | ||
source2: self.DownloadJobObservable.SelectMany(job => job.ObservableStatus.ToObservable()).Prepend(JobStatus.None), | ||
resultSelector: static (a, b) => (a, b)) | ||
.ObserveOnUIThreadDispatcher() | ||
.Subscribe(self, static (tuple, self) => | ||
{ | ||
var (inLibrary, status) = tuple; | ||
self.DownloadState.Value = inLibrary ? JobStatus.Completed : status; | ||
self.DownloadButtonText.Value = ILibraryItemWithDownloadAction.GetButtonText(status: self.DownloadState.Value); | ||
}).AddTo(disposables); | ||
}); | ||
|
||
_modelDisposable = Disposable.Combine( | ||
modelActivationDisposable, | ||
Name, | ||
ItemSize, | ||
FormattedSize, | ||
DownloadItemCommand, | ||
DownloadState, | ||
DownloadButtonText | ||
); | ||
} | ||
|
||
public required Observable<bool> IsInLibraryObservable { get; init; } | ||
public required Observable<IJob> DownloadJobObservable { get; init; } | ||
|
||
public BindableReactiveProperty<string> Name { get; } = new(value: "-"); | ||
|
||
public ReactiveProperty<Size> ItemSize { get; } = new(); | ||
public BindableReactiveProperty<string> FormattedSize { get; } | ||
|
||
public DownloadableItem DownloadableItem { get; } | ||
|
||
public ReactiveCommand<Unit, DownloadableItem> DownloadItemCommand { get; } | ||
|
||
public BindableReactiveProperty<JobStatus> DownloadState { get; } = new(); | ||
|
||
public BindableReactiveProperty<string> DownloadButtonText { get; } = new(value: ILibraryItemWithDownloadAction.GetButtonText(status: JobStatus.None)); | ||
|
||
private bool _isDisposed; | ||
private readonly IDisposable _modelDisposable; | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (!_isDisposed) | ||
{ | ||
if (disposing) | ||
{ | ||
_modelDisposable.Dispose(); | ||
} | ||
|
||
_isDisposed = true; | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
|
||
public override string ToString() => $"External Download: {Name.Value}"; | ||
} |
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
Oops, something went wrong.