From 84c122dccc5659652148bddf937eabb8e12a3644 Mon Sep 17 00:00:00 2001 From: kuangxj Date: Wed, 8 May 2024 02:19:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Morin.Shared/Models/FavoriteModel.cs | 2 +- .../ViewModels/Account/AccountViewModel.cs | 6 ---- .../ViewModels/Players/PlayerViewModel.cs | 34 ++++++++++++------- Morin.Wpf/ViewModels/ShellViewModel.cs | 20 ++++++++--- Morin.Wpf/ViewModels/Videos/VideoViewModel.cs | 6 ++-- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/Morin.Shared/Models/FavoriteModel.cs b/Morin.Shared/Models/FavoriteModel.cs index e1b64fc..c211c19 100644 --- a/Morin.Shared/Models/FavoriteModel.cs +++ b/Morin.Shared/Models/FavoriteModel.cs @@ -5,7 +5,7 @@ namespace Morin.Shared.Models; public class FavoriteModel : Model { [JsonIgnore] - public string Key => $"{VodSourceID}|{VodId}|{Episode}"; + public string Key => $"{VodSourceID}|{VodId}"; public int VodSourceID { get; set; } [JsonIgnore] public string? VodSourceTitle { get; set; } diff --git a/Morin.Wpf/ViewModels/Account/AccountViewModel.cs b/Morin.Wpf/ViewModels/Account/AccountViewModel.cs index 990aee4..048dba3 100644 --- a/Morin.Wpf/ViewModels/Account/AccountViewModel.cs +++ b/Morin.Wpf/ViewModels/Account/AccountViewModel.cs @@ -28,12 +28,6 @@ protected override void OnInitialActivate() { base.OnInitialActivate(); SetMenusAsync("我的"); - - // 加载历史观看 - appService?.LoadHistoryViews(); - - // 加载收藏 - appService?.LoadFavorites(); } private void SetDefaultMenu() { diff --git a/Morin.Wpf/ViewModels/Players/PlayerViewModel.cs b/Morin.Wpf/ViewModels/Players/PlayerViewModel.cs index fcd6103..3d9519b 100644 --- a/Morin.Wpf/ViewModels/Players/PlayerViewModel.cs +++ b/Morin.Wpf/ViewModels/Players/PlayerViewModel.cs @@ -30,7 +30,7 @@ public class PlayerViewModel(IEventAggregator eventAggregator, private readonly IMapper mapper = mapper; private readonly ISnackbarMessageQueue snackbarMessageQueue = snackbarMessageQueue; public WindowState WindowState { get; set; } - public bool IsPlay { get; set; } + public bool IsPlay { get; set; } public bool IsFavorite { get; set; } private VideoSettingsConfig videoSettings; private List playSkipTimes; @@ -85,25 +85,28 @@ public bool SkipTimeSwitch } } private VideoModel curVideo; - private Dictionary IsSkipTimeDict = []; + private Dictionary SkipTimeStateDict = []; public PlayerListViewModel? PlayerListView { get; set; } public void Handle(OnEpisodeChangedMessage message) { - if (message.Model != null && message.Model.VodPlayUrl.EndsWith("m3u8")) + if (message.Model != null ) { curVideo = message.Model; + // 设置收藏状态 + SetFavoriteState(message.Model); + // 初始化跳转记录 - IsSkipTimeDict.TryAdd(curVideo.Key, false); + SkipTimeStateDict.TryAdd(curVideo.Key, false); Player.OpenAsync(message.Model.VodPlayUrl); } } - private void InitializeComponent() + private void InitializePlayerComponent() { // Initializes Engine (Specifies FFmpeg libraries path which is required) Engine.Start(new EngineConfig() @@ -187,14 +190,14 @@ private void Player_PropertyChanged(object? sender, System.ComponentModel.Proper if (sender is Player player) { // 跳转开关:开的情况 - if (SkipTimeSwitch && IsSkipTimeDict.TryGetValue(curVideo.Key, out var isSkipTime)) + if (SkipTimeSwitch && SkipTimeStateDict.TryGetValue(curVideo.Key, out var isSkipTime)) { if (!isSkipTime) { // 满足条件就结尾 SkipEnd(); // 置跳转记录 - IsSkipTimeDict[curVideo.Key] = true; + SkipTimeStateDict[curVideo.Key] = true; } } } @@ -223,17 +226,24 @@ protected override void OnInitialActivate() { base.OnInitialActivate(); - appService.LoadHistoryViews(); - appService.LoadPlaySkipTimes(); - videoSettings = appService.GetVideoSettings(); playSkipTimes = [.. appService.GetPlaySkipTimes()]; - InitializeComponent(); + InitializePlayerComponent(); - InitPlayListView(); + InitPlayListView(); + } + private void SetFavoriteState(VideoModel model) + { + var favorites = appService.GetFavorites(); + if (model != null) + { + IsFavorite = favorites.FirstOrDefault(x => x.VodSourceID == model.VodSourceID + && x.VodId == model.VodId) != null; + } } + private void InitPlayListView() { PlayerListView = container.Get(); diff --git a/Morin.Wpf/ViewModels/ShellViewModel.cs b/Morin.Wpf/ViewModels/ShellViewModel.cs index f3025d5..16aec68 100644 --- a/Morin.Wpf/ViewModels/ShellViewModel.cs +++ b/Morin.Wpf/ViewModels/ShellViewModel.cs @@ -107,20 +107,30 @@ private void ClosePopupTimer_Tick(object? sender, EventArgs e) private void LoadDefaultData() { - // 加载历史查询 + // 加载来源 + appService.LoadMediaSources(); + // 加载历史 appService.LoadHistorySearchs(); - HistorySearchs = [.. appService.GetHistorySearchs()]; + // 加载电视设置 + appService.LoadTVSources(); + // 加载历史观看 + appService?.LoadHistoryViews(); + // 加载收藏 + appService?.LoadFavorites(); + // 加载跳过【开始、结尾】 + appService?.LoadPlaySkipTimes(); + + HistorySearchs = [.. appService?.GetHistorySearchs()]; // 菜单设置 var menus = CreateMenuBars(); - appService.MenusSave(menus); + appService?.MenusSave(menus); // 加载菜单 Menus = [.. menus.Where(x => x.Pid == 0&&x.Visvisibility==true)]; MenuItem = Menus.First(x => x.Selected == true); - // 加载电视设置 - appService.LoadTVSources(); + } diff --git a/Morin.Wpf/ViewModels/Videos/VideoViewModel.cs b/Morin.Wpf/ViewModels/Videos/VideoViewModel.cs index b63c9ca..ed2f9ce 100644 --- a/Morin.Wpf/ViewModels/Videos/VideoViewModel.cs +++ b/Morin.Wpf/ViewModels/Videos/VideoViewModel.cs @@ -129,9 +129,7 @@ protected override void OnInitialActivate() base.OnInitialActivate(); CreateDirectories(); - appService.LoadMediaSources(); - appService.LoadHistoryViews(); - LoadMediaSources(); + SetMediaSources(); } @@ -249,7 +247,7 @@ private void OnPageIndexChanged(int pageIndex) }); } - private void LoadMediaSources() + private void SetMediaSources() { var videoSources = appService.GetMediaSources(); if (videoSources.Any())