xref: /MusicPlayer2/MusicPlayer2/UiMediaLibItemMgr.h (revision 5fc30e0abf53adbd9bf838ea947d2a6e1e1ea732)
1 #pragma once
2 #include <map>
3 #include "MediaLibHelper.h"
4 #include "UIElement.h"
5 
6 class CUiMediaLibItemMgr
7 {
8 public:
9     ~CUiMediaLibItemMgr();
10     static CUiMediaLibItemMgr& Instance();
11 
12     void Init();
13 
14     int GetItemCount(CMediaClassifier::ClassificationType type) const;                              //获取指定类别下项目的数量
15     std::wstring GetItemDisplayName(CMediaClassifier::ClassificationType type, int index) const;    //获取指定类别下项目显示到界面中的名称
16     const std::wstring& GetItemName(CMediaClassifier::ClassificationType type, int index) const;    //获取指定项的原始名称,如果是<未知xxx>返回的是空
17     int GetItemSongCount(CMediaClassifier::ClassificationType type, int index) const;               //获取指定类别下项目的曲目数量
18     void SetCurrentName(CMediaClassifier::ClassificationType type, const std::wstring& name);       //设置指定类别下正在播放项目的名称,其中name为原始名称
19     int GetCurrentIndex(CMediaClassifier::ClassificationType type);                                 //获取指定类别下正在播放项目的序号
IsLoading()20     bool IsLoading() const { return m_loading; }
IsInited()21     bool IsInited() const { return m_inited; }
22 
23 private:
24     CUiMediaLibItemMgr();
25     void GetClassifiedMeidaLibItemList(CMediaClassifier::ClassificationType type);
26 
27     static CUiMediaLibItemMgr m_instance;
28     struct ItemInfo
29     {
30         std::wstring name;
31         int count{};
32     };
33 
34     const ItemInfo& GetItemInfo(CMediaClassifier::ClassificationType type, int index) const;
35 
36     std::map<CMediaClassifier::ClassificationType, std::vector<ItemInfo>> m_item_map;   //保存媒体库中所有分类的名称列表
37     bool m_loading{};
38     bool m_inited{};                        //如果已经初始化过,则为true
39     std::map<CMediaClassifier::ClassificationType, int> m_current_index_map;    //保存媒体库模式下每种模式正在播放的曲目
40     std::map<CMediaClassifier::ClassificationType, std::wstring> m_current_name_map;    //保存媒体库模式下每种模式正在播放的曲目
41     mutable std::shared_mutex m_shared_mutex;
42 };
43 
44 
45 class CUiMyFavouriteItemMgr
46 {
47 public:
48     ~CUiMyFavouriteItemMgr();
49     static CUiMyFavouriteItemMgr& Instance();
50 
51     int GetSongCount() const;
52     const SongInfo& GetSongInfo(int index) const;
53     void UpdateMyFavourite();
IsLoading()54     bool IsLoading() const { return m_loading; }
IsInited()55     bool IsInited() const { return m_inited; }
56     void GetSongList(std::vector<SongInfo>& song_list) const;
57     bool Contains(const SongInfo& song) const;
58 
59 private:
60     CUiMyFavouriteItemMgr();
61     static CUiMyFavouriteItemMgr m_instance;
62 
63     vector<SongInfo> m_may_favourite_song_list;     //“我喜欢的音乐”列表
64     bool m_loading{};
65     bool m_inited{};                        //如果已经初始化过,则为true
66     mutable std::shared_mutex m_shared_mutex;
67 
68 };
69 
70 
71 class CUiAllTracksMgr
72 {
73 public:
74     ~CUiAllTracksMgr();
75     static CUiAllTracksMgr& Instance();
76 
77     //用于在UI中显示的曲目信息
78     struct UTrackInfo
79     {
80         SongKey song_key;
81         std::wstring name;
82         Time length;
83         bool is_favourite{};
84     };
85 
86     int GetSongCount() const;
87     SongInfo GetSongInfo(int index) const;
88     const UTrackInfo& GetItem(int index) const;
89     int GetCurrentIndex() const;                //获取正在播放的曲目在m_all_tracks_list中的序号
90     void SetCurrentSong(const SongInfo& song);  //设置正在播放的曲目,将其在m_all_tracks_list中的序号保存起来
91     void UpdateAllTracks();                     //从CSongDataManager中更新所有曲目信息
IsLoading()92     bool IsLoading() const { return m_loading; }
IsInited()93     bool IsInited() const { return m_inited; }
94     void GetSongList(std::vector<SongInfo>& song_list) const;
95     void AddOrRemoveMyFavourite(int index);     //仅更新UI中显示的“我喜欢”的状态,不更新到“我喜欢的音乐”播放列表中
96 
97 private:
98     CUiAllTracksMgr();
99     static CUiAllTracksMgr m_instance;
100 
101     std::vector<UTrackInfo> m_all_tracks_list;  //所有曲目信息列表
102     bool m_loading{};                       //如果正在初始化中,则为true
103     int m_current_index{ -1 };              //正在播放的曲目在m_all_tracks_list中的序号
104     bool m_inited{};                        //如果已经初始化过,则为true
105     mutable std::shared_mutex m_shared_mutex;
106 };
107 
108 
109 class CUiFolderExploreMgr
110 {
111 public:
112     static CUiFolderExploreMgr& Instance();
113 
114     std::vector<std::shared_ptr<UiElement::TreeElement::Node>>& GetRootNodes();
115     void UpdateFolders();
IsLoading()116     bool IsLoading() const { return m_loading; }
IsInited()117     bool IsInited() const { return m_inited; }
118 
119 private:
120     CUiFolderExploreMgr();
121     void CreateFolderNodeByPath(std::wstring path, std::shared_ptr<UiElement::TreeElement::Node> parent);
122     int GetAudioFilesNum(std::wstring path);
123 
124     static CUiFolderExploreMgr m_instance;
125 
126     bool m_loading{};                       //如果正在初始化中,则为true
127     bool m_inited{};                        //如果已经初始化过,则为true
128 
129     std::vector<std::shared_ptr<UiElement::TreeElement::Node>> m_root_nodes;
130     std::map<std::wstring, int> m_folder_audio_files_num;       //保存每个文件夹下音频文件的数量
131 };
132