Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
kuangxj committed May 7, 2024
1 parent a40e423 commit 84c122d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Morin.Shared/Models/FavoriteModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
6 changes: 0 additions & 6 deletions Morin.Wpf/ViewModels/Account/AccountViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ protected override void OnInitialActivate()
{
base.OnInitialActivate();
SetMenusAsync("我的");

// 加载历史观看
appService?.LoadHistoryViews();

// 加载收藏
appService?.LoadFavorites();
}
private void SetDefaultMenu()
{
Expand Down
34 changes: 22 additions & 12 deletions Morin.Wpf/ViewModels/Players/PlayerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlaySkipTimeModel> playSkipTimes;
Expand Down Expand Up @@ -85,25 +85,28 @@ public bool SkipTimeSwitch
}
}
private VideoModel curVideo;
private Dictionary<string, bool> IsSkipTimeDict = [];
private Dictionary<string, bool> 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()
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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<PlayerListViewModel>();
Expand Down
20 changes: 15 additions & 5 deletions Morin.Wpf/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}


Expand Down
6 changes: 2 additions & 4 deletions Morin.Wpf/ViewModels/Videos/VideoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ protected override void OnInitialActivate()
base.OnInitialActivate();
CreateDirectories();

appService.LoadMediaSources();
appService.LoadHistoryViews();
LoadMediaSources();
SetMediaSources();
}


Expand Down Expand Up @@ -249,7 +247,7 @@ private void OnPageIndexChanged(int pageIndex)
});
}

private void LoadMediaSources()
private void SetMediaSources()
{
var videoSources = appService.GetMediaSources();
if (videoSources.Any())
Expand Down

0 comments on commit 84c122d

Please sign in to comment.