This commit is contained in:
Dylech30th 2024-09-16 03:03:27 +08:00 committed by Poker
parent ddcb9ca9c0
commit 422d7c3572
No known key found for this signature in database
GPG Key ID: C65A6AD457D5C8F8
7 changed files with 59 additions and 62 deletions

View File

@ -72,9 +72,10 @@ public class ObservableCollectionAdapter<TInput, TOutput> : 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<TInput, TOutput> : 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<TInput, TOutput> : 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<TInput, TOutput> : 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);

View File

@ -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

View File

@ -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):

View File

@ -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<FrameworkElement>().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<FrameworkElement>().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());
}
}
}

View File

@ -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<Feed?> 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;
}
}
}

View File

@ -34,7 +34,7 @@ namespace Pixeval.Pages.Capability.Feeds;
public partial class FeedItemSparseViewModel(Feed entry) : AbstractFeedItemViewModel(new IFeedEntry.SparseFeedEntry(entry)), IViewModelFactory<Feed, FeedItemSparseViewModel>
public partial class FeedItemSparseViewModel(Feed entry) : AbstractFeedItemViewModel(new IFeedEntry.SparseFeedEntry(entry)), IFactory<Feed, FeedItemSparseViewModel>
{
[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;
}
}

View File

@ -55,7 +55,7 @@ public interface IFeedEntry : IIdEntry
}
}
public abstract class AbstractFeedItemViewModel(IFeedEntry entry) : EntryViewModel<IFeedEntry>(entry), IViewModelFactory<IFeedEntry, AbstractFeedItemViewModel>
public abstract class AbstractFeedItemViewModel(IFeedEntry entry) : EntryViewModel<IFeedEntry>(entry), IFactory<IFeedEntry, AbstractFeedItemViewModel>
{
public SolidColorBrush FeedBrush => GetMostSignificantEntry()!.Type switch
{