JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using System.Text;
using Shared;
using Shared.SimpleControl.Phone;
using Shared.SimpleControl;
using Shared.SimpleControl.R;
using System.Xml;
using SmartHome.UI.SimpleControl.Phone;
using System.Security;
using SmartHome;
using System.Net;
using System.Security.Cryptography;
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
 
namespace Shared.SimpleControl.Phone
{
    public class SonosLikeList : FrameLayout
    {
        public void Show (SonosMusic sonosMusic)
        {
            AddChidren (new Button {
                Height = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            });
 
            var topFrameLayout = new FrameLayout {
                Height = Application.GetRealHeight (90),
                Y = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            };
            AddChidren (topFrameLayout);
 
        
            var back = new Button {
                Width = Application.GetRealWidth (82),
                Height = Application.GetRealHeight (89),
                X = Application.GetRealWidth (10),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "MusicIcon/HomepageBack.png",
            };
            topFrameLayout.AddChidren (back);
            back.MouseDownEventHandler += (sender, e) => {
                this.RemoveFromParent ();
            };
 
            var musiclist = new Button {
                Width = Application.GetRealWidth (200),
                Height = Application.GetRealHeight (150),
                TextID = MyInternationalizationString.Musiclike,
                X = Application.GetRealWidth (200),
                Gravity = Gravity.CenterVertical,
            };
            topFrameLayout.AddChidren (musiclist);
 
            var likelistview = new VerticalScrolViewLayout {
                Height = Application.GetRealHeight (Application.DesignHeight - 126),
                Y = topFrameLayout.Bottom,
                BackgroundColor = 0xff2F2F2F,
            };
            this.AddChidren (likelistview);
 
 
 
            //if (sonosMusic.SonosLovePlayList.Count == 0) {
            sonosMusic.SonosLovePlayList.Clear ();
            MainPage.Loading.Start ();
            System.Threading.Tasks.Task.Run (() => {
                try {
 
                    var tempsonosList = SuperGateWay.Control.getsonosLikeList ();
                    if (tempsonosList == null) {
                        return;
                    }
                    if (tempsonosList != null) {
                        foreach (var str in tempsonosList) {
                            try {
                                var result = SuperGateWay.Control.getsonosLikeSongs(str.Replace (".json", ""));
                                if (result != null) {
                                    var obj = JObject.Parse (result);
                                    var songitems = obj ["songitems"]?.ToString ();
                                    var songlist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<songifon>> (songitems);
                                    foreach (var songinof in songlist) {
                                        songifon songs = new songifon ();
                                        songs.id = songinof.id;
                                        songs.imageUrl = songinof.imageUrl;
                                        songs.songname = songinof.songname;
                                        sonosMusic.SonosLovePlayList.Add (songs);
                                    }
 
                                }
                            } catch { }
                        }
 
                    }
                } catch { } finally {
                    Application.RunOnMainThread (() => {
                        MainPage.Loading.Hide ();
                        likeView (likelistview, sonosMusic);
                    });
                }
            });
 
 
            //} else {
            //    likeView (likelistview, sonosMusic);
            //}
 
 
        }
 
        void likeView (VerticalScrolViewLayout likelistview, SonosMusic sonosMusic)
        {
 
            for (int i = 0; i < sonosMusic.SonosLovePlayList.Count; i++) {
                var music = sonosMusic.SonosLovePlayList [i];
                var likemusic = new RowLayout {
                    Width = LayoutParams.MatchParent,
                    Height = Application.GetRealHeight (100),
                };
                likelistview.AddChidren (likemusic);
 
                var titleMusic = new Button {
                    Width = Application.GetRealWidth (61),
                    Height = Application.GetRealHeight (61),
                    X = Application.GetRealWidth (20),
                    Gravity = Gravity.CenterVertical,
                    Radius = (uint)Application.GetRealHeight (4),
                    UnSelectedImagePath = "MusicIcon/musicplay1.png",
                };
                likemusic.AddChidren (titleMusic);
 
 
                string patn = "SonosMusicImage_";
                if (Shared.IO.FileUtils.Exists (patn + music.songname)) {
                    titleMusic.UnSelectedImagePath = patn + music.songname;
                } else {
                    titleMusic.UnSelectedImagePath = "MusicIcon/musicplay1.png";
                    System.Threading.Tasks.Task.Run (() => {
                        var filePath = SonosMusic.SonosMusicImage (music.imageUrl, music.songname);
                        if (filePath != null) {
                            Application.RunOnMainThread (() => {
                                titleMusic.UnSelectedImagePath = filePath;
                            });
                        }
                    });
                }
 
                var songmker = new Button {
 
                    Width = Application.GetRealWidth (400),
                    Height = Application.GetRealHeight (50),
                    TextAlignment = TextAlignment.BottomLeft,
                    X = Application.GetRealWidth (100),
                    Text = music.songname,
                    TextColor = SkinStyle.Current.MusicTextColor,
                };
                likemusic.AddChidren (songmker);
 
 
                var artists = new Button {
                    Width = Application.GetRealWidth (400),
                    Height = Application.GetRealHeight (40),
                    TextAlignment = TextAlignment.TopLeft,
                    X = Application.GetRealWidth (100),
                    Y = songmker.Bottom,
                    //TextColor = 0x75ffffff,
                    Text ="unkown",
                    TextColor = SkinStyle.Current.MusicArtistTextColor,
 
                };
                likemusic.AddChidren (artists);
 
                            
                EventHandler<MouseEventArgs> clickLovesong = (sender, e) => {
                    likemusic.BackgroundColor = 0xffFE5E00;
                    System.Threading.Tasks.Task.Run (() => {
                        Application.RunOnMainThread (() => {
                            //先移除当前控件的前面那个控件   
                            this.Parent.RemoveAt (this.Parent.ChildrenCount - 3);
                            this.Parent.RemoveAt (this.Parent.ChildrenCount - 2);
                            //当前控件界面
                            this.RemoveFromParent ();
                            var sonosPlay = new SonosPlay { };
                            MainPage.MainFrameLayout.AddChidren (sonosPlay);
                            sonosPlay.Show (sonosMusic);
                            System.Threading.Tasks.Task.Run (() => {
                                sonosMusic.eventsend (sonosMusic, 6, music.id);
                            });
                        });
                    });
 
                };
 
 
                likemusic.MouseUpEventHandler += clickLovesong;
                titleMusic.MouseUpEventHandler += clickLovesong;
                songmker.MouseUpEventHandler += clickLovesong;
                artists.MouseUpEventHandler += clickLovesong;
 
                new System.Threading.Thread (() => {
                    while (this.Parent != null) {
                        System.Threading.Thread.Sleep (1000);
                        Shared.Application.RunOnMainThread (() => {
                            try {
                                for (int j = 0; j < likelistview.ChildrenCount; j++) {
                                    RowLayout view = (RowLayout)likelistview.GetChildren (j);
                                    var songName = (Button)view.GetChildren (1);
                                    if (sonosMusic.sonosPlayStatus.songName == songName.Text) {
                                        songName.TextColor = 0xffFE5E00;
                                    } else {
                                        songName.TextColor = SkinStyle.Current.MusicTextColor;
                                    }
                                }
                            } catch { }
 
                        });
                    }
                }) { IsBackground = true }.Start ();
            }
 
        }
             
    }
}