From 3f6685c77beeb12baf840733fb890860f4c26e7c Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 25 七月 2024 17:25:59 +0800
Subject: [PATCH] 2024年07月25日17:24:45

---
 HDL_ON/UI/UI2/FuntionControlView/Music/SendMethod.cs |  233 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 200 insertions(+), 33 deletions(-)

diff --git a/HDL_ON/UI/UI2/FuntionControlView/Music/SendMethod.cs b/HDL_ON/UI/UI2/FuntionControlView/Music/SendMethod.cs
index 5c5590d..7ba3ab9 100644
--- a/HDL_ON/UI/UI2/FuntionControlView/Music/SendMethod.cs
+++ b/HDL_ON/UI/UI2/FuntionControlView/Music/SendMethod.cs
@@ -6,22 +6,25 @@
 using System.Text;
 using HDL_ON.DAL.Server;
 using HDL_ON.Entity;
+using HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock;
+using Newtonsoft.Json.Linq;
 using Shared;
+using static HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock.CommonMethod;
 
 namespace HDL_ON.UI.Music
 {
     public class SendMethod
     {
-        private static SendMethod sMethod = null;
-        public static SendMethod mMethod
+        private static SendMethod s_Current = null;
+        public static SendMethod Current
         {
             get
             {
-                if (sMethod == null)
+                if (s_Current == null)
                 {
-                    sMethod = new SendMethod();
+                    s_Current = new SendMethod();
                 }
-                return sMethod;
+                return s_Current;
             }
 
         }
@@ -44,12 +47,11 @@
         {
             new System.Threading.Thread(() =>
             {
-                DriverLayer.Control.Ins.SendWriteCommand(function, dic);
+                DriverLayer.Control.Ins.SendWriteCommand(function, dic, false, 0);
             })
             { IsBackground = true }.Start();
         }
-        //璁板綍姝屾洸鎾斁鏃堕棿
-        private int songPlayTime = -1;
+
         /// <summary>
         /// 鑾峰彇璁惧鏈�鏂扮殑鐘舵��
         /// </summary>
@@ -59,8 +61,8 @@
             try
             {
                 //RefreshDeviceStatus(functionIds);
-                //a31Music.LastDateTime = DateTime.Now;
-                ///浠庣紦瀛橀噷闈㈡煡鎵鹃煶涔愭挱鏀惧櫒瀵硅薄<缂撳瓨鏁版嵁鏀跺埌鎺ㄩ�佽繃鏉ョ殑鐘舵�佷細鏇存柊缂撳瓨鏁版嵁>
+                a31Music.LastDateTime = DateTime.Now;
+                ///浠庣紦瀛橀噷闈㈡煡鎵鹃煶涔愭挱鏀惧櫒瀵硅薄<鏀跺埌鎺ㄩ�佽繃鏉ョ殑鐘舵�佷細鏇存柊缂撳瓨鏁版嵁>
                 var allLocalFuntion = FunctionList.List.GetDeviceFunctionList();
                 var localFunction = allLocalFuntion.Find((obj) => obj.sid == sid);
                 if (localFunction == null)
@@ -69,13 +71,6 @@
                 }
                 ///鏇存柊鐨勬暟鎹�
                 a31Music.functionMusic = localFunction;
-                if (int.Parse(A31MusicModel.Current.functionMusic.GetAttrState(UI2.FuntionControlView.Music.KeyProperty.playing_time)) != songPlayTime)
-                {
-                    ///姝屾洸璁板綍鏃堕棿鍜屽綋鍓嶆椂闂翠笉涓�鏍凤紝绔嬪嵆鏇存柊鏁版嵁鍙嶉鏃堕棿
-                    a31Music.LastDateTime = DateTime.Now;
-                    ///姝屾洸璁板綍鏃堕棿鍜屽綋鍓嶆椂闂翠笉涓�鏍凤紝绔嬪嵆鏇存柊姝屾洸鎾斁鏃堕棿
-                    songPlayTime = int.Parse(A31MusicModel.Current.functionMusic.GetAttrState(UI2.FuntionControlView.Music.KeyProperty.playing_time));
-                }
 
             }
             catch { }
@@ -84,20 +79,20 @@
         /// <summary>
         /// 鍒锋柊璁惧鐘舵��
         /// </summary>
+        /// <param name="tipType">鏄惁闇�瑕佹彁绀�,榛樿鎻愮ず</param>
         /// <returns></returns>
-        public void RefreshDeviceStatus(List<string> functionIds)
+        public void RefreshDeviceStatus(List<string> functionIds,TipType tipType = TipType.flicker)
         {
             try
             {
                 Dictionary<string, object> d = new Dictionary<string, object>();
                 d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
                 d.Add("deviceIds", functionIds);
-                var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_RefreshDeviceStatus);
-                if (responsePackNew.Code != "0" || responsePackNew.Data == null || responsePackNew.Data.ToString() == "")
+                var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_RefreshDeviceStatus, "鍒锋柊璁惧鐘舵��");
+                if (!this.DataChecking(responsePackNew, tipType))
                 {
                     return;
                 }
-
             }
             catch { }
         }
@@ -118,50 +113,222 @@
         }
 
         /// <summary>
-        /// 鑾峰彇闊充箰鍒楄〃
+        /// 鑾峰彇褰撳墠鎾斁闊充箰鍒楄〃
         /// </summary>
-        /// <param name="music"></param>
+        /// <param name="music">闊充箰鎾斁鍣�</param>
+        /// <param name="action">鍥炶皟</param>
+        ///  <param name="tipType">鏄惁闇�瑕佹彁绀�,榛樿鎻愮ず</param>
         /// <returns></returns>
-        public void GetPalyList(Function music)
+        public void GetCurrentPalyList(Function music, Action action, TipType tipType = TipType.flicker)
         {
             try
             {
                 Dictionary<string, object> d = new Dictionary<string, object>();
                 d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
                 d.Add("deviceIds", new List<string> { music.deviceId });
-                var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_PlayerList);
-                if (responsePackNew.Code != "0" || responsePackNew.Data == null || responsePackNew.Data.ToString() == "")
+                var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_PlayerList, "鑾峰彇闊充箰鍒楄〃");
+                if (!this.DataChecking(responsePackNew,tipType))
                 {
                     return;
                 }
                 //鏁版嵁杩斿簭鍒楀寲涓篎unction瀵硅薄
                 var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data);
-                var palyLists = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PalyListInfo>>(str);
+                var palyLists = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PalyerSongListInfo>>(str);
                 if (palyLists == null)
                 {
-                    palyLists = new List<PalyListInfo>();
+                    palyLists = new List<PalyerSongListInfo>();
                 }
                 if (palyLists.Count > 0)
                 {
                     ///榛樿鎷跨涓�涓垪琛�
-                    A31MusicModel.Current.palyLists = palyLists[0].playlist;
+                    A31MusicModel.Current.CurrentPlayMusicInfoList = palyLists[0].playlist;
                 }
             }
             catch
             {
             }
+            finally
+            {
+                Application.RunOnMainThread(() =>
+                {
+                    action();
+                });
+            }
+
+        }
+        /// <summary>
+        /// 鑾峰彇銆愬涓煶涔愭簮銆戝垪琛ㄥ悕鍒楄〃
+        /// </summary>
+        /// <param name="music"></param>
+        /// <param name="source">闊充箰婧愪负null,鏀寔澶氫釜婧愯幏鍙�</param>
+        ///  <param name="tipType">鏄惁闇�瑕佹彁绀�,榛樿鎻愮ず</param>
+        /// <returns></returns>
+        public List<GroupList> GetMultipleSourceListName(Function music, string source,TipType tipType=TipType.flicker)
+        {
+            try
+            {
+                Dictionary<string, object> d = new Dictionary<string, object>();
+                d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
+                d.Add("gatewayId", DB_ResidenceData.Instance.HomeGateway.gatewayId);
+                Dictionary<string, object> deviceIds = new Dictionary<string, object>();
+                deviceIds.Add("deviceId", music.deviceId);
+                if (!string.IsNullOrEmpty(source))
+                {
+                    deviceIds.Add("source", source);
+                }
+                d.Add("deviceInfos", new List<Dictionary<string, object>> { deviceIds });
+                var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_GroupList, "鑾峰彇鍒楄〃鍚嶅垪琛�");
+                if (!this.DataChecking(responsePackNew, tipType))
+                {
+                    return new List<GroupList>();
+                }
+                //鏁版嵁杩斿簭鍒楀寲涓篎unction瀵硅薄
+                var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data);
+                var groupLists = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GroupList>>(str);
+                if (groupLists == null)
+                {
+                    groupLists = new List<GroupList>();
+                }
+                return groupLists;
+            }
+            catch
+            {
+                return new List<GroupList>();
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇銆愬崟涓煶涔愭簮銆戝垪琛ㄥ悕鍒楄〃(榛樿鍙栧畾鍒楄〃涓竴涓�)
+        /// </summary>
+        /// <param name="music"></param>
+        /// <param name="source">闊充箰婧�</param>
+        /// <returns></returns>
+        public GroupList GetSingleSourceListNameList(Function music, string source)
+        {
+            List<GroupList> groupList = this.GetMultipleSourceListName(music, source);
+            if (groupList.Count == 0)
+            {
+                return new GroupList();
+            }
+            ////榛樿鍙栧畾鍒楄〃涓竴涓�
+            return groupList.Count > 0 ? groupList[0] : new GroupList();
+        }
+
+
+
+
+        /// <summary>
+        /// 閫氳繃鍒楄〃鍚嶈幏鍙栥�愬涓瓕鏇插垪琛ㄣ��
+        /// </summary>
+        /// <param name="music"></param>
+        /// <param name="listName">鍒楄〃鍚�</param>
+        /// <param name="source">闊充箰婧�</param>
+        /// <param name="tipType">鏄惁闇�瑕佹彁绀�,榛樿鎻愮ず</param>
+        /// <returns></returns>
+        public List<PalyerSongListInfo> GetMultipleSongListM(Function music, string listName, string source, TipType tipType= TipType.flicker)
+        {
+            try
+            {
+                Dictionary<string, object> d = new Dictionary<string, object>();
+                Dictionary<string, object> d1 = new Dictionary<string, object>();
+                Dictionary<string, object> d2 = new Dictionary<string, object>();
+                d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
+                d.Add("gatewayId", DB_ResidenceData.Instance.HomeGateway.gatewayId);
+                d2.Add("group", listName);
+                d1.Add("sid", music.sid);
+                if (!string.IsNullOrEmpty(source))
+                {
+                    d1.Add("source", source);
+                }
+                d1.Add("groupList", new List<Dictionary<string, object>> { d2 });
+                d.Add("sidGroups", new List<Dictionary<string, object>> { d1 });
+
+                var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_GroupPlayerList, "閫氳繃鍒楄〃鍚嶈幏鍙栨瓕鏇插垪琛�");
+                if (!this.DataChecking(responsePackNew, tipType))
+                {
+                    return new List<PalyerSongListInfo>();
+                }
+                //鏁版嵁杩斿簭鍒楀寲涓篎unction瀵硅薄
+                var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data);
+                var palyLists = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PalyerSongListInfo>>(str);
+                if (palyLists == null)
+                {
+                    return new List<PalyerSongListInfo>();
+                }
+
+                return palyLists;
+
+            }
+            catch
+            {
+                return new List<PalyerSongListInfo>();
+            }
+        }
+        /// <summary>
+        /// 閫氳繃鍒楄〃鍚嶈幏鍙栥�愬崟涓瓕鏇插垪琛ㄣ��(榛樿鍙栧畾鍒楄〃涓竴涓瓕鏇插垪琛�)
+        /// </summary>
+        /// <param name="music"></param>
+        /// <param name="listName">鍒楄〃鍚�</param>
+        /// <param name="source">闊充箰婧�</param>
+        /// <returns></returns>
+        public SongList GetSingleSongList(Function music, string listName, string source, TipType tipType= TipType.flicker)
+        {
+            List<PalyerSongListInfo> listInfos = this.GetMultipleSongListM(music, listName, source, tipType);
+            if (listInfos.Count == 0)
+            {
+                return new SongList();
+            }
+            ////榛樿绗竴涓垪琛ㄩ噷闈㈢涓�涓煶涔愬垪琛�
+            SongList songList = listInfos[0].playlist.Count > 0 ? listInfos[0].playlist[0] : new SongList();
+            return songList;
 
         }
 
         /// <summary>
+        /// <summary>
+        /// 妫�楠屾暟鎹洖澶嶆垚鍔熸垨鑰呭け璐�
+        /// </summary>
+        /// <param name="responsePackNew">鍥炲鏁版嵁瀵硅薄</param>
+        /// <param name="tipType">鏄惁闇�瑕佹彁绀�</param>
+        /// <returns></returns>
+        private bool DataChecking(ResponsePackNew responsePackNew, TipType tipType)
+        {
+            if (responsePackNew.Data == null || responsePackNew.Code != "0" || responsePackNew.Data.ToString() == "")
+            {
+                if (TipType.flicker == tipType)
+                {
+                    if (responsePackNew == null)
+                    {
+                        responsePackNew = new ResponsePackNew { message = "娌″洖澶�,璇风‘璁ょ綉缁滄槸鍚︽甯�.", Code = "-1", };
+                    }
+                    Application.RunOnMainThread(() =>
+                    {
+                        //new Tip()
+                        //{
+                        //    CloseTime = 1,
+                        //    Text = responsePackNew.message + "(" + responsePackNew.Code + ")",
+                        //    Direction = AMPopTipDirection.None,
+                        //}.Show(MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1));
+                        CommonMethod.Current.ShowTip(responsePackNew.message + "(" + responsePackNew.Code + ")", 3);
+                    });
+                }
+                return false;
+            }
+            return true;
+        }
+
+
+        /// <summary>
         ///璇锋眰鏈嶅姟鍣紙涓庝綇瀹呮湁鍏�:渚嬪锛沨omeId锛� 
         /// </summary>
+        /// <param name="o">鍙戦�佹暟鎹�</param>
+        /// <param name="api_Url">璇锋眰鍦板潃(涓嶆槸缁濆鍦板潃)</param>
+        /// <param name="tag">鏍囪->鎻忚堪鎺ュ彛(鑷畾涔�)</param>
         /// <returns></returns>
-        public ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 5)
+        public ResponsePackNew RequestServerhomeId(object o, string api_Url, string tag, int mTimeout = 10)
         {
-            var requestJson = HttpUtil.GetSignRequestJson(o);
-            return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout);
-
+            JObject jobject = JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(o));
+            return UI2.Intelligence.Automation.Send.Current.RequestServerhomeId(jobject, api_Url, tag, mTimeout);
         }
     }
 }

--
Gitblit v1.8.0