CrabtreeOn,印度客户定制APP,迁移2.0平台版本
JLChen
2021-03-04 ac3c6b64df51443519d3a27fa8cf0d25dd6ff6d7
Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/AddSchedule.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Shared.SimpleControl.Phone.Music;
namespace Shared.SimpleControl.Phone
@@ -666,13 +667,15 @@
                        timerTemp.whichDay.Add (5);
                    }
                }
                if (string.IsNullOrEmpty (timerTemp.id)) {
                    timerTemp.id =Guid.NewGuid().ToString ();
                }
                //if (string.IsNullOrEmpty (timerTemp.id)) {
                //    timerTemp.id = Guid.NewGuid ().ToString ();
                //}
                DeviceDate deviceDate = new DeviceDate ();
                deviceDate.gatewayId = SmartHome.Send.GatewayId;
                deviceDate.homeId = SmartHome.Send.HomeId;
                deviceDate.actions.AddRange (selectedDeviceList);
                timerTemp.controlData = deviceDate;
@@ -687,6 +690,8 @@
                            revertObj = SmartHome.Send.UpdateTimer (timerTemp);
                        } else {
                            revertObj = SmartHome.Send.AddTimer (timerTemp);
                        }
@@ -694,12 +699,23 @@
                            if (revertObj == null) {
                                new Alert ("", "Unable to save data, please check the network.", "Close").Show ();
                            } else if (revertObj.Code == StateCode.SUCCESS) {
                                string id = "";
                                if (!isEdit) {
                                    var jObject = JObject.Parse (revertObj.Data.ToString ());
                                     id = jObject ["id"].ToString ();
                                    timerTemp.id = id;
                                }
                                this.RemoveFromParent ();
                                action (timerTemp);
                            } else {
                                //提示错误
                                SmartHome.Method method = new SmartHome.Method ();
                                if (revertObj.Data != null) {
                                method.ShowGetTimerListErrorInfo (revertObj.Data.ToString ());
                                }
                            }
                        });
                    } catch (Exception ex) {
@@ -773,7 +789,8 @@
                                    deviceRowView.AddChidren (tempSwitch);
                                    switch (device.spk) {
                                    case "light.dimming": {
                                //DeviceType.LightDALI
                                case SPK.LightDimming: {
                                            #region 调光器A
                                            tempSwitch.RemoveFromParent ();
@@ -832,6 +849,7 @@
                                                    }
                                                    for (int a = 0; a < dev.attributes.Count; a++) {
                                                        var fundev = dev.attributes [a];
                                                        if (fundev.key == "brightness") {
                                                        if (fundev.value == "0") {
                                                            btnLevel.Text = "OFF";
                                                        } else {
@@ -840,12 +858,17 @@
                                                        levelBar.Progress = int.Parse (fundev.value);
                                                    }
                                                }
                                                }
                                                } catch { }
                                            }
                                            #endregion
                                        }
                                        break;
                                    case "light.switch": {
                                //DeviceType.LightEnergySwitch
                                //DeviceType.LightEnergySocket
                                //DeviceType.LightSwitchSocket
                                case SPK.ElectricSocket:
                                case SPK.LightSwitch: {
                                            #region 继电器
                                            tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                                                tempSwitch.IsSelected = !tempSwitch.IsSelected;
@@ -864,7 +887,7 @@
                                        
                                            btnChoose.MouseUpEventHandler += (dds, ddss) => {
                                                btnChoose.IsSelected = !btnChoose.IsSelected;
                                                if (btnChoose.IsSelected) {
                                            if (tempSwitch.IsSelected) {
                                                    value = "on";
                                                } else {
                                                    value = "off";
@@ -894,9 +917,9 @@
                                            #endregion
                                        }
                                        break;
                                    case "curtain.roller":
                                    case "curtain.trietex":
                                    case "curtain.switch": {
                                case SPK.CurtainRoller:
                                case SPK.CurtainTrietex:
                                case SPK.CurtainSwitch: {
                                            #region 窗帘
                                            tempSwitch.RemoveFromParent ();
                                            var tempSwitch1 = new Button () {
@@ -967,11 +990,7 @@
                                            #endregion
                                        }
                                        break;
                                    case "electrical.socket": {
                                        }
                                        break;
                                    case "fan": {
                                case SPK.ElectricFan: {
                                            #region 风扇
                                            tempSwitch.RemoveFromParent ();
                                            deviceRowView.Height = Application.GetRealHeight (130);
@@ -1008,7 +1027,6 @@
                                                    btnFanLevelTip.TextSize = 11;
                                                }
                                            }
                                            var fanLevel = new HorizontalSeekBar () {
                                                X = btnFanLevel.Right,
                                                Y = btnFanLevel.Y + Application.GetRealHeight (10),
@@ -1022,14 +1040,18 @@
                                            };
                                            deviceRowView.AddChidren (fanLevel);
                                        value = "2";
                                            fanLevel.ProgressChanged += (sender, e) => {
                                            if (!btnChoose.IsSelected) {
                                                btnChoose.IsSelected = true;
                                            }
                                                value = e.ToString ();
                                                DeviceDateFun (btnChoose.Tag as Function, value, btnChoose.IsSelected);
                                            };
                                            btnChoose.MouseUpEventHandler += (dds, ddss) => {
                                                btnChoose.IsSelected = !btnChoose.IsSelected;
                                                DeviceDateFun (btnChoose.Tag as Function, "0", btnChoose.IsSelected);
                                            DeviceDateFun (btnChoose.Tag as Function, value, btnChoose.IsSelected);
                                            };
                                            if (IsEdit) {
                                                try {
@@ -1040,11 +1062,15 @@
                                                        }
                                                        for (int a = 0; a < dev.attributes.Count; a++) {
                                                            var fundev = dev.attributes [a];
                                                            if (fundev.value == "0") {
                                                        if (fundev.key == "fan_speed_percent") {
                                                           // if (fundev.value == "0") {
                                                                //btnLevel.Text = "OFF";
                                                            } else {
                                                          //  } else {
                                                                fanLevel.Progress = int.Parse (fundev.value);
                                                           // }
                                                            }
                                                           
                                                        }
                                                    }
@@ -1084,16 +1110,20 @@
        {
            string keyValue = "";
            switch (function.spk) {
            case "curtain.trietex":
            case "curtain.roller":
            case "light.switch":
            case "curtain.switch":
            case "electrical.socket": {
            case SPK.CurtainTrietex:
            case SPK.CurtainRoller:
            case SPK.LightSwitch:
            case SPK.CurtainSwitch:
            case SPK.ElectricSocket: {
                    keyValue = "on_off";
                }
                break;
            case "light.dimming": {
            case SPK.LightDimming: {
                    keyValue = "brightness";
                }
                break;
            case SPK.ElectricFan: {
                    keyValue = "fan_speed_percent";
                }
                break;
@@ -1113,6 +1143,43 @@
        /// <param name="isSelected">判断控件点击状态</param>
        public  void AddDeviceList (Fun fun, bool isSelected)
        {
            switch (fun.spk) {
            case SPK.LightDimming: {
                    //调光做了一个特殊处理;
                    if (fun.attributes.Count == 1) {
                        var dic = fun.attributes [0];
                        if (dic.key == "brightness") {
                            Attributes attributes = new Attributes ();
                            attributes.key = "on_off";
                            if (dic.value == "0") {
                                attributes.value = "off";
                            } else {
                                attributes.value = "on";
                            }
                            fun.attributes.Add (attributes);
                        }
                    }
                    break;
                }
            case SPK.ElectricFan: {
                    if (fun.attributes.Count == 1) {
                        var dic = fun.attributes [0];
                        if (dic.key == "fan_speed_percent") {
                            Attributes attributes = new Attributes ();
                            attributes.key = "on_off";
                            if (dic.value == "0") {
                                attributes.value = "off";
                            } else {
                                attributes.value = "on";
                            }
                            fun.attributes.Add (attributes);
                        }
                    }
                }
                break;
            }
            var device = selectedDeviceList.Find ((dev) => dev.deviceId == fun.deviceId);
            if (device != null) {
                selectedDeviceList.Remove (device);