| | |
| | | using System; |
| | | using HDL_ON.DriverLayer; |
| | | using HDL_ON.Entity; |
| | | using Shared; |
| | | |
| | | namespace HDL_ON.UI |
| | | { |
| | | |
| | | |
| | | public partial class HomePage |
| | | { |
| | | /// <summary> |
| | | /// 更新主页天气 |
| | | /// </summary> |
| | | public static void LoadEvent_RefreshAir() |
| | | { |
| | | bodyView.btnTempValues.Text = MainPage.cityInfo.temperature == null ? "--" : MainPage.cityInfo.temperature + "°"; |
| | | bodyView.btnHumidityValues.Text = MainPage.cityInfo.humidity == null ? "--" : MainPage.cityInfo.humidity + "%"; |
| | | bodyView.btnPm25Values.Text = MainPage.cityInfo.pm25 == null ? "--" : MainPage.cityInfo.pm25; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载功能收藏按钮事件 |
| | | /// </summary> |
| | | void LoadEvent_FunctionCollection(Button btn,Function function,bool isDevice) |
| | | { |
| | | btn.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | function.collection = false; |
| | | if(function.functionCategory == FunctionCategory.Music)//处理音乐主从关系 |
| | | { |
| | | if ((function as Music.A31MusicModel).ServerClientType == 1) |
| | | { |
| | | (function as Music.A31MusicModel).MainPlayCollection = false; |
| | | Music.A31MusicModel.Save(); |
| | | } |
| | | } |
| | | string msg = function.name + Language.StringByID(StringId.CollectionCancelled); |
| | | if (isDevice) |
| | | { |
| | | LoadDeviceFunctionControlZone(); |
| | | } |
| | | else |
| | | { |
| | | LoadSceneFunctionControlZone(); |
| | | } |
| | | function.SaveFunctionData(); |
| | | new PublicAssmebly().TipMsgAutoClose(msg, true); |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改显示的功能类型 |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 更新灯光显示状态 |
| | | /// 更新显示状态 |
| | | /// </summary> |
| | | /// <param name="light"></param> |
| | | public static void UpdataLightView(Light light) |
| | | public static void UpdataFunctionStates(Function function) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | if (bodyView != null) |
| | | try |
| | | { |
| | | foreach (var dic in LightViews) |
| | | if (bodyView != null) |
| | | { |
| | | if (dic.Key == light.sid) |
| | | foreach (var view in bodyView.functionViews) |
| | | { |
| | | var state = light.on_off == 1; |
| | | var view = dic.Value; |
| | | for (int i = 0; i < view.ChildrenCount; i++) |
| | | if (view.Tag.ToString() == function.sid) |
| | | { |
| | | if (view.GetChildren(i).GetType() == typeof(Button)) |
| | | var state = function.trait_on_off.value.ToString() == "on"; |
| | | for (int i = 0; i < view.ChildrenCount; i++) |
| | | { |
| | | var btn = view.GetChildren(i) as Button; |
| | | btn.IsSelected = state; |
| | | if (btn.Tag != null && btn.Tag.ToString() == "state") |
| | | if (view.GetChildren(i).GetType() == typeof(Button)) |
| | | { |
| | | btn.Text = light.lastState; |
| | | var btn = view.GetChildren(i) as Button; |
| | | btn.IsSelected = state; |
| | | if (btn.Tag != null && btn.Tag.ToString() == "state") |
| | | { |
| | | if(function.functionCategory == FunctionCategory.Music) |
| | | { |
| | | btn.Text = (function as Music.A31MusicModel).A31PlayStatus.Title; |
| | | } |
| | | else |
| | | { |
| | | btn.Text = function.lastState; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"HomePage updata funciton states error {ex.Message}"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载继电器开关事件 |
| | | /// 加载场景控制事件 |
| | | /// </summary> |
| | | void LoadEvent_ControlScene(Button btnCoverd,Button btnName,Button btnZone ,Function function) |
| | | { |
| | | |
| | | EventHandler<MouseEventArgs> eventHandler = (sender, e) => |
| | | { |
| | | string msg = function.name + Language.StringByID(StringId.AlreadyOpened); |
| | | new PublicAssmebly().TipMsgAutoClose(msg, true); |
| | | Control.ins.ControlScene(function as Scene); |
| | | }; |
| | | btnCoverd.MouseUpEventHandler = eventHandler; |
| | | btnName.MouseUpEventHandler = eventHandler; |
| | | btnZone.MouseUpEventHandler = eventHandler; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载灯光开关事件 |
| | | /// </summary> |
| | | /// <param name="function"></param> |
| | | /// <param name="btnSwitch"></param> |
| | | /// <param name="view"></param> |
| | | void LoadRelaySwitchEvent(Function function, Button btnSwitch, FrameLayout view) |
| | | void LoadEvent_SwitchFunction(Function function, Button btnSwitch) |
| | | { |
| | | |
| | | btnSwitch.MouseUpEventHandler += (sender, e) => |
| | | btnSwitch.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | if (function.functionCategory == FunctionType.Light) |
| | | btnSwitch.IsSelected = !btnSwitch.IsSelected; |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var curState = !btnSwitch.IsSelected; |
| | | for (int i = 0; i < view.ChildrenCount; i++) |
| | | { |
| | | if (view.GetChildren(i).GetType() == typeof(Button)) |
| | | { |
| | | var btn = view.GetChildren(i) as Button; |
| | | btn.IsSelected = curState; |
| | | } |
| | | } |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var light = function as Light; |
| | | light.on_off = btnSwitch.IsSelected ? 1 : 0; |
| | | Control.Send("write", function); |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | function.trait_on_off.value = btnSwitch.IsSelected ? "on" : "off"; |
| | | System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>(); |
| | | d.Add("on_off", function.trait_on_off.value.ToString()); |
| | | Control.ins.SendWriteCommand(function, d); |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载电视控制事件 |
| | | /// </summary> |
| | | /// <param name="tV"></param> |
| | | /// <param name="button"></param> |
| | | void LoadEvent_ControlTV(TV tV,Button button) |
| | | { |
| | | button.MouseUpEventHandler = (sender, e) => { |
| | | tV.ControlTV(InfraredCode_TV.Power); |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载窗帘控制事件 |
| | | /// </summary> |
| | | void LoadEvent_ControlCurtain(Curtain curtain, Button btnClose, Button btnOpen) |
| | | { |
| | | btnClose.MouseDownEventHandler = (sender, e) => |
| | | { |
| | | btnClose.IsSelected = true; |
| | | }; |
| | | btnClose.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | btnClose.IsSelected = false; |
| | | curtain.trait_on_off.value = "off"; |
| | | curtain.percent = 0; |
| | | System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>(); |
| | | d.Add("on_off",curtain.trait_on_off.value.ToString()); |
| | | Control.ins.SendWriteCommand(curtain, d); |
| | | }; |
| | | |
| | | btnOpen.MouseDownEventHandler = (sender, e) => |
| | | { |
| | | btnOpen.IsSelected = true; |
| | | }; |
| | | btnOpen.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | btnOpen.IsSelected = false; |
| | | curtain.trait_on_off.value = "on"; |
| | | curtain.percent = 100; |
| | | System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>(); |
| | | d.Add("on_off", curtain.trait_on_off.value.ToString()); |
| | | Control.ins.SendWriteCommand(curtain, d); |
| | | }; |
| | | } |
| | | |
| | | } |
| | | } |