using System;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
public partial class FloorHeatingPage
{
public static void UpdataStates(FloorHeating uFh)
{
try
{
Application.RunOnMainThread(() =>
{
if (bodyView == null)
{
return;
}
bodyView.arcBar.ProgressBarColor = bodyView.fh.trait_on_off.value.ToString() == "on" ? CSS_Color.MainColor : CSS_Color.PromptingColor2;
bodyView.btnTemp.Text = uFh.curTemp.ToString();
bodyView.btnIndoorTemp.Text = Language.StringByID(StringId.IndoorTemp) + uFh.indoorTemp + "°C";
bodyView.btnMode.UnSelectedImagePath = uFh.curModeImage;
bodyView.btnSwitch.IsSelected = uFh.trait_on_off.value.ToString() == "on";
if (uFh.refreshTime.AddMilliseconds(1000) < DateTime.Now)
{
bodyView.arcBar.Progress = (int)uFh.curTemp;
}
});
}
catch (Exception ex)
{
MainPage.Log($"acpage updata error {ex.Message}");
}
}
void LoadEventList()
{
LoadCollectionEvent();
LoadEvent_AcStatesChange();
LoadEvent_TempChange();
//回退刷新信息事件
actionRefresh = () =>
{
btnFunctionName.Text = btnFunctionName_Out.Text = fh.name;
btnFromFloor_Out.Text = btnFromFoorAndRoom.Text = fh.GetRoomListName();
};
}
///
/// 收藏功能按钮事件
///
void LoadCollectionEvent()
{
btnCollection.MouseUpEventHandler += (sender, e) =>
{
btnCollection.IsSelected = fh.collection = btnCollection_Out.IsSelected = !btnCollection.IsSelected;
fh.SaveFunctionData();
};
}
///
/// 温度改变模式
///
void LoadEvent_TempChange()
{
btnMinus.MouseUpEventHandler = (sender, e) =>
{
if (fh.curTemp < 6)
{
return;
}
fh.curTemp--;
arcBar.Progress = (int)fh.curTemp;
btnTemp.Text = fh.curTemp.ToString();
//Control.Send(CommandType_A.write, fh);
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add("temp", fh.curTemp.ToString());
Control.SendWriteCommand(fh, d);
};
btnPlus.MouseUpEventHandler = (sender, e) =>
{
if (fh.curTemp > 34)
{
return;
}
fh.curTemp++;
arcBar.Progress = (int)fh.curTemp;
btnTemp.Text = fh.curTemp.ToString();
//Control.Send(CommandType_A.write, fh);
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add("temp", fh.curTemp.ToString());
Control.SendWriteCommand(fh, d);
};
arcBar.OnStopTrackingTouchEvent = (sender, e) =>
{
fh.curTemp = arcBar.Progress;
btnTemp.Text = fh.curTemp.ToString();
//Control.Send(CommandType_A.write, fh);
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add("temp", fh.curTemp.ToString());
Control.SendWriteCommand(fh, d);
};
arcBar.OnProgressChangedEvent = (sender, e) =>
{
fh.curTemp = e;
btnTemp.Text = fh.curTemp.ToString();
};
}
///
/// 控制模式事件
///
void LoadEvent_AcStatesChange()
{
btnMode.MouseUpEventHandler = (sender, e) =>
{
LoadDiv_ChangeModeView();
};
btnSwitch.MouseUpEventHandler = (sender, e) =>
{
btnSwitch.IsSelected = !btnSwitch.IsSelected;
fh.trait_on_off.value = btnSwitch.IsSelected ? "on" : "off";
//Control.Send(CommandType_A.write, fh);
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add("on_off", fh.trait_on_off.value.ToString());
Control.SendWriteCommand(fh, 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;
fh.trait_mode.value = curMode;
//Control.Send(CommandType_A.write, fh);
System.Collections.Generic.Dictionary d = new System.Collections.Generic.Dictionary();
d.Add("mode", fh.curModeIndex.ToString());
Control.SendWriteCommand(fh, d);
dialog.Close();
};
btn1.MouseUpEventHandler = eventHandler1;
btn2.MouseUpEventHandler = eventHandler1;
dialogView.MouseUpEventHandler = eventHandler;
}
}
}