gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindTargetsPage.cs
@@ -45,19 +45,17 @@
        FrameLayout blankFrameLayout;//空数据显示布局
        List<int> typeModeList;//动态获取按键支持的模式大类型
        public List<ScenesListInfo> gwScenesList = new List<ScenesListInfo>();//网关中的场景列表
        bool IsRead = false;
        #endregion
        //初始化按键数据
        private void InitListInfo()
        void InitListInfo()
        {
            System.Threading.Tasks.Task.Run(async () =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                    });
                    localDeviceList.Clear();
                    scList.Clear();
                    //获取本地设备列表
@@ -73,15 +71,8 @@
                    {
                        gwScenesList = gwSceneObj.getSceneInfo.ScenesList;
                    }
                    else
                    {
                        Application.RunOnMainThread(() =>
                        {
                            CommonPage.Loading.Hide();
                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                        });
                    }
                    //动态获取按键支持的大类
                    typeModeList = await GetTypeMode();
                    #region 读取面板当前模式
                    //读取按键当前模式
                    var tempDeata = await currentKey.ReadPanelConfigureInfoAsync();
@@ -106,78 +97,81 @@
                            {
                                currentClusterID = 258;
                            }
                            currentKey.ReSave();
                            //读取按键当前绑定目标
                            var getBindList = await currentKey.GetDeviceBindAsync();
                            var bindDeviceListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                            var bindSceneListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                            if (getBindList != null && getBindList.getAllBindResponseData != null)
                            {
                                currentKey.bindList.Clear();
                                foreach (var b in getBindList.getAllBindResponseData.BindList)
                                {
                                    if (b.BindCluster == currentClusterID)
                                    {
                                        if (b.BindCluster == 6)
                                        {
                                            if (b.BindType == 2)
                                            {
                                                bindSceneListTemp.Add(b);
                                            }
                                            else
                                            {
                                                bindDeviceListTemp.Add(b);
                                            }
                                        }
                                        else
                            //读取按键当前绑定目标
                            GetDeviceBindResponseAllData getBindList = null;
                            if (IsRead)
                            {
                                getBindList = await currentKey.GetDeviceBindAsync();
                                var bindDeviceListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                                var bindSceneListTemp = new System.Collections.Generic.List<BindListResponseObj> { };
                                if (getBindList != null && getBindList.getAllBindResponseData != null)
                                {
                                    currentKey.bindList.Clear();
                                    foreach (var b in getBindList.getAllBindResponseData.BindList)
                                    {
                                        if (b.BindCluster == currentClusterID)
                                        {
                                            if (currentClusterID == 8)
                                            if (b.BindCluster == 6)
                                            {
                                                if (b.BindCluster == 8)
                                                if (b.BindType == 2)
                                                {
                                                    currentKey.bindList.Add(b);
                                                    bindSceneListTemp.Add(b);
                                                }
                                                else
                                                {
                                                    bindDeviceListTemp.Add(b);
                                                }
                                            }
                                            else
                                            {
                                                currentKey.bindList.Add(b);
                                                if (currentClusterID == 8)
                                                {
                                                    if (b.BindCluster == 8)
                                                    {
                                                        currentKey.bindList.Add(b);
                                                    }
                                                }
                                                else
                                                {
                                                    currentKey.bindList.Add(b);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Application.RunOnMainThread(() =>
                                else
                                {
                                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                                });
                                    Application.RunOnMainThread(() =>
                                    {
                                        CommonPage.Loading.Hide();
                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                                        return;
                                    });
                                }
                                if (currentKey.panelMode == 1)
                                {
                                    currentKey.bindList = bindSceneListTemp;
                                    currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddScene);
                                }
                                else if (currentKey.panelMode == 100 || currentKey.panelMode == 101 || currentKey.panelMode == 102)
                                {
                                    currentKey.bindList = bindDeviceListTemp;
                                    currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddSwitch);
                                }
                                else if (currentKey.panelMode == 200 || currentKey.panelMode == 201 || currentKey.panelMode == 203 || currentKey.panelMode == 204 || currentKey.panelMode == 205)
                                {
                                    currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddDimmer);
                                }
                                else if (currentKey.panelMode == 300 || currentKey.panelMode == 301 || currentKey.panelMode == 302 || currentKey.panelMode == 303 || currentKey.panelMode == 304)
                                {
                                    currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddCurtain);
                                }
                            }
                            if (currentKey.panelMode == 1)
                            {
                                currentKey.bindList = bindSceneListTemp;
                                currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddScene);
                            }
                            else if (currentKey.panelMode == 100 || currentKey.panelMode == 101 || currentKey.panelMode == 102)
                            {
                                currentKey.bindList = bindDeviceListTemp;
                                currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddSwitch);
                            }
                            else if (currentKey.panelMode == 200 || currentKey.panelMode == 201 || currentKey.panelMode == 203 || currentKey.panelMode == 204 || currentKey.panelMode == 205)
                            {
                                currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddDimmer);
                            }
                            else if (currentKey.panelMode == 300 || currentKey.panelMode == 301 || currentKey.panelMode == 302 || currentKey.panelMode == 303 || currentKey.panelMode == 304)
                            {
                                currentKey.currentKeySelectModeText = Language.StringByID(R.MyInternationalizationString.AddCurtain);
                            }
                            currentKey.ReSave();
                        }
                        #endregion
                        //动态获取按键支持的大类
                        typeModeList = await GetTypeMode();
                        #endregion
                        Application.RunOnMainThread(() =>
                        {
                            RefreshList();
@@ -189,7 +183,6 @@
                        Application.RunOnMainThread(() =>
                        {
                            CommonPage.Loading.Hide();
                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                        });
                        return;
@@ -216,13 +209,14 @@
            var btnAddFrameLayout = new FrameLayout()
            {
                X = Application.GetRealWidth(913),
                X = Application.GetRealWidth(888),
                Width = Application.GetRealWidth(192),
            };
            this.titleFrameLayout.AddChidren(btnAddFrameLayout);
            var btnBindAdd = new Button
            {
                X = Application.GetRealWidth(62),
                Height = Application.GetRealHeight(72),
                Width = Application.GetRealWidth(72),
                UnSelectedImagePath = "BindPic/BindAdd.png",
@@ -310,6 +304,14 @@
            #endregion
            CommonPage.Loading.Start("");
            middleFrameLayout();
            if (currentKey.bindList.Count == 0)
            {
                IsRead = true;
            }
            else
            {
                IsRead = false;
            }
            InitListInfo();
        }
@@ -325,6 +327,7 @@
            midVerticalRefreshLayout.BeginHeaderRefreshingAction += () =>
            {
                midVerticalRefreshLayout.BeginHeaderRefreshing();
                IsRead = true;
                InitListInfo();
                midVerticalRefreshLayout.EndHeaderRefreshing();
            };
@@ -358,7 +361,7 @@
                TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                Gravity = Gravity.CenterHorizontal,
                Visible = false,
                TextSize =12,
                TextSize = 12,
            };
            blankFrameLayout.AddChidren(btnPicTip);
        }
@@ -484,7 +487,7 @@
                                    devicePic.Width = Application.GetRealWidth(110);
                                    devicePic.Text = "";
                                }
                                if (tempDev.DeviceEpointName == "")
                                if (string.IsNullOrEmpty(tempDev.DeviceEpointName))
                                {
                                    btnBindNameText = tempDev.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit);
                                }
@@ -514,7 +517,7 @@
                    };
                    #endregion
                }
                 midVerticalRefreshLayout.AdjustTableHeight(Application.GetRealHeight(23));
                midVerticalRefreshLayout.AdjustTableHeight(Application.GetRealHeight(23));
            }
            #endregion
        }
@@ -528,7 +531,7 @@
            modeRowLayout.BackgroundColor = ZigbeeColor.Current.XMWhite;
            midVerticalRefreshLayout.AddChidrenRow(modeRowLayout);
            modeRowLayout.frameTable.UseClickStatu = false;
            modeRowLayout.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.keyMode), 500);
            modeRowLayout.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.keyMode), 400);
            var btnKeyModeTipText = "";
            #region 当前模式文本显示
            switch (currentKey.panelMode)
@@ -574,103 +577,72 @@
                    break;
            }
            #endregion
            modeRowLayout.frameTable.AddMostRightView(btnKeyModeTipText, 500);
            modeRowLayout.frameTable.AddMostRightView(btnKeyModeTipText, 800);
            modeRowLayout.frameTable.AddBottomLine();
            var btnDel = modeRowLayout.AddDeleteControl();
            //一键清除按键事件
            btnDel.ButtonClickEvent += async (sender, e) =>
            {
                var dialog2 = new Dialog { };
                var doorDialog2 = new Shared.Phone.UserCenter.DoorLock.DoorlockDialog(dialog2, Language.StringByID(R.MyInternationalizationString.Tip));
                doorDialog2.Show();
                doorDialog2.dialogMidFraFrameLayout.Width = Application.GetRealWidth(674);
                doorDialog2.dialogMidFraFrameLayout.Height = Application.GetRealHeight(115);
                doorDialog2.dialogMidFraFrameLayout.X = Application.GetRealWidth(60);
                doorDialog2.dialogMidFraFrameLayout.Y = Application.GetRealHeight(167);
                doorDialog2.dialogBtnConfirm.Text = Language.StringByID(R.MyInternationalizationString.DoorlockConfirm);
                var midText1 = new Button()
                {
                    Width = Application.GetRealWidth(674),
                    Height = Application.GetRealHeight(115 / 2),
                    TextSize = 14,
                    TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                    TextAlignment = TextAlignment.Center,
                    TextID = R.MyInternationalizationString.ClearAllTargeta1,
                };
                doorDialog2.dialogMidFraFrameLayout.AddChidren(midText1);
                var midText2 = new Button()
                {
                    Width = Application.GetRealWidth(674),
                    Height = Application.GetRealHeight(115 / 2),
                    Y = Application.GetRealHeight(115 / 2),
                    TextSize = 14,
                    TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                    TextAlignment = TextAlignment.Center,
                    TextID = R.MyInternationalizationString.ClearAllTargeta2,
                };
                doorDialog2.dialogMidFraFrameLayout.AddChidren(midText2);
                doorDialog2.dialogBtnCancel.MouseUpEventHandler += (sender2, e2) =>
                {
                    dialog2.Close();
                };
                doorDialog2.dialogBtnConfirm.MouseUpEventHandler += async (sender2, e2) =>
                {
                    bool isDelSuccess = false;
                    try
                    {
                        CommonPage.Loading.Start("");
                        var bindResult = await currentKey.ClearBindInfoAsync();
                        if (bindResult != null && bindResult.clearBindInfoResponseData != null)
                        {
                            if (bindResult.clearBindInfoResponseData.Result != 0)
                            {
                                new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.RemoveFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnDel);
                                CommonPage.Loading.Hide();
                                return;
                            }
                            else
                            {
                                var temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Default);
                                if (temp.setWritableValueResponData?.Status != 0)
                                {
                                    var temp1 = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Default);
                                    if (temp1.setWritableValueResponData?.Status != 0)
                                    {
                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnDel);
                                    }
                                    else
                                    {
                                        isDelSuccess = true;
                                    }
                                }
                                else
                                {
                                    isDelSuccess = true;
                                }
                            }
                        }
                        else
                        {
                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnDel);
                        }
                    }
                    catch { }
                    finally
                    {
                        if (isDelSuccess)
                        {
                            currentKey.panelMode = 65535;
                            currentKey.bindList.Clear();
                            RefreshList();
                            //如果是场景,用户删除清空当前到房间列表
                            currentKey.RoomId = "";
                            currentKey.ReSave();
                        }
                        CommonPage.Loading.Hide();
                    }
                    dialog2.Close();
                };
                string msg = Language.StringByID(R.MyInternationalizationString.ClearAllTargets).Replace("{0}", "\r\n");
                var alert = new Shared.Phone.UserCenter.ShowMsgControl(ShowMsgType.Confirm, msg, Language.StringByID(R.MyInternationalizationString.DoorlockConfirm));
                alert.Show();
                //使用确认型弹框时,的回调函数
                alert.ConfirmClickEvent += async () =>
                 {
                     bool isDelSuccess = false;
                     try
                     {
                         CommonPage.Loading.Start("");
                         var bindResult = await currentKey.ClearBindInfoAsync();
                         if (bindResult != null && bindResult.clearBindInfoResponseData != null)
                         {
                             if (bindResult.clearBindInfoResponseData.Result != 0)
                             {
                                 new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.RemoveFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnDel);
                                 CommonPage.Loading.Hide();
                                 return;
                             }
                             else
                             {
                                 var temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Default);
                                 if (temp.setWritableValueResponData?.Status != 0)
                                 {
                                     var temp1 = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Default);
                                     if (temp1.setWritableValueResponData?.Status != 0)
                                     {
                                         new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnDel);
                                     }
                                     else
                                     {
                                         isDelSuccess = true;
                                     }
                                 }
                                 else
                                 {
                                     isDelSuccess = true;
                                 }
                             }
                         }
                         else
                         {
                             new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnDel);
                         }
                     }
                     catch { }
                     finally
                     {
                         if (isDelSuccess)
                         {
                             currentKey.panelMode = 65535;
                             currentKey.bindList.Clear();
                             RefreshList();
                             //如果是场景,用户删除清空当前到房间列表
                             currentKey.RoomId = "";
                             currentKey.ReSave();
                         }
                         CommonPage.Loading.Hide();
                     }
                 };
            };
        }
@@ -860,49 +832,34 @@
                            var bindSc = currentKey.bindList.Find(obj => (obj.BindType == 2));
                            if (bindSc != null)
                            {
                                var dialog1 = new Dialog { };
                                var doorDialog = new Shared.Phone.UserCenter.DoorLock.DoorlockDialog(dialog1, Language.StringByID(R.MyInternationalizationString.Tip));
                                doorDialog.Show();
                                doorDialog.dialogMidFraFrameLayout.Height = Application.GetRealHeight(58);
                                doorDialog.dialogMidFraFrameLayout.X = Application.GetRealWidth(0);
                                doorDialog.dialogMidFraFrameLayout.Y = Application.GetRealHeight(202);
                                doorDialog.dialogMidFraFrameLayout.AddChidren(doorDialog.dialogMidText);
                                doorDialog.dialogMidText.Text = Language.StringByID(R.MyInternationalizationString.DelLocalBindListThenAddAgain);
                                doorDialog.dialogMidFraFrameLayout.AddChidren(doorDialog.dialogMidText);
                                doorDialog.dialogBtnConfirm.Text = Language.StringByID(R.MyInternationalizationString.DoorlockConfirm);
                                doorDialog.dialogBtnCancel.MouseUpEventHandler += (sender1, e1) =>
                                {
                                    currentKey.currentKeySelectModeText = oldKeySelectModeText;
                                    dialog.Close();
                                    dialog1.Close();
                                };
                                doorDialog.dialogBtnConfirm.MouseUpEventHandler += async (sender1, e1) =>
                                {
                                    var result = await RemoveTargets(bindSc, line2);
                                    if (result == 0)
                                    {
                                        var addScenePage = new Shared.Phone.UserCenter.DeviceBind.AddScenePage(currentKey, gwScenesList);
                                        Shared.Phone.UserView.HomePage.Instance.AddChidren(addScenePage);
                                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                                        addScenePage.Show();
                                string msg = Language.StringByID(R.MyInternationalizationString.DelLocalBindListThenAddAgain);
                                var alert = new Shared.Phone.UserCenter.ShowMsgControl(ShowMsgType.Confirm, msg, Language.StringByID(R.MyInternationalizationString.DoorlockConfirm));
                                alert.Show();
                                //使用确认型弹框时,的回调函数
                                alert.ConfirmClickEvent += async () =>
                                 {
                                     var result = await RemoveTargets(bindSc, line2);
                                     if (result == 0)
                                     {
                                         var addScenePage = new Shared.Phone.UserCenter.DeviceBind.AddScenePage(currentKey, gwScenesList);
                                         Shared.Phone.UserView.HomePage.Instance.AddChidren(addScenePage);
                                         Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                                         addScenePage.Show();
                                        Action<List<BindListResponseObj>> action = (obj) =>
                                        {
                                            currentKey.bindList = obj;
                                            RefreshList();
                                        };
                                        addScenePage.action += action;
                                        dialog.Close();
                                        dialog1.Close();
                                    }
                                    else
                                    {
                                        currentKey.currentKeySelectModeText = oldKeySelectModeText;
                                        dialog.Close();
                                        dialog1.Close();
                                    }
                                };
                                         Action<List<BindListResponseObj>> action = (obj) =>
                                         {
                                             currentKey.bindList = obj;
                                             RefreshList();
                                         };
                                         addScenePage.action += action;
                                         dialog.Close();
                                     }
                                     else
                                     {
                                         currentKey.currentKeySelectModeText = oldKeySelectModeText;
                                         dialog.Close();
                                     }
                                 };
                            }
                        }
                        else
@@ -928,48 +885,34 @@
                            var bindSc = currentKey.bindList.Find(obj => (obj.BindType == 2));
                            if (bindSc != null)
                            {
                                var dialog1 = new Dialog { };
                                var doorDialog = new Shared.Phone.UserCenter.DoorLock.DoorlockDialog(dialog1, Language.StringByID(R.MyInternationalizationString.Tip));
                                doorDialog.Show();
                                doorDialog.dialogMidFraFrameLayout.Height = Application.GetRealHeight(58);
                                doorDialog.dialogMidFraFrameLayout.X = Application.GetRealWidth(0);
                                doorDialog.dialogMidFraFrameLayout.Y = Application.GetRealHeight(202);
                                doorDialog.dialogMidFraFrameLayout.AddChidren(doorDialog.dialogMidText);
                                doorDialog.dialogMidText.Text = Language.StringByID(R.MyInternationalizationString.DelLocalBindListThenAddAgain1);
                                doorDialog.dialogMidFraFrameLayout.AddChidren(doorDialog.dialogMidText);
                                doorDialog.dialogBtnConfirm.Text = Language.StringByID(R.MyInternationalizationString.DoorlockConfirm);
                                doorDialog.dialogBtnCancel.MouseUpEventHandler += (sender1, e1) =>
                                {
                                    currentKey.currentKeySelectModeText = oldKeySelectModeText;
                                    dialog.Close();
                                    dialog1.Close();
                                };
                                doorDialog.dialogBtnConfirm.MouseUpEventHandler += async (sender1, e1) =>
                                {
                                    var result = await RemoveTargets(bindSc, line2);
                                    if (result == 0)
                                    {
                                        var addDevicePage = new Shared.Phone.UserCenter.DeviceBind.AddDevicePage(currentKey, "AddSwitch");
                                        Shared.Phone.UserView.HomePage.Instance.AddChidren(addDevicePage);
                                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                                        addDevicePage.Show();
                                string msg = Language.StringByID(R.MyInternationalizationString.DelLocalBindListThenAddAgain1);
                                var alert = new Shared.Phone.UserCenter.ShowMsgControl(ShowMsgType.Confirm, msg, Language.StringByID(R.MyInternationalizationString.DoorlockConfirm));
                                alert.Show();
                                //使用确认型弹框时,的回调函数
                                alert.ConfirmClickEvent += async () =>
                                 {
                                     var result = await RemoveTargets(bindSc, line2);
                                     if (result == 0)
                                     {
                                         var addDevicePage = new Shared.Phone.UserCenter.DeviceBind.AddDevicePage(currentKey, "AddSwitch");
                                         Shared.Phone.UserView.HomePage.Instance.AddChidren(addDevicePage);
                                         Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                                         addDevicePage.Show();
                                        Action<List<BindListResponseObj>> action = (obj) =>
                                        {
                                            currentKey.bindList = obj;
                                            RefreshList();
                                        };
                                        addDevicePage.actionAddDevicePage += action;
                                        dialog.Close();
                                        dialog1.Close();
                                    }
                                    else
                                    {
                                        currentKey.currentKeySelectModeText = oldKeySelectModeText;
                                        dialog.Close();
                                        dialog1.Close();
                                    }
                                };
                                         Action<List<BindListResponseObj>> action = (obj) =>
                                         {
                                             currentKey.bindList = obj;
                                             RefreshList();
                                         };
                                         addDevicePage.actionAddDevicePage += action;
                                         dialog.Close();
                                     }
                                     else
                                     {
                                         currentKey.currentKeySelectModeText = oldKeySelectModeText;
                                         dialog.Close();
                                     }
                                 };
                            }
                        }
                        else