@@ -34,6 +34,9 @@ public class ViewVideoDetailViewModel : BaseViewModel
34
34
// 保存输入字符串,避免被用户修改
35
35
private string input = null ;
36
36
37
+ // 保存当前页面服务,减少new的开销和接口调用次数
38
+ private IInfoService infoService ;
39
+
37
40
#region 页面属性申明
38
41
39
42
private VectorImage arrowBack ;
@@ -233,7 +236,7 @@ await Task.Run(() =>
233
236
input = InputText ;
234
237
235
238
// 更新页面
236
- UnityUpdateView ( UpdateView , input , null ) ;
239
+ UnityUpdateView ( UpdateView , input , null , true ) ;
237
240
238
241
// 是否自动解析视频
239
242
if ( SettingsManager . GetInstance ( ) . IsAutoParseVideo ( ) == AllowStatus . YES )
@@ -410,7 +413,7 @@ await Task.Run(() =>
410
413
{
411
414
LogManager . Debug ( Tag , $ "Video Page: { videoPage . Cid } ") ;
412
415
413
- UnityUpdateView ( ParseVideo , input , videoPage ) ;
416
+ UnityUpdateView ( ParseVideo , input , videoPage , true ) ;
414
417
} ) ;
415
418
}
416
419
catch ( Exception e )
@@ -635,25 +638,34 @@ private void InitView()
635
638
/// <param name="action"></param>
636
639
/// <param name="input"></param>
637
640
/// <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 )
639
643
{
640
- // 视频
641
- if ( ParseEntrance . IsAvUrl ( input ) || ParseEntrance . IsBvUrl ( input ) )
644
+ if ( infoService == null || force )
642
645
{
643
- action ( new VideoInfoService ( input ) , page ) ;
644
- }
646
+ // 视频
647
+ if ( ParseEntrance . IsAvUrl ( input ) || ParseEntrance . IsBvUrl ( input ) )
648
+ {
649
+ infoService = new VideoInfoService ( input ) ;
650
+ }
645
651
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
+ }
651
657
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 )
654
665
{
655
- action ( new CheeseInfoService ( input ) , page ) ;
666
+ return ;
656
667
}
668
+ action ( infoService , page ) ;
657
669
}
658
670
659
671
/// <summary>
0 commit comments