From 1962150ec63e781a153c9839772d4e94fdaf1188 Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Tue, 11 Jan 2022 13:16:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=A4=84=E7=90=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=BE=93=E5=85=A5=EF=BC=8C=E5=88=86=E5=88=AB=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DownKyi/DownKyi.csproj | 1 + DownKyi/Services/SearchService.cs | 104 ++++++++++++++++++++++ DownKyi/ViewModels/MainWindowViewModel.cs | 71 +-------------- DownKyi/ViewModels/ViewIndexViewModel.cs | 76 ++-------------- 4 files changed, 116 insertions(+), 136 deletions(-) create mode 100644 DownKyi/Services/SearchService.cs diff --git a/DownKyi/DownKyi.csproj b/DownKyi/DownKyi.csproj index 3f8e5ca..d3f6769 100644 --- a/DownKyi/DownKyi.csproj +++ b/DownKyi/DownKyi.csproj @@ -93,6 +93,7 @@ + diff --git a/DownKyi/Services/SearchService.cs b/DownKyi/Services/SearchService.cs new file mode 100644 index 0000000..f1426da --- /dev/null +++ b/DownKyi/Services/SearchService.cs @@ -0,0 +1,104 @@ +using DownKyi.Core.BiliApi.BiliUtils; +using DownKyi.Utils; +using DownKyi.ViewModels; +using Prism.Events; + +namespace DownKyi.Services +{ + public class SearchService + { + /// + /// 解析支持的输入 + /// + /// + /// + /// + /// + public bool BiliInput(string input, string parentViewName, IEventAggregator eventAggregator) + { + // 视频 + if (ParseEntrance.IsAvId(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, $"{ParseEntrance.VideoUrl}{input.ToLower()}"); + } + else if (ParseEntrance.IsAvUrl(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, input); + } + else if (ParseEntrance.IsBvId(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, $"{ParseEntrance.VideoUrl}{input}"); + } + else if (ParseEntrance.IsBvUrl(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, input); + } + // 番剧(电影、电视剧) + else if (ParseEntrance.IsBangumiSeasonId(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, $"{ParseEntrance.BangumiUrl}{input.ToLower()}"); + } + else if (ParseEntrance.IsBangumiSeasonUrl(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, input); + } + else if (ParseEntrance.IsBangumiEpisodeId(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, $"{ParseEntrance.BangumiUrl}{input.ToLower()}"); + } + else if (ParseEntrance.IsBangumiEpisodeUrl(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, input); + } + else if (ParseEntrance.IsBangumiMediaId(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, $"{ParseEntrance.BangumiMediaUrl}{input.ToLower()}"); + } + else if (ParseEntrance.IsBangumiMediaUrl(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, input); + } + // 课程 + else if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, parentViewName, input); + } + // 用户(参数传入mid) + else if (ParseEntrance.IsUserId(input)) + { + NavigateToView.NavigateToViewUserSpace(eventAggregator, ViewIndexViewModel.Tag, ParseEntrance.GetUserId(input)); + } + else if (ParseEntrance.IsUserUrl(input)) + { + NavigateToView.NavigateToViewUserSpace(eventAggregator, ViewIndexViewModel.Tag, ParseEntrance.GetUserId(input)); + } + // 收藏夹 + else if (ParseEntrance.IsFavoritesId(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewPublicFavoritesViewModel.Tag, parentViewName, ParseEntrance.GetFavoritesId(input)); + } + else if (ParseEntrance.IsFavoritesUrl(input)) + { + NavigateToView.NavigationView(eventAggregator, ViewPublicFavoritesViewModel.Tag, parentViewName, ParseEntrance.GetFavoritesId(input)); + } + else + { + return false; + } + return true; + } + + /// + /// 搜索关键词 + /// + /// + /// + /// + public void SearchKey(string key, string parentViewName, IEventAggregator eventAggregator) + { + // TODO + } + + + } +} diff --git a/DownKyi/ViewModels/MainWindowViewModel.cs b/DownKyi/ViewModels/MainWindowViewModel.cs index 5167f55..c806981 100644 --- a/DownKyi/ViewModels/MainWindowViewModel.cs +++ b/DownKyi/ViewModels/MainWindowViewModel.cs @@ -1,8 +1,8 @@ -using DownKyi.Core.BiliApi.BiliUtils; -using DownKyi.Core.Logging; +using DownKyi.Core.Logging; using DownKyi.Core.Settings; using DownKyi.Events; using DownKyi.Images; +using DownKyi.Services; using DownKyi.Utils; using Prism.Commands; using Prism.Events; @@ -353,71 +353,8 @@ namespace DownKyi.ViewModels return; } - // 视频 - if (ParseEntrance.IsAvId(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, $"{ParseEntrance.VideoUrl}{input.ToLower()}"); - } - else if (ParseEntrance.IsAvUrl(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, input); - } - else if (ParseEntrance.IsBvId(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, $"{ParseEntrance.VideoUrl}{input}"); - } - else if (ParseEntrance.IsBvUrl(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, input); - } - // 番剧(电影、电视剧) - else if (ParseEntrance.IsBangumiSeasonId(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, $"{ParseEntrance.BangumiUrl}{input.ToLower()}"); - } - else if (ParseEntrance.IsBangumiSeasonUrl(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, input); - } - else if (ParseEntrance.IsBangumiEpisodeId(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, $"{ParseEntrance.BangumiUrl}{input.ToLower()}"); - } - else if (ParseEntrance.IsBangumiEpisodeUrl(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, input); - } - else if (ParseEntrance.IsBangumiMediaId(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, $"{ParseEntrance.BangumiMediaUrl}{input.ToLower()}"); - } - else if (ParseEntrance.IsBangumiMediaUrl(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, input); - } - // 课程 - else if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, ViewIndexViewModel.Tag, input); - } - // 用户(参数传入mid) - else if (ParseEntrance.IsUserId(input)) - { - NavigateToView.NavigateToViewUserSpace(eventAggregator, ViewIndexViewModel.Tag, ParseEntrance.GetUserId(input)); - } - else if (ParseEntrance.IsUserUrl(input)) - { - NavigateToView.NavigateToViewUserSpace(eventAggregator, ViewIndexViewModel.Tag, ParseEntrance.GetUserId(input)); - } - // 收藏夹 - else if (ParseEntrance.IsFavoritesId(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewPublicFavoritesViewModel.Tag, ViewIndexViewModel.Tag, ParseEntrance.GetFavoritesId(input)); - } - else if (ParseEntrance.IsFavoritesUrl(input)) - { - NavigateToView.NavigationView(eventAggregator, ViewPublicFavoritesViewModel.Tag, ViewIndexViewModel.Tag, ParseEntrance.GetFavoritesId(input)); - } + SearchService searchService = new SearchService(); + searchService.BiliInput(input, ViewIndexViewModel.Tag, eventAggregator); } #endregion diff --git a/DownKyi/ViewModels/ViewIndexViewModel.cs b/DownKyi/ViewModels/ViewIndexViewModel.cs index 7da23ea..c052ef1 100644 --- a/DownKyi/ViewModels/ViewIndexViewModel.cs +++ b/DownKyi/ViewModels/ViewIndexViewModel.cs @@ -1,10 +1,10 @@ -using DownKyi.Core.BiliApi.BiliUtils; -using DownKyi.Core.BiliApi.Users; +using DownKyi.Core.BiliApi.Users; using DownKyi.Core.Logging; using DownKyi.Core.Settings; using DownKyi.Core.Settings.Models; using DownKyi.Core.Storage; using DownKyi.Images; +using DownKyi.Services; using DownKyi.Utils; using Prism.Commands; using Prism.Events; @@ -222,74 +222,12 @@ namespace DownKyi.ViewModels LogManager.Debug(Tag, $"InputText: {InputText}"); - // 视频 - if (ParseEntrance.IsAvId(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, $"{ParseEntrance.VideoUrl}{InputText.ToLower()}"); - } - else if (ParseEntrance.IsAvUrl(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, InputText); - } - else if (ParseEntrance.IsBvId(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, $"{ParseEntrance.VideoUrl}{InputText}"); - } - else if (ParseEntrance.IsBvUrl(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, InputText); - } - // 番剧(电影、电视剧) - else if (ParseEntrance.IsBangumiSeasonId(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, $"{ParseEntrance.BangumiUrl}{InputText.ToLower()}"); - } - else if (ParseEntrance.IsBangumiSeasonUrl(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, InputText); - } - else if (ParseEntrance.IsBangumiEpisodeId(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, $"{ParseEntrance.BangumiUrl}{InputText.ToLower()}"); - } - else if (ParseEntrance.IsBangumiEpisodeUrl(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, InputText); - } - else if (ParseEntrance.IsBangumiMediaId(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, $"{ParseEntrance.BangumiMediaUrl}{InputText.ToLower()}"); - } - else if (ParseEntrance.IsBangumiMediaUrl(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, InputText); - } - // 课程 - else if (ParseEntrance.IsCheeseSeasonUrl(InputText) || ParseEntrance.IsCheeseEpisodeUrl(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, Tag, InputText); - } - // 用户(参数传入mid) - else if (ParseEntrance.IsUserId(InputText)) - { - NavigateToView.NavigateToViewUserSpace(eventAggregator, Tag, ParseEntrance.GetUserId(InputText)); - } - else if (ParseEntrance.IsUserUrl(InputText)) - { - NavigateToView.NavigateToViewUserSpace(eventAggregator, Tag, ParseEntrance.GetUserId(InputText)); - } - // 收藏夹 - else if (ParseEntrance.IsFavoritesId(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewPublicFavoritesViewModel.Tag, Tag, ParseEntrance.GetFavoritesId(InputText)); - } - else if (ParseEntrance.IsFavoritesUrl(InputText)) - { - NavigateToView.NavigationView(eventAggregator, ViewPublicFavoritesViewModel.Tag, Tag, ParseEntrance.GetFavoritesId(InputText)); - } - // TODO 关键词搜索 - else + SearchService searchService = new SearchService(); + bool isSupport = searchService.BiliInput(InputText, Tag, eventAggregator); + if (!isSupport) { + // 关键词搜索 + searchService.SearchKey(InputText, Tag, eventAggregator); } InputText = string.Empty;