using System;
using Shared;
using Shared.Common;
using Shared.R;
namespace Shared.Phone.Device.Logic.DoorLockLogic
{
public class LockLogicList : FrameLayout
{
public LockLogicList()
{
Tag = "LockLogicList";
}
VerticalRefreshLayout middle;
public void Show()
{
#region 最上面的布局代码
var topRowLayout = new RowLayout
{
BackgroundColor = ZigbeeColor.Current.LogicTopBackgroundColor,
Height = Application.GetRealHeight(184),
LineColor = ZigbeeColor.Current.LogicRowLayoutTopLineColor,
};
this.AddChidren(topRowLayout);
var titleName = new Button
{
TextSize = 17,
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
TextAlignment = TextAlignment.CenterLeft,
X = Application.GetRealWidth(176),
Width = Application.GetRealWidth(600),
Height = Application.GetRealHeight(69),
Y = Application.GetRealHeight(92),
TextID = MyInternationalizationString.linkageevent,
IsBold = true,
};
topRowLayout.AddChidren(titleName);
var clickBtn = new Button
{
Width = Application.GetRealWidth(81 + 51),
Height = Application.GetRealHeight(58 + 40),
Y = Application.GetRealHeight(98 - 40),
};
topRowLayout.AddChidren(clickBtn);
clickBtn.MouseDownEventHandler += (sender, e) =>
{
RemoveFromParent();
};
var back = new Button
{
Width = Application.GetRealWidth(30),
Height = Application.GetRealHeight(51),
X = Application.GetRealWidth(81),
Y = Application.GetRealHeight(98),
//Gravity = Gravity.CenterVertical;
UnSelectedImagePath = "ZigeeLogic/back.png",
};
topRowLayout.AddChidren(back);
back.MouseDownEventHandler += (sender, e) =>
{
RemoveFromParent();
};
var addiocn = new Button
{
Width = Application.GetRealWidth(72),
Height = Application.GetRealHeight(72),
X = Application.GetRealWidth(1080 - 108 - 58),
UnSelectedImagePath = "ZigeeLogic/lockadd.png",
Y = Application.GetRealHeight(184 - 72 - 20),
};
topRowLayout.AddChidren(addiocn);
addiocn.MouseUpEventHandler += (sender, e) =>
{
//new一个新逻辑对象;
Common.Logic.CurrentLogic = new Common.Logic();
Common.Logic.CurrentLogic.IsEnable = 1;//默认为开
Common.Logic.CurrentLogic.LogicType = 1;
Common.Logic.CurrentLogic.Relationship = 1;
Common.Logic.CurrentLogic.LogicName = Language.StringByID(MyInternationalizationString.automation1);
var lockLogicCommunalPage = new LockLogicCommunalPage();
UserView.HomePage.Instance.AddChidren(lockLogicCommunalPage);
UserView.HomePage.Instance.PageIndex += 1;
lockLogicCommunalPage.Show(() => { });
};
#endregion
middle = new VerticalRefreshLayout
{
Y = topRowLayout.Bottom,
Height = Application.GetRealHeight(1920 - 184),
BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
};
this.AddChidren(middle);
middle.BeginHeaderRefreshingAction += () =>
{
//重新刷新logic列表
Common.Logic.LockLogicList.Clear();
Read();
//关闭刷新View;
middle.EndHeaderRefreshing();
};
Read();
}
///
/// 读取自动化数据
///
public async void Read()
{
CommonPage.Loading.Start();
if (Common.Logic.LockLogicList.Count == 0)
{
var Idlist = await Send.GetLogicId(1);
if (Idlist.Count != 0)
{
var listlogic = await Send.ReadList(Idlist.Count, 1);
//foreach可能集合已被修改,枚举操作可能不会执行,可能出现崩溃(建议for)。
for (int j = 0; j < listlogic.Count; j++)
{
var logic = listlogic[j];
if (logic.LogicType == 0)
{
continue;
}
bool yes = false;
for (int a = 0; a < logic.Accounts.Count; a++)
{
if (logic.Accounts[a]["Account"].ToString() == Config.Instance.Guid)
{
//查找自己账号下的创建联动事件;
yes = true;
break;
}
}
if (yes)
{
Common.Logic.LockLogicList.Add(listlogic[j]);
}
}
}
}
Automationview();
CommonPage.Loading.Hide();
}
///
/// 加载自动化列表的界面
///
public void Automationview()
{
middle.RemoveAll();
if (Common.Logic.LockLogicList.Count == 0)
{
//就是为了显示引导添加图标;
var noFrameLayout = new FrameLayout
{
Height = Application.GetRealHeight(434 + 200 + 32 + 320),
//BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
};
middle.AddChidren(noFrameLayout);
var noIconBtn = new Button
{
Y = Application.GetRealHeight(320),
Width = Application.GetMinRealAverage(756),
Height = Application.GetMinRealAverage(434),
UnSelectedImagePath = "Item/NoFunction.png",
X = Application.GetRealWidth(162),
};
noFrameLayout.AddChidren(noIconBtn);
var noTextBtn = new Button()
{
Y = noIconBtn.Bottom,
Height = Application.GetRealHeight(200) + Application.GetRealHeight(32),
Width = Application.GetRealWidth(700),
//Gravity = Gravity.CenterHorizontal,
Text = Language.StringByID(MyInternationalizationString.automationaddtext).Replace("{\\r\\n}", "\r\n"),
TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
TextAlignment = TextAlignment.Center,
IsMoreLines = true,
X = Application.GetRealWidth(190),
};
noFrameLayout.AddChidren(noTextBtn);
}
for (int i = 0; i < Common.Logic.LockLogicList.Count; i++)
{
var logic = Common.Logic.LockLogicList[i];
var logicRowlayout = new RowLayout
{
Width = Application.GetRealWidth(1080),
Height = Application.GetRealHeight(190),
LineColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
};
middle.AddChidren(logicRowlayout);
var logicnameBtn = new Button
{
Height = Application.GetRealHeight(190),
Width = Application.GetRealWidth(600),
Text = logic.LogicName,
X = Application.GetRealWidth(58),
TextAlignment = TextAlignment.CenterLeft,
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
Gravity = Gravity.CenterVertical,
TextSize = 15,
};
logicRowlayout.AddChidren(logicnameBtn);
var logicswitchBtn = new Button
{
Width = Application.GetMinRealAverage(104),
Height = Application.GetMinRealAverage(63),
UnSelectedImagePath = "ZigeeLogic/logicclose.png",
SelectedImagePath = "ZigeeLogic/logicopen.png",
X = logicRowlayout.Width - Application.GetRealWidth(104 + 58),
Gravity = Gravity.CenterVertical,
};
logicRowlayout.AddChidren(logicswitchBtn);
logicswitchBtn.MouseUpEventHandler += (sender, e) =>
{
logicswitchBtn.IsSelected = !logicswitchBtn.IsSelected;
if (logicswitchBtn.IsSelected)
{
//逻辑开
logic.IsEnable = 1;
}
else
{
//逻辑关
logic.IsEnable = 0;
}
Send.LogicControlSwitch(logic);
};
if (logic.IsEnable == 1)
{
logicswitchBtn.IsSelected = true;
}
else if (logic.IsEnable == 0)
{
logicswitchBtn.IsSelected = false;
}
///编辑
var edit = new Button
{
BackgroundColor = ZigbeeColor.Current.LogicEditBlackColor1,
Text = Language.StringByID(MyInternationalizationString.edit),
TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor,
};
logicRowlayout.AddRightView(edit);
edit.MouseUpEventHandler += (sender, e) =>
{
Common.Logic.CurrentLogic = logic;
var lockLogicCommunalPage = new LockLogicCommunalPage();
UserView.HomePage.Instance.AddChidren(lockLogicCommunalPage);
UserView.HomePage.Instance.PageIndex += 1;
lockLogicCommunalPage.Show(() => { logicnameBtn.Text = logic.LogicName; Automationview(); });
};
///删除
var del = new Button
{
BackgroundColor = ZigbeeColor.Current.LogicDelBlackColor1,
Text = Language.StringByID(MyInternationalizationString.del),
TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor,
};
logicRowlayout.AddRightView(del);
del.MouseUpEventHandler += (sender, e) =>
{
var alert = new Alert(Language.StringByID(MyInternationalizationString.tip), Language.StringByID(MyInternationalizationString.doyouwanttodelete),
Language.StringByID(MyInternationalizationString.cancel), Language.StringByID(MyInternationalizationString.confrim));
alert.ResultEventHandler += (sender1, e1) =>
{
if (e1)
{
Common.Logic.LockLogicList.Remove(logic);
Automationview();
Send.DelLogic(logic.LogicId);
}
};
alert.Show();
};
}
}
}
}