-
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.
- Loading branch information
Showing
24 changed files
with
735 additions
and
480 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Globalization; | ||
using Humanizer; | ||
using Humanizer.Bytes; | ||
using NexusMods.Paths; | ||
using R3; | ||
|
||
namespace NexusMods.App.UI.Extensions; | ||
|
||
public static class FormatExtensions | ||
{ | ||
public static string FormatDate(this DateTimeOffset date, DateTimeOffset now) | ||
{ | ||
if (date == DateTimeOffset.MinValue || date == DateTimeOffset.MaxValue || date == DateTimeOffset.UnixEpoch) return "-"; | ||
return date.Humanize(dateToCompareAgainst: now, culture: CultureInfo.CurrentUICulture); | ||
} | ||
|
||
public static BindableReactiveProperty<string> ToFormattedProperty(this Observable<DateTimeOffset> source) | ||
{ | ||
return source | ||
.Select(static date => date.FormatDate(now: TimeProvider.System.GetLocalNow())) | ||
.ToBindableReactiveProperty(initialValue: ""); | ||
} | ||
|
||
public static BindableReactiveProperty<string> ToFormattedProperty(this Observable<Size> source) | ||
{ | ||
return source | ||
.Select(static size => ByteSize.FromBytes(size.Value).Humanize()) | ||
.ToBindableReactiveProperty(initialValue: ""); | ||
} | ||
} |
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
83 changes: 0 additions & 83 deletions
83
src/NexusMods.App.UI/Pages/LibraryPage/FakeParentLibraryItemModel.cs
This file was deleted.
Oops, something went wrong.
76 changes: 75 additions & 1 deletion
76
src/NexusMods.App.UI/Pages/LibraryPage/ILibraryItemModel.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,5 +1,79 @@ | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using DynamicData; | ||
using JetBrains.Annotations; | ||
using NexusMods.Abstractions.Library.Models; | ||
using NexusMods.Abstractions.Loadouts; | ||
using NexusMods.Abstractions.MnemonicDB.Attributes.Extensions; | ||
using NexusMods.App.UI.Controls; | ||
using NexusMods.App.UI.Extensions; | ||
using NexusMods.MnemonicDB.Abstractions; | ||
using ObservableCollections; | ||
using R3; | ||
|
||
namespace NexusMods.App.UI.Pages.LibraryPage; | ||
|
||
public interface ILibraryItemModel : ITreeDataGridItemModel; | ||
public interface ILibraryItemModel : ITreeDataGridItemModel<ILibraryItemModel, EntityId>; | ||
|
||
public interface IHasTicker | ||
{ | ||
Observable<DateTimeOffset>? Ticker { get; set; } | ||
} | ||
|
||
public interface IHasLinkedLoadoutItems | ||
{ | ||
IObservable<IChangeSet<LibraryLinkedLoadoutItem.ReadOnly, EntityId>> LinkedLoadoutItemsObservable { get; } | ||
ObservableDictionary<EntityId, LibraryLinkedLoadoutItem.ReadOnly> LinkedLoadoutItems { get; } | ||
|
||
[MustDisposeResource] static IDisposable SetupLinkedLoadoutItems<TModel>(TModel self, SerialDisposable serialDisposable) | ||
where TModel : IHasLinkedLoadoutItems, ILibraryItemWithInstallAction, ILibraryItemWithInstalledDate | ||
{ | ||
var disposable = self.LinkedLoadoutItems | ||
.ObserveCountChanged(notifyCurrentCount: true) | ||
.Subscribe(self, static (count, self) => | ||
{ | ||
var isInstalled = count > 0; | ||
self.IsInstalled.Value = isInstalled; | ||
self.InstallButtonText.Value = ILibraryItemWithInstallAction.GetButtonText(isInstalled); | ||
self.InstalledDate.Value = isInstalled ? self.LinkedLoadoutItems.Select(static kv => kv.Value.GetCreatedAt()).Max() : DateTimeOffset.MinValue; | ||
}); | ||
|
||
if (serialDisposable.Disposable is null) | ||
{ | ||
serialDisposable.Disposable = self.LinkedLoadoutItemsObservable.OnUI().SubscribeWithErrorLogging(changes => self.LinkedLoadoutItems.ApplyChanges(changes)); | ||
} | ||
|
||
return disposable; | ||
} | ||
} | ||
|
||
public interface IIsParentLibraryItemModel : ILibraryItemModel | ||
{ | ||
IReadOnlyList<LibraryItemId> LibraryItemIds { get; } | ||
} | ||
|
||
public interface IIsChildLibraryItemModel : ILibraryItemModel | ||
{ | ||
LibraryItemId LibraryItemId { get; } | ||
} | ||
|
||
[SuppressMessage("ReSharper", "PossibleInterfaceMemberAmbiguity")] | ||
public interface ILibraryItemWithDates : IHasTicker, ILibraryItemWithDownloadedDate, ILibraryItemWithInstalledDate | ||
{ | ||
[MustDisposeResource] | ||
static IDisposable SetupDates<TModel>(TModel self) where TModel : class, ILibraryItemWithDates | ||
{ | ||
return self.WhenActivated(static (self, disposables) => | ||
{ | ||
Debug.Assert(self.Ticker is not null, "should've been set before activation"); | ||
self.Ticker.Subscribe(self, static (now, self) => | ||
{ | ||
ILibraryItemWithDownloadedDate.FormatDate(self, now: now); | ||
ILibraryItemWithInstalledDate.FormatDate(self, now: now); | ||
}).AddTo(disposables); | ||
ILibraryItemWithDownloadedDate.FormatDate(self, now: TimeProvider.System.GetLocalNow()); | ||
ILibraryItemWithInstalledDate.FormatDate(self, now: TimeProvider.System.GetLocalNow()); | ||
}); | ||
} | ||
} |
Oops, something went wrong.