Merge pull request #937 from yaobiao131/main

feat: 减少视频解析页面接口调用次数
This commit is contained in:
leiurayer 2023-12-14 19:17:45 +08:00 committed by GitHub
commit 29c6aa0375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,6 +34,9 @@ namespace DownKyi.ViewModels
// 保存输入字符串,避免被用户修改 // 保存输入字符串,避免被用户修改
private string input = null; private string input = null;
// 保存当前页面服务减少new的开销和接口调用次数
private IInfoService infoService;
#region #region
private VectorImage arrowBack; private VectorImage arrowBack;
@ -233,7 +236,7 @@ namespace DownKyi.ViewModels
input = InputText; input = InputText;
// 更新页面 // 更新页面
UnityUpdateView(UpdateView, input, null); UnityUpdateView(UpdateView, input, null, true);
// 是否自动解析视频 // 是否自动解析视频
if (SettingsManager.GetInstance().IsAutoParseVideo() == AllowStatus.YES) if (SettingsManager.GetInstance().IsAutoParseVideo() == AllowStatus.YES)
@ -410,7 +413,7 @@ namespace DownKyi.ViewModels
{ {
LogManager.Debug(Tag, $"Video Page: {videoPage.Cid}"); LogManager.Debug(Tag, $"Video Page: {videoPage.Cid}");
UnityUpdateView(ParseVideo, input, videoPage); UnityUpdateView(ParseVideo, input, videoPage, true);
}); });
} }
catch (Exception e) catch (Exception e)
@ -635,26 +638,35 @@ namespace DownKyi.ViewModels
/// <param name="action"></param> /// <param name="action"></param>
/// <param name="input"></param> /// <param name="input"></param>
/// <param name="page"></param> /// <param name="page"></param>
private void UnityUpdateView(Action<IInfoService, VideoPage> action, string input, VideoPage page) /// <param name="force">强制new</param>
private void UnityUpdateView(Action<IInfoService, VideoPage> action, string input, VideoPage page,bool force = false)
{
if (infoService == null || force)
{ {
// 视频 // 视频
if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input)) if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input))
{ {
action(new VideoInfoService(input), page); infoService = new VideoInfoService(input);
} }
// 番剧(电影、电视剧) // 番剧(电影、电视剧)
if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input)) if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input))
{ {
action(new BangumiInfoService(input), page); infoService = new BangumiInfoService(input);
} }
// 课程 // 课程
if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input)) if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input))
{ {
action(new CheeseInfoService(input), page); infoService = new CheeseInfoService(input);
} }
} }
if (infoService == null)
{
return;
}
action(infoService, page);
}
/// <summary> /// <summary>
/// 更新页面 /// 更新页面