From 422d7c3572abb16594028aa5a989f782ddafdc01 Mon Sep 17 00:00:00 2001 From: Dylech30th Date: Mon, 16 Sep 2024 03:03:27 +0800 Subject: [PATCH] fix (#523) --- .../ObservableCollectionAdapter.cs | 15 ++-- .../Download/DownloadItemViewModel.cs | 2 +- .../IllustrationItemViewModel.Commands.cs | 4 +- src/Pixeval/Controls/Novel/NovelItem.xaml.cs | 87 +++++++++---------- .../Feeds/FeedItemViewModel.Condensed.cs | 5 +- .../Feeds/FeedItemViewModel.Sparse.cs | 6 +- .../Capability/Feeds/FeedItemViewModel.cs | 2 +- 7 files changed, 59 insertions(+), 62 deletions(-) diff --git a/src/Pixeval.Utilities/ObservableCollectionAdapter.cs b/src/Pixeval.Utilities/ObservableCollectionAdapter.cs index ca43513a..e5af58df 100644 --- a/src/Pixeval.Utilities/ObservableCollectionAdapter.cs +++ b/src/Pixeval.Utilities/ObservableCollectionAdapter.cs @@ -72,9 +72,10 @@ public class ObservableCollectionAdapter : ObservableCollection SourceCollection.CollectionChanged += SourceCollectionChanged; Clear(); - foreach (var element in _sourceCollection) + for (var index = 0; index < _sourceCollection.Count; index++) { - var item = TOutput.CreateInstance(element); + var element = _sourceCollection[index]; + var item = TOutput.CreateInstance(element, index); Add(item); } } @@ -92,7 +93,7 @@ public class ObservableCollectionAdapter : ObservableCollection var input = (TInput)args.NewItems[i]!; if (_filter?.Invoke(input) is false) continue; - var item = TOutput.CreateInstance(input); + var item = TOutput.CreateInstance(input, i); Insert(args.NewStartingIndex + i, item); } break; @@ -116,7 +117,7 @@ public class ObservableCollectionAdapter : ObservableCollection } else { - var item = TOutput.CreateInstance(input); + var item = TOutput.CreateInstance(input, i); this[args.OldStartingIndex + i - removedCount] = item; } } @@ -129,13 +130,15 @@ public class ObservableCollectionAdapter : ObservableCollection break; case NotifyCollectionChangedAction.Reset: Clear(); - foreach (var element in SourceCollection) + for (var index = 0; index < SourceCollection.Count; index++) { + var element = SourceCollection[index]; if (_filter?.Invoke(element) is false) continue; - var item = TOutput.CreateInstance(element); + var item = TOutput.CreateInstance(element, index); Add(item); } + break; default: ThrowUtils.ArgumentOutOfRange(args.Action); diff --git a/src/Pixeval/Controls/Download/DownloadItemViewModel.cs b/src/Pixeval/Controls/Download/DownloadItemViewModel.cs index 83c518bb..612d0ae4 100644 --- a/src/Pixeval/Controls/Download/DownloadItemViewModel.cs +++ b/src/Pixeval/Controls/Download/DownloadItemViewModel.cs @@ -73,7 +73,7 @@ public sealed partial class DownloadItemViewModel(IDownloadTaskGroup downloadTas return await base.TryLoadThumbnailAsync(key); } - public static DownloadItemViewModel CreateInstance(IDownloadTaskGroup entry) => new(entry); + public static DownloadItemViewModel CreateInstance(IDownloadTaskGroup entry, int index) => new(entry); #pragma warning disable CA1822 diff --git a/src/Pixeval/Controls/Illustration/IllustrationItemViewModel.Commands.cs b/src/Pixeval/Controls/Illustration/IllustrationItemViewModel.Commands.cs index 5eab828d..22745464 100644 --- a/src/Pixeval/Controls/Illustration/IllustrationItemViewModel.Commands.cs +++ b/src/Pixeval/Controls/Illustration/IllustrationItemViewModel.Commands.cs @@ -49,7 +49,7 @@ public partial class IllustrationItemViewModel protected override void SaveCommandOnExecuteRequested(XamlUICommand sender, ExecuteRequestedEventArgs args) { var hWnd = null as ulong?; - GetImageStream? getImageStreamAsync = null; + GetImageStreams? getImageStream = null; switch (args.Parameter) { case (ulong h, GetImageStreams f): @@ -71,7 +71,7 @@ public partial class IllustrationItemViewModel protected override async void SaveAsCommandOnExecuteRequested(XamlUICommand sender, ExecuteRequestedEventArgs args) { ulong hWnd; - GetImageStream? getImageStreamAsync = null; + GetImageStreams? getImageStream = null; switch (args.Parameter) { case (ulong h, GetImageStreams f): diff --git a/src/Pixeval/Controls/Novel/NovelItem.xaml.cs b/src/Pixeval/Controls/Novel/NovelItem.xaml.cs index fb1d517d..974cc92c 100644 --- a/src/Pixeval/Controls/Novel/NovelItem.xaml.cs +++ b/src/Pixeval/Controls/Novel/NovelItem.xaml.cs @@ -45,54 +45,49 @@ public sealed partial class NovelItem var old = _isPointerOver; _isPointerOver = value; var currentView = ConnectedAnimationService.GetForCurrentView(); - switch (IsPointerOver) + if (IsPointerOver > 0 && old <= 0) { - case > 0 when old <= 0: + var anim1 = currentView.PrepareToAnimate("ForwardConnectedAnimation1", this); + var anim2 = currentView.PrepareToAnimate("ForwardConnectedAnimation2", Image); + var anim3 = currentView.PrepareToAnimate("ForwardConnectedAnimation3", HeartButton); + var anim4 = currentView.PrepareToAnimate("ForwardConnectedAnimation4", TitleTextBlock); + var anim5 = currentView.PrepareToAnimate("ForwardConnectedAnimation5", AuthorTextBlock); + var anim6 = currentView.PrepareToAnimate("ForwardConnectedAnimation6", TagsList); + anim1.Configuration = anim2.Configuration = anim3.Configuration = + anim4.Configuration = anim5.Configuration = anim6.Configuration = + new BasicConnectedAnimationConfiguration(); + _ = anim1.TryStart(NovelItemPopup); + _ = anim2.TryStart(PopupImage); + _ = anim3.TryStart(PopupHeartButton); + _ = anim4.TryStart(PopupTitleTextBlock); + _ = anim5.TryStart(PopupAuthorButton); + _ = anim6.TryStart(PopupTagsList); + NovelItemPopup.Child.To().Width = ActualWidth + 10; + NovelItemPopup.IsOpen = true; + } + else if (IsPointerOver <= 0 && old > 0) + { + var anim1 = currentView.PrepareToAnimate("BackwardConnectedAnimation1", NovelItemPopup); + var anim2 = currentView.PrepareToAnimate("BackwardConnectedAnimation2", PopupImage); + var anim3 = currentView.PrepareToAnimate("BackwardConnectedAnimation3", PopupHeartButton); + var anim4 = currentView.PrepareToAnimate("BackwardConnectedAnimation4", PopupTitleTextBlock); + var anim5 = currentView.PrepareToAnimate("BackwardConnectedAnimation5", PopupAuthorButton); + var anim6 = currentView.PrepareToAnimate("BackwardConnectedAnimation6", PopupTagsList); + anim1.Configuration = anim2.Configuration = anim3.Configuration = + anim4.Configuration = anim5.Configuration = anim6.Configuration = + new BasicConnectedAnimationConfiguration(); + anim1.Completed += (_, _) => { - var anim1 = currentView.PrepareToAnimate("ForwardConnectedAnimation1", this); - var anim2 = currentView.PrepareToAnimate("ForwardConnectedAnimation2", Image); - var anim3 = currentView.PrepareToAnimate("ForwardConnectedAnimation3", HeartButton); - var anim4 = currentView.PrepareToAnimate("ForwardConnectedAnimation4", TitleTextBlock); - var anim5 = currentView.PrepareToAnimate("ForwardConnectedAnimation5", AuthorTextBlock); - var anim6 = currentView.PrepareToAnimate("ForwardConnectedAnimation6", TagsList); - anim1.Configuration = anim2.Configuration = anim3.Configuration = - anim4.Configuration = anim5.Configuration = anim6.Configuration = - new BasicConnectedAnimationConfiguration(); - _ = anim1.TryStart(NovelItemPopup); - _ = anim2.TryStart(PopupImage); - _ = anim3.TryStart(PopupHeartButton); - _ = anim4.TryStart(PopupTitleTextBlock); - _ = anim5.TryStart(PopupAuthorTextBlock); - _ = anim6.TryStart(PopupTagsList); - NovelItemPopup.Child.To().Width = ActualWidth + 10; - NovelItemPopup.IsOpen = true; - break; - } - case <= 0 when old > 0: - { - var anim1 = currentView.PrepareToAnimate("BackwardConnectedAnimation1", NovelItemPopup); - var anim2 = currentView.PrepareToAnimate("BackwardConnectedAnimation2", PopupImage); - var anim3 = currentView.PrepareToAnimate("BackwardConnectedAnimation3", PopupHeartButton); - var anim4 = currentView.PrepareToAnimate("BackwardConnectedAnimation4", PopupTitleTextBlock); - var anim5 = currentView.PrepareToAnimate("BackwardConnectedAnimation5", PopupAuthorTextBlock); - var anim6 = currentView.PrepareToAnimate("BackwardConnectedAnimation6", PopupTagsList); - anim1.Configuration = anim2.Configuration = anim3.Configuration = - anim4.Configuration = anim5.Configuration = anim6.Configuration = - new BasicConnectedAnimationConfiguration(); - anim1.Completed += (_, _) => - { - NovelItemPopup.IsOpen = false; - NovelItemPopup.Visibility = Visibility.Visible; - }; - _ = anim1.TryStart(this); - _ = anim2.TryStart(Image); - _ = anim3.TryStart(HeartButton); - _ = anim4.TryStart(TitleTextBlock); - _ = anim5.TryStart(AuthorTextBlock); - _ = anim6.TryStart(TagsList); - _ = Task.Delay(100).ContinueWith(_ => NovelItemPopup.Visibility = Visibility.Collapsed, TaskScheduler.FromCurrentSynchronizationContext()); - break; - } + NovelItemPopup.IsOpen = false; + NovelItemPopup.Visibility = Visibility.Visible; + }; + _ = anim1.TryStart(this); + _ = anim2.TryStart(Image); + _ = anim3.TryStart(HeartButton); + _ = anim4.TryStart(TitleTextBlock); + _ = anim5.TryStart(AuthorTextBlock); + _ = anim6.TryStart(TagsList); + _ = Task.Delay(100).ContinueWith(_ => NovelItemPopup.Visibility = Visibility.Collapsed, TaskScheduler.FromCurrentSynchronizationContext()); } } } diff --git a/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.Condensed.cs b/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.Condensed.cs index 5bb7c891..64ec983e 100644 --- a/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.Condensed.cs +++ b/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.Condensed.cs @@ -24,7 +24,6 @@ using Pixeval.Util.IO; using System.Collections.Generic; using System.Threading.Tasks; using System; -using System.Linq; using Microsoft.UI; using Pixeval.AppManagement; @@ -82,12 +81,12 @@ public class FeedItemCondensedViewModel(List entries) : AbstractFeedItemV if (entries[0]?.PostUserThumbnail is { Length: > 0 } url) { - var image = (await App.AppViewModel.MakoClient.DownloadBitmapImageAsync(url, 35)).UnwrapOrElse(await AppInfo.ImageNotAvailable.ValueAsync)!; + var image = (await App.AppViewModel.MakoClient.DownloadBitmapImageAsync(url, 35)).UnwrapOrElse(await AppInfo.ImageNotAvailable)!; UserAvatar = image; } else { - UserAvatar = await AppInfo.ImageNotAvailable.ValueAsync; + UserAvatar = await AppInfo.ImageNotAvailable; } } } diff --git a/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.Sparse.cs b/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.Sparse.cs index 23d66975..b41584d9 100644 --- a/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.Sparse.cs +++ b/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.Sparse.cs @@ -34,7 +34,7 @@ namespace Pixeval.Pages.Capability.Feeds; -public partial class FeedItemSparseViewModel(Feed entry) : AbstractFeedItemViewModel(new IFeedEntry.SparseFeedEntry(entry)), IViewModelFactory +public partial class FeedItemSparseViewModel(Feed entry) : AbstractFeedItemViewModel(new IFeedEntry.SparseFeedEntry(entry)), IFactory { [ObservableProperty] private TimelineAxisPlacement _placement; @@ -84,12 +84,12 @@ public partial class FeedItemSparseViewModel(Feed entry) : AbstractFeedItemViewM if (entry.PostUserThumbnail is { } url) { - var image = (await App.AppViewModel.MakoClient.DownloadBitmapImageAsync(url, 35)).UnwrapOrElse(await AppInfo.ImageNotAvailable.ValueAsync)!; + var image = (await App.AppViewModel.MakoClient.DownloadBitmapImageAsync(url, 35)).UnwrapOrElse(await AppInfo.ImageNotAvailable)!; UserAvatar = image; } else { - UserAvatar = await AppInfo.ImageNotAvailable.ValueAsync; + UserAvatar = await AppInfo.ImageNotAvailable; } } diff --git a/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.cs b/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.cs index e977d238..a494bc2b 100644 --- a/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.cs +++ b/src/Pixeval/Pages/Capability/Feeds/FeedItemViewModel.cs @@ -55,7 +55,7 @@ public interface IFeedEntry : IIdEntry } } -public abstract class AbstractFeedItemViewModel(IFeedEntry entry) : EntryViewModel(entry), IViewModelFactory +public abstract class AbstractFeedItemViewModel(IFeedEntry entry) : EntryViewModel(entry), IFactory { public SolidColorBrush FeedBrush => GetMostSignificantEntry()!.Type switch {