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.GetRealWidth(28), Height = Application.GetRealWidth(28), UnSelectedImagePath = "MusicIcon/addMusic.png", }; topView.TopFLayoutView().AddChidren(addIconBtn); addIconBtn.MouseUpEventHandler += (sender, e) => { var fileNameList = new List(); 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(); } /// /// 加载文件夹View的方法 /// 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.GetRealWidth(88), Height = Application.GetRealWidth(88), UnSelectedImagePath = "MusicIcon/fileList.png", }; addFlieRow.AddChidren(fileIconBtn); //播放/暂停图标 Button playIconBtn = new Button { X = Application.GetRealWidth(78), Y = Application.GetRealHeight(70), Width = Application.GetRealWidth(24), Height = Application.GetRealWidth(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(); 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(); }; } } /// /// 定时更新文件夹播放状态 /// 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(); } } }