From 9d61367c1fd278f58f721d4c0e69999f89e4485d Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 12 十二月 2019 14:14:30 +0800
Subject: [PATCH] 添加最新绑定机制
---
ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs | 461 ++++++++++++++++++++++++++++++++-------------------------
1 files changed, 260 insertions(+), 201 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs
old mode 100755
new mode 100644
index 1815322..2ec8ba7
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs
@@ -13,14 +13,8 @@
/// <param name="common">Common.</param>
public void Changed(CommonDevice common)
{
- //if (common.Type != ZigBee.Device.DeviceType.OnOffSwitch)
- //{
- // return;
- //}
-
Shared.Application.RunOnMainThread(() =>
{
- //var dev = common as Panel;
});
}
@@ -31,28 +25,32 @@
{
this.currentKey = key;
this.currentModeID = key.panelMode;
- this.oldModeID = key.panelMode;
this.curDeviceBindType = deviceBindType;
this.targetList = targetSelectList;
}
#region 鈼� 鍙橀噺鐢虫槑__________________________
- ZigBee.Device.Panel currentKey;
+ ZigBee.Device.Panel currentKey;//褰撳墠鎸夐敭
//鏄剧ず琚粦瀹氳澶囨垨鍦烘櫙鐨剉iew
- VerticalScrolViewLayout midVerticalScrolViewLayout;
- HorizontalScrolViewLayout btnHorizontalScrolViewLayout;
+ VerticalScrolViewLayout midVerticalScrolViewLayout;//涓儴鍒锋柊鍒楄〃
+ HorizontalScrolViewLayout btnHorizontalScrolViewLayout;//鎴块棿鍒楄〃宸﹀彸婊戝姩甯冨眬
/// <summary>
/// 鎸夐敭閰嶇疆鐨勭洰鏍囧垪琛�
/// </summary>
- List<CommonDevice> targetList = new List<CommonDevice>();
- List<Room> roomList = new List<Room>();
- int currentClusterID = 6;
- public Action<List<BindListResponseObj>> action;
- int currentModeID = 0;
- int oldModeID = 0;
- string curDeviceBindType = "";
+ List<CommonDevice> targetList = new List<CommonDevice>();//鏈湴涓存椂閫変腑鍒楄〃
+ /// <summary>
+ /// 鏂扮殑鎸夐敭閰嶇疆鐩爣鍒楄〃涓紝鐩爣瀹為檯瀛樺湪鎸夐敭涓紝姝ゆ椂瑕佸垹鎺夌殑鏁版嵁
+ /// </summary>
+ List<CommonDevice> oldTargetList = new List<CommonDevice>();//鏈湴鏃х殑閫変腑鍒楄〃
+ int currentClusterID = 6;//褰撳墠绨嘔D
+ public Action<List<BindListResponseObj>> action;//鍥炶皟缁戝畾鐩爣椤甸潰鍒锋柊
+ int currentModeID = 0;//褰撳墠妯″紡ID
+ string curDeviceBindType = "";//褰撳墠璁惧缁戝畾绫诲瀷
#endregion
+ /// <summary>
+ /// 鏄剧ず鎸夐敭妯″紡椤�
+ /// </summary>
public void Show()
{
this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.ChooseKeyMode));
@@ -68,6 +66,9 @@
MidFrameLayoutContent();
}
+ /// <summary>
+ /// 涓儴甯冨眬
+ /// </summary>
async void MidFrameLayoutContent()
{
#region UI
@@ -99,227 +100,253 @@
#endregion
#region 鏁版嵁澶勭悊
- roomList = Shared.Common.Room.Lists;
- Shared.Common.Room curRoom = roomList[0];
- int index = 0;
- KeyModeList(roomList[index]);
-
+ KeyModeList();
btnFinifh.MouseUpEventHandler += async (sender, e) =>
{
+ oldTargetList.Clear();
+ bool isFinish = false;
btnFinifh.Enable = false;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
- if (oldModeID != 65535 && oldModeID != currentModeID)
+ try
{
- var bindResult = await currentKey.ClearBindInfoAsync();
- if (bindResult.clearBindInfoResponseData != null)
+ CommonPage.Loading.Start("");
+ //1銆佹竻绌烘墍鏈夌洰鏍�
+ if (currentKey.bindList != null)
{
- if (bindResult.clearBindInfoResponseData.Result != 0)
+ var bindResult = await currentKey.ClearBindInfoAsync();
+ if (bindResult != null && bindResult.clearBindInfoResponseData != null)
{
- new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
- CommonPage.Loading.Hide();
- this.RemoveFromParent();
- btnFinifh.Enable = true;
- return;
+ if (bindResult.clearBindInfoResponseData.Result != 0)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ CommonPage.Loading.Hide();
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
+ });
+ btnFinifh.Enable = true;
+ btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+ return;
+ }
+ else
+ {
+ currentKey.bindList.Clear();
+ }
}
else
{
- currentKey.bindList.Clear();
+ Application.RunOnMainThread(() =>
+ {
+ CommonPage.Loading.Hide();
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
+ });
+ btnFinifh.Enable = true;
+ btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+ return;
}
}
- }
- else
- {
- foreach (var bindedDev in currentKey.bindList)
+
+ //2銆侀厤缃ā寮�
+ Panel.SetWritableValueResponAllData temp = null;
+ switch (currentModeID)
{
- for (int i = 0; i < targetList.Count; i++)
+ case 100:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_On);
+ break;
+ case 101:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_oFF);
+ break;
+ case 102:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_OnOff);
+ break;
+ case 200:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Up);
+ break;
+ case 201:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Down);
+ break;
+ case 203:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up);
+ break;
+ case 204:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Down);
+ break;
+ case 205:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up_Down);
+ break;
+ case 300:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up);
+ break;
+ case 301:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down);
+ break;
+ case 302:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Stop);
+ break;
+ case 303:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up_Stop);
+ break;
+ case 304:
+ temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down_Stop);
+ break;
+ }
+ if (temp != null && temp.setWritableValueResponData != null)
+ {
+ if (temp.setWritableValueResponData.Status == 0)
{
- var de = targetList[i];
- if (de.DeviceAddr == bindedDev.BindMacAddr && de.DeviceEpoint == bindedDev.BindEpoint)
+ //3銆佺粦瀹氭柊鐨勬暟鎹�
+ var addBindeDev = new AddBindData();
+ addBindeDev.DeviceAddr = currentKey.DeviceAddr;
+ addBindeDev.Epoint = currentKey.DeviceEpoint;
+
+ foreach (var de in targetList)
{
- targetList.RemoveAt(i);
- i--;
+ if (de.DeviceAddr != null)
+ {
+ var addBindInfo = new AddBindListObj();
+ addBindInfo.BindType = 0;
+ addBindInfo.BindCluster = currentClusterID;
+ addBindInfo.BindMacAddr = de.DeviceAddr;
+ addBindInfo.BindEpoint = de.DeviceEpoint;
+ addBindeDev.BindList.Add(addBindInfo);
+ }
}
- }
- }
- }
- var temp = new Panel.SetWritableValueResponAllData();
- switch (currentModeID)
- {
- case 100:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_On);
- break;
- case 101:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_oFF);
- break;
- case 102:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_OnOff);
- break;
- case 200:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Up);
- break;
- case 201:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Down);
- break;
- case 203:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up);
- break;
- case 204:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Down);
- break;
- case 205:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up_Down);
- break;
- case 300:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up);
- break;
- case 301:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down);
- break;
- case 302:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Stop);
- break;
- case 303:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up_Stop);
- break;
- case 304:
- temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down_Stop);
- break;
- }
- if (temp.setWritableValueResponData?.Status != 0)
- {
- new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh);
- btnFinifh.Enable = true;
- btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
- return;
- }
- else
- {
- var addBindeDev = new AddBindData();
- addBindeDev.DeviceAddr = currentKey.DeviceAddr;
- addBindeDev.Epoint = currentKey.DeviceEpoint;
-
- foreach (var de in targetList)
- {
- if (de.DeviceAddr != null)
- {
- var addBindInfo = new AddBindListObj();
- addBindInfo.BindType = 0;
- addBindInfo.BindCluster = currentClusterID;
- addBindInfo.BindMacAddr = de.DeviceAddr;
- addBindInfo.BindEpoint = de.DeviceEpoint;
- addBindeDev.BindList.Add(addBindInfo);
- }
- }
- bool isFinish = false;
- try
- {
- CommonPage.Loading.Start("");
- var dev = new AddedDeviceBindResponseAllData();
- dev = await currentKey.AddDeviceBindAsync(addBindeDev);
- foreach (var ab in dev.addedDeviceBindResponseData?.BindList)
- {
- switch (ab.Result)
+ //鏄寒搴﹀啀娆″彂6鍛戒护
+ if (currentClusterID == 8)
{
- case 0:
- currentKey.bindList.Add((BindListResponseObj)ab);
-
- for (int i = 0; i < targetList.Count; i++)
+ foreach (var de in targetList)
+ {
+ if (de.DeviceAddr != null)
{
- var de = targetList[i];
- var sc1 = new SceneUI();
- if (de.DeviceAddr == null)
- {
- sc1 = (SceneUI)de;
+ var addBindInfo = new AddBindListObj();
+ addBindInfo.BindType = 0;
+ addBindInfo.BindCluster = 6;
+ addBindInfo.BindMacAddr = de.DeviceAddr;
+ addBindInfo.BindEpoint = de.DeviceEpoint;
+ addBindeDev.BindList.Add(addBindInfo);
+ }
+ }
+ }
- if (sc1.Id == ab.BindScenesId)
+ var dev = new AddedDeviceBindResponseAllData();
+ dev = await currentKey.AddDeviceBindAsync(addBindeDev);
+ if (dev.addedDeviceBindResponseData == null)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ CommonPage.Loading.Hide();
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
+ });
+ btnFinifh.Enable = true;
+ btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+ return;
+ }
+ else
+ {
+ if (dev.addedDeviceBindResponseData.Result == 0)
+ {
+ if (currentClusterID == 8)
+ {
+ foreach (var de in dev.addedDeviceBindResponseData.BindList)
+ {
+ if (de.BindCluster == 8)
{
- targetList.RemoveAt(i);
- i--;
+ currentKey.bindList.Add(de);
}
}
}
- isFinish = true;
- break;
- case 1:
- new Tip()
+ else
{
- MaxWidth = 150,
- Text = Language.StringByID(R.MyInternationalizationString.BindErrorAbsence),
- Direction = AMPopTipDirection.Up,
- CloseTime = 1
- }.Show(btnFinifh);
- break;
- case 2:
- var abr = dev.addBindResultResponseData?.Result;
- switch (dev.addBindResultResponseData?.Result)
- {
- case 0:
- currentKey.bindList.Add((BindListResponseObj)ab);
- for (int i = 0; i < targetList.Count; i++)
- {
- var de = targetList[i];
- if (de.DeviceAddr == ab.BindMacAddr && de.DeviceEpoint == ab.BindEpoint)
- {
- targetList.RemoveAt(i);
- i--;
- }
- }
- isFinish = true;
- break;
- case 140:
- new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
- break;
- default:
- new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
- break;
+ currentKey.bindList = dev.addedDeviceBindResponseData.BindList;
}
- break;
- case 3:
- new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindErrorExisted), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
- break;
- case 4:
- new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
- break;
- default:
- break;
+ if (action != null)
+ {
+ action(currentKey.bindList);
+ }
+ this.RemoveFromParent();
+ targetList.Clear();
+ CommonPage.Loading.Hide();
+ btnFinifh.Enable = true;
+ btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+ }
+ else if (dev.addedDeviceBindResponseData.Result == 1)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ CommonPage.Loading.Hide();
+ new Tip()
+ {
+ MaxWidth = 150,
+ Text = Language.StringByID(R.MyInternationalizationString.BindFailed),
+ Direction = AMPopTipDirection.Up,
+ CloseTime = 1
+ }.Show(btnFinifh);
+ });
+ btnFinifh.Enable = true;
+ btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+ return;
+ }
+ else
+ {
+ Application.RunOnMainThread(() =>
+ {
+ CommonPage.Loading.Hide();
+ new Tip()
+ {
+ MaxWidth = 150,
+ Text = Language.StringByID(R.MyInternationalizationString.BindUnknownError),
+ Direction = AMPopTipDirection.Up,
+ CloseTime = 1
+ }.Show(btnFinifh);
+ });
+ btnFinifh.Enable = true;
+ btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+ return;
+ }
}
- }
- }
- catch { }
- finally
- {
- if (isFinish)
- {
- if (action != null)
- {
- action(currentKey.bindList);
-
- }
- this.RemoveFromParent();
}
else
{
- this.RemoveFromParent();
+ Application.RunOnMainThread(() =>
+ {
+ CommonPage.Loading.Hide();
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh);
+ });
+ btnFinifh.Enable = true;
+ btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+ return;
}
- CommonPage.Loading.Hide();
+ }
+ else
+ {
+ Application.RunOnMainThread(() =>
+ {
+ CommonPage.Loading.Hide();
+ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh);
+ });
btnFinifh.Enable = true;
btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+ return;
}
+ }
+ catch
+ {
+ CommonPage.Loading.Hide();
+ btnFinifh.Enable = true;
+ btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
}
};
#endregion
- }
-
+ }
+
/// <summary>
/// 鎸夐敭妯″紡鏄剧ず
/// </summary>
/// <param name="gateway">Gateway.</param>
/// <param name="key">Key.</param>
- void KeyModeList(Shared.Common.Room curRoom)
+ private void KeyModeList()
{
midVerticalScrolViewLayout.RemoveAll();
-
switch (curDeviceBindType)
{
case "AddSwitch":
@@ -337,7 +364,7 @@
}
}
- public void AddSwitchMode()
+ private void AddSwitchMode()
{
Button oldMode = null;
for (int i = 0; i < 3; i++)
@@ -414,6 +441,15 @@
btnChoose.IsSelected = true;
btnChoose.Visible = true;
oldMode = btnChoose;
+ }
+ else if ((currentKey.panelMode == 65535) && i == 0)
+ {
+ //榛樿绗竴涓�
+ btnChoose.IsSelected = true;
+ btnChoose.Visible = true;
+ oldMode = btnChoose;
+ currentModeID = 100;
+ currentKey.panelMode = currentModeID;
}
EventHandler<MouseEventArgs> hander = async (sender, e) =>
@@ -451,9 +487,9 @@
btnModeText.MouseUpEventHandler += hander;
btnChoose.MouseUpEventHandler += hander;
}
- }
-
- public void AddDimmerMode()
+ }
+
+ private void AddDimmerMode()
{
Button oldMode = null;
for (int i = 0; i < 5; i++)
@@ -550,6 +586,15 @@
btnChoose.IsSelected = true;
btnChoose.Visible = true;
oldMode = btnChoose;
+ }
+ else if ((currentKey.panelMode == 65535) && i == 0)
+ {
+ //榛樿绗竴涓�
+ btnChoose.IsSelected = true;
+ btnChoose.Visible = true;
+ oldMode = btnChoose;
+ currentModeID = 200;
+ currentKey.panelMode = currentModeID;
}
EventHandler<MouseEventArgs> hander = (sender, e) =>
@@ -597,9 +642,9 @@
btnChoose.MouseUpEventHandler += hander;
}
- }
-
- public void AddCurtainMode()
+ }
+
+ private void AddCurtainMode()
{
Button oldMode = null;
for (int i = 0; i < 5; i++)
@@ -696,6 +741,15 @@
btnChoose.IsSelected = true;
btnChoose.Visible = true;
oldMode = btnChoose;
+ }
+ else if ((currentKey.panelMode == 65535) && i == 0)
+ {
+ //榛樿绗竴涓�
+ btnChoose.IsSelected = true;
+ btnChoose.Visible = true;
+ oldMode = btnChoose;
+ currentModeID = 300;
+ currentKey.panelMode = currentModeID;
}
EventHandler<MouseEventArgs> hander = (sender, e) =>
@@ -744,6 +798,11 @@
}
}
+ private void FinisfhEventHandler(object sender, MouseEventArgs e)
+ {
+
+ }
+
public void DeviceInfoChange(CommonDevice common, string typeTag)
{
}
--
Gitblit v1.8.0