Skip to content

Commit 6bf03de

Browse files
committed
feat: 减少视频解析页面接口调用次数
1 parent 0a5a13c commit 6bf03de

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/DownKyi/ViewModels/ViewVideoDetailViewModel.cs

+27-15
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class ViewVideoDetailViewModel : BaseViewModel
3434
// 保存输入字符串,避免被用户修改
3535
private string input = null;
3636

37+
// 保存当前页面服务,减少new的开销和接口调用次数
38+
private IInfoService infoService;
39+
3740
#region 页面属性申明
3841

3942
private VectorImage arrowBack;
@@ -233,7 +236,7 @@ await Task.Run(() =>
233236
input = InputText;
234237

235238
// 更新页面
236-
UnityUpdateView(UpdateView, input, null);
239+
UnityUpdateView(UpdateView, input, null, true);
237240

238241
// 是否自动解析视频
239242
if (SettingsManager.GetInstance().IsAutoParseVideo() == AllowStatus.YES)
@@ -410,7 +413,7 @@ await Task.Run(() =>
410413
{
411414
LogManager.Debug(Tag, $"Video Page: {videoPage.Cid}");
412415

413-
UnityUpdateView(ParseVideo, input, videoPage);
416+
UnityUpdateView(ParseVideo, input, videoPage, true);
414417
});
415418
}
416419
catch (Exception e)
@@ -635,25 +638,34 @@ private void InitView()
635638
/// <param name="action"></param>
636639
/// <param name="input"></param>
637640
/// <param name="page"></param>
638-
private void UnityUpdateView(Action<IInfoService, VideoPage> action, string input, VideoPage page)
641+
/// <param name="force">强制new</param>
642+
private void UnityUpdateView(Action<IInfoService, VideoPage> action, string input, VideoPage page,bool force = false)
639643
{
640-
// 视频
641-
if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input))
644+
if (infoService == null || force)
642645
{
643-
action(new VideoInfoService(input), page);
644-
}
646+
// 视频
647+
if (ParseEntrance.IsAvUrl(input) || ParseEntrance.IsBvUrl(input))
648+
{
649+
infoService = new VideoInfoService(input);
650+
}
645651

646-
// 番剧(电影、电视剧)
647-
if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input))
648-
{
649-
action(new BangumiInfoService(input), page);
650-
}
652+
// 番剧(电影、电视剧)
653+
if (ParseEntrance.IsBangumiSeasonUrl(input) || ParseEntrance.IsBangumiEpisodeUrl(input) || ParseEntrance.IsBangumiMediaUrl(input))
654+
{
655+
infoService = new BangumiInfoService(input);
656+
}
651657

652-
// 课程
653-
if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input))
658+
// 课程
659+
if (ParseEntrance.IsCheeseSeasonUrl(input) || ParseEntrance.IsCheeseEpisodeUrl(input))
660+
{
661+
infoService = new CheeseInfoService(input);
662+
}
663+
}
664+
if (infoService == null)
654665
{
655-
action(new CheeseInfoService(input), page);
666+
return;
656667
}
668+
action(infoService, page);
657669
}
658670

659671
/// <summary>

0 commit comments

Comments
 (0)