wxr
2020-08-11 2bec9c838d2d688025698de8ec1de401ffd7dd1f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
using System;
using System.Collections.Generic;
using System.Text;
using Shared;
namespace HDL_ON.UI.Music
{
    public class A31MyList : FrameLayout
    {
        public A31MyList()
        {
            Tag = "Music";
        }
        VerticalScrolViewLayout middViewLayout;
        public void Show()
        {
            this.BackgroundColor = MusicColor.ViewColor;
            var topView = new TopView();
            this.AddChidren(topView.TopFLayoutView());
            topView.topNameBtn.TextID = StringId.myList;
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
 
                if (updateSelectedMusicThread != null)
                {
                    try
                    {
                        if (updateSelectedMusicThread.IsAlive)
                        {
                            updateSelectedMusicThread.Abort();
                            ///关闭线程
                        }
                    }
                    catch { }
                }
                this.RemoveFromParent();
            };
 
           
            var addIconBtn = new Button
            {
                X = Application.GetRealWidth(336),
                Y = Application.GetRealHeight(30),
                Width = Application.GetMinRealAverage(28),
                Height = Application.GetMinRealAverage(28),
                UnSelectedImagePath = "MusicIcon/addMusic.png",
            };
            topView.TopFLayoutView().AddChidren(addIconBtn);
            addIconBtn.MouseUpEventHandler += (sender, e) =>
            {
                var fileNameList = new List<string>();
                fileNameList.Clear();
                foreach (var stringName in A31MusicModel.Current.FileLists)
                {
                    fileNameList.Add(stringName.ListName);
 
                }
                new View.TipView().InputBox(StringId.addNewList, "", StringId.listNameNull, StringId.listNamesSame, fileNameList, (name) =>
                {
 
                    A31MusicModel.Current.FileLists.Add(new FileListInfo { ListName = name, });
                    A31MusicModel.Save();
                    FileView();
                });
            };
 
            middViewLayout = new VerticalScrolViewLayout
            {
                BackgroundColor = MusicColor.WhiteColor,
                Y = topView.fLayout.Bottom,
                Height = Application.GetRealHeight(H_W.H - H_W.T_Height),
            };
            this.AddChidren(middViewLayout);
            FileView();
 
 
 
        }
        /// <summary>
        /// 加载文件夹View的方法
        /// </summary>
        void FileView()
        {
            middViewLayout.RemoveAll();
            for (int i = 0; i < A31MusicModel.Current.FileLists.Count; i++)
            {
                var list = A31MusicModel.Current.FileLists[i];
                RowLayout addFlieRow = new RowLayout
                {
                    Height = Application.GetRealHeight(104),
                    LineColor = MusicColor.WhiteColor,
                    SubViewWidth = Application.GetRealWidth(90),//改变编辑控件宽度多少;
                };
                middViewLayout.AddChidren(addFlieRow);
                //文件图标
                Button fileIconBtn = new Button
                {
                    X = Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(8),
                    Width = Application.GetMinRealAverage(88),
                    Height = Application.GetMinRealAverage(88),
                    UnSelectedImagePath = "MusicIcon/fileList.png",
                };
                addFlieRow.AddChidren(fileIconBtn);
                //播放/暂停图标
                Button playIconBtn = new Button
                {
                    X = Application.GetRealWidth(78),
                    Y = Application.GetRealHeight(70),
                    Width = Application.GetMinRealAverage(24),
                    Height = Application.GetMinRealAverage(24),
                    UnSelectedImagePath = "MusicIcon/filePause.png",
                    SelectedImagePath = "MusicIcon/filePlay.png",
                    Tag= list,
                };
                addFlieRow.AddChidren(playIconBtn);
 
                playIconBtn.MouseUpEventHandler = (sender, e) =>
                {
 
                   
 
                    ///查找当前播放音乐是否这个列表
                    if (playIconBtn.IsSelected)
                    {
                        if (list.ListName == A31MusicModel.Current.A31PlayStatus.Artist && A31MusicModel.Current.A31PlayStatus.status == "play")
                        {
 
                            SendMethod.Pause(A31MusicModel.Current);
                            A31MusicModel.Current.A31PlayStatus.status = "pause";
                        }
 
                    }
                    else
                    {
                        if (list.MusicInfoList.Count == 0)
                        {
                            return;
                        }
 
                        if (list.ListName == A31MusicModel.Current.A31PlayStatus.Artist && A31MusicModel.Current.A31PlayStatus.status != "play")
                        {
                            SendMethod.Play(A31MusicModel.Current);
                            A31MusicModel.Current.A31PlayStatus.status = "play";
                        }
                        else
                        {
                            ///取随机数;
                            var ra = new Random { }.Next(0, list.MusicInfoList.Count);
                            ///查找当前的音乐;
                            var songs = list.MusicInfoList[ra];
                            //点击按钮随机播放音乐
                            System.Threading.Tasks.Task.Run(() =>
                            {
                                System.Threading.Thread.Sleep(50);
                                Application.RunOnMainThread(() =>
                                {
                                    //移除界面
                                    System.Threading.Tasks.Task.Run(() =>
                                    {
                                       SendMethod.PushList(songs, list.ListName, list.MusicInfoList,A31MusicModel.Current, "我的列表");
                                    });
                                });
                            });
                        }
 
                    }
 
                };
                //文件名控件
                Button fileNameBtn = new Button
                {
                    X = fileIconBtn.Right + Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(42),
                    Width = Application.GetRealWidth(217),
                    Height = Application.GetRealHeight(20),
                    TextColor = MusicColor.TextColor,
                    TextSize = TextSize.Text14,
                    TextAlignment = TextAlignment.CenterLeft,
                    Text= list.ListName,
                };
                addFlieRow.AddChidren(fileNameBtn);
                ///编辑控件
                var editBtn = new Button
                {
                    BackgroundColor = MusicColor.MusicEditColor,
                    Text = Language.StringByID(StringId.editMusic),
                    TextColor = MusicColor.WhiteColor,
                    TextSize = TextSize.Text16,
                };
                addFlieRow.AddRightView(editBtn);
                editBtn.MouseUpEventHandler += (sender, e) =>
                {
 
                    var fileNameList = new List<string>();
                    fileNameList.Clear();
                    foreach (var stringName in A31MusicModel.Current.FileLists)
                    {
                        fileNameList.Add(stringName.ListName);
 
                    }
                    new View.TipView().InputBox(StringId.modifyName, list.ListName, StringId.listNameNull, StringId.listNamesSame, fileNameList, (name) =>
                    {
                        if (list.ListName != name)
                        {  ///修改名称不一样更新保存
                            list.ListName = name;
                            fileNameBtn.Text = name;
                            A31MusicModel.Save();
                        }
                    });
 
                };
                ///删除控件
                var delBtn = new Button
                {
                    BackgroundColor = MusicColor.MusicDelColor,
                    Text = Language.StringByID(StringId.delMusic),
                    TextColor = MusicColor.WhiteColor,
                    TextSize = TextSize.Text16,
                };
                addFlieRow.AddRightView(delBtn);
                delBtn.MouseUpEventHandler += (sender, e) =>
                {
                    new View.TipView().TipBox(StringId.tip, StringId.delMusicFile, () =>
                    {
                        A31MusicModel.Current.FileLists.Remove(list);
                        A31MusicModel.Save();
                        addFlieRow.RemoveFromParent();
 
                    });
                };
                
                Button clickBtn = new Button
                {
                    X = fileIconBtn.Right + Application.GetRealWidth(16),
                    Width = Application.GetRealWidth(375 - 138),
                    Height = Application.GetRealHeight(104),
                };
                addFlieRow.AddChidren(clickBtn);
                clickBtn.MouseUpEventHandler += (sender, e) =>
                {
                    A31MyListMusic a31MyListMusic = new A31MyListMusic();
                    MainPage.BasePageView.AddChidren(a31MyListMusic);
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    a31MyListMusic.Show(list);
                    a31MyListMusic.UpdateSelectedMusic();
                };
 
            }
        }
        /// <summary>
        /// 定时更新文件夹播放状态
        /// </summary>
        System.Threading.Thread updateSelectedMusicThread;
        public void UpdateSelectedFile()
        {
            updateSelectedMusicThread = new System.Threading.Thread(() =>
            {
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(1000);
                    Application.RunOnMainThread(() =>
                    {
                        try
                        {
                            for (int i = 0; i < middViewLayout.ChildrenCount; i++)
                            {
                                RowLayout view = (RowLayout)middViewLayout.GetChildren(i);
                                var playBtn = (Button)view.GetChildren(1);//直接FrameLayout父控件找到该控件Button
                                var listIfon = playBtn.Tag as FileListInfo;//强制转换为FileListInfo类型;
                                ///查找当前播放音乐是否这个列表
                                if (A31MusicModel.Current.A31PlayStatus.Artist == listIfon.ListName && A31MusicModel.Current.A31PlayStatus.status == "play")
                                {
                                    playBtn.IsSelected = true;
                                }
                                else
                                {
                                    playBtn.IsSelected = false;
                                }
                            }
                        }
                        catch { }
 
                    });
                }
            })
            { IsBackground = true };
            updateSelectedMusicThread.Start();
        }
       
    }
}