From f37f3a667bd81f78736e381717b82f632cb1fdeb Mon Sep 17 00:00:00 2001
From: lss <316519258@qq.com>
Date: 星期三, 10 六月 2020 15:52:57 +0800
Subject: [PATCH] test

---
 ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs |  198 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 143 insertions(+), 55 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs
index 2a5d080..b352d26 100644
--- a/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlForm.cs
@@ -1,7 +1,11 @@
 锘縰sing System;
 using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
 using Shared.Common;
 using Shared.Phone.UserCenter.SmartSound.Forms;
+using Shared.Phone.UserCenter.SmartSound.Util;
+using Shared.Phone.UserCenter.SmartSound.Widget;
 using ZigBee.Device;
 
 namespace Shared.Phone.UserCenter.SmartSound
@@ -17,17 +21,21 @@
         private FrameLayout contentLayout = null;
         public int CurrentIndex = 0;
         private MostRightIconControl btnAddDeviceIcon = null;
+        /// <summary>
+        ///  鏅鸿兘闊崇鏁版嵁
+        /// </summary>
+        private static SmartSoundInfo.SoundInfo mSoundInfo = null;
 
-        public SmartSoundControlForm()
+        public SmartSoundControlForm(SmartSoundInfo.SoundInfo soundInfo)
         {
+            mSoundInfo = soundInfo;
         }
 
         /// <summary>
         /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
         /// </summary>
         public void ShowForm()
-        {
-            
+        {            
             //璁剧疆鏍囬淇℃伅
             base.SetTitleText("璇煶鎺у埗");
 
@@ -40,49 +48,88 @@
                 btnAddDeviceIcon.InitControl();
                 btnAddDeviceIcon.ButtonClickEvent += (sender, e) =>
                 {
-                    var smartSoundDataAdd = new SmartSoundControlContentForm();
+                    var smartSoundDataAdd = new SmartSoundControlContentForm(mSoundInfo);
                     smartSoundDataAdd.AddForm();
                 };
             }
 
             //鍒濆鍖栦腑閮ㄦ帶浠�
             this.InitMiddleFrame();
-
         }
-        
+
         private void InitMiddleFrame()
         {
+            this.ClearBodyFrame();
 
-            if (SmartSound.CurretnData == null || SmartSound.CurretnData.Count < 1)
-                return;
-
-            // 娣诲姞鏁版嵁
-            if (contentLayout != null)
+            HdlThreadLogic.Current.RunThread(async () =>
             {
-                contentLayout.RemoveAll();
-                contentLayout = null;
-            }
-                
-            contentLayout = new FrameLayout();
-            this.bodyFrameLayout.AddChidren(contentLayout);
-            contentLayout.RemoveAll();
+                this.ShowProgressBar();
 
-            var pullLayout = new MyPullControl(this, SmartSound.CurretnData);
-            contentLayout.AddChidren(pullLayout);
-            pullLayout.InitControl();
+                string json = await GetData();//鑾峰彇鏁版嵁
+                SmartSoundDataInfo dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<SmartSoundDataInfo>(json);
+                if (dataInfo != null)
+                {
+                    if (dataInfo.StateCode == "SUCCESS")
+                    {
+                        SmartSound.getInstantiate().LayerList = dataInfo.ResponseData.LayerList;
+                        SmartSound.getInstantiate().TokenID = mSoundInfo.Id;
+                        SmartSound.getInstantiate().UserID = mSoundInfo.UserID;
+                    }
+                }
 
-            LoadAllRoomListView();
+                HdlThreadLogic.Current.RunMainInThread(() =>
+                {
+                    if (SmartSound.getInstantiate().LayerList == null || SmartSound.getInstantiate().LayerList.Count < 1)
+                    {
+                        this.CloseProgressBar();
+                        return;
+                    }
 
+                    contentLayout = new FrameLayout();
+                    this.bodyFrameLayout.AddChidren(contentLayout);
+                    contentLayout.RemoveAll();
+
+                    var pullLayout = new MyPullControl(this, SmartSound.getInstantiate().LayerList);
+                    contentLayout.AddChidren(pullLayout);
+                    pullLayout.InitControl();
+
+                    LoadAllRoomListView();
+
+                    //鏃犳暟鎹殑鏃跺�欒鍋氫竴涓彁绀�
+                    {
+                        bool bol = false;
+                        for (int i = 0; i < SmartSound.getInstantiate().LayerList.Count; i++)
+                        {
+                            if (SmartSound.getInstantiate().LayerList[i].RoomList.Count > 0)
+                            {
+                                bol = true;
+                                break;
+                            }
+                        }
+
+                        if (!bol)
+                        {
+                            pullLayout.Visible = false;
+                            this.ShowNotDataImage(this.bodyFrameLayout, new string[] { "杩樻病鏈夋帶鍒跺唴瀹瑰摝锛�", "鐐瑰嚮\"+\"娣诲姞" });
+                        }
+                    }
+
+                    this.CloseProgressBar();
+
+                });
+            });
         }
 
+        /// <summary>
+        /// 鍔犺浇鎴块棿鍒楄〃
+        /// </summary>
         private void LoadAllRoomListView()
         {
             try
             {
-
-                if (SmartSound.CurretnData == null || SmartSound.CurretnData.Count < 1)
+                if (SmartSound.getInstantiate().LayerList == null || SmartSound.getInstantiate().LayerList.Count < 1)                            
                     return;
-
+                                
                 // 鍔犺浇褰撳墠妤煎眰鐨勬墍鏈夋埧闂� ListView
                 if (listView == null)
                 {
@@ -102,7 +149,7 @@
 
                 listView.RemoveAll();
 
-                SmartSound.Layer layer = SmartSound.CurretnData[CurrentIndex];
+                SmartSound.Layer layer = SmartSound.getInstantiate().LayerList[CurrentIndex];
 
                 foreach (SmartSound.Room room in layer.RoomList)
                 {
@@ -112,47 +159,82 @@
 
                     roomRowLayout.frameTable.ButtonClickEvent += (sender, e) =>
                     {
+                        // 鐐瑰嚮鎴块棿锛岃繘鍏ラ�夋嫨璁惧鐣岄潰
                         var deviceChange = new SmartSoundContentForDeviceChange(room);
                         deviceChange.AddForm();
                     };
 
                     roomRowLayout.btnDelect.ButtonClickEvent += (sender, e) =>
                     {
-                        try
-                        {
-                            var delBtn = sender as NormalViewControl;
-                            var tag = (SmartSound.Room)delBtn.GetTagByKey("obj");
-
-                            if (SmartSound.CurretnData == null)
-                                return;
-
-                            for (int i = 0; i < SmartSound.CurretnData.Count; i++)
-                            {
-                                SmartSound.Layer _layer = SmartSound.CurretnData[i];
-
-                                for (int j = 0; j < _layer.RoomList.Count; j++)
-                                {
-                                    SmartSound.Room _room = _layer.RoomList[j];
-
-                                    if (_room.RoomID == tag.RoomID)
-                                    {
-                                        _layer.RoomList.Remove(_room);
-                                        this.LoadAllRoomListView();
-                                    }
-                                }
-                            }                            
-                        }
-                        catch(Exception ex)
-                        {
-                            string error = ex.Message;
-                        }
+                        var delBtn = sender as NormalViewControl;
+                        DelectRoom(delBtn);
                     };
                 }
             }
-            catch(Exception e)
+            catch (Exception e)
             {
                 string error = e.Message;
             }
+        }
+
+        private void DelectRoom(NormalViewControl delBtn)
+        {
+            this.ShowMassage(ShowMsgType.Confirm, "纭鍒犻櫎璇ユ埧闂寸殑鎺у埗鍐呭锛�", async () =>
+            {
+
+                HdlThreadLogic.Current.RunThread(async () =>
+                {
+
+                    this.ShowProgressBar("姝e湪鍒犻櫎鏁版嵁....");
+                    //鍒犻櫎鎴块棿
+                    var tag = (SmartSound.Room)delBtn.GetTagByKey("obj");
+
+                    if (SmartSound.getInstantiate().LayerList == null)
+                        return;
+
+                    for (int i = 0; i < SmartSound.getInstantiate().LayerList.Count; i++)
+                    {
+                        SmartSound.Layer _layer = SmartSound.getInstantiate().LayerList[i];
+
+                        for (int j = 0; j < _layer.RoomList.Count; j++)
+                        {
+                            SmartSound.Room _room = _layer.RoomList[j];
+
+                            if (_room.RoomName == tag.RoomName)
+                            {
+                                _layer.RoomList.Remove(_room);                                
+                            }
+                        }
+                    }
+                    
+                    // 閲嶆柊涓婁紶鏁版嵁
+                    string json = await postBatchEdit();
+
+                    HdlThreadLogic.Current.RunMainInThread(() =>
+                    {
+                        //this.InitMiddleFrame();
+                        this.LoadAllRoomListView();
+                    });
+                    this.CloseProgressBar();
+                });
+
+            }, Language.StringByID(R.MyInternationalizationString.OkMsg));
+        }
+
+        private async Task<string> GetData()
+        {
+            // 浠庢湇鍔″櫒鑾峰彇鏁版嵁
+            string url = string.Format("https://developer.hdlcontrol.com/zigbeespeakerservice/BatchEdit?Platform&UserID={0}&TokenID={1}", mSoundInfo.UserID, mSoundInfo.Id);
+            return await MyHttpWebResponse.GetWebRequest(url);
+        }
+
+        private async Task<string> postBatchEdit()
+        {
+            // 鎻愪氦鏁版嵁鑷虫湇鍔″櫒
+            string url = "https://developer.hdlcontrol.com/zigbeespeakerservice/BatchEdit";
+            string json = Newtonsoft.Json.JsonConvert.SerializeObject(SmartSound.getInstantiate());
+            string response_str = await MyHttpWebResponse.PostWebRequest(url, json, Encoding.UTF8);
+            return response_str;
         }
 
         public override int FormActionAgainEvent()
@@ -216,6 +298,12 @@
                     {
                         ShowPullList();
                     };
+
+                    if (SmartSound.getInstantiate().LayerList.Count < 2)
+                    {
+                        right_icon.Visible = false;
+                        layout.Visible = false;
+                    }
                 }
                 catch(Exception e)
                 {

--
Gitblit v1.8.0