using System;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
public partial class ACPage
{
static DateTime updataTime = DateTime.MinValue;
public static void UpdataStates(AC uAc)
{
try
{
Application.RunOnMainThread(() =>
{
if (bodyView == null)
{
return;
}
if (updataTime.AddMilliseconds(300) > DateTime.Now)
{
return;
}
updataTime = DateTime.Now;
bodyView.arcBar.ProgressBarColor = bodyView.aC.trait_on_off.curValue.ToString() == "on" ? CSS_Color.MainColor : CSS_Color.PromptingColor2;
bodyView.btnTemp.Text = uAc.trait_temp.curValue.ToString();
bodyView.btnIndoorTemp.Text = Language.StringByID(StringId.IndoorTemp) + Convert.ToInt32(Convert.ToDouble(uAc.trait_IndoorTemp.curValue)) + "°C";
bodyView.btnMode.UnSelectedImagePath = uAc.curModeImage;
bodyView.btnWindSpeed.UnSelectedImagePath = uAc.curFanImage;
bodyView.btnSwitch.IsSelected = uAc.trait_on_off.curValue.ToString() == "on";
if (uAc.refreshTime.AddMilliseconds(1000) < DateTime.Now)
{
bodyView.arcBar.Progress = Convert.ToInt32(Convert.ToDouble(uAc.trait_temp.curValue));
}
bodyView.arcBar.ThumbImagePath = uAc.trait_on_off.curValue.ToString() == "on" ? "FunctionIcon/AC/DiyThumbIconOn.png" : "FunctionIcon/AC/DiyThumbIcon.png";
bodyView.arcBar.IsClickable = uAc.trait_on_off.curValue.ToString() == "on";
});
}
catch (Exception ex)
{
MainPage.Log($"acpage updata error {ex.Message}");
}
}
void LoadEventList()
{
LoadCollectionEvent();
LoadEvent_AcStatesChange();
LoadEvent_TempChange();
//回退刷新信息事件
actionRefresh = () =>
{
btnFunctionName.Text = btnFunctionName_Out.Text = aC.name;
btnFromFloor_Out.Text = btnFromFoorAndRoom.Text = aC.GetRoomListName();
};
}
///
/// 收藏功能按钮事件
///
void LoadCollectionEvent()
{
btnCollection.MouseUpEventHandler += (sender, e) =>
{
btnCollection.IsSelected = aC.collect = btnCollection_Out.IsSelected = !btnCollection.IsSelected;
aC.SaveFunctionData(true);
};
}
///
/// 温度改变模式
///
void LoadEvent_TempChange()
{
btnMinus.MouseUpEventHandler = (sender, e) =>
{
var temp = Convert.ToInt32(aC.trait_temp.curValue);
if (temp < 17)
{
return;
}
temp--;
arcBar.Progress = temp;
btnTemp.Text = temp.ToString();
aC.trait_temp.curValue = temp.ToString();
//Control.Send(CommandType_A.write, aC);
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add(FunctionAttributeKey.SetTemp, temp.ToString());
Control.Ins.SendWriteCommand(aC, d);
};
btnPlus.MouseUpEventHandler = (sender, e) =>
{
var temp = Convert.ToInt32(aC.trait_temp.curValue);
if (temp > 37)
{
return;
}
temp++;
arcBar.Progress = temp;
btnTemp.Text = temp.ToString();
aC.trait_temp.curValue = temp.ToString();
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add(FunctionAttributeKey.SetTemp, aC.trait_temp.curValue.ToString());
Control.Ins.SendWriteCommand(aC, d);
//aC.GetSendJObject
};
arcBar.OnStopTrackingTouchEvent = (sender, e) =>
{
aC.trait_temp.curValue = arcBar.Progress.ToString();
btnTemp.Text = aC.trait_temp.curValue.ToString();
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add(FunctionAttributeKey.SetTemp, aC.trait_temp.curValue.ToString());
Control.Ins.SendWriteCommand(aC, d);
};
arcBar.OnProgressChangedEvent = (sender, e) =>
{
aC.trait_temp.curValue = e.ToString();
btnTemp.Text = aC.trait_temp.curValue.ToString();
};
}
///
/// 控制模式事件
///
void LoadEvent_AcStatesChange()
{
btnMode.MouseUpEventHandler = (sender, e) =>
{
LoadDiv_ChangeModeView();
};
btnWindSpeed.MouseUpEventHandler = (sender, e) =>
{
LoadDiv_ChangeFanView();
};
btnSwitch.MouseUpEventHandler = (sender, e) =>
{
btnSwitch.IsSelected = !btnSwitch.IsSelected;
aC.trait_on_off.curValue = btnSwitch.IsSelected ? "on" : "off";
if (aC.trait_on_off.curValue.ToString() == "on")
{
arcBar.ThumbImagePath = "FunctionIcon/AC/DiyThumbIconOn.png";
btnSwitch.IsSelected = true;
arcBar.IsOffline = false;
}
else
{
arcBar.ThumbImagePath = "FunctionIcon/AC/DiyThumbIcon.png";
btnSwitch.IsBold = false;
arcBar.IsOffline = true;
}
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add(FunctionAttributeKey.OnOff, aC.trait_on_off.curValue.ToString());
Control.Ins.SendWriteCommand(aC, d);
};
}
///
/// 加载模式改变事件
///
void LoadEvent_ChangeMode(Dialog dialog, FrameLayout dialogView, Button btn1, Button btn2, string curMode)
{
EventHandler eventHandler = (sender, e) =>
{
dialog.Close();
};
EventHandler eventHandler1 = (sender, e) =>
{
btn1.IsSelected = btn2.IsSelected = true;
aC.trait_mode.curValue = curMode;
btnMode.UnSelectedImagePath = aC.curModeImage;
//Control.Send(CommandType_A.write, aC);
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add(FunctionAttributeKey.Mode, curMode);
Control.Ins.SendWriteCommand(aC, d);
dialog.Close();
};
btn1.MouseUpEventHandler = eventHandler1;
btn2.MouseUpEventHandler = eventHandler1;
dialogView.MouseUpEventHandler = eventHandler;
}
///
/// 加载风速改变事件
///
void LoadEvent_ChangeFan(Dialog dialog, FrameLayout dialogView, Button btn1, Button btn2, string curFan)
{
EventHandler eventHandler = (sender, e) =>
{
dialog.Close();
};
EventHandler eventHandler1 = (sender, e) =>
{
btn1.IsSelected = btn2.IsSelected = true;
aC.trait_fan.curValue = curFan;
btnWindSpeed.UnSelectedImagePath = aC.curFanImage;
//Control.Send(CommandType_A.write, aC);
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add(FunctionAttributeKey.FanSpeed, curFan);
Control.Ins.SendWriteCommand(aC, d);
dialog.Close();
};
btn1.MouseUpEventHandler = eventHandler1;
btn2.MouseUpEventHandler = eventHandler1;
dialogView.MouseUpEventHandler = eventHandler;
}
}
}