mac
2024-07-25 3f6685c77beeb12baf840733fb890860f4c26e7c
HDL_ON/UI/UI2/FuntionControlView/VideoDoorLock/VideoDoorlockAudioSetupPage.cs
@@ -12,8 +12,17 @@
        FrameLayout bodyView;
        Function device;
        /// <summary>
        /// 门锁系统音量
        /// </summary>
        DoorLockSystemSound doorLockSystemSound;
        /// <summary>
        /// 门铃音量
        /// </summary>
        int doorbellVol = 0;
        public VideoDoorlockAudioSetupPage(Function function)
        {
            doorLockSystemSound = new DoorLockSystemSound();
            device = function;
            bodyView = this;
        }
@@ -65,7 +74,7 @@
            btnDoorlockSystemVolumeText.MouseUpEventHandler = (sender, e) =>
            {
                LoadEditDialog(StringId.DoorlockSystemVolume, btnDoorlockSystemVolumeStateText,true);
            };
            #endregion
@@ -115,6 +124,7 @@
            btnDoorbellVolumeText.MouseUpEventHandler = (sender, e) =>
            {
                LoadEditDialog(StringId.DoorbellVolume, btnDoorbellVolumeStateText,false);
            };
            #endregion
@@ -139,7 +149,7 @@
                        Application.RunOnMainThread(() =>
                        {
                            //更新界面
                            var doorLockSystemSound = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLockSystemSound>(pack.Data.ToString());
                            doorLockSystemSound = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLockSystemSound>(pack.Data.ToString());
                            if(doorLockSystemSound != null)
                            {
                                switch (doorLockSystemSound.sound)
@@ -165,7 +175,11 @@
                        //失败提示
                        Application.RunOnMainThread(() =>
                        {
                            if (!string.IsNullOrEmpty(pack.message))
                            if (string.IsNullOrEmpty(pack.message))
                            {
                                pack.message = Language.StringByID(StringId.OperationFailed);
                            }
                            {
                                var tip = new Tip()
                                {
@@ -191,18 +205,22 @@
                            {
                                if (doorbellTone.volume == 0)
                                {
                                    doorbellVol = 0;
                                    btnDoorbellVolumeStateText.TextID = StringId.Mute;
                                }
                                else if (doorbellTone.volume > 0 && doorbellTone.volume < 35)
                                {
                                    doorbellVol = 1;
                                    btnDoorbellVolumeStateText.TextID = StringId.Low;
                                }
                                else if (doorbellTone.volume > 35 && doorbellTone.volume < 70)
                                {
                                    doorbellVol = 2;
                                    btnDoorbellVolumeStateText.TextID = StringId.Moderate;
                                }
                                else if (doorbellTone.volume > 70)
                                {
                                    doorbellVol = 3;
                                    btnDoorbellVolumeStateText.TextID = StringId.High;
                                }
                            }
@@ -213,7 +231,10 @@
                        //失败提示
                        Application.RunOnMainThread(() =>
                        {
                            if (!string.IsNullOrEmpty(pack.message))
                            if (string.IsNullOrEmpty(pack.message))
                            {
                                pack.message = Language.StringByID(StringId.OperationFailed);
                            }
                            {
                                var tip = new Tip()
                                {
@@ -253,10 +274,10 @@
        /// <summary>
        /// 加载功能属性数据选择弹窗
        /// </summary>
        void LoadEditDialog_FunctionPar(int titleId, int index, Button btn)
        void LoadEditDialog(int titleId, Button btn,bool isDoorlockSystemVolume)
        {
            Button lastButton = new Button();
            var lastData = "";
            var lastText = "";
            Dialog dialog = new Dialog();
@@ -293,7 +314,7 @@
            {
                Gravity = Gravity.CenterHorizontal,
                TextAlignment = TextAlignment.Center,
                Width = Application.GetRealWidth(100),
                Width = Application.GetRealWidth(150),
                TextID = titleId,
                IsBold = true,
                TextColor = CSS_Color.FirstLevelTitleColor,
@@ -314,14 +335,15 @@
            var btnConfrim = new Button()
            {
                Width = Application.GetRealWidth(320),
                X = Application.GetRealWidth(200),
                Width = Application.GetRealWidth(120),
                TextAlignment = TextAlignment.CenterRight,
                TextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.TextFontSize,
                TextID = StringId.Complete,
            };
            topView.AddChidren(btnConfrim);
            int hei = 1;
            int index = 1;
            var statusList = new List<string>
            {
                Language.StringByID(StringId.High),
@@ -334,11 +356,11 @@
            {
                var row = new FrameLayout()
                {
                    Y = Application.GetRealHeight(50 * hei),
                    Y = Application.GetRealHeight(50 * index),
                    Height = Application.GetRealHeight(50),
                };
                optionBaseView.AddChidren(row);
                if (statusList.Count > hei)
                if (statusList.Count > index)
                {
                    optionBaseView.AddChidren(new Button()
                    {
@@ -349,7 +371,6 @@
                        Height = 1,
                    });
                }
                hei++;
                var btnChoose = new Button()
                {
@@ -359,13 +380,76 @@
                    Height = Application.GetMinRealAverage(28),
                    UnSelectedImagePath = "Public/ChooseIcon.png",
                    SelectedImagePath = "Public/ChooseOnIcon.png",
                    Tag = index - 1,
                };
                row.AddChidren(btnChoose);
                if (index == hei - 1)
                if (isDoorlockSystemVolume) {//设置门锁系统音量
                    switch (doorLockSystemSound.sound)
                    {
                        case 0:
                            if (index == 3 + 1)
                            {
                                lastButton = btnChoose;
                                btnChoose.IsSelected = true;
                            }
                            break;
                        case 1:
                            if (index == 2 + 1)
                            {
                                lastButton = btnChoose;
                                btnChoose.IsSelected = true;
                            }
                            break;
                        case 2:
                            if (index == 1 + 1)
                            {
                                lastButton = btnChoose;
                                btnChoose.IsSelected = true;
                            }
                            break;
                        case 3:
                            if (index == 0 + 1)
                            {
                                lastButton = btnChoose;
                                btnChoose.IsSelected = true;
                            }
                            break;
                    }
                }
                else//设置门铃音量
                {
                    lastButton = btnChoose;
                    btnChoose.IsSelected = true;
                    switch (doorbellVol)
                    {
                        case 0:
                            if (index == 3 + 1)
                            {
                                lastButton = btnChoose;
                                btnChoose.IsSelected = true;
                            }
                            break;
                        case 1:
                            if (index == 2 + 1)
                            {
                                lastButton = btnChoose;
                                btnChoose.IsSelected = true;
                            }
                            break;
                        case 2:
                            if (index == 1 + 1)
                            {
                                lastButton = btnChoose;
                                btnChoose.IsSelected = true;
                            }
                            break;
                        case 3:
                            if (index == 0 + 1)
                            {
                                lastButton = btnChoose;
                                btnChoose.IsSelected = true;
                            }
                            break;
                    }
                }
                var btnPropertyTitle = new Button()
                {
@@ -373,21 +457,24 @@
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.TextFontSize,
                    Tag = index,
                    Text = m
                };
                row.AddChidren(btnPropertyTitle);
                btnPropertyTitle.MouseUpEventHandler = (sender, e) => {
                    if (btnChoose.IsSelected)
                    {
                        return;
                    }
                    btnChoose.IsSelected = true;
                    if (lastButton != null)
                    {
                        lastButton.IsSelected = false;
                    }
                    lastButton = btnChoose;
                    lastData = btnPropertyTitle.Tag.ToString();
                    lastText = btnPropertyTitle.Text;
                };
                index++;
            }
@@ -404,9 +491,201 @@
            };
            btnConfrim.MouseUpEventHandler = (sender, e) => {
                dialog.Close();
                trait.value = lastData;
                //sceneFunction.status.Find((obj) => obj.key == FunctionAttributeKey.OnOff).value = trait.curValue.ToString() ;
                btn.Text = lastText;
                var lastData = lastButton.Tag.ToString();
                if (isDoorlockSystemVolume)
                {
                    var waitPage = new Loading();
                    bodyView.AddChidren(waitPage);
                    waitPage.Start("");
                    new System.Threading.Thread(() => {
                        try
                        {
                            int sound = 0;
                            /// 0-静音 1-低音 2-中音 3-高音 4-自动
                            switch (lastData)
                            {
                                case "0":
                                    sound = 3;
                                    break;
                                case "1":
                                    sound = 2;
                                    break;
                                case "2":
                                    sound = 1;
                                    break;
                                case "3":
                                    sound = 0;
                                    break;
                            }
                            var pack = ApiUtlis.Ins.HttpRequest.SetDoorLockSystemSound(device.deviceId,sound);
                            if (pack != null && pack.Code == StateCode.SUCCESS)
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    //更新界面
                                    switch (sound)
                                    {
                                        case 0:
                                            doorLockSystemSound.sound = 0;
                                            btn.TextID = StringId.Mute;
                                            break;
                                        case 1:
                                            doorLockSystemSound.sound = 1;
                                            btn.TextID = StringId.Low;
                                            break;
                                        case 2:
                                            doorLockSystemSound.sound = 2;
                                            btn.TextID = StringId.Moderate;
                                            break;
                                        case 3:
                                            doorLockSystemSound.sound = 3;
                                            btn.TextID = StringId.High;
                                            break;
                                    }
                                });
                            }
                            else
                            {
                                //失败提示
                                Application.RunOnMainThread(() =>
                                {
                                    if (string.IsNullOrEmpty(pack.message))
                                    {
                                        pack.message = Language.StringByID(StringId.OperationFailed);
                                    }
                                    {
                                        var tip = new Tip()
                                        {
                                            MaxWidth = Application.GetRealWidth(300),
                                            Text = $"{pack.message}({pack.Code})",
                                            CloseTime = 3,
                                            Direction = AMPopTipDirection.None
                                        };
                                        tip.Show(MainPage.BaseView);
                                    }
                                });
                            }
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"{this.GetType()} error 4: {ex.Message}");
                        }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                waitPage.Hide();
                            });
                        }
                    })
                    { IsBackground = true }.Start();
                }
                else
                {
                    var waitPage = new Loading();
                    bodyView.AddChidren(waitPage);
                    waitPage.Start("");
                    new System.Threading.Thread(() => {
                        try
                        {
                            int Vol = 0;
                            switch (lastData)
                            {
                                case "0":
                                    Vol = 100;
                                    break;
                                case "1":
                                    Vol = 70;
                                    break;
                                case "2":
                                    Vol = 30;
                                    break;
                                case "3":
                                    Vol = 0;
                                    break;
                            }
                            var pack = ApiUtlis.Ins.HttpRequest.SetDoorBellTone(device.deviceId,Vol);
                            if (pack != null && pack.Code == StateCode.SUCCESS)
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    //更新界面
                                    switch (lastData)
                                    {
                                        case "0":
                                            doorbellVol = 3;
                                            btn.TextID = StringId.High;
                                            break;
                                        case "1":
                                            doorbellVol = 2;
                                            btn.TextID = StringId.Moderate;
                                            break;
                                        case "2":
                                            doorbellVol = 1;
                                            btn.TextID = StringId.Low;
                                            break;
                                        case "3":
                                            doorbellVol = 0;
                                            btn.TextID = StringId.Mute;
                                            break;
                                    }
                                });
                            }
                            else
                            {
                                //失败提示
                                Application.RunOnMainThread(() =>
                                {
                                    if (string.IsNullOrEmpty(pack.message))
                                    {
                                        pack.message = Language.StringByID(StringId.OperationFailed);
                                    }
                                    {
                                        var tip = new Tip()
                                        {
                                            MaxWidth = Application.GetRealWidth(300),
                                            Text = $"{pack.message}({pack.Code})",
                                            CloseTime = 3,
                                            Direction = AMPopTipDirection.None
                                        };
                                        tip.Show(MainPage.BaseView);
                                    }
                                });
                            }
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"{this.GetType()} error 5 : {ex.Message}");
                        }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                waitPage.Hide();
                            });
                        }
                    })
                    { IsBackground = true }.Start();
                }
            };
        }