using System; using System.Collections.Generic; using Shared; using Shared.SimpleControl; using Shared.SimpleControl.Phone.Music; using Shared.SimpleControl.R; namespace SmartHome.UI.SimpleControl.Phone.Music { class A31TidalHomePage : FrameLayout { public void Show () { AddChidren (new Button { Height = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MusicTopFrameLayout, }); var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight (100), Y = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MusicTopFrameLayout, }; AddChidren (topFrameLayout); var LocallistName = new Button { Text = "TIDAL", TextColor = SkinStyle.Current.MusicTextColor, }; topFrameLayout.AddChidren (LocallistName); var Search = new Button { Width = Application.GetMinRealAverage (60), Height = Application.GetMinRealAverage (80), X = Application.GetRealWidth (535), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/seekdevice.png", }; topFrameLayout.AddChidren (Search); Search.MouseUpEventHandler += (sender, e) => { A31TidalSearchTrackPage a31TidalSearchTrackPage = new A31TidalSearchTrackPage (); MainPage.MainFrameLayout.AddChidren (a31TidalSearchTrackPage); a31TidalSearchTrackPage.Show (); }; 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) => { RemoveFromParent (); }; var middle = new VerticalScrolViewLayout (); middle.Y = topFrameLayout.Bottom; middle.Height = Application.GetRealHeight (Application.DesignHeight - 136); middle.BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout; AddChidren (middle); #region New...新... var newrow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (newrow); var radius = new Button { Width = Application.GetRealWidth (36), Height = Application.GetRealHeight (36), TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), UnSelectedImagePath = "MusicIcon/radius.png", Gravity = Gravity.CenterVertical, }; newrow.AddChidren (radius); var btnnew = new Button { Height = Application.GetRealHeight (100), TextID =MyInternationalizationString.News, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; newrow.AddChidren (btnnew); var nextnew = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; newrow.AddChidren (nextnew); EventHandler newsource = (sender, e) => { Tidal.ReadPlayList ("tidal/new/tracks", () => { Application.RunOnMainThread (() => { RemoveFromParent (); A31TidalLogin a31TidalLogin = new A31TidalLogin (); MainPage.MainFrameLayout.AddChidren (a31TidalLogin); a31TidalLogin.Show (A31MusicModel.Current); }); }, (path) => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31NewPage a31NewPage = new A31NewPage (); MainPage.MainFrameLayout.AddChidren (a31NewPage); a31NewPage.Show (path, Language.StringByID(MyInternationalizationString.News)); }); }); /* MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); var NewTrackList = Tidal.TempMusicInfoList.FindAll ((obj) => obj.Tag.ToString () == "NewTracks"); System.Threading.Tasks.Task.Run (() => { try { if (NewTrackList.Count == 0) { #region //var PlayListstring = Tidal.GetResult ("https://meta.airable.io/tidal/new/playlists"); //var List1 = Newtonsoft.Json.JsonConvert.DeserializeObject (PlayListstring); ////token过期,需要重新登录. //if (List1.id != null) { // if (List1.id [2].ToString () == "authorization") { // var dd = login (); // if (dd != "login") { // var alert = new Alert (Language.StringByID (MyInternationalizationString.prompt), "可能户名或者密码不正确,返回登录界面", Language.StringByID (MyInternationalizationString.confirm)); // alert.ResultEventHandler += (sender1, e1) => { // if (e1) { // Application.RunOnMainThread (() => { // RemoveFromParent (); // A31TidalLogin a31TidalLogin = new A31TidalLogin (); // MainPage.MainFrameLayout.AddChidren (a31TidalLogin); // a31TidalLogin.Show (A31MusicModel.Current); // }); // } // }; // alert.Show (); // } // return; // } //} //foreach (var v in List1.content.entries) { // var musicinfo = new MusicInfo (); // musicinfo.Title = v.title; // musicinfo.URL = v.url; // musicinfo.Tag = "NewPlayLists"; // if (v.images != null) { // #region 初始化网络图片路径 // string path = ""; // if (Shared.Application.IsPad) { // path = "Pad/" + "MusicImage/"; // } else { // path = "Phone/" + "MusicImage/"; // } // path = System.IO.Path.Combine (Shared.IO.FileUtils.RootPath, path + v.images [0].url.Replace ('/', '_').Replace ('\\', '_').Replace (':', '_').Replace ('*', '_').Replace ('?', '_').Replace ('"', '_').Replace ('<', '_').Replace ('>', '_').Replace ('|', '_')); // musicinfo.Image = path; // #endregion // Shared.IO.FileUtils.DownLoadImage (musicinfo.Image, v.images [0].url); // } // Tidal.TempMusicInfoList.Add (musicinfo); //} //var albumsListstring = Tidal.GetResult ("https://meta.airable.io/tidal/new/albums"); //var List2 = Newtonsoft.Json.JsonConvert.DeserializeObject (albumsListstring); //foreach (var v in List2.content.entries) { // var musicinfo = new MusicInfo (); // musicinfo.Title = v.title; // musicinfo.URL = v.url; // musicinfo.Image = v.images [0].url; // musicinfo.Tag = "NewAlbumsLists"; // Tidal.TempMusicInfoList.Add (musicinfo); //} #endregion var result = Tidal.GetResult ("https://meta.airable.io/tidal/new/tracks"); if (result == null) { return; } var tracks = Newtonsoft.Json.JsonConvert.DeserializeObject (result); //token过期,需要重新登录. if (tracks.id != null) { if (tracks.id [2].ToString () == "authorization") { var dd = Tidal.login (); if (dd != "login") { var alert = new Alert (Language.StringByID (MyInternationalizationString.prompt), "可能户名或者密码不正确,返回登录界面", Language.StringByID (MyInternationalizationString.confirm)); alert.ResultEventHandler += (sender1, e1) => { if (e1) { Application.RunOnMainThread (() => { RemoveFromParent (); A31TidalLogin a31TidalLogin = new A31TidalLogin (); MainPage.MainFrameLayout.AddChidren (a31TidalLogin); a31TidalLogin.Show (A31MusicModel.Current); }); } }; alert.Show (); } } } foreach (var v in tracks.content.entries) { var tidalMusicInfo = new MusicInfo () { Tag = "NewTracks" }; tidalMusicInfo.Title = v.title; tidalMusicInfo.Artist = v.artist.title.Replace ("&", ""); //var l = new List (v.id); //if (l.Contains ("track")) { // tidalMusicInfo.ID = l [2]; // tidalMusicInfo.IsDirectory = false; //} if (v.streams != null) { if (v.streams [0].url != null) { tidalMusicInfo.URL = v.streams [0].url; } } if (v.images != null) { #region 初始化网络图片路径 string path = ""; if (Shared.Application.IsPad) { path = "Pad/" + "MusicImage/"; } else { path = "Phone/" + "MusicImage/"; } path = System.IO.Path.Combine (Shared.IO.FileUtils.RootPath, path + v.images [0].url.Replace ('/', '_').Replace ('\\', '_').Replace (':', '_').Replace ('*', '_').Replace ('?', '_').Replace ('"', '_').Replace ('<', '_').Replace ('>', '_').Replace ('|', '_')); tidalMusicInfo.Image = path; #endregion Shared.IO.FileUtils.DownLoadImage (tidalMusicInfo.Image, v.images [0].url); } Tidal.TempMusicInfoList.Add (tidalMusicInfo); } } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); //A31TidalWhatNew a31NewPage = new A31TidalWhatNew (); A31NewPage a31NewPage = new A31NewPage (); MainPage.MainFrameLayout.AddChidren (a31NewPage); a31NewPage.Show (); }); } }); */ }; radius.MouseUpEventHandler += newsource; btnnew.MouseUpEventHandler += newsource; nextnew.MouseUpEventHandler += newsource; #endregion #region TIDAL Rising..新星.. var risingrow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (risingrow); var radius1 = new Button { Width = Application.GetRealWidth (36), Height = Application.GetRealHeight (36), TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), UnSelectedImagePath = "MusicIcon/radius.png", Gravity = Gravity.CenterVertical, }; risingrow.AddChidren (radius1); var btnRising = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.TIDALRising, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; risingrow.AddChidren (btnRising); var nextRising = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; risingrow.AddChidren (nextRising); EventHandler tidalrisingsource = (sender, e) => { Tidal.ReadPlayList ("tidal/rising/tracks", () => { Application.RunOnMainThread (() => { RemoveFromParent (); A31TidalLogin a31TidalLogin = new A31TidalLogin (); MainPage.MainFrameLayout.AddChidren (a31TidalLogin); a31TidalLogin.Show (A31MusicModel.Current); }); }, (path) => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31TidalRisingPage a31TidalRisingPage = new A31TidalRisingPage (); MainPage.MainFrameLayout.AddChidren (a31TidalRisingPage); a31TidalRisingPage.Show (path, Language.StringByID(MyInternationalizationString.TIDALRising)); }); }); /* MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); var TidalRisingTrackList = Tidal.TempMusicInfoList.FindAll ((obj) => obj.Tag.ToString () == "TidalRisingTrack"); System.Threading.Tasks.Task.Run (() => { try { if (TidalRisingTrackList.Count == 0) { var result = Tidal.GetResult ("https://meta.airable.io/tidal/rising/tracks"); if (result == null) { return; } var tracks = Newtonsoft.Json.JsonConvert.DeserializeObject (result); //token过期,需要重新登录. if (tracks.id != null) { if (tracks.id [2].ToString () == "authorization") { var dd = Tidal.login (); if (dd != "login") { var alert = new Alert (Language.StringByID (MyInternationalizationString.prompt), "可能户名或者密码不正确,返回登录界面", Language.StringByID (MyInternationalizationString.confirm)); alert.ResultEventHandler += (sender1, e1) => { if (e1) { Application.RunOnMainThread (() => { RemoveFromParent (); A31TidalLogin a31TidalLogin = new A31TidalLogin (); MainPage.MainFrameLayout.AddChidren (a31TidalLogin); a31TidalLogin.Show (A31MusicModel.Current); }); } }; alert.Show (); } } } foreach (var v in tracks.content.entries) { var tidalMusicInfo = new MusicInfo () { Tag = "TidalRisingTrack" }; tidalMusicInfo.Title = v.title.Replace ("&", ""); tidalMusicInfo.Artist = v.artist.title.Replace ("&", ""); if (v.streams != null) { if (v.streams [0].url != null) { tidalMusicInfo.URL = v.streams [0].url; } } if (v.images != null) { #region 初始化网络图片路径 string path = ""; if (Shared.Application.IsPad) { path = "Pad/" + "MusicImage/"; } else { path = "Phone/" + "MusicImage/"; } path = System.IO.Path.Combine (Shared.IO.FileUtils.RootPath, path + v.images [0].url.Replace ('/', '_').Replace ('\\', '_').Replace (':', '_').Replace ('*', '_').Replace ('?', '_').Replace ('"', '_').Replace ('<', '_').Replace ('>', '_').Replace ('|', '_')); tidalMusicInfo.Image = path; #endregion Shared.IO.FileUtils.DownLoadImage (tidalMusicInfo.Image, v.images [0].url); } Tidal.TempMusicInfoList.Add (tidalMusicInfo); } } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31TidalRisingPage a31TidalRisingPage = new A31TidalRisingPage (); MainPage.MainFrameLayout.AddChidren (a31TidalRisingPage); a31TidalRisingPage.Show (); }); } }); */ }; nextRising.MouseUpEventHandler += tidalrisingsource; btnRising.MouseUpEventHandler += tidalrisingsource; radius1.MouseUpEventHandler += tidalrisingsource; #endregion #region Playlists ..播放列表.. var Playlistrow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (Playlistrow); var radius2 = new Button { Width = Application.GetRealWidth (36), Height = Application.GetRealHeight (36), TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), UnSelectedImagePath = "MusicIcon/radius.png", Gravity = Gravity.CenterVertical, }; Playlistrow.AddChidren (radius2); var btnPlaylist = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Playlists, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; Playlistrow.AddChidren (btnPlaylist); var nextPlaylist = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; Playlistrow.AddChidren (nextPlaylist); EventHandler Playlistsource = (sender, e) => { Tidal.ReadPlayList ("tidal/playlists", () => { Application.RunOnMainThread (() => { RemoveFromParent (); A31TidalLogin a31TidalLogin = new A31TidalLogin (); MainPage.MainFrameLayout.AddChidren (a31TidalLogin); a31TidalLogin.Show (A31MusicModel.Current); }); }, (path) => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31PlayListPage a31PlayListPage = new A31PlayListPage (); MainPage.MainFrameLayout.AddChidren (a31PlayListPage); a31PlayListPage.Show (path, Language.StringByID(MyInternationalizationString.Playlists)); }); }); }; radius2.MouseUpEventHandler += Playlistsource; btnPlaylist.MouseUpEventHandler += Playlistsource; nextPlaylist.MouseUpEventHandler += Playlistsource; #endregion #region Genres ..类型.. var Genresrow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (Genresrow); var radius3 = new Button { Width = Application.GetRealWidth (36), Height = Application.GetRealHeight (36), TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), UnSelectedImagePath = "MusicIcon/radius.png", Gravity = Gravity.CenterVertical, }; Genresrow.AddChidren (radius3); var btnGenres = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Genres, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; Genresrow.AddChidren (btnGenres); var nextGenres = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; Genresrow.AddChidren (nextGenres); EventHandler genressource = (sender, e) => { Tidal.ReadPlayList ("tidal/genres", () => { Application.RunOnMainThread (() => { RemoveFromParent (); A31TidalLogin a31TidalLogin = new A31TidalLogin (); MainPage.MainFrameLayout.AddChidren (a31TidalLogin); a31TidalLogin.Show (A31MusicModel.Current); }); }, (path) => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31GenresListPage a31GenresListPage = new A31GenresListPage (); MainPage.MainFrameLayout.AddChidren (a31GenresListPage); a31GenresListPage.Show (path, Language.StringByID(MyInternationalizationString.Genres)); }); }); }; radius3.MouseUpEventHandler += genressource; btnGenres.MouseUpEventHandler += genressource; nextGenres.MouseUpEventHandler += genressource; #endregion #region My muisc..我的音乐... var mymusicrow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (mymusicrow); var radius4 = new Button { Width = Application.GetRealWidth (36), Height = Application.GetRealHeight (36), TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), UnSelectedImagePath = "MusicIcon/radius.png", Gravity = Gravity.CenterVertical, }; mymusicrow.AddChidren (radius4); var btnmymusic = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Mymuisc, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; mymusicrow.AddChidren (btnmymusic); var nextmymusic = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; mymusicrow.AddChidren (nextmymusic); EventHandler mymusic = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31TidalMymusic a31TidalMymusic = new A31TidalMymusic (); MainPage.MainFrameLayout.AddChidren (a31TidalMymusic); a31TidalMymusic.Show (Language.StringByID(MyInternationalizationString.Mymuisc)); }); }); }; radius4.MouseUpEventHandler += mymusic; btnmymusic.MouseUpEventHandler += mymusic; nextmymusic.MouseUpEventHandler += mymusic; #endregion #region 登录退出 var loginrow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (loginrow); var radius5 = new Button { Width = Application.GetRealWidth (36), Height = Application.GetRealHeight (36), TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), UnSelectedImagePath = "MusicIcon/radius.png", Gravity = Gravity.CenterVertical, }; loginrow.AddChidren (radius5); var tidalConfigText = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (TidalConfig.FileName))); if (tidalConfigText != null) { var btnlogin = new Button { Width=Application.GetRealWidth(400), Height = Application.GetRealHeight (100), Text = tidalConfigText.UserName, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; loginrow.AddChidren (btnlogin); } var nextlogin = new Button { Width = Application.GetRealWidth (120), Height = Application.GetRealHeight (100), TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (520), TextID=MyInternationalizationString.logout, Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; loginrow.AddChidren (nextlogin); nextlogin.MouseUpEventHandler += (sender, e) => { Shared.IO.FileUtils.DeleteFile (Tidal.fileName); Tidal.CurrentTidal.IsLogin = false; loginrow.BackgroundColor = 0xffFE5E00; System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { RemoveFromParent (); A31TidalLogin a31TidalLogin = new A31TidalLogin (); MainPage.MainFrameLayout.AddChidren (a31TidalLogin); a31TidalLogin.Show (A31MusicModel.Current); }); }); }; #endregion } } }