陈嘉乐
2020-07-31 f3c8cf07fad2e39a32af549b305da6723159f755
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
using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.Music
{
    public class A31USBMusicList : FrameLayout
    {
        public A31USBMusicList()
        {
            Tag = "Music";
        }
 
        VerticalRefreshLayout middViewLayout;
        /// <summary>
        /// 先加载界面出来
        /// </summary>
        public void UIView()
        {
            #region   界面布局------
 
            this.BackgroundColor = Color.ViewColor;
            var topView = new TopView();
            this.AddChidren(topView.TopFLayoutView());
            topView.topNameBtn.TextID = StringId.usb;
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
            middViewLayout = new VerticalRefreshLayout
            {
                BackgroundColor = Color.WhiteColor,
                Y = topView.fLayout.Bottom,
                Height = Application.GetRealHeight(H_W.H - H_W.T_Height),
            };
            this.AddChidren(middViewLayout);
 
            middViewLayout.BeginHeaderRefreshingAction += () =>
            {
                //System.Threading.Tasks.Task.Run(() =>
                //{
                //    try
                //    {
                //        var list = SendMethod.GetUsbList();
                //        A31MusicModel.Current.USBList.Clear();
                //        A31MusicModel.Current.USBList.AddRange(list);
                //    }
                //    catch { }
                //    finally
                //    {
                //        Application.RunOnMainThread(() =>
                //        {
                //            Show();
                //            middViewLayout.EndHeaderRefreshing();
                //        });
                //    }
                //});
                var list = SendMethod.GetUsbList(A31MusicModel.Current);
                A31MusicModel.Current.USBList.Clear();
                A31MusicModel.Current.USBList.AddRange(list);
                Show();
                middViewLayout.EndHeaderRefreshing();
            };
            #endregion
        }
        /// <summary> 
        /// 加载数据的方法
        /// </summary>
        public void Show()
        {
            middViewLayout.RemoveAll();
            int number = 0;
            for (int i = 0; i < A31MusicModel.Current.USBList.Count; i++)
            {
                number++;
                var songs = A31MusicModel.Current.USBList[i];
                View.SongView songView = new View.SongView();
                songView.SongFrameLayout(middViewLayout, songs);
                // 添加喜爱音乐控件
                songView.loveIcon.MouseUpEventHandler += (sender, e) =>
                {
                    songView.loveIcon.IsSelected = !songView.loveIcon.IsSelected;
                    if (songView.loveIcon.IsSelected)
                    {
                        ///查找音乐是否存在在列表
                        var music1 = A31MusicModel.Current.LoveMusicInfoList.Find((m) => m.URL == songs.URL);
                        if (music1 == null)
                        {
                            ///没有存在就添加
                            A31MusicModel.Current.LoveMusicInfoList.Add(songs);
                        }
                    }
                    else
                    {
                        ///查找音乐是否存在在列表
                        var music1 = A31MusicModel.Current.LoveMusicInfoList.Find((m) => m.URL == songs.URL);
                        if (music1 != null)
                        {
                            ///存在就删除
                            A31MusicModel.Current.LoveMusicInfoList.Remove(songs);
                        }
 
                    }
                    A31MusicModel.Save();
                };
                //添加到我的列表
                songView.addIcon.MouseUpEventHandler = (sender, e) =>
                {
                    new View.DialogView { }.FieListView(songs);
                };
                songView.clickBtn.Tag = number;//标记播放哪一首歌曲
                ///点击播放事件
                songView.clickBtn.MouseUpEventHandler += (sender, e) =>
                {
 
                    System.Threading.Tasks.Task.Run(() =>
                    {
                        System.Threading.Thread.Sleep(50);
                        Application.RunOnMainThread(() =>
                        {
                            //移除界面
                            A31MusicModel.Current.A31PlayStatus.Title = songView.songBtn.Text;
                            MainPage.BasePageView.RemoveViewByTag("Music");
                            System.Threading.Tasks.Task.Run(() =>
                            {
                                SendMethod.ListMusicPlay("USBDiskQueue", songView.clickBtn.Tag, A31MusicModel.Current);
                            });
                        });
                    });
 
                };
 
            }
        }
        /// <summary>
        /// 定时更新当前播放音乐
        /// </summary>
        public void UpdateSelectedMusic()
        {
            UI2.FuntionControlView.Music.UpdateThread.updateThread(this, middViewLayout, A31MusicModel.Current);
        }
 
    }
}