From 9acd3887f1f8db40d59f991b1726a61aa7c7637c Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期三, 12 五月 2021 15:13:56 +0800 Subject: [PATCH] Merge branch 'CJL' into wxr4 --- HDL_ON/UI/UI2/4-PersonalCenter/SmartSpeaker/SmartSpeakerListPage.cs | 576 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 576 insertions(+), 0 deletions(-) diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/SmartSpeaker/SmartSpeakerListPage.cs b/HDL_ON/UI/UI2/4-PersonalCenter/SmartSpeaker/SmartSpeakerListPage.cs new file mode 100644 index 0000000..4b29afa --- /dev/null +++ b/HDL_ON/UI/UI2/4-PersonalCenter/SmartSpeaker/SmartSpeakerListPage.cs @@ -0,0 +1,576 @@ +锘縰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 SmartSpeakerListPage : FrameLayout + { + FrameLayout bodyView; + /// <summary> + /// + /// </summary> + FrameLayout emptyTipFrameLayout; + /// <summary> + /// 褰撳墠 + /// </summary> + VerticalScrolViewLayout bodyScrolView; + /// <summary> + /// 鍐呭涓虹┖鎻愮ずView + /// </summary> + FrameLayout emptyTipView; + + /// 鐩墠瀵规帴鐨勯煶绠辩被鍨� + /// 灏忓害=DuerOS + /// Google Home = Google + /// Alexa Echo = Alexa + /// Alice = Alice + /// 澶╃尗绮剧伒=Aligenie + /// 鎬濆繀椹�=AISpeech + + + /// <summary> + /// + /// </summary> + public SmartSpeakerListPage() + { + bodyView = this; + bodyView.BackgroundColor = CSS_Color.BackgroundColor; + } + + /// <summary> + /// 鍔犺浇瑙嗗浘 + /// </summary> + public void LoadPage() + { + new TopViewDiv(bodyView, Language.StringByID(StringId.SmartSpeaker)).LoadTopView(); + + int bodyY = Application.GetRealHeight(64); + bodyScrolView = new VerticalScrolViewLayout() + { + Y = bodyY, + Height = bodyView.Height - bodyY, + BackgroundColor = CSS_Color.BackgroundColor, + + }; + bodyView.AddChidren(bodyScrolView); + + LoadSmartSpeakertListView(bodyScrolView); + } + + /// <summary> + /// 娣诲姞鍐呭涓虹┖鎻愮ず椤甸潰 + /// </summary> + void AddEmptyTipView() + { + emptyTipView = new FrameLayout() + { + Height = bodyScrolView.Height, + Width = bodyScrolView.Width, + }; + bodyScrolView.AddChidren(emptyTipView); + + var tipView = new EmptyTipView() + { + Gravity = Gravity.Center + }; + emptyTipView.AddChidren(tipView); + } + + /// <summary> + /// 鍔犺浇闊崇鍒楄〃 + /// </summary> + /// <param name="VerticalScrolViewMiddle"></param> + void LoadSmartSpeakertListView(VerticalScrolViewLayout VerticalScrolViewMiddle) + { + VerticalScrolViewMiddle.RemoveAll(); + + var waitPage = new Loading(); + bodyView.AddChidren(waitPage); + waitPage.Start(Language.StringByID(StringId.PleaseWait)); + + System.Threading.Tasks.Task.Run(() => + { + try + { + + var revertObj = new HttpServerRequest().GetSpeakerList(); + if (revertObj.Code == StateCode.SUCCESS) + { + var speakerListRes = Newtonsoft.Json.JsonConvert.DeserializeObject<SpeakerListRes>(revertObj.Data.ToString()); + if (speakerListRes != null && speakerListRes.list != null && speakerListRes.list.Count > 0) + { + Application.RunOnMainThread(() => + { + foreach (var speaker in speakerListRes.list) + { + AddRowView(speaker, VerticalScrolViewMiddle); + } + + }); + } + else + { + Application.RunOnMainThread(() => + { + AddEmptyTipView(); + }); + } + } + else + { + Application.RunOnMainThread(() => + { + AddEmptyTipView(); + }); + //鎻愮ず閿欒 + IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code); + } + } + catch + { + + } + finally + { + Application.RunOnMainThread(() => + { + if (waitPage != null) + { + waitPage.RemoveFromParent(); + waitPage = null; + } + }); + } + }); + } + + + + /// <summary> + /// + /// </summary> + /// <param name="speakerInfo"></param> + /// <param name="VerticalScrolViewMiddle"></param> + void AddRowView(SpeakerInfo speakerInfo, VerticalScrolViewLayout VerticalScrolViewMiddle) + { + //閫忔槑濉厖鍒嗗壊view + var lineView = new FrameLayout() + { + Height = Application.GetRealWidth(12), + }; + VerticalScrolViewMiddle.AddChidren(lineView); + + var rowView = new FrameLayout() + { + Gravity = Gravity.CenterHorizontal, + Width = Application.GetRealWidth(343), + Height = Application.GetRealWidth(200), + BackgroundColor = CSS_Color.MainBackgroundColor, + Radius = (uint)Application.GetRealWidth(12), + BorderColor = 0x00000000, + BorderWidth = 0, + }; + VerticalScrolViewMiddle.AddChidren(rowView); + + #region 闊崇绫诲瀷 + var view1 = new FrameLayout() + { + Height = Application.GetRealWidth(49), + }; + rowView.AddChidren(view1); + + var btnSpeakerNameTitle = new Button() + { + X = Application.GetRealWidth(16), + Width = Application.GetRealWidth(200), + TextAlignment = TextAlignment.CenterLeft, + TextColor = CSS_Color.FirstLevelTitleColor, + TextSize = CSS_FontSize.TextFontSize, + Text = GetSpeakerTypeString(speakerInfo.platformName) + }; + view1.AddChidren(btnSpeakerNameTitle); + + Button line1 = new Button() + { + Y = view1.Bottom, + Gravity = Gravity.CenterHorizontal, + Height = Application.GetRealWidth(1), + Width = Application.GetRealWidth(311), + BackgroundColor = CSS_Color.DividingLineColor, + }; + rowView.AddChidren(line1); + + #endregion + + #region 澶囨敞 + var view2 = new FrameLayout() + { + Y = line1.Bottom, + Height = Application.GetRealWidth(49), + }; + rowView.AddChidren(view2); + + var btnNicknameTitle = new Button() + { + X = Application.GetRealWidth(16), + Width = Application.GetRealWidth(200), + TextAlignment = TextAlignment.CenterLeft, + TextColor = CSS_Color.FirstLevelTitleColor, + TextSize = CSS_FontSize.TextFontSize, + TextID = StringId.Remarks, + }; + view2.AddChidren(btnNicknameTitle); + + var btnNickname = new Button() + { + Width = Application.GetRealWidth(295), + TextAlignment = TextAlignment.CenterRight, + TextColor = CSS_Color.PromptingColor1, + TextSize = CSS_FontSize.TextFontSize, + Text = speakerInfo.remark + }; + view2.AddChidren(btnNickname); + + if (string.IsNullOrEmpty(speakerInfo.remark)) + { + btnNickname.TextID = StringId.SmartSpeaker; + } + + var btnNicknameRight = new Button() + { + X = Application.GetRealWidth(311), + Gravity = Gravity.CenterVertical, + Width = Application.GetMinRealAverage(16), + Height = Application.GetMinRealAverage(16), + UnSelectedImagePath = "Public/Right.png", + }; + view2.AddChidren(btnNicknameRight); + + Button line2 = new Button() + { + Y = view2.Bottom, + Gravity = Gravity.CenterHorizontal, + Height = Application.GetRealWidth(1), + Width = Application.GetRealWidth(311), + BackgroundColor = CSS_Color.DividingLineColor, + }; + rowView.AddChidren(line2); + + + //淇濆瓨浜嬩欢 + Action<string> renameAction = (newName) => + { + RenameAlexaRemark(newName, speakerInfo, btnNickname); + }; + + btnNickname.MouseUpEventHandler += (sender, e) => + { + new PublicAssmebly().LoadDialog_EditParater(StringId.Remarks, speakerInfo.remark, renameAction, StringId.RemarksCannotBeBlank, 0, new List<string>(),false, Language.StringByID(StringId.Save)); + }; + #endregion + + #region 鏁版嵁绠$悊 + var view3 = new FrameLayout() + { + Y = line2.Bottom, + Height = Application.GetRealWidth(49), + }; + rowView.AddChidren(view3); + + var btnDataTitle = new Button() + { + X = Application.GetRealWidth(16), + Width = Application.GetRealWidth(200), + TextAlignment = TextAlignment.CenterLeft, + TextColor = CSS_Color.FirstLevelTitleColor, + TextSize = CSS_FontSize.TextFontSize, + TextID = StringId.DataManagement, + }; + view3.AddChidren(btnDataTitle); + + var btnDataRight = new Button() + { + X = Application.GetRealWidth(311), + Gravity = Gravity.CenterVertical, + Width = Application.GetMinRealAverage(16), + Height = Application.GetMinRealAverage(16), + UnSelectedImagePath = "Public/Right.png", + }; + view3.AddChidren(btnDataRight); + + Button line3 = new Button() + { + Y = view3.Bottom, + Gravity = Gravity.CenterHorizontal, + Height = Application.GetRealWidth(1), + Width = Application.GetRealWidth(311), + BackgroundColor = CSS_Color.DividingLineColor, + }; + rowView.AddChidren(line3); + + EventHandler<MouseEventArgs> eHandler = (sender, e) => + { + //璺宠浆鏁版嵁绠$悊鎴块棿鍒楄〃 + GotoPage(speakerInfo); + }; + view3.MouseUpEventHandler += eHandler; + btnDataTitle.MouseUpEventHandler += eHandler; + btnDataRight.MouseUpEventHandler += eHandler; + #endregion + + #region 瑙i櫎缁戝畾 + var view4 = new FrameLayout() + { + Y = line3.Bottom, + Height = Application.GetRealWidth(49), + }; + rowView.AddChidren(view4); + + var btnUnbindTitle = new Button() + { + X = Application.GetRealWidth(16), + Width = Application.GetRealWidth(200), + TextAlignment = TextAlignment.CenterLeft, + TextColor = CSS_Color.FirstLevelTitleColor, + TextSize = CSS_FontSize.TextFontSize, + TextID = StringId.Unbind, + }; + view4.AddChidren(btnUnbindTitle); + + var btnUnbindRight = new Button() + { + X = Application.GetRealWidth(311), + Gravity = Gravity.CenterVertical, + Width = Application.GetMinRealAverage(16), + Height = Application.GetMinRealAverage(16), + UnSelectedImagePath = "Public/Right.png", + }; + view4.AddChidren(btnUnbindRight); + + EventHandler<MouseEventArgs> eHandler4 = (sender, e) => + { + Action okAction = () => + { + //瑙g粦闊崇 + UnbindSpeaker(speakerInfo, rowView, lineView); + }; + new ConfirmDialog().ShowDialog(StringId.Tip, StringId.DoYouWantToUnbind, okAction, null, StringId.Cancel, StringId.Confirm); + + }; + view4.MouseUpEventHandler += eHandler4; + btnUnbindTitle.MouseUpEventHandler += eHandler4; + btnUnbindRight.MouseUpEventHandler += eHandler4; + + #endregion + + + + } + + /// <summary> + /// 璇锋眰淇敼澶囨敞 + /// </summary> + /// <param name="newName"></param> + /// <param name="speakerInfo"></param> + /// <param name="btnName"></param> + void RenameAlexaRemark(string newName, SpeakerInfo speakerInfo, Button btnName) + { + //鏄剧ずloading鍔ㄧ敾鏁堟灉 + var waitPage = new Loading(); + bodyView.AddChidren(waitPage); + waitPage.Start(Language.StringByID(StringId.PleaseWait)); + + System.Threading.Tasks.Task.Run(() => + { + try + { + var updateSpeakerRemarkObj = new UpdateSpeakerRemarkObj() + { + homeId = speakerInfo.homeId, + tokenId = speakerInfo.tokenId, + remark = newName + }; + + var revertObj = new HttpServerRequest().UpdateSpeakerRemark(updateSpeakerRemarkObj); + if (revertObj.Code == StateCode.SUCCESS) + { + //AmendTheSuccess 淇敼鎴愬姛 + Application.RunOnMainThread(() => + { + speakerInfo.remark = newName; + btnName.Text = newName; + Utlis.ShowTip(Language.StringByID(StringId.ModifySuccess)); + //Utlis.ShowAlertOnMainThread(Language.StringByID(R.MyInternationalizationString.AmendTheSuccess)); + + }); + } + else + { + //鎻愮ず閿欒 + IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code); + } + } + catch + { + + } + finally + { + Application.RunOnMainThread(() => + { + if (waitPage != null) + { + waitPage.RemoveFromParent(); + waitPage = null; + } + }); + } + }); + + } + + /// <summary> + /// + /// </summary> + /// <param name="platformName"></param> + /// <returns></returns> + string GetSpeakerTypeString(string platformName){ + //1.platformName鍒ょ┖ + if (string.IsNullOrEmpty(platformName)) + { + return ""; + } + //2.鍏堣祴浜戠杩斿洖鐨勯粯璁ゅ�� + var name = platformName; + if (platformName == SpeakerType.DuerOS.ToString()) + { + if (Language.CurrentLanguage == "Chinese") + { + name = "灏忓害"; + } + //2.1褰撳墠璇█涓嶆槸涓枃鐨勮瘽锛岀洿鎺ョ瓑浜庝簯绔繑鍥炵殑platformName闊崇绫诲瀷 + + } + else if (platformName == SpeakerType.Google.ToString()){ + name = "Google Home"; + } + else if (platformName == SpeakerType.Alexa.ToString()) + { + name = "Alexa Echo"; + } + else if (platformName == SpeakerType.Alice.ToString()) + { + name = "Alice"; + } + else if (platformName == SpeakerType.Aligenie.ToString()) + { + if (Language.CurrentLanguage == "Chinese") + { + name = "澶╃尗绮剧伒"; + } + //2.1褰撳墠璇█涓嶆槸涓枃鐨勮瘽锛岀洿鎺ョ瓑浜庝簯绔繑鍥炵殑platformName闊崇绫诲瀷 + } + else if (platformName == SpeakerType.AISpeech.ToString()) + { + if (Language.CurrentLanguage == "Chinese") + { + name = "鎬濆繀椹�"; + } + //2.1褰撳墠璇█涓嶆槸涓枃鐨勮瘽锛岀洿鎺ョ瓑浜庝簯绔繑鍥炵殑platformName 鑻辨枃闊崇绫诲瀷 + } + + return name; + } + + /// <summary> + /// 璇锋眰瑙g粦闊崇 + /// </summary> + /// <param name="speakerInfo">闊崇鍙傛暟</param> + /// <param name="rowView">闊崇rowView</param> + /// <param name="lineView">濉厖鐨刲ineView</param> + void UnbindSpeaker(SpeakerInfo speakerInfo, FrameLayout rowView, FrameLayout lineView) + { + if (speakerInfo == null || string.IsNullOrEmpty(speakerInfo.tokenId)) { + + Utlis.ShowTip(Language.StringByID(StringId.RequestFailedParameterException) + "(-3)"); + } + + var waitPage = new Loading(); + bodyView.AddChidren(waitPage); + waitPage.Start(Language.StringByID(StringId.PleaseWait)); + + System.Threading.Tasks.Task.Run(() => + { + try + { + var revertObj = new HttpServerRequest().UnbindSpeaker(speakerInfo.tokenId); + if (revertObj.Code == StateCode.SUCCESS) + { + //瑙g粦鎴愬姛 + Application.RunOnMainThread(() => + { + //lineView + if (lineView != null) + { + lineView.RemoveFromParent(); + } + + //绉婚櫎rowView + if (rowView != null) + { + rowView.RemoveFromParent(); + } + + //鎻愮ず瑙g粦鎴愬姛 + Utlis.ShowTip(Language.StringByID(StringId.UnbindEmailSuccess)); + + }); + } + else + { + //鎻愮ず閿欒 + IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code); + } + } + catch + { + + } + finally + { + Application.RunOnMainThread(() => + { + if (waitPage != null) + { + waitPage.RemoveFromParent(); + waitPage = null; + } + }); + } + }); + + } + + /// <summary> + /// 璺宠浆椤甸潰 + /// </summary> + void GotoPage(SpeakerInfo speakerInfo) + { + var page = new SmartSpeakerRoomListPage(speakerInfo); + MainPage.BasePageView.AddChidren(page); + page.LoadPage(); + MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; + } + + } + + + +} -- Gitblit v1.8.0