-
Notifications
You must be signed in to change notification settings - Fork 52
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 #2170 from erri120/feat/collection-download-page
Collection download page
- Loading branch information
Showing
19 changed files
with
436 additions
and
139 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
41 changes: 41 additions & 0 deletions
41
src/NexusMods.App.UI/Pages/CollectionDownload/CollectionDownloadPage.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,41 @@ | ||
using JetBrains.Annotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NexusMods.Abstractions.NexusModsLibrary.Models; | ||
using NexusMods.Abstractions.Serialization.Attributes; | ||
using NexusMods.App.UI.WorkspaceSystem; | ||
using NexusMods.MnemonicDB.Abstractions; | ||
|
||
namespace NexusMods.App.UI.Pages.CollectionDownload; | ||
|
||
[JsonName(nameof(CollectionDownloadPageContext))] | ||
public record CollectionDownloadPageContext : IPageFactoryContext | ||
{ | ||
public required CollectionRevisionMetadataId CollectionRevisionMetadataId { get; init; } | ||
} | ||
|
||
[UsedImplicitly] | ||
public class CollectionDownloadPageFactory : APageFactory<ICollectionDownloadViewModel, CollectionDownloadPageContext> | ||
{ | ||
public static readonly PageFactoryId StaticId = PageFactoryId.From(Guid.Parse("50790b33-41cb-432e-a877-4730d2b3c13e")); | ||
|
||
private readonly IConnection _connection; | ||
public CollectionDownloadPageFactory(IServiceProvider serviceProvider) : base(serviceProvider) | ||
{ | ||
_connection = serviceProvider.GetRequiredService<IConnection>(); | ||
} | ||
|
||
public override PageFactoryId Id => StaticId; | ||
|
||
public override ICollectionDownloadViewModel CreateViewModel(CollectionDownloadPageContext context) | ||
{ | ||
var metadata = CollectionRevisionMetadata.Load(_connection.Db, context.CollectionRevisionMetadataId); | ||
if (!metadata.IsValid()) throw new InvalidOperationException($"{nameof(CollectionRevisionMetadata)} is invalid for `{context.CollectionRevisionMetadataId}`"); | ||
|
||
return new CollectionDownloadViewModel( | ||
windowManager: WindowManager, | ||
tileImagePipeline: ImagePipelines.GetCollectionTileImagePipeline(ServiceProvider), | ||
backgroundImagePipeline: ImagePipelines.GetCollectionBackgroundImagePipeline(ServiceProvider), | ||
revisionMetadata: metadata | ||
); | ||
} | ||
} |
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
77 changes: 77 additions & 0 deletions
77
src/NexusMods.App.UI/Pages/CollectionDownload/CollectionDownloadViewModel.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,77 @@ | ||
using Avalonia.Media.Imaging; | ||
using NexusMods.Abstractions.Jobs; | ||
using NexusMods.Abstractions.NexusModsLibrary.Models; | ||
using NexusMods.Abstractions.NexusWebApi.Types; | ||
using NexusMods.Abstractions.Resources; | ||
using NexusMods.App.UI.Windows; | ||
using NexusMods.App.UI.WorkspaceSystem; | ||
using NexusMods.MnemonicDB.Abstractions; | ||
using NexusMods.Paths; | ||
using R3; | ||
using ReactiveUI; | ||
using ReactiveUI.Fody.Helpers; | ||
|
||
namespace NexusMods.App.UI.Pages.CollectionDownload; | ||
|
||
public class CollectionDownloadViewModel : APageViewModel<ICollectionDownloadViewModel>, ICollectionDownloadViewModel | ||
{ | ||
private readonly CollectionRevisionMetadata.ReadOnly _revision; | ||
private readonly CollectionMetadata.ReadOnly _collection; | ||
|
||
public CollectionDownloadViewModel( | ||
IWindowManager windowManager, | ||
IResourceLoader<EntityId, Bitmap> tileImagePipeline, | ||
IResourceLoader<EntityId, Bitmap> backgroundImagePipeline, | ||
CollectionRevisionMetadata.ReadOnly revisionMetadata) : base(windowManager) | ||
{ | ||
_revision = revisionMetadata; | ||
_collection = revisionMetadata.Collection; | ||
|
||
// TODO: | ||
CollectionStatusText = "TODO"; | ||
|
||
var requiredModCount = 0; | ||
var optionalModCount = 0; | ||
foreach (var file in _revision.Files) | ||
{ | ||
var isOptional = file.IsOptional; | ||
|
||
requiredModCount += isOptional ? 0 : 1; | ||
optionalModCount += isOptional ? 1 : 0; | ||
} | ||
|
||
RequiredModCount = requiredModCount; | ||
OptionalModCount = optionalModCount; | ||
|
||
this.WhenActivated(disposables => | ||
{ | ||
ImagePipelines.CreateObservable(_collection.Id, tileImagePipeline) | ||
.ObserveOnUIThreadDispatcher() | ||
.Subscribe(this, static (bitmap, self) => self.TileImage = bitmap) | ||
.AddTo(disposables); | ||
|
||
ImagePipelines.CreateObservable(_collection.Id, backgroundImagePipeline) | ||
.ObserveOnUIThreadDispatcher() | ||
.Subscribe(this, static (bitmap, self) => self.BackgroundImage = bitmap) | ||
.AddTo(disposables); | ||
}); | ||
} | ||
|
||
public string Name => _collection.Name; | ||
public string Summary => _collection.Summary; | ||
public int ModCount => _revision.Files.Count; | ||
public ulong EndorsementCount => _collection.Endorsements; | ||
public ulong DownloadCount => _revision.Downloads; | ||
public Size TotalSize => _revision.TotalSize; | ||
public Percent OverallRating => Percent.CreateClamped(_revision.OverallRating); | ||
public string AuthorName => _collection.Author.Name; | ||
|
||
public CollectionSlug Slug => _collection.Slug; | ||
public RevisionNumber RevisionNumber => _revision.RevisionNumber; | ||
public int RequiredModCount { get; } | ||
public int OptionalModCount { get; } | ||
|
||
[Reactive] public Bitmap? TileImage { get; private set; } | ||
[Reactive] public Bitmap? BackgroundImage { get; private set; } | ||
[Reactive] public string CollectionStatusText { get; private set; } | ||
} |
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
Oops, something went wrong.