修复杂项问题 (#524)

This commit is contained in:
Poker 2024-09-16 20:51:17 +08:00
parent 422d7c3572
commit da60a5a3b2
No known key found for this signature in database
GPG Key ID: C65A6AD457D5C8F8
45 changed files with 41 additions and 64 deletions

View File

@ -30,7 +30,6 @@ public class LocalizationMetadataAttribute(Type resourceType) : Attribute
public bool IsPartial { get; init; }
}
[AttributeUsage(AttributeTargets.Class)]
public class AttachedLocalizationMetadataAttribute<T>(Type resourceType) : Attribute
{

View File

@ -1,5 +1,3 @@
using Windows.UI;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
@ -72,7 +70,6 @@ public sealed partial class TimelineUnit : ContentControl
return FoldThreshold is not -1 && ActualWidth < FoldThreshold;
}
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
if (FoldCriteria())

View File

@ -24,5 +24,5 @@ namespace Pixeval.Controls;
public interface IFactory<in T, out TSelf>
{
static abstract TSelf CreateInstance(T entry, int index);
static abstract TSelf CreateInstance(T entry);
}

View File

@ -75,7 +75,7 @@ public class ObservableCollectionAdapter<TInput, TOutput> : ObservableCollection
for (var index = 0; index < _sourceCollection.Count; index++)
{
var element = _sourceCollection[index];
var item = TOutput.CreateInstance(element, index);
var item = TOutput.CreateInstance(element);
Add(item);
}
}
@ -93,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, i);
var item = TOutput.CreateInstance(input);
Insert(args.NewStartingIndex + i, item);
}
break;
@ -117,7 +117,7 @@ public class ObservableCollectionAdapter<TInput, TOutput> : ObservableCollection
}
else
{
var item = TOutput.CreateInstance(input, i);
var item = TOutput.CreateInstance(input);
this[args.OldStartingIndex + i - removedCount] = item;
}
}
@ -135,7 +135,7 @@ public class ObservableCollectionAdapter<TInput, TOutput> : ObservableCollection
var element = SourceCollection[index];
if (_filter?.Invoke(element) is false)
continue;
var item = TOutput.CreateInstance(element, index);
var item = TOutput.CreateInstance(element);
Add(item);
}

View File

@ -20,7 +20,6 @@
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Windows.Storage;
@ -28,7 +27,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml.Media.Imaging;
using Pixeval.Controls.Windowing;
using Pixeval.Database.Managers;
using Pixeval.Download;
using Pixeval.Util.IO;
using Pixeval.Utilities;
using WinUI3Utilities;
@ -93,7 +91,6 @@ public static partial class AppInfo
public static Uri NavigationIconUri(string name) => new Uri($"ms-appx:///Assets/Images/Icons/{name}.png");
public static string ApplicationUriToPath(Uri uri)
{
if (uri.Scheme is not "ms-appx")

View File

@ -130,7 +130,7 @@ public partial record AppSettings() : IWindowSettings
public string ReverseSearchApiKey { get; set; } = "";
[SettingsEntry(Symbol.Cookies, nameof(WebCookieEntryHeader), nameof(WebCookieEntryDescription))]
public string? WebCookie { get; set; }
public string WebCookie { get; set; } = "";
[SettingsEntry(Symbol.TargetArrow, nameof(ReverseSearchResultSimilarityThresholdEntryHeader), nameof(ReverseSearchResultSimilarityThresholdEntryDescription))]
public int ReverseSearchResultSimilarityThreshold { get; set; } = 80;

View File

@ -23,13 +23,11 @@ using System.Threading.Tasks;
using LiteDB;
using Microsoft.Extensions.DependencyInjection;
using Pixeval.AppManagement;
using Pixeval.Controls;
using Pixeval.Controls.Windowing;
using Pixeval.CoreApi;
using Pixeval.CoreApi.Net;
using Pixeval.Database.Managers;
using Pixeval.Download;
using Pixeval.Download.Models;
using Pixeval.Logging;
using Pixeval.Util.IO;
using Pixeval.Util.UI;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 348 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 151 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 423 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 365 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -33,7 +33,7 @@
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" />
<TextBlock
Foreground="{ThemeResource PixevalTipTextForeground}"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind ViewModel.Entry.User.Name, Mode=OneWay}"
TextTrimming="CharacterEllipsis"

View File

@ -23,8 +23,6 @@ using System.IO;
using Windows.Foundation;
using Windows.System;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Documents;
using Pixeval.Util.UI;
using WinUI3Utilities;
using WinUI3Utilities.Attributes;

View File

@ -73,7 +73,7 @@ public sealed partial class DownloadItemViewModel(IDownloadTaskGroup downloadTas
return await base.TryLoadThumbnailAsync(key);
}
public static DownloadItemViewModel CreateInstance(IDownloadTaskGroup entry, int index) => new(entry);
public static DownloadItemViewModel CreateInstance(IDownloadTaskGroup entry) => new(entry);
#pragma warning disable CA1822

View File

@ -33,7 +33,6 @@ using Symbol = FluentIcons.Common.Symbol;
namespace Pixeval.Controls;
[DebuggerDisplay("{Entry}")]
public abstract class EntryViewModel<T>(T entry) : ObservableObject, IDisposable where T : IEntry
{

View File

@ -75,5 +75,5 @@ public class FetchEngineIncrementalSource<T, TViewModel>(IAsyncEnumerable<T?> as
protected virtual long Identifier(T entity) => entity.Id;
protected TViewModel Select(T entity, int index) => TViewModel.CreateInstance(entity, index);
protected TViewModel Select(T entity, int index) => TViewModel.CreateInstance(entity);
}

View File

@ -85,7 +85,7 @@ public sealed partial class EnumValuesExtension : MarkupExtension
EnumValuesEnum.WorkSortOption => WorkSortOptionExtension.GetItems(),
EnumValuesEnum.PrivacyPolicy => PrivacyPolicyExtension.GetItems(),
EnumValuesEnum.DownloadListOption => DownloadListOptionExtension.GetItems(),
_ => throw new ArgumentOutOfRangeException()
_ => ThrowHelper.ArgumentOutOfRange<EnumValuesEnum, object>(Type)
};
}
}

View File

@ -30,7 +30,6 @@ using System.IO;
using System.Linq;
using Pixeval.Download;
using Microsoft.Extensions.DependencyInjection;
using Pixeval.Download.Models;
using Pixeval.Util.IO;
using Symbol = FluentIcons.Common.Symbol;

View File

@ -35,7 +35,7 @@ namespace Pixeval.Controls;
/// </summary>
public partial class IllustrationItemViewModel : WorkEntryViewModel<Illustration>, IFactory<Illustration, IllustrationItemViewModel>
{
public static IllustrationItemViewModel CreateInstance(Illustration entry, int _) => new(entry);
public static IllustrationItemViewModel CreateInstance(Illustration entry) => new(entry);
public IllustrationItemViewModel(Illustration illustration) : base(illustration)
{

View File

@ -26,7 +26,7 @@ namespace Pixeval.Controls;
public sealed partial class IllustratorItemViewModel : EntryViewModel<User>, IFactory<User, IllustratorItemViewModel>
{
public static IllustratorItemViewModel CreateInstance(User entry, int _) => new(entry);
public static IllustratorItemViewModel CreateInstance(User entry) => new(entry);
[ObservableProperty]
private bool _isFollowed;

View File

@ -28,7 +28,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml.Controls;
using Pixeval.CoreApi.Model;
using Pixeval.Download;
using Pixeval.Download.Models;
using Pixeval.Util.UI;
namespace Pixeval.Controls;

View File

@ -27,7 +27,7 @@ namespace Pixeval.Controls;
public partial class NovelItemViewModel(Novel novel) : WorkEntryViewModel<Novel>(novel), IFactory<Novel, NovelItemViewModel>
{
public static NovelItemViewModel CreateInstance(Novel entry, int _) => new(entry);
public static NovelItemViewModel CreateInstance(Novel entry) => new(entry);
public int TextLength => Entry.TextLength;

View File

@ -26,7 +26,7 @@ namespace Pixeval.Controls;
public partial class SpotlightItemViewModel : ThumbnailEntryViewModel<Spotlight>, IFactory<Spotlight, SpotlightItemViewModel>
{
public static SpotlightItemViewModel CreateInstance(Spotlight entry, int _) => new(entry);
public static SpotlightItemViewModel CreateInstance(Spotlight entry) => new(entry);
public SpotlightItemViewModel(Spotlight spotlight) : base(spotlight) => InitializeCommandsBase();

View File

@ -23,18 +23,14 @@ using Windows.System;
using Microsoft.UI.Xaml.Input;
using Pixeval.Util.UI;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using FluentIcons.Common;
using Pixeval.CoreApi.Model;
using Pixeval.Utilities;
namespace Pixeval.Controls;
public partial class WorkEntryViewModel<T>
{
/// <summary>
/// Parameter: <see cref="ValueTuple{T1, T2, T3}"/>
/// <list type="bullet">
@ -125,7 +121,6 @@ public partial class WorkEntryViewModel<T>
private void AddToBookmarkCommandOnExecuteRequested(XamlUICommand sender, ExecuteRequestedEventArgs args)
{
if (args.Parameter is not (IEnumerable<string> userTags, bool isPrivate, var parameter))
return;
IsBookmarked = true;

View File

@ -20,12 +20,10 @@
using Pixeval.Utilities;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
namespace Pixeval.Controls;
public partial class WorkEntryViewModel<T>
{
private readonly Debounce<BookmarkDebounceTag, bool> _bookmarkDebounce = new();

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Windows.Foundation;

View File

@ -27,7 +27,6 @@ using System.Threading.Tasks;
using Pixeval.Controls;
using Pixeval.CoreApi.Model;
using Pixeval.Database;
using Pixeval.Download.Macros;
using Pixeval.Options;
using Pixeval.Util;
using Pixeval.Util.IO;

View File

@ -26,6 +26,7 @@ using System.Threading.Tasks;
using System;
using Microsoft.UI;
using Pixeval.AppManagement;
using WinUI3Utilities;
namespace Pixeval.Pages.Capability.Feeds;
@ -36,11 +37,11 @@ public class FeedItemCondensedViewModel(List<Feed?> entries) : AbstractFeedItemV
GC.SuppressFinalize(this);
}
public override Uri AppUri => throw new NotSupportedException("AppUri is not supported for condensed feeds");
public override Uri AppUri => ThrowHelper.NotSupported<Uri>("AppUri is not supported for condensed feeds");
public override Uri WebUri => throw new NotSupportedException("WebUri is not supported for condensed feeds");
public override Uri WebUri => ThrowHelper.NotSupported<Uri>("WebUri is not supported for condensed feeds");
public override Uri PixEzUri => throw new NotSupportedException("PixEzUri is not supported for condensed feeds");
public override Uri PixEzUri => ThrowHelper.NotSupported<Uri>("PixEzUri is not supported for condensed feeds");
private ImageSource? _userAvatar;

View File

@ -29,11 +29,10 @@ using System.Threading.Tasks;
using System;
using Microsoft.UI;
using Pixeval.AppManagement;
using WinUI3Utilities;
namespace Pixeval.Pages.Capability.Feeds;
public partial class FeedItemSparseViewModel(Feed entry) : AbstractFeedItemViewModel(new IFeedEntry.SparseFeedEntry(entry)), IFactory<Feed, FeedItemSparseViewModel>
{
[ObservableProperty]
@ -67,7 +66,7 @@ public partial class FeedItemSparseViewModel(Feed entry) : AbstractFeedItemViewM
set => SetProperty(ref _itemBackground, value);
}
public static FeedItemSparseViewModel CreateInstance(Feed entry, int index)
public static FeedItemSparseViewModel CreateInstance(Feed entry)
{
return new FeedItemSparseViewModel(entry);
}
@ -103,7 +102,7 @@ public partial class FeedItemSparseViewModel(Feed entry) : AbstractFeedItemViewM
FeedType.AddBookmark or FeedType.PostIllust => MakoHelper.GenerateIllustrationAppUri(entry.Id),
FeedType.AddFavorite => MakoHelper.GenerateUserAppUri(entry.Id),
FeedType.AddNovelBookmark => MakoHelper.GenerateNovelAppUri(entry.Id),
_ => throw new ArgumentOutOfRangeException()
_ => ThrowHelper.ArgumentOutOfRange<FeedType?, Uri>(entry.Type)
};
public override Uri WebUri => entry.Type switch
@ -111,7 +110,7 @@ public partial class FeedItemSparseViewModel(Feed entry) : AbstractFeedItemViewM
FeedType.AddBookmark or FeedType.PostIllust => MakoHelper.GenerateIllustrationWebUri(entry.Id),
FeedType.AddFavorite => MakoHelper.GenerateUserWebUri(entry.Id),
FeedType.AddNovelBookmark => MakoHelper.GenerateNovelWebUri(entry.Id),
_ => throw new ArgumentOutOfRangeException()
_ => ThrowHelper.ArgumentOutOfRange<FeedType?, Uri>(entry.Type)
};
public override Uri PixEzUri => entry.Type switch
@ -119,6 +118,6 @@ public partial class FeedItemSparseViewModel(Feed entry) : AbstractFeedItemViewM
FeedType.AddBookmark or FeedType.PostIllust => MakoHelper.GenerateIllustrationPixEzUri(entry.Id),
FeedType.AddFavorite => MakoHelper.GenerateUserPixEzUri(entry.Id),
FeedType.AddNovelBookmark => MakoHelper.GenerateNovelPixEzUri(entry.Id),
_ => throw new ArgumentOutOfRangeException()
_ => ThrowHelper.ArgumentOutOfRange<FeedType?, Uri>(entry.Type)
};
}

View File

@ -18,7 +18,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -29,6 +28,7 @@ using Microsoft.UI.Xaml.Media;
using Pixeval.Controls;
using Pixeval.CoreApi.Model;
using Pixeval.Util.UI;
using WinUI3Utilities;
#pragma warning disable CS9107 // Parameter is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well.
@ -51,7 +51,7 @@ public interface IFeedEntry : IIdEntry
public record CondensedFeedEntry(List<Feed?> Entries) : IFeedEntry
{
public long Id => Entries.First()?.Id ?? 0;
public long Id => Entries[0]?.Id ?? 0;
}
}
@ -63,7 +63,7 @@ public abstract class AbstractFeedItemViewModel(IFeedEntry entry) : EntryViewMod
FeedType.AddFavorite => FeedItemColors.AddFavorite,
FeedType.PostIllust => FeedItemColors.PostIllust,
FeedType.AddNovelBookmark => FeedItemColors.AddNovelBookmark,
_ => throw new ArgumentOutOfRangeException()
_ => ThrowHelper.ArgumentOutOfRange<FeedType, SolidColorBrush?>(default)
};
public abstract ImageSource UserAvatar { get; protected set; }
@ -86,24 +86,27 @@ public abstract class AbstractFeedItemViewModel(IFeedEntry entry) : EntryViewMod
ItemBackground = value ? new SolidColorBrush(selectedBackground) : new SolidColorBrush(Colors.Transparent);
}
public static AbstractFeedItemViewModel CreateInstance(IFeedEntry entry, int index)
public static AbstractFeedItemViewModel CreateInstance(IFeedEntry entry)
{
return entry switch
{
IFeedEntry.SparseFeedEntry(var feed) => new FeedItemSparseViewModel(feed),
IFeedEntry.CondensedFeedEntry condensed => new FeedItemCondensedViewModel(condensed.Entries),
_ => throw new ArgumentOutOfRangeException()
_ => ThrowHelper.ArgumentOutOfRange<IFeedEntry, AbstractFeedItemViewModel?>(entry)
};
}
// Reify the entry from IFeedEntry.
/// <summary>
/// Reify the entry from IFeedEntry.
/// </summary>
/// <returns></returns>
public Feed? GetMostSignificantEntry()
{
return Entry switch
{
IFeedEntry.SparseFeedEntry(var feed) => feed,
IFeedEntry.CondensedFeedEntry condensed => condensed.Entries.First(),
_ => throw new ArgumentOutOfRangeException()
_ => ThrowHelper.ArgumentOutOfRange<IFeedEntry, Feed?>(Entry)
};
}
}

View File

@ -23,7 +23,6 @@ using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using Pixeval.Controls;
using Pixeval.CoreApi.Model;
namespace Pixeval.Pages.Capability.Feeds;
@ -42,7 +41,6 @@ public partial class FeedPageViewModel : EntryViewViewModel<IFeedEntry, Abstract
public FeedPageViewModel() : this(new SharableViewDataProvider<IFeedEntry, AbstractFeedItemViewModel>())
{
}
public override IDataProvider<IFeedEntry, AbstractFeedItemViewModel> DataProvider { get; }

View File

@ -18,8 +18,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Diagnostics;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Pixeval.CoreApi.Global.Enum;

View File

@ -125,7 +125,7 @@ public sealed partial class MainPage
// args.SelectedItem may be null here
if (sender.SelectedItem is NavigationViewItem { Tag: NavigationViewTag tag } selectedItem)
{
if (Equals(selectedItem, FeedTab) && App.AppViewModel.AppSettings.WebCookie.IsNullOrBlank())
if (Equals(selectedItem, FeedTab) && App.AppViewModel.AppSettings.WebCookie is "")
{
_ = this.CreateAcknowledgementAsync(MainPageResources.FeedTabCannotBeOpenedTitle, MainPageResources.FeedTabCannotBeOpenedContent);
sender.SelectedItem = _lastSelected;

View File

@ -64,7 +64,6 @@ public sealed partial class NovelViewerPage
ThumbnailItemsView.StartBringItemIntoView(vm.CurrentNovelIndex, new BringIntoViewOptions { AnimationDesired = true });
};
_viewModel.PropertyChanged += (sender, args) =>
{
var vm = sender.To<NovelViewerPageViewModel>();

View File

@ -129,5 +129,9 @@ public partial class TagsEntryViewModel : ObservableObject, IEntry, IDisposable
entry.Thumbnail = await (await IoHelper.GetFileThumbnailAsync(path)).GetSoftwareBitmapSourceAsync(true);
}
public void Dispose() => Thumbnail?.Dispose();
public void Dispose()
{
GC.SuppressFinalize(this);
Thumbnail?.Dispose();
}
}

View File

@ -84,7 +84,6 @@ public static partial class NovelRankOptionExtension
];
}
[AttachedLocalizationMetadata<TargetFilter>(typeof(MiscResources))]
[AttachedLocalizedResource(nameof(TargetFilter.ForAndroid), nameof(MiscResources.TargetFilterForAndroid))]
[AttachedLocalizedResource(nameof(TargetFilter.ForIos), nameof(MiscResources.TargetFilterForIOS))]

View File

@ -1,4 +1,4 @@
#region Copyright (c) Pixeval/Pixeval
#region Copyright (c) Pixeval/Pixeval
// GPL v3 License
//
// Pixeval/Pixeval
@ -35,7 +35,6 @@ public class DoubleValueAnimation(TimeSpan duration,
double to,
IEasingFunction<double>? easingFunction = null) : this(duration, TimeSpan.FromMilliseconds(10), from, to, easingFunction)
{
}
public override TimeSpan Duration { get; } = duration;
@ -47,4 +46,4 @@ public class DoubleValueAnimation(TimeSpan duration,
public override double To { get; } = to;
public override IEasingFunction<double>? EasingFunction { get; } = easingFunction;
}
}