Skip to content

Commit 841ff84

Browse files
committed
Subject Search Completion
1 parent c0cc1cc commit 841ff84

31 files changed

+660
-62
lines changed

BangumiNet.Api/ExtraEnums/SubjectType.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,18 @@ public enum SubjectType
2525
/// 三次元
2626
/// </summary>
2727
RealLife = 6,
28-
}
28+
}
29+
30+
public static partial class EnumExtensions
31+
{
32+
public static string ToStringSC(this SubjectType type)
33+
=> type switch
34+
{
35+
SubjectType.Book => "书籍",
36+
SubjectType.Anime => "动画",
37+
SubjectType.Music => "音乐",
38+
SubjectType.Game => "游戏",
39+
SubjectType.RealLife => "三次元",
40+
_ => throw new NotImplementedException(),
41+
};
42+
}

BangumiNet.Shared/Settings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Settings : IApiSettings
2525
public string EpCmBg { get; set; } = "#7f7f7f7f";
2626
public string EpMadBg { get; set; } = "#7f7f7f7f";
2727
public string EpOtherBg { get; set; } = "#7f7f7f7f";
28-
public string EpNullBg { get; set; } = "#ffff0000";
2928

30-
public string ConfirmBg { get; set; } = "";
29+
public string ErrorBg { get; set; } = "#7fff7f7f";
30+
public string OkBg { get; set; } = "#7f7fff7f";
3131
}

BangumiNet/App.axaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
xmlns:ice="using:FluentIcons.Avalonia.MarkupExtensions"
77
xmlns:sty="using:FluentAvalonia.Styling"
88
xmlns:utils="using:BangumiNet.Utils"
9+
xmlns:cvt="using:BangumiNet.Converters"
910
RequestedThemeVariant="Default">
1011

1112
<Application.DataTemplates>
@@ -15,7 +16,7 @@
1516
<Application.Styles>
1617
<sty:FluentAvaloniaTheme PreferSystemTheme="True" PreferUserAccentColor="True"/>
1718
<Style Selector="Border.Card">
18-
<Setter Property="BorderBrush" Value="Gray"/>
19+
<Setter Property="BorderBrush" Value="#7f000000"/>
1920
<Setter Property="BorderThickness" Value="1"/>
2021
<Setter Property="CornerRadius" Value="10"/>
2122
<Setter Property="BoxShadow" Value="0 0 10 0 LightGray"/>
@@ -65,4 +66,18 @@
6566
<Setter Property="Background" Value="#BF7FFF7F"/>
6667
</Style>
6768
</Application.Styles>
69+
70+
<Application.Resources>
71+
<cvt:NEWCvt x:Key="NEWCvt"/>
72+
<cvt:EpBrushCvt x:Key="EpBrushCvt"/>
73+
<cvt:InNullCvt x:Key="InNullCvt"/>
74+
<cvt:NullCvt x:Key="NullCvt"/>
75+
<cvt:NameCnCvt x:Key="NameCnCvt"/>
76+
<cvt:SearchSortCvt x:Key="SearchSortCvt"/>
77+
<cvt:SearchTypeCvt x:Key="SearchTypeCvt"/>
78+
<x:Double x:Key="TextControlThemeMinHeight">0</x:Double>
79+
<x:Double x:Key="DatePickerThemeMinWidth">100</x:Double>
80+
<Thickness x:Key="DatePickerHostPadding">0,0,0,0</Thickness>
81+
<Thickness x:Key="DatePickerHostMonthPadding">5,0,0,0</Thickness>
82+
</Application.Resources>
6883
</Application>

BangumiNet/App.axaml.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using Avalonia;
22
using Avalonia.Controls;
33
using Avalonia.Controls.ApplicationLifetimes;
4-
using Avalonia.Data.Converters;
54
using Avalonia.Markup.Xaml;
6-
using BangumiNet.Converters;
5+
using Avalonia.Media;
76
using BangumiNet.ViewModels;
87
using BangumiNet.Views;
98
using System.Net;
@@ -19,18 +18,13 @@ public override void OnFrameworkInitializationCompleted()
1918
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
2019
desktop.MainWindow = new MainWindow { DataContext = new MainWindowViewModel() };
2120

22-
AddConverter(NameCnCvt.Instance);
23-
AddConverter(NullCvt.Instance);
24-
AddConverter(InNullCvt.Instance);
25-
AddConverter(EpBrushCvt.Instance);
21+
Resources["ErrorBg"] = Brush.Parse(SettingProvider.CurrentSettings.ErrorBg);
22+
Resources["OkBg"] = Brush.Parse(SettingProvider.CurrentSettings.OkBg);
2623

2724
CacheProvider.CalculateCacheSize();
2825

2926
TextBlock.TextProperty.Changed.AddClassHandler<TextBlock>((tb, e) => tb.Text = WebUtility.HtmlDecode(tb.Text));
3027

3128
base.OnFrameworkInitializationCompleted();
3229
}
33-
34-
private void AddConverter(IValueConverter res)
35-
=> Resources[res.GetType().Name] = res;
3630
}

BangumiNet/BangumiNet.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@
3535
<PrivateAssets>all</PrivateAssets>
3636
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3737
</PackageReference>
38-
<PackageReference Include="Svg.Controls.Skia.Avalonia" Version="11.3.0.4" />
38+
<PackageReference Include="Svg.Controls.Skia.Avalonia" Version="11.3.6.2" />
3939
</ItemGroup>
4040

4141
<ItemGroup>
4242
<ProjectReference Include="..\BangumiNet.Api\BangumiNet.Api.csproj" />
4343
<ProjectReference Include="..\BangumiNet.Shared\BangumiNet.Shared.csproj" />
4444
</ItemGroup>
45+
46+
<ItemGroup>
47+
<Compile Update="Views\SubjectListView.axaml.cs">
48+
<DependentUpon>SubjectListView.axaml</DependentUpon>
49+
</Compile>
50+
</ItemGroup>
4551
</Project>

BangumiNet/Converters/EnumCvt.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Avalonia.Data.Converters;
2+
using BangumiNet.Api.V0.V0.Search.Subjects;
3+
using BangumiNet.ViewModels;
4+
using System.Globalization;
5+
6+
namespace BangumiNet.Converters;
7+
8+
public class SearchSortCvt : IValueConverter
9+
{
10+
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
11+
=> (SubjectsPostRequestBody_sort?)value switch
12+
{
13+
SubjectsPostRequestBody_sort.Match => "相关",
14+
SubjectsPostRequestBody_sort.Heat => "热度",
15+
SubjectsPostRequestBody_sort.Rank => "排名",
16+
SubjectsPostRequestBody_sort.Score => "评分",
17+
null => "默认",
18+
_ => throw new NotImplementedException(),
19+
};
20+
21+
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
22+
=> throw new NotImplementedException();
23+
}
24+
public class SearchTypeCvt : IValueConverter
25+
{
26+
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
27+
=> (SearchType?)value switch
28+
{
29+
SearchType.Subject => "项目",
30+
SearchType.Character => "角色",
31+
SearchType.Person => "人物",
32+
null => string.Empty,
33+
_ => throw new NotImplementedException(),
34+
};
35+
36+
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
37+
=> throw new NotImplementedException();
38+
}

BangumiNet/Converters/EpBrushCvt.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class EpBrushCvt : IValueConverter
1212
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
1313
=> throw new NotImplementedException();
1414

15-
public static EpBrushCvt Instance { get; } = new();
1615
public static IBrush? Convert(object? obj)
1716
=> (obj as EpisodeType?) switch
1817
{
@@ -23,7 +22,7 @@ public class EpBrushCvt : IValueConverter
2322
EpisodeType.Advertisement => Brush.Parse(SettingProvider.CurrentSettings.EpCmBg),
2423
EpisodeType.Mad => Brush.Parse(SettingProvider.CurrentSettings.EpMadBg),
2524
EpisodeType.Other => Brush.Parse(SettingProvider.CurrentSettings.EpOtherBg),
26-
null => Brush.Parse(SettingProvider.CurrentSettings.EpNullBg),
25+
null => Brush.Parse(SettingProvider.CurrentSettings.ErrorBg),
2726
_ => throw new NotImplementedException(),
2827
};
2928
}

BangumiNet/Converters/NameCnCvt.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class NameCnCvt : IValueConverter
1111
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
1212
=> throw new NotImplementedException();
1313

14-
public static NameCnCvt Instance { get; } = new();
1514
public static string? Convert(object? obj)
1615
{
1716
if (obj is not { } subject) return "Null";

BangumiNet/Converters/NullCvt.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@ namespace BangumiNet.Converters;
55

66
public class NullCvt : IValueConverter
77
{
8-
public static NullCvt Instance { get; } = new();
98
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
109
=> value != null;
1110
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
1211
=> throw new NotImplementedException();
1312
}
1413
public class InNullCvt : IValueConverter
1514
{
16-
public static InNullCvt Instance { get; } = new();
1715
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
1816
=> value == null;
1917
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
2018
=> throw new NotImplementedException();
2119
}
20+
public class NEWCvt : IValueConverter
21+
{
22+
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
23+
=> !string.IsNullOrWhiteSpace((string?)value);
24+
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
25+
=> throw new NotImplementedException();
26+
}

BangumiNet/Utils/Common.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ public static class Common
88
/// 将 Bangumi 的日期 string 转换为 <see cref="DateOnly"/>.
99
/// </summary>
1010
/// <param name="date"><c>yyyy-MM-dd</c></param>
11-
/// <returns></returns>
12-
public static DateOnly? ParseDate(string? date)
11+
public static DateOnly? ParseBangumiDate(string? date)
1312
{
1413
if (DateOnly.TryParseExact(date, "yyyy-MM-dd", out DateOnly result))
1514
return result;

0 commit comments

Comments
 (0)