陈嘉乐
2020-05-14 1e0014f5c2e2fe1cfaaacfb2bebe8adc577bc944
HDL_ON/UI/Music/View/TipView.cs
@@ -1,233 +1,458 @@
using System;
using System.Collections.Generic;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI.Music.View
{
    public class TipView:FrameLayout
    public class TipView
    {
        public  void FieListView()
        /// <summary>
        /// 大框圆角值
        /// </summary>
        public int RradiusFrameLayout = 15;
        /// <summary>
        /// 小框圆角值
        /// </summary>
        public int radiusEditFrameLayout = 4;
        /// <summary>
        /// 输入框
        /// </summary>
        /// <param name="titleId">标题文本</param>
        /// <param name="tnputEditTxet">输入文本</param>
        /// <param name="errorId_IsNullOrEmpty">输入框文本为空自定义提示错误文本</param>
        /// <param name="errorId_PresenceP">检索已存在名称自定义提示错误文本</param>
        /// <param name="confirmAction">回调函数</param>
        /// <param name="List">被检索列表</param>
        /// <param name="confirmAction">回调函数</param>
        public void InputBox(int titleId, string tnputEditTxet,int errorId_IsNullOrEmpty, int errorId_PresenceP, List<string> List, Action<string> confirmAction)
        {
            //主控件
            Dialog dialog = new Dialog()
            {
                BackgroundColor = Color.PopupBackgroundColor,
            };
            dialog.Show();
            //父控件
            FrameLayout frame = new FrameLayout { };
            dialog.AddChidren(frame);
            frame.MouseUpEventHandler += (sen, e) =>
            FrameLayout whiteView = new FrameLayout()
            {
                dialog.Close();
            };
            //白色快父控件
            FrameLayout dialogFra = new FrameLayout()
            {
                X = Application.GetRealWidth(16),
                Y = Application.GetRealHeight(187),
                Width = Application.GetRealWidth(344),
                Height = Application.GetRealHeight(460),
                //Gravity = Gravity.Center,
                X=Application.GetRealWidth(53),
                Y = Application.GetRealHeight(264),
                Width = Application.GetRealWidth(270),
                Height = Application.GetRealHeight(172),
                BackgroundColor = Color.WhiteColor,
                Radius = (uint)Application.GetRealHeight(12),
                BorderColor = 0x00000000,
                BorderWidth = 0,
                Radius = (uint)Application.GetRealHeight(RradiusFrameLayout),
            };
            frame.AddChidren(dialogFra);
            //显示头部信息父控件
            FrameLayout topFra = new FrameLayout()
            dialog.AddChidren(whiteView);
            Button btnTitle = new Button()
            {
                Width = Application.GetRealWidth(344),
                Height = Application.GetRealHeight(70),
                Y = Application.GetRealHeight(20),
                X=Application.GetRealWidth(35),
                Height = Application.GetRealHeight(22),
                Width=Application.GetRealWidth(200),
                TextColor =Color.SelectedColor,
                TextSize =TextSize.Text16,
                TextAlignment = TextAlignment.Center,
                TextID = titleId,
            };
            dialogFra.AddChidren(topFra);
            //取消控件
            Button cancelnBtn = new Button
            whiteView.AddChidren(btnTitle);
            FrameLayout editBjView = new FrameLayout()
            {
                X = Application.GetRealWidth(16),
                Y = Application.GetRealHeight(24),
                Width = Application.GetRealWidth(100),
                Height = Application.GetRealHeight(20),
                TextID = StringId.cancelMusic,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = Color.MusicNoTxetColor,
               // Gravity = Gravity.CenterHorizontal,
                Y = btnTitle.Bottom + Application.GetRealHeight(16),
                X=Application.GetRealWidth(24),
                Width = Application.GetRealWidth(222),
                Height = Application.GetRealHeight(40),
                BackgroundColor =Color.ViewColor,
                BorderColor = 0x00000000,
                BorderWidth = 0,
                Radius = (uint)Application.GetMinRealAverage(radiusEditFrameLayout),
            };
            whiteView.AddChidren(editBjView);
            EditText editText = new EditText()
            {
                X = Application.GetRealWidth(12),
                Y=Application.GetRealHeight(10),
                Width = Application.GetRealWidth(160),
                Height=Application.GetRealHeight(20),
                Text = tnputEditTxet,
                TextColor = Color.TextColor,
                TextSize = TextSize.Text14,
                TextAlignment=TextAlignment.CenterLeft,
            };
            topFra.AddChidren(cancelnBtn);
            cancelnBtn.MouseUpEventHandler += (sen, e) =>
            editBjView.AddChidren(editText);
            Button clearIconBtn = new Button
            {
                X = Application.GetRealWidth(194),
                Y = Application.GetRealHeight(8),
                Width = Application.GetMinRealAverage(24),
                Height = Application.GetMinRealAverage(24),
                UnSelectedImagePath = "MusicIcon/clear.png",
            };
            editBjView.AddChidren(clearIconBtn);
            clearIconBtn.MouseUpEventHandler += (sender, e) =>
            {
                editText.Text = "";
            };
            Button btnLine = new Button()
            {
                Y = whiteView.Height-Application.GetRealHeight(44+1),
                Height = Application.GetRealHeight(1),
                BackgroundColor =Color.LineColor,
            };
            whiteView.AddChidren(btnLine);
            Button btnCancel = new Button()
            {
                Y = btnLine.Bottom,
                Width = Application.GetRealWidth(135),
                Height = Application.GetRealHeight(44),
                TextAlignment = TextAlignment.Center,
                TextColor = Color.TextCancelColor,
                TextSize = TextSize.Text16,
                TextID = StringId.cancelMusic,
            };
            whiteView.AddChidren(btnCancel);
            Button btnConfirm = new Button()
            {
                X = btnCancel.Right,
                Y = btnLine.Bottom,
                Width = Application.GetRealWidth(135),
                Height = Application.GetRealHeight(44),
                TextAlignment = TextAlignment.Center,
                TextColor = Color.WhiteColor,
                IsBold = true,
                TextSize = TextSize.Text16,
                TextID = StringId.confirmMusic,
                BackgroundColor = Color.SelectedColor,
                Gravity = Gravity.BottomRight,
            };
            whiteView.AddChidren(btnConfirm);
            btnConfirm.SetCornerWithSameRadius(Application.GetRealHeight(RradiusFrameLayout), HDLUtils.RectCornerBottomRight);
            dialog.Show();
            btnCancel.MouseUpEventHandler += (sender, e) =>
            {
                dialog.Close();
            };
            //标题控件
            Button txetBtn = new Button
            Button btnTip = new Button
            {
                X = cancelnBtn.Right + Application.GetRealWidth(20),
                Y = Application.GetRealHeight(23),
                Width = Application.GetRealWidth(100),
                Width = Application.GetRealWidth(0),
            };
            whiteView.AddChidren(btnTip);//一直错误,一直猛点,一直加控件
            btnConfirm.MouseUpEventHandler += (sender, e) =>
            {
                string listNameText = editText.Text.Trim();
                if (string.IsNullOrEmpty(listNameText) || List.Contains(listNameText))
                {
                    string tipMsgString = "";
                    if (string.IsNullOrEmpty(editText.Text.Trim()))
                    {
                        tipMsgString = Language.StringByID(errorId_IsNullOrEmpty);
                    }
                    else
                    {
                        tipMsgString = Language.StringByID(errorId_PresenceP);
                    }
                    whiteView.Height = Application.GetRealHeight(183);
                    btnLine.Y = whiteView.Height - Application.GetRealHeight(44 + 1);
                    btnCancel.Y = btnLine.Bottom;
                    btnConfirm.Y = btnLine.Bottom;
                    btnConfirm.Gravity = Gravity.BottomRight;
                    btnTip.X = Application.GetRealWidth(24);
                    btnTip.Y = editBjView.Bottom + Application.GetRealHeight(12);
                    btnTip.Width = Application.GetRealWidth(222);
                    btnTip.Height = Application.GetRealHeight(17);
                    btnTip.Text = tipMsgString;
                    btnTip.TextColor = Color.RedColor;
                    btnTip.TextSize = TextSize.Text12;
                    btnTip.TextAlignment = TextAlignment.CenterLeft;
                    return;
                }
                confirmAction(editText.Text.Trim());
                dialog.Close();
            };
        }
        /// <summary>
        /// 输入框
        /// </summary>
        /// <param name="titleId">标题文本</param>
        /// <param name="tnputEditTxet">输入文本</param>
        /// <param name="errorId_IsNullOrEmpty">输入框本文为空自定义提示错误文本</param>
        /// <param name="confirmAction">回调函数</param>
        public void InputBox(int titleId, string tnputEditTxet, int errorId_IsNullOrEmpty, Action<string> confirmAction)
        {
            Dialog dialog = new Dialog()
            {
                BackgroundColor = Color.PopupBackgroundColor,
            };
            FrameLayout whiteView = new FrameLayout()
            {
                //Gravity = Gravity.Center,
                X = Application.GetRealWidth(53),
                Y = Application.GetRealHeight(264),
                Width = Application.GetRealWidth(270),
                Height = Application.GetRealHeight(172),
                BackgroundColor = Color.WhiteColor,
                BorderColor = 0x00000000,
                BorderWidth = 0,
                Radius = (uint)Application.GetRealHeight(RradiusFrameLayout),
            };
            dialog.AddChidren(whiteView);
            Button btnTitle = new Button()
            {
                Y = Application.GetRealHeight(20),
                X = Application.GetRealWidth(35),
                Height = Application.GetRealHeight(22),
                TextColor = Color.TextColor,
                Width = Application.GetRealWidth(200),
                TextColor = Color.SelectedColor,
                TextSize = TextSize.Text16,
                TextAlignment = TextAlignment.Center,
                TextID = StringId.myList,
                IsBold=true,
            };
            topFra.AddChidren(txetBtn);
                TextID = titleId,
            //添加图标控件
            Button addIconBtn = new Button
            {
                X = Application.GetRealWidth(304),
                Y = Application.GetRealHeight(20),
                Width = Application.GetMinRealAverage(28),
                Height = Application.GetMinRealAverage(28),
                UnSelectedImagePath = "MusicIcon/addMusic.png",
            };
            topFra.AddChidren(addIconBtn);
            whiteView.AddChidren(btnTitle);
            VerticalScrolViewLayout verticalScrolViewLayout = new VerticalScrolViewLayout
            FrameLayout editBjView = new FrameLayout()
            {
                Y = Application.GetRealHeight(70),
                Height = dialogFra.Height - Application.GetRealHeight(70),
                Width = Application.GetRealWidth(344),
                // Gravity = Gravity.CenterHorizontal,
                Y = btnTitle.Bottom + Application.GetRealHeight(16),
                X = Application.GetRealWidth(24),
                Width = Application.GetRealWidth(222),
                Height = Application.GetRealHeight(40),
                BackgroundColor = Color.ViewColor,
                BorderColor = 0x00000000,
                BorderWidth = 0,
                Radius = (uint)Application.GetMinRealAverage(radiusEditFrameLayout),
            };
            dialogFra.AddChidren(verticalScrolViewLayout);
            addIconBtn.MouseUpEventHandler += (sender, e) =>
            whiteView.AddChidren(editBjView);
            EditText editText = new EditText()
            {
                new PublicAssmebly().LoadDialog_EditParater(StringId.addNewList, StringId.listNameInput, "", (name) =>
                 {
                     if (string.IsNullOrEmpty(name))
                     {
                        //列表名为空
                        new PublicAssmebly().TipMsg(StringId.tip, StringId.listNameNull);
                         return;
                     }
                     foreach (var lists in A31MusicModel.Current.FileLists)
                     {
                         if (lists.ListName == name)
                         {
                            //列表名称相同
                            new PublicAssmebly().TipMsg(StringId.tip, StringId.listNamesSame);
                             return;
                         }
                     }
                     A31MusicModel.Current.FileLists.Add(new FileListInfo { ListName = name, });
                     A31MusicModel.Save();
                     FileView(verticalScrolViewLayout);
                 });
                X = Application.GetRealWidth(12),
                Y = Application.GetRealHeight(10),
                Width = Application.GetRealWidth(160),
                Height = Application.GetRealHeight(20),
                Text = tnputEditTxet,
                TextColor = Color.TextColor,
                TextSize = TextSize.Text14,
                TextAlignment = TextAlignment.CenterLeft,
            };
            FileView(verticalScrolViewLayout);
            editBjView.AddChidren(editText);
            Button clearIconBtn = new Button
            {
                X = Application.GetRealWidth(194),
                Y = Application.GetRealHeight(8),
                Width = Application.GetMinRealAverage(24),
                Height = Application.GetMinRealAverage(24),
                UnSelectedImagePath = "MusicIcon/clear.png",
            };
            editBjView.AddChidren(clearIconBtn);
            clearIconBtn.MouseUpEventHandler += (sender, e) =>
            {
                editText.Text = "";
            };
            Button btnLine = new Button()
            {
                Y = whiteView.Height - Application.GetRealHeight(44 + 1),
                Height = Application.GetRealHeight(1),
                BackgroundColor = Color.LineColor,
            };
            whiteView.AddChidren(btnLine);
            Button btnCancel = new Button()
            {
                Y = btnLine.Bottom,
                Width = Application.GetRealWidth(135),
                Height = Application.GetRealHeight(44),
                TextAlignment = TextAlignment.Center,
                TextColor = Color.TextCancelColor,
                TextSize = TextSize.Text16,
                TextID = StringId.cancelMusic,
            };
            whiteView.AddChidren(btnCancel);
            Button btnConfirm = new Button()
            {
                X = btnCancel.Right,
                Y = btnLine.Bottom,
                Width = Application.GetRealWidth(135),
                Height = Application.GetRealHeight(44),
                TextAlignment = TextAlignment.Center,
                TextColor = Color.WhiteColor,
                IsBold = true,
                TextSize = TextSize.Text16,
                TextID = StringId.confirmMusic,
                BackgroundColor = Color.SelectedColor,
                Gravity=Gravity.BottomRight,
            };
            whiteView.AddChidren(btnConfirm);
            btnConfirm.SetCornerWithSameRadius(Application.GetRealHeight(RradiusFrameLayout), HDLUtils.RectCornerBottomRight);
            dialog.Show();
            btnCancel.MouseUpEventHandler += (sender, e) =>
            {
                dialog.Close();
            };
            Button btnTip = new Button
            {
                Width = Application.GetRealWidth(0),
            };
            whiteView.AddChidren(btnTip);//一直错误,一直猛点,一直加控件
            btnConfirm.MouseUpEventHandler += (sender, e) =>
            {
                if (string.IsNullOrEmpty(editText.Text.Trim()))
                {
                    whiteView.Height = Application.GetRealHeight(183);
                    btnLine.Y = whiteView.Height - Application.GetRealHeight(44 + 1);
                    btnCancel.Y = btnLine.Bottom;
                    btnConfirm.Y = btnLine.Bottom;
                    btnConfirm.Gravity = Gravity.BottomRight;
                    btnTip.X = Application.GetRealWidth(24);
                    btnTip.Y = editBjView.Bottom + Application.GetRealHeight(12);
                    btnTip.Width = Application.GetRealWidth(222);
                    btnTip.Height = Application.GetRealHeight(17);
                    btnTip.Text = Language.StringByID(errorId_IsNullOrEmpty);
                    btnTip.TextColor = Color.RedColor;
                    btnTip.TextSize = TextSize.Text12;
                    btnTip.TextAlignment = TextAlignment.CenterLeft;
                    return;
                }
                confirmAction(editText.Text.Trim());
                dialog.Close();
            };
        }
        void FileView(VerticalScrolViewLayout verticalScrolViewLayout)
        /// <summary>
        /// 确定提示框
        /// </summary>
        /// <param name="titleId">标题文本</param>
        /// <param name="tipTxet">自定义提示文本</param>
        /// <param name="confirmAction">回调函数</param>
        public void TipBox(int titleId, int tipTxet, Action confirmAction)
        {
            verticalScrolViewLayout.RemoveAll();
            for (int i = 0; i < A31MusicModel.Current.FileLists.Count; i++)
            Dialog dialog = new Dialog()
            {
                var list = A31MusicModel.Current.FileLists[i];
                RowLayout addFlieRow = new RowLayout
                {
                    Height = Application.GetRealHeight(78),
                    LineColor = Color.WhiteColor,
                    SubViewWidth = Application.GetRealWidth(80),//改变编辑控件宽度多少;
                };
                verticalScrolViewLayout.AddChidren(addFlieRow);
                //文件图标
                Button fileIconBtn = new Button
                {
                    X = Application.GetRealWidth(12),
                    Y = Application.GetRealHeight(8),
                    Width = Application.GetMinRealAverage(62),
                    Height = Application.GetMinRealAverage(62),
                    UnSelectedImagePath = "MusicIcon/file.png",
                };
                addFlieRow.AddChidren(fileIconBtn);
                BackgroundColor = Color.PopupBackgroundColor,
            };
                //文件名控件
                Button fileNameBtn = new Button
                {
                    X = fileIconBtn.Right + Application.GetRealWidth(12),
                    Y = Application.GetRealHeight(29),
                    Width = Application.GetRealWidth(189),
                    Height = Application.GetRealHeight(20),
                    TextColor = Color.TextColor,
                    TextSize = TextSize.Text14,
                    TextAlignment = TextAlignment.CenterLeft,
                    Text = list.ListName,
                };
                addFlieRow.AddChidren(fileNameBtn);
            FrameLayout whiteView = new FrameLayout()
            {
                //Gravity = Gravity.Center,
                X = Application.GetRealWidth(53),
                Y = Application.GetRealHeight(264),
                Width = Application.GetRealWidth(270),
                Height = Application.GetRealHeight(140),
                BackgroundColor = Color.WhiteColor,
                BorderColor = 0x00000000,
                BorderWidth = 0,
                Radius = (uint)Application.GetRealHeight(RradiusFrameLayout),
            };
            dialog.AddChidren(whiteView);
                ///编辑控件
                var editBtn = new Button
                {
                    BackgroundColor = Color.MusicEditColor,
                    Text = Language.StringByID(StringId.editMusic),
                    TextColor = Color.WhiteColor,
                    TextSize = TextSize.Text16,
                };
                addFlieRow.AddRightView(editBtn);
            Button titleBtn = new Button()
            {
                Y = Application.GetRealHeight(20),
                X = Application.GetRealWidth(35),
                Height = Application.GetRealHeight(22),
                Width = Application.GetRealWidth(270 - 35 * 2),
                TextColor = Color.SelectedColor,
                TextSize = TextSize.Text16,
                TextAlignment = TextAlignment.Center,
                TextID = titleId,
            };
            whiteView.AddChidren(titleBtn);
                editBtn.MouseUpEventHandler += (sender, e) =>
                {
                    new PublicAssmebly().LoadDialog_EditParater(StringId.ChangeName, list.ListName, (name) =>
                        {
                            if (string.IsNullOrEmpty(name))
                            {
                                //列表名为空
                                new PublicAssmebly().TipMsg(StringId.tip, StringId.listNameNull);
                                return;
                            }
                            foreach (var lists in A31MusicModel.Current.FileLists)
                            {
                                if (lists.ListName == name)
                                {
                                    //列表名称相同
                                    new PublicAssmebly().TipMsg(StringId.tip, StringId.listNamesSame);
                                    return;
                                }
                            }
            Button tipBtn = new Button()
            {
                Y = titleBtn.Bottom + Application.GetRealHeight(8),
                X = Application.GetRealWidth(20),
                Height = Application.GetRealHeight(22),
                Width = Application.GetRealWidth(270 - 20 * 2),
                TextColor = Color.TextCancelColor,
                TextSize = TextSize.Text12,
                TextAlignment = TextAlignment.Center,
                TextID = tipTxet,
            };
            whiteView.AddChidren(tipBtn);
                            var file = A31MusicModel.Current.FileLists.Find((c) => { return c.ListName == list.ListName; });
                            if (file != null)
                            {
                                if (file.ListName != name)
                                {  ///修改名称不一样更新保存
                                    file.ListName = name;
                                    fileNameBtn.Text = name;
                                    A31MusicModel.Save();
                                }
                            }
                            if (list.ListName != name)
                            {  ///修改名称不一样更新保存
                                list.ListName = name;
                                fileNameBtn.Text = name;
                                A31MusicModel.Save();
                            }
                        });
                };
            Button btnLine = new Button()
            {
                Y = whiteView.Height - Application.GetRealHeight(44 + 1),
                Height = Application.GetRealHeight(1),
                BackgroundColor = Color.LineColor,
            };
            whiteView.AddChidren(btnLine);
                ///删除控件
                var delBtn = new Button
                {
                    BackgroundColor = Color.MusicDelColor,
                    Text = Language.StringByID(StringId.delMusic),
                    TextColor = Color.WhiteColor,
                    TextSize=TextSize.Text16,
                };
                addFlieRow.AddRightView(delBtn);
                delBtn.MouseUpEventHandler += (sender, e) =>
                {
                    new PublicAssmebly().TipMsg(StringId.tip, StringId.delMusicFile, () =>
                    {
                        addFlieRow.RemoveFromParent();
                        A31MusicModel.Current.FileLists.Remove(list);
                        A31MusicModel.Save();
                    });
            Button btnCancel = new Button()
            {
                Y = btnLine.Bottom,
                Width = Application.GetRealWidth(135),
                Height = Application.GetRealHeight(44),
                TextAlignment = TextAlignment.Center,
                TextColor = Color.TextCancelColor,
                TextSize = TextSize.Text16,
                TextID = StringId.cancelMusic,
            };
            whiteView.AddChidren(btnCancel);
                };
            Button btnConfirm = new Button()
            {
                X = btnCancel.Right,
                Y = btnLine.Bottom,
                Width = Application.GetRealWidth(135),
                Height = Application.GetRealHeight(44),
                TextAlignment = TextAlignment.Center,
                TextColor = Color.WhiteColor,
                IsBold = true,
                TextSize = TextSize.Text16,
                TextID = StringId.confirmMusic,
                BackgroundColor = Color.SelectedColor,
                Gravity = Gravity.BottomRight,
            };
            whiteView.AddChidren(btnConfirm);
            btnConfirm.SetCornerWithSameRadius(Application.GetRealHeight(RradiusFrameLayout), HDLUtils.RectCornerBottomRight);
            dialog.Show();
            btnCancel.MouseUpEventHandler += (sender, e) =>
            {
                dialog.Close();
            };
            }
            btnConfirm.MouseUpEventHandler += (sender, e) =>
            {
                confirmAction();
                dialog.Close();
            };
        }
    }
}