From 4d6c9858844d1545a9b253c1b31842fa89695c1d Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期日, 06 六月 2021 13:59:01 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/wxr4' into WJC
---
HDL_ON/UI/UI2/4-PersonalCenter/SmartSpeaker/SmartSpeakerSelectDevicesPage.cs | 433 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 433 insertions(+), 0 deletions(-)
diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/SmartSpeaker/SmartSpeakerSelectDevicesPage.cs b/HDL_ON/UI/UI2/4-PersonalCenter/SmartSpeaker/SmartSpeakerSelectDevicesPage.cs
new file mode 100644
index 0000000..ce32f35
--- /dev/null
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/SmartSpeaker/SmartSpeakerSelectDevicesPage.cs
@@ -0,0 +1,433 @@
+锘縰sing System;
+using Shared;
+using HDL_ON.UI.CSS;
+using System.Collections.Generic;
+using HDL_ON.DAL.Server;
+
+namespace HDL_ON.UI
+{
+
+ /// <summary>
+ /// 绠$悊閰嶇疆缁欓煶绠辩殑璁惧鎴栫潃鍦烘櫙鍒楄〃
+ /// </summary>
+ public class SmartSpeakerSelectDevicesPage : FrameLayout
+ {
+ /// <summary>
+ /// bodyView
+ /// </summary>
+ FrameLayout bodyView;
+ /// <summary>
+ /// 鍏ㄩ�夋寜閽�
+ /// </summary>
+ Button btnChooseAll;
+ /// <summary>
+ /// 褰撳墠
+ /// </summary>
+ VerticalScrolViewLayout bodyScrolView;
+ ///// <summary>
+ ///// 搴曢儴淇濆瓨鎿嶄綔鎸夐挳
+ ///// </summary>
+ //Button btnSave;
+
+ /// <summary>
+ /// 闊崇鍙傛暟
+ /// </summary>
+ SpeakerInfo speakerInfo;
+
+ /// <summary>
+ /// 璁惧銆佸満鏅垪琛�
+ /// </summary>
+ List<SpeakerTargetInfo> targetInfoList = new List<SpeakerTargetInfo>();
+
+ /// <summary>
+ /// 褰撳墠鎴块棿鐨勮澶囧拰鍦烘櫙
+ /// </summary>
+ List<SpeakerTargetInfo> roomFunctionOrSceneList = new List<SpeakerTargetInfo>();
+
+ /// <summary>
+ /// 绠$悊閰嶇疆缁欓煶绠辩殑璁惧鎴栫潃鍦烘櫙鍒楄〃
+ /// </summary>
+ /// <param name="speakerInfo">闊崇鍙傛暟</param>
+ /// <param name="roomFunctionOrSceneList">褰撳墠鎴块棿鐨勫姛鑳芥垨鑰呭満鏅�</param>
+ public SmartSpeakerSelectDevicesPage(SpeakerInfo speakerInfo, List<SpeakerTargetInfo> roomFunctionOrSceneList)
+ {
+ bodyView = this;
+ bodyView.BackgroundColor = CSS_Color.MainBackgroundColor;
+ this.speakerInfo = speakerInfo;
+ this.roomFunctionOrSceneList = roomFunctionOrSceneList;
+ }
+
+ /// <summary>
+ /// 鍔犺浇瑙嗗浘
+ /// </summary>
+ public void LoadPage()
+ {
+ //鍔犺浇椤堕儴鑿滃崟鏍�
+ new TopViewDiv(bodyView, Language.StringByID(StringId.DataManagement)).LoadTopView();
+ //椤堕儴鍏ㄩ�夋寜閽�
+ var allView = new FrameLayout()
+ {
+ Y = Application.GetRealHeight(64),
+ Height = Application.GetRealHeight(50),
+ BackgroundColor = CSS_Color.MainBackgroundColor,
+ };
+ bodyView.AddChidren(allView);
+
+ Button btnAllRoomText = new Button()
+ {
+ X = Application.GetRealWidth(16),
+ Width = Application.GetRealWidth(280),
+ TextID = StringId.SelectedAll,
+ TextSize = CSS_FontSize.SubheadingFontSize,
+ TextColor = CSS_Color.FirstLevelTitleColor,
+ TextAlignment = TextAlignment.CenterLeft,
+ };
+ allView.AddChidren(btnAllRoomText);
+
+ btnChooseAll = new Button()
+ {
+ X = Application.GetRealWidth(331),
+ Gravity = Gravity.CenterVertical,
+ Width = Application.GetMinRealAverage(28),
+ Height = Application.GetMinRealAverage(28),
+ UnSelectedImagePath = "Public/ChooseIcon.png",
+ SelectedImagePath = "Public/ChooseOnIcon.png",
+ };
+ allView.AddChidren(btnChooseAll);
+
+ allView.AddChidren(new Button()
+ {
+ Gravity = Gravity.CenterHorizontal,
+ Y = Application.GetRealHeight(49),
+ Height = Application.GetMinReal(1),
+ Width = Application.GetRealWidth(343),
+ BackgroundColor = CSS_Color.DividingLineColor,
+ });
+
+ bodyScrolView = new VerticalScrolViewLayout()
+ {
+ Y = allView.Bottom,
+ Height = Application.GetRealHeight(450),
+ };
+ bodyView.AddChidren(bodyScrolView);
+
+ var btnSave = new ConfirmButton()
+ {
+ Y = Application.GetRealHeight(519 + 64),
+ TextID = StringId.Save
+ };
+ bodyView.AddChidren(btnSave);
+
+ //鍏ㄩ�夋寜閽偣鍑讳簨浠�
+ LoadEvent_AllSharedDataChange(allView, btnChooseAll);
+ //淇濆瓨鎸夐挳鐐瑰嚮浜嬩欢
+ LoadEvent_Save(btnSave);
+ //鍔犺浇鎴块棿鐨勫姛鑳藉拰鍦烘櫙锛屽苟姣旇緝閰嶇疆杩囩殑鏁版嵁瀹炵幇閫変腑鏁堟灉
+ GetDeviceAndSceneList();
+ }
+
+
+ /// <summary>
+ /// 鍏ㄩ�夋寜閽偣鍑讳簨浠�
+ /// </summary>
+ void LoadEvent_AllSharedDataChange(FrameLayout allView, Button btnChooseAll)
+ {
+ EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
+ {
+ btnChooseAll.IsSelected = !btnChooseAll.IsSelected;
+ var IsSelected = btnChooseAll.IsSelected;
+ //鍏ㄩ儴鏁版嵁閫変腑鐘舵�佽缃负true鎴栬�協alse
+ foreach (var info in roomFunctionOrSceneList)
+ {
+ info.IsSelect = IsSelected;
+ }
+ //鍒锋柊涓�娆″垪琛�
+ RefreshListView();
+ };
+ btnChooseAll.MouseUpEventHandler = eventHandler;
+ allView.MouseUpEventHandler = eventHandler;
+
+ }
+
+ /// <summary>
+ /// 淇濆瓨鎸夐挳鐐瑰嚮浜嬩欢
+ /// </summary>
+ /// <param name="btnSave"></param>
+ void LoadEvent_Save(Button btnSave)
+ {
+ EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
+ {
+ AddDevicesSceneList(targetInfoList);
+ };
+
+ btnSave.MouseUpEventHandler = eventHandler;
+ }
+
+ /// <summary>
+ /// 鍏ㄩ噺鏇存柊閰嶇疆鏁版嵁锛堝姛鑳藉拰鍦烘櫙鍚屾椂鏇存柊锛�
+ /// </summary>
+ /// <param name="updateList">鏈�鏂扮殑閰嶇疆鏁版嵁</param>
+ void AddDevicesSceneList(List<SpeakerTargetInfo> updateList)
+ {
+ var waitPage = new Loading();
+ bodyView.AddChidren(waitPage);
+ waitPage.Start(Language.StringByID(StringId.PleaseWait));
+
+ System.Threading.Tasks.Task.Run(() =>
+ {
+ try
+ {
+ //鏌ユ壘闇�瑕侀�変腑鐨勭洰鏍�
+ foreach (var info in roomFunctionOrSceneList)
+ {
+ var targetData = updateList.Find((obj) => obj.targetId == info.targetId);
+ if (info.IsSelect)
+ {
+ if (targetData == null)
+ {
+ updateList.Add(info);
+ }
+ }
+ else
+ {
+ if (targetData != null)
+ {
+ updateList.Remove(targetData);
+ }
+ }
+ }
+
+ //鏋勫缓璇锋眰鍙傛暟
+ var updateSpeakerDeviceListObj = new UpdateSpeakerDeviceListObj()
+ {
+ homeId = speakerInfo.homeId,
+ tokenId = speakerInfo.tokenId,
+ targetInfos = updateList
+ };
+ //鍙戣捣璇锋眰
+ var revertObj = new HttpServerRequest().UpdateSpeakerDeviceList(updateSpeakerDeviceListObj);
+ if (revertObj.Code == StateCode.SUCCESS)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ //淇濆瓨鎴愬姛銆侀〉闈㈠叧闂�
+ Utlis.ShowTip(Language.StringByID(StringId.SavedSuccessfully));
+ if (bodyView != null)
+ {
+ bodyView.RemoveFromParent();
+ }
+ });
+
+ }
+ else
+ {
+ //鎻愮ず閿欒
+ IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code);
+ }
+ }
+ catch
+ {
+
+ }
+ finally
+ {
+ Application.RunOnMainThread(() =>
+ {
+ if (waitPage != null)
+ {
+ waitPage.RemoveFromParent();
+ waitPage = null;
+ }
+ });
+ }
+ });
+ }
+
+ /// <summary>
+ /// 鍔犺浇鎴块棿鐨勮澶囧拰鍦烘櫙鍒楄〃
+ /// </summary>
+ void GetDeviceAndSceneList()
+ {
+ bodyScrolView.RemoveAll();
+
+ var waitPage = new Loading();
+ bodyView.AddChidren(waitPage);
+ waitPage.Start(Language.StringByID(StringId.PleaseWait));
+
+ System.Threading.Tasks.Task.Run(() =>
+ {
+ try
+ {
+ var revertObj = new HttpServerRequest().GetSpeakerDeviceList(0, speakerInfo.tokenId);
+ if (revertObj.Code == StateCode.SUCCESS)
+ {
+ var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpeakerTargetInfo>>(revertObj.Data.ToString());
+ if (list != null && list.Count > 0)
+ {
+ targetInfoList = list;
+ }
+ else
+ {
+ targetInfoList = new List<SpeakerTargetInfo>();
+ }
+
+ //榛樿鍏ㄩ��
+ bool isSelectAll = true;
+ //鏌ユ壘闇�瑕侀�変腑鐨勭洰鏍�
+ foreach (var info in roomFunctionOrSceneList)
+ {
+ var targetData = targetInfoList.Find((obj) => obj.targetId == info.targetId);
+ if(targetData == null)
+ {
+ info.IsSelect = false;
+ //鏈変竴涓病閫夋嫨鍒欏叏閫夎缃负false
+ isSelectAll = false;
+ }
+ else
+ {
+ info.IsSelect = true;
+ }
+ }
+
+ Application.RunOnMainThread(() => {
+ //璁剧疆褰撳墠鍏ㄩ��
+ btnChooseAll.IsSelected = isSelectAll;
+ RefreshListView();
+ });
+
+ }
+ else
+ {
+ //鎻愮ず閿欒
+ IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code);
+ }
+ }
+ catch
+ {
+
+ }
+ finally
+ {
+ Application.RunOnMainThread(() =>
+ {
+ if (waitPage != null)
+ {
+ waitPage.RemoveFromParent();
+ waitPage = null;
+ }
+ });
+ }
+ });
+ }
+
+ /// <summary>
+ /// RefreshListView
+ /// </summary>
+ void RefreshListView()
+ {
+ bodyScrolView.RemoveAll();
+
+ if (roomFunctionOrSceneList == null) return;
+
+ foreach (var roomData in roomFunctionOrSceneList)
+ {
+ AddRowView(roomData);
+ }
+
+ }
+
+
+ /// <summary>
+ /// AddRowView
+ /// </summary>
+ /// <param name="info"></param>
+ void AddRowView(SpeakerTargetInfo info)
+ {
+
+ var roomView = new FrameLayout()
+ {
+ Height = Application.GetRealHeight(50),
+ BackgroundColor = CSS_Color.MainBackgroundColor,
+ Tag = "row"
+ };
+ bodyScrolView.AddChidren(roomView);
+
+ Button btnRoomText = new Button()
+ {
+ X = Application.GetRealWidth(16),
+ Width = Application.GetRealWidth(280),
+ TextSize = CSS_FontSize.SubheadingFontSize,
+ TextColor = CSS_Color.FirstLevelTitleColor,
+ TextAlignment = TextAlignment.CenterLeft,
+ Text = info.targetName,
+ };
+ roomView.AddChidren(btnRoomText);
+
+ Button btnChoose = new Button()
+ {
+ X = Application.GetRealWidth(331),
+ Gravity = Gravity.CenterVertical,
+ Width = Application.GetMinRealAverage(28),
+ Height = Application.GetMinRealAverage(28),
+ UnSelectedImagePath = "Public/ChooseIcon.png",
+ SelectedImagePath = "Public/ChooseOnIcon.png",
+ Tag = "ChooseIcon"
+ };
+ roomView.AddChidren(btnChoose);
+
+ btnChoose.IsSelected = info.IsSelect;
+
+ var btnLine = new Button()
+ {
+ Gravity = Gravity.CenterHorizontal,
+ //Y = Application.GetRealHeight(49),
+ Height = Application.GetRealHeight(1),
+ Width = Application.GetRealWidth(343),
+ BackgroundColor = CSS_Color.DividingLineColor,
+ };
+ bodyScrolView.AddChidren(btnLine);
+
+
+ EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
+ {
+ btnChoose.IsSelected = !btnChoose.IsSelected;
+ info.IsSelect = btnChoose.IsSelected;
+ //1.濡傛灉鐐瑰嚮閫夋嫨锛屽垽鏂槸鍚﹂渶瑕佽缃叏閫�
+ if (btnChoose.IsSelected)
+ {
+ //1.1 榛樿鍏ㄩ��
+ bool isSelectAll = true;
+ foreach (var targetInfo in roomFunctionOrSceneList)
+ {
+ if(targetInfo.IsSelect == false)
+ {
+ //1.2 鏈変竴涓繕娌¢�変腑灏遍��鍑猴紝鏃犻渶閫変腑鍏ㄩ�夋寜閽�
+ isSelectAll = false;
+ break;
+ }
+ }
+
+ if (isSelectAll)
+ {
+ btnChooseAll.IsSelected = true;
+ }
+ }
+ else
+ {
+ //鍙栨秷鍏ㄩ��
+ if (btnChooseAll.IsSelected)
+ {
+ btnChooseAll.IsSelected = false;
+ }
+ }
+
+ };
+
+ btnChoose.MouseUpEventHandler = eventHandler;
+ roomView.MouseUpEventHandler = eventHandler;
+ btnRoomText.MouseUpEventHandler = eventHandler;
+ }
+
+
+ }
+}
--
Gitblit v1.8.0