From c1de48884fa145a16a0f8bcee93274dcfaa0ff82 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 07 五月 2020 10:40:28 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev-tzy' into dev-2020xm

---
 ZigbeeApp/Shared/Phone/UserCenter/SharedContent/LookSharedContentForm.cs |  464 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 464 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/SharedContent/LookSharedContentForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/SharedContent/LookSharedContentForm.cs
new file mode 100755
index 0000000..36270f7
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/SharedContent/LookSharedContentForm.cs
@@ -0,0 +1,464 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter.SharedContent
+{
+    /// <summary>
+    /// 鏌ョ湅宸查厤缃叡浜唴瀹圭殑涓荤晫闈�
+    /// </summary>
+    public class LookSharedContentForm : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 鏌ョ湅鐨勬埧闂村璞�
+        /// </summary>
+        private Common.Room lookRoom = null;
+        /// <summary>
+        /// 鎴愬憳鐨勫垎浜暟鎹�
+        /// </summary>
+        private MemberShardInfoData memberShardInfo = null;
+        /// <summary>
+        /// 璁惧妗屽竷鎺т欢
+        /// </summary>
+        private FrameLayout frameDeviceTable = null;
+        /// <summary>
+        /// 璁惧妗屽竷鎺т欢
+        /// </summary>
+        private FrameLayout frameSceneTable = null;
+        /// <summary>
+        /// 鍒犻櫎鎸夐挳
+        /// </summary>
+        private BottomClickButton btnDelete = null;
+        /// <summary>
+        /// 閫夋嫨鐨勫満鏅�
+        /// </summary>
+        private Dictionary<int, Common.SceneUI> dicSelectScene = new Dictionary<int, Common.SceneUI>();
+        /// <summary>
+        /// 閫夋嫨鐨勮澶�
+        /// </summary>
+        private Dictionary<string, CommonDevice> dicSelectDevice = new Dictionary<string, CommonDevice>();
+        /// <summary>
+        /// 褰撳墠閫夋嫨鐨勫垎鏀� 0锛氬満鏅�  1锛氬姛鑳�
+        /// </summary>
+        private int nowSwitchIndex = 0;
+        /// <summary>
+        /// 褰撳墠閫夋嫨鐨勮澶囩储寮�
+        /// </summary>
+        private string nowDeviceIndex = string.Empty;
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        /// <param name="i_room">鏌ョ湅鐨勬埧闂村璞�</param>
+        /// <param name="i_memberShardInfo">鎴愬憳鐨勫垎浜暟鎹�</param>
+        public void ShowForm(Common.Room i_room, MemberShardInfoData i_memberShardInfo)
+        {
+            this.lookRoom = i_room;
+            this.memberShardInfo = i_memberShardInfo;
+
+            //璁剧疆澶撮儴淇℃伅
+            base.SetTitleText(i_room.Name);
+
+            //鍒濆鍖栦腑閮ㄤ俊鎭�
+            this.InitMiddleFrame();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+        /// </summary>
+        private void InitMiddleFrame()
+        {
+            //娓呯┖bodyFrame
+            this.ClearBodyFrame();
+            this.dicSelectDevice = new Dictionary<string, CommonDevice>();
+            this.dicSelectScene = new Dictionary<int, Common.SceneUI>();
+
+            //鍒濆鍖栨甯冩帶浠�
+            this.frameSceneTable = new FrameLayout();
+            frameSceneTable.Y = Application.GetRealHeight(132);
+            frameSceneTable.Height = bodyFrameLayout.Height - Application.GetRealHeight(132);
+            bodyFrameLayout.AddChidren(frameSceneTable);
+
+            this.frameDeviceTable = new FrameLayout();
+            frameDeviceTable.Y = frameSceneTable.Y;
+            frameDeviceTable.Height = frameSceneTable.Height;
+            bodyFrameLayout.AddChidren(frameDeviceTable);
+            frameDeviceTable.Visible = false;
+
+            //鍒濆鍖栧垎鏀帶浠�
+            this.InitSwitchControl();
+
+            //鍒犻櫎鎸夐挳
+            this.btnDelete = new BottomClickButton();
+            btnDelete.BackgroundColor = 0xfff75858;
+            btnDelete.TextID = R.MyInternationalizationString.uDelete;
+            bodyFrameLayout.AddChidren(btnDelete);
+            btnDelete.Visible = false;
+            btnDelete.ButtonClickEvent += (sender, e) =>
+            {
+                //鍒犻櫎鍒嗕韩
+                this.DeleteShardData();
+            };
+
+            //鍒濆鍖栧満鏅垪琛�
+            this.InitSceneList();
+            //鍒濆鍔熻兘鍒楄〃
+            this.InitFunctionList();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栧垎鏀帶浠�
+        /// </summary>
+        private void InitSwitchControl()
+        {
+            var tabControl = new SceneFunctionSwitchControl();
+            tabControl.Y = Application.GetRealHeight(40);
+            bodyFrameLayout.AddChidren(tabControl);
+            //璁剧疆鍒濆鍖栧��
+            tabControl.SetDefultIndex(nowSwitchIndex);
+            tabControl.SelectTabEvent += (tabIndex) =>
+            {
+                this.nowSwitchIndex = tabIndex;
+                if (tabIndex == 0)
+                {
+                    //鏄剧ず鍦烘櫙鍒楄〃
+                    this.frameSceneTable.Visible = true;
+                    this.frameDeviceTable.Visible = false;
+                }
+                else
+                {
+                    //鏄剧ず鍔熻兘鍒楄〃
+                    this.frameSceneTable.Visible = false;
+                    this.frameDeviceTable.Visible = true;
+                }
+            };
+            //寮�濮嬪垵濮嬪寲鍦烘櫙鍔熻兘鍒囨崲鎺т欢
+            var listTitle = new List<string>();
+            listTitle.Add(Language.StringByID(R.MyInternationalizationString.uScence));
+            listTitle.Add(Language.StringByID(R.MyInternationalizationString.uFunction));
+            tabControl.InitControl(listTitle);
+        }
+
+        #endregion
+
+        #region 鈻� 鍦烘櫙鏄剧ず___________________________
+
+        /// <summary>
+        /// 鍒濆鍖栧満鏅垪琛�
+        /// </summary>
+        private void InitSceneList()
+        {
+            //娓呯┖妗屽竷
+            this.frameSceneTable.RemoveAll();
+
+            var listScene = new List<Common.SceneUI>();
+            for (int i = 0; i < lookRoom.ListSceneId.Count; i++)
+            {
+                var byteData = HdlShardLogic.Current.GetShardFileContent($"Scene_{lookRoom.ListSceneId[i]}.json");
+                if (byteData == null)
+                {
+                    continue;
+                }
+                var sceneUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(System.Text.Encoding.UTF8.GetString(byteData));
+                listScene.Add(sceneUi);
+            }
+            if (listScene.Count == 0)
+            {
+                //鏃犲彲鍙栨秷鍏变韩鐨勫満鏅�
+                this.ShowNotDataImage(frameSceneTable, Language.StringByID(R.MyInternationalizationString.uNotCanCancelShardSceneMsg), "Item/NotShardPic.png", 383, 279);
+                return;
+            }
+
+            HdlThreadLogic.Current.RunMainInThread(() =>
+            {
+                var listView = new VerticalFrameControl(3);
+                listView.Y = Application.GetRealHeight(53);
+                listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(187);
+                frameSceneTable.AddChidren(listView);
+
+                foreach (var data in listScene)
+                {
+                    //鍦烘櫙鎺т欢
+                    var frameContr = new ScenePictrueControl();
+                    listView.AddChidrenFrame(frameContr);
+                    frameContr.InitControl(data);
+
+                    var btnSelect = new IconViewControl(58);
+                    btnSelect.UnSelectedImagePath = "Item/ItemUnSelected.png";
+                    btnSelect.SelectedImagePath = "Item/ItemSelected.png";
+                    btnSelect.X = Application.GetRealWidth(887);
+                    btnSelect.Y = Application.GetRealHeight(35);
+                    frameContr.AddChidren(btnSelect, ChidrenBindMode.BindEventOnly);
+                    if (dicSelectScene.ContainsKey(data.Id) == true)
+                    {
+                        btnSelect.IsSelected = true;
+                    }
+                    frameContr.ButtonClickEvent += (sender, e) =>
+                    {
+                        //閫夋嫨
+                        btnSelect.IsSelected = !btnSelect.IsSelected;
+                        if (btnSelect.IsSelected == true)
+                        {
+                            dicSelectScene[data.Id] = data;
+                            if (this.btnDelete.Visible == false)
+                            {
+                                this.btnDelete.Visible = true;
+                            }
+                        }
+                        else
+                        {
+                            dicSelectScene.Remove(data.Id);
+                            if (dicSelectScene.Count == 0 && dicSelectDevice.Count == 0)
+                            {
+                                this.btnDelete.Visible = false;
+                            }
+                        }
+                    };
+                }
+                //璋冩暣涓�涓嬮珮搴�
+                listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(185));
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鍔熻兘鏄剧ず___________________________
+
+        /// <summary>
+        /// 鍒濆鍖栧姛鑳藉垪琛�
+        /// </summary>
+        private void InitFunctionList()
+        {
+            //娓呯┖妗屽竷
+            this.frameDeviceTable.RemoveAll();
+
+            HdlThreadLogic.Current.RunMainInThread(() =>
+            {
+                //鑾峰彇鍒嗙粍鍚庣殑璁惧鍒楄〃
+                var dicGroupDevice = this.GetAllGroupDevice();
+                if (dicGroupDevice.Count == 0)
+                {
+                    //鏃犲彲鍙栨秷鍏变韩鐨勮澶�
+                    this.ShowNotDataImage(frameDeviceTable, Language.StringByID(R.MyInternationalizationString.uNotCanCancelDeviceMsg), "Item/NotShardPic.png", 383, 279);
+                }
+                else
+                {
+                    var frameBack = new FrameLayout();
+                    frameBack.X = ControlCommonResourse.XXLeft;
+                    frameBack.Y = Application.GetRealHeight(178);
+                    frameBack.BackgroundColor = UserCenterColor.Current.White;
+                    frameBack.Width = bodyFrameLayout.Width;
+                    frameBack.Height = Application.GetRealHeight(1650);
+                    frameBack.Radius = (uint)Application.GetRealHeight(58);
+                    frameDeviceTable.AddChidren(frameBack);
+
+                    var listView = new VerticalListControl(23);
+                    listView.Y = Application.GetRealHeight(23);
+                    listView.Height = Application.GetRealHeight(1437 - 23);
+                    frameBack.AddChidren(listView);
+                    //鍒濆鍖栬澶囩被鍨嬭
+                    this.InitDeviceObjectRow(dicGroupDevice, listView);
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖栬澶囩被鍨嬭___________________
+
+        /// <summary>
+        /// 鍒濆鍖栬澶囩被鍨嬭
+        /// </summary>
+        /// <param name="dicData"></param>
+        /// <param name="listView"></param>
+        private void InitDeviceObjectRow(Dictionary<int, List<CommonDevice>> dicData, VerticalListControl listView)
+        {
+            var scrolContr = new RoomDeviceGroupMenuControl(dicData);
+            this.frameDeviceTable.AddChidren(scrolContr);
+            //璁剧疆鍒濆鍊�
+            scrolContr.SetDefultIndex(nowDeviceIndex);
+            scrolContr.SelectDeviceEvent += (listdevice) =>
+            {
+                this.nowDeviceIndex = scrolContr.nowSelectKeys;
+                //娣诲姞璁惧琛�
+                this.AddDeviceRow(listdevice, listView);
+            };
+            scrolContr.InitControl();
+        }
+
+        #endregion
+
+        #region 鈻� 娣诲姞璁惧琛宊________________________
+
+        /// <summary>
+        /// 娣诲姞璁惧琛�
+        /// </summary>
+        /// <param name="listDevice"></param>
+        /// <param name="listView"></param>
+        private void AddDeviceRow(List<CommonDevice> listDevice, VerticalListControl listView)
+        {
+            listView.RemoveAll();
+            //杩樺師楂樺害
+            listView.RecoverHeight();
+
+            foreach (var device in listDevice)
+            {
+                var frameRow = new FrameRowControl(listView.rowSpace / 2);
+                frameRow.LeftOffset = Application.GetRealWidth(46) - ControlCommonResourse.XXLeft;
+                frameRow.RightOffset = -ControlCommonResourse.XXLeft;
+                listView.AddChidren(frameRow);
+                //鍥炬爣
+                var btnIcon = frameRow.AddLeftIcon(81);
+                Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
+                //鍚嶇О
+                var btnView = frameRow.AddLeftCaption(string.Empty, 600);
+                btnView.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
+                btnView.TextSize = 15;
+                //搴曠嚎
+                frameRow.AddBottomLine();
+                //閫夋嫨
+                var btnSelect = frameRow.AddMostRightEmptyIcon(69, 69);
+                btnSelect.UnSelectedImagePath = "Item/ItemUnSelected.png";
+                btnSelect.SelectedImagePath = "Item/ItemSelected.png";
+
+                string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+                if (dicSelectDevice.ContainsKey(mainKeys) == true)
+                {
+                    btnSelect.IsSelected = true;
+                }
+                frameRow.ButtonClickEvent += (sender, e) =>
+                {
+                    //閫夋嫨
+                    btnSelect.IsSelected = !btnSelect.IsSelected;
+                    if (btnSelect.IsSelected == true)
+                    {
+                        dicSelectDevice[mainKeys] = device;
+                        if (this.btnDelete.Visible == false)
+                        {
+                            this.btnDelete.Visible = true;
+                        }
+                    }
+                    else
+                    {
+                        dicSelectDevice.Remove(mainKeys);
+                        if (dicSelectScene.Count == 0 && dicSelectDevice.Count == 0)
+                        {
+                            this.btnDelete.Visible = false;
+                        }
+                    }
+                };
+            }
+            //鍒楄〃鑷繁鏈変釜23鐨刌杞村潗鏍�
+            listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23), Application.GetRealHeight(300 - 23));
+        }
+
+        #endregion
+
+        #region 鈻� 鏁村悎璁惧___________________________
+
+        /// <summary>
+        /// 鑾峰彇鍒嗙粍鍚庣殑璁惧
+        /// </summary>
+        /// <returns></returns>
+        private Dictionary<int, List<CommonDevice>> GetAllGroupDevice()
+        {
+            //鍏ㄩ儴鐨勮澶�
+            var listDevice = this.GetShardListDevice();
+            var dic = new Dictionary<int, List<CommonDevice>>();
+            foreach (var device in listDevice)
+            {
+                var typeInfo = Common.LocalDevice.Current.GetDeviceBelongEnumInfo(device);
+                if (dic.ContainsKey(typeInfo.BeloneTextId) == false)
+                {
+                    dic[typeInfo.BeloneTextId] = new List<CommonDevice>();
+                }
+                dic[typeInfo.BeloneTextId].Add(device);
+            }
+            return dic;
+        }
+
+        #endregion
+
+        #region 鈻� 鍒犻櫎鍒嗕韩___________________________
+
+        /// <summary>
+        /// 鍒犻櫎鍒嗕韩
+        /// </summary>
+        private void DeleteShardData()
+        {
+            //閫夋嫨鐨勮澶�
+            var listDevice = new List<CommonDevice>();
+            foreach (var device in dicSelectDevice.Values)
+            {
+                listDevice.Add(device);
+            }
+            //閫夋嫨鐨勫満鏅�
+            var listScene = new List<Common.SceneUI>();
+            foreach (var scene in dicSelectScene.Values)
+            {
+                listScene.Add(scene);
+            }
+
+            //纭鍒犻櫎閫夋嫨鐨勫叡浜満鏅拰鍔熻兘锛�
+            this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uDeleteShardContentMsg), () =>
+            {
+                HdlThreadLogic.Current.RunThread(async () =>
+                {
+                    //涓婁紶鏂囦欢
+                    var result = await HdlShardLogic.Current.DoDeleteSharedContent(memberShardInfo, this.lookRoom, listDevice, listScene);
+                    if (result == true)
+                    {
+                        HdlThreadLogic.Current.RunMain(() =>
+                        {
+                            //閲嶆柊鍒濆鍖栫晫闈�
+                            this.InitMiddleFrame();
+                        });
+                    }
+                });
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 鑾峰彇鍒嗕韩鐨勮澶�
+        /// </summary>
+        /// <returns></returns>
+        private List<CommonDevice> GetShardListDevice()
+        {
+            //鑾峰彇杩欎釜鎴块棿閲岄潰鐨勫垎浜澶�
+            var listDevice = new List<CommonDevice>();
+            foreach (var deviceKeys in this.lookRoom.ListDevice)
+            {
+                string deviceFile = HdlShardLogic.Current.GetShardDeviceFileName(deviceKeys);
+                if (memberShardInfo.dicAllShardKeys.ContainsKey(deviceFile) == true)
+                {
+                    var strArry = deviceFile.Split('_');
+                    if (strArry.Length < 3)
+                    {
+                        continue;
+                    }
+                    //浠庡垎浜枃浠朵腑搴忓垪鍖栧洖鏉�
+                    var deviceData = HdlShardLogic.Current.GetShardFileContent(deviceFile);
+                    var device = ZigBee.Device.CommonDevice.CommonDeviceByByteString(strArry[1], System.Text.Encoding.UTF8.GetString(deviceData));
+                    if (device != null)
+                    {
+                        listDevice.Add(device);
+                    }
+                }
+            }
+            return listDevice;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0