From e9864244cbb178f0d77d18ed8b1708e79a9789a7 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Wed, 28 Apr 2021 14:27:16 -0600 Subject: [PATCH] Modlist contents viewer --- Wabbajack/Converters/FileSizeConverter.cs | 20 ++++++++++++++ Wabbajack/Themes/Styles.xaml | 1 + .../View Models/Gallery/ModListGalleryVM.cs | 1 + .../View Models/Gallery/ModListMetadataVM.cs | 26 ++++++++++++++----- Wabbajack/View Models/ModListContentsVM.cs | 20 +++++++++++--- Wabbajack/Views/ModListContentsView.xaml | 19 +++++--------- Wabbajack/Views/ModListContentsView.xaml.cs | 22 +++++----------- 7 files changed, 70 insertions(+), 39 deletions(-) create mode 100644 Wabbajack/Converters/FileSizeConverter.cs diff --git a/Wabbajack/Converters/FileSizeConverter.cs b/Wabbajack/Converters/FileSizeConverter.cs new file mode 100644 index 00000000..632d4705 --- /dev/null +++ b/Wabbajack/Converters/FileSizeConverter.cs @@ -0,0 +1,20 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using Wabbajack.Common; + +namespace Wabbajack +{ + public class FileSizeConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return ((long)value).ToFileSizeString(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Wabbajack/Themes/Styles.xaml b/Wabbajack/Themes/Styles.xaml index 37a95f19..88495b48 100644 --- a/Wabbajack/Themes/Styles.xaml +++ b/Wabbajack/Themes/Styles.xaml @@ -18,6 +18,7 @@ + #121212 diff --git a/Wabbajack/View Models/Gallery/ModListGalleryVM.cs b/Wabbajack/View Models/Gallery/ModListGalleryVM.cs index bb31ad23..160e3bba 100644 --- a/Wabbajack/View Models/Gallery/ModListGalleryVM.cs +++ b/Wabbajack/View Models/Gallery/ModListGalleryVM.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reactive; using System.Reactive.Disposables; using System.Reactive.Linq; +using System.Reactive.Subjects; using System.Text; using System.Threading.Tasks; using System.Windows.Input; diff --git a/Wabbajack/View Models/Gallery/ModListMetadataVM.cs b/Wabbajack/View Models/Gallery/ModListMetadataVM.cs index 9b594cee..221a1056 100644 --- a/Wabbajack/View Models/Gallery/ModListMetadataVM.cs +++ b/Wabbajack/View Models/Gallery/ModListMetadataVM.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net; using System.Reactive; using System.Reactive.Linq; +using System.Reactive.Subjects; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -74,6 +75,8 @@ namespace Wabbajack private readonly ObservableAsPropertyHelper _LoadingImage; public bool LoadingImage => _LoadingImage.Value; + private Subject IsLoadingIdle; + public ModListMetadataVM(ModListGalleryVM parent, ModlistMetadata metadata) { _parent = parent; @@ -92,15 +95,26 @@ namespace Wabbajack IsBroken = metadata.ValidationSummary.HasFailures || metadata.ForceDown; //https://www.wabbajack.org/#/modlists/info?machineURL=eldersouls OpenWebsiteCommand = ReactiveCommand.Create(() => Utils.OpenWebsite(new Uri($"https://www.wabbajack.org/#/modlists/info?machineURL={Metadata.Links.MachineURL}"))); + + IsLoadingIdle = new Subject(); + ModListContentsCommend = ReactiveCommand.Create(async () => { _parent.MWVM.ModListContentsVM.Value.Name = metadata.Title; - var status = await ClientAPI.GetDetailedStatus(metadata.Links.MachineURL); - var coll = _parent.MWVM.ModListContentsVM.Value.Status; - coll.Clear(); - coll.AddRange(status.Archives); - _parent.MWVM.NavigateTo(_parent.MWVM.ModListContentsVM.Value); - }); + IsLoadingIdle.OnNext(false); + try + { + var status = await ClientAPI.GetDetailedStatus(metadata.Links.MachineURL); + var coll = _parent.MWVM.ModListContentsVM.Value.Status; + coll.Clear(); + coll.AddRange(status.Archives); + _parent.MWVM.NavigateTo(_parent.MWVM.ModListContentsVM.Value); + } + finally + { + IsLoadingIdle.OnNext(true); + } + }, IsLoadingIdle.StartWith(true)); ExecuteCommand = ReactiveCommand.CreateFromObservable( canExecute: this.WhenAny(x => x.IsBroken).Select(x => !x), execute: (unit) => diff --git a/Wabbajack/View Models/ModListContentsVM.cs b/Wabbajack/View Models/ModListContentsVM.cs index cf4ec36c..cf22e431 100644 --- a/Wabbajack/View Models/ModListContentsVM.cs +++ b/Wabbajack/View Models/ModListContentsVM.cs @@ -15,7 +15,7 @@ using Wabbajack.Common; namespace Wabbajack { - public class ModListContentsVM : ViewModel + public class ModListContentsVM : BackNavigatingVM { private MainWindowVM _mwvm; [Reactive] @@ -30,10 +30,11 @@ namespace Wabbajack private readonly ReadOnlyObservableCollection _archives; public ReadOnlyObservableCollection Archives => _archives; - public ModListContentsVM(MainWindowVM mwvm) + public ModListContentsVM(MainWindowVM mwvm) : base(mwvm) { _mwvm = mwvm; Status = new ObservableCollectionExtended(); + Regex nameMatcher = new Regex(@"(?<=\.)[^\.]+(?=\+State)"); string TransformClassName(Archive a) @@ -50,11 +51,22 @@ namespace Wabbajack .Transform(a => new ModListArchive { Name = a.Name, - Size = a.Archive?.Size.ToFileSizeString(), + Size = a.Archive?.Size ?? 0, Url = a.Url ?? "", Downloader = TransformClassName(a.Archive) ?? "Unknown", Hash = a.Archive!.Hash.ToBase64() }) + .Filter(this.WhenAny(x => x.SearchString) + .StartWith("") + .Throttle(TimeSpan.FromMilliseconds(250)) + .Select>(s => (ModListArchive ar) => + string.IsNullOrEmpty(s) || + ar.Name.ContainsCaseInsensitive(s) || + ar.Downloader.ContainsCaseInsensitive(s) || + ar.Hash.ContainsCaseInsensitive(s) || + ar.Size.ToString() == s || + ar.Url.ContainsCaseInsensitive(s))) + .ObserveOnGuiThread() .Bind(out _archives) .Subscribe() .DisposeWith(CompositeDisposable); @@ -64,7 +76,7 @@ namespace Wabbajack public class ModListArchive { public string Name { get; set; } - public string Size { get; set; } + public long Size { get; set; } public string Url { get; set; } public string Downloader { get; set; } public string Hash { get; set; } diff --git a/Wabbajack/Views/ModListContentsView.xaml b/Wabbajack/Views/ModListContentsView.xaml index d2c68948..cb7a3b38 100644 --- a/Wabbajack/Views/ModListContentsView.xaml +++ b/Wabbajack/Views/ModListContentsView.xaml @@ -30,15 +30,8 @@ Text="Search" /> -