From f7063b6fb7b46e3612afb1c6bb426c94fb92593d Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 10 一月 2023 14:44:32 +0800
Subject: [PATCH] 设备加载优化

---
 HDL_ON/UI/UI2/2-Classification/FunctionPage.cs |  178 ++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 122 insertions(+), 56 deletions(-)

diff --git a/HDL_ON/UI/UI2/2-Classification/FunctionPage.cs b/HDL_ON/UI/UI2/2-Classification/FunctionPage.cs
index 87341e4..5ba2bed 100644
--- a/HDL_ON/UI/UI2/2-Classification/FunctionPage.cs
+++ b/HDL_ON/UI/UI2/2-Classification/FunctionPage.cs
@@ -215,70 +215,136 @@
             #endregion
 
         }
-
+        /// <summary>
+        /// 鏄剧ず鐨勮澶囩殑鎬绘暟
+        /// </summary>
+        int showCount = 0;
         /// <summary>
         /// 鍔犺浇鍔熻兘row
         /// </summary>
-        void ShowFunctionRow(List<Function> showList)
+        void ShowFunctionRow(List<Function> showList, bool isAppend = false)
         {
-            functionListView.RemoveAll();
-            foreach (var function in showList)
-            {
-                if(function.spk == SPK.SensorDryContact|| function.spk == SPK.SensorDryContact2)
-                {
-                    continue;
-                }
-                if (function.spk == SPK.LightRGBW || function.spk == SPK.LightRGB || function.spk == SPK.LightDimming)
-                {
-                    var functionDiv = new FunctionControlZone(function)
-                    {
-                        Gravity = Gravity.CenterHorizontal,
-                        Width = Application.GetRealWidth(343),
-                        Height = Application.GetRealHeight(116),
-                        Radius = (uint)Application.GetMinRealAverage(12),
-                        BorderColor = 0x00FFFFFF,
-                        BorderWidth = 1,
-                        BackgroundColor = CSS_Color.MainBackgroundColor,
-                        Tag = function.spk + function.sid
-                    };
-                    functionDiv.LoadFunctionDiv();
-                    functionListView.AddChidren(functionDiv);
-                }
-                else if(function.spk == SPK.IpCam_Imou)
-                {
-                    var functionDiv = new FunctionControlZone(function)
-                    {
-                        Gravity = Gravity.CenterHorizontal,
-                        Width = Application.GetRealWidth(343),
-                        Height = Application.GetRealHeight(96),
-                        Radius = (uint)Application.GetMinRealAverage(12),
-                        BorderColor = 0x00FFFFFF,
-                        BorderWidth = 1,
-                        BackgroundColor = CSS_Color.MainBackgroundColor,
-                        Tag = function.spk + function.sid
-                    };
-                    functionDiv.LoadFunctionDiv();
-                    functionListView.AddChidren(functionDiv);
+            var waitPage = new Loading();
+            bodyView.AddChidren(waitPage);
+            waitPage.Start("");
 
-                }
-                else
+            new System.Threading.Thread(() =>
+            {
+                try
                 {
-                    var functionDiv = new FunctionControlZone(function)
+                    Application.RunOnMainThread(() =>
                     {
-                        Gravity = Gravity.CenterHorizontal,
-                        Width = Application.GetRealWidth(343),
-                        Height = Application.GetRealHeight(96),
-                        Radius = (uint)Application.GetMinRealAverage(12),
-                        BorderColor = 0x00FFFFFF,
-                        BorderWidth = 1,
-                        BackgroundColor = CSS_Color.MainBackgroundColor,
-                        Tag = function.spk + function.sid
-                    };
-                    functionDiv.LoadFunctionDiv();
-                    functionListView.AddChidren(functionDiv);
+                        if (!isAppend)
+                        {
+                            showCount = 0;
+                            functionListView.RemoveAll();
+                        }
+                        int i = 0;
+                        foreach (var function in showList)
+                        {
+                            i++;
+                            if (i > 50)
+                            {
+                                break;
+                            }
+                            showCount++;
+
+                            if (function.spk == SPK.SensorDryContact || function.spk == SPK.SensorDryContact2)
+                            {
+                                continue;
+                            }
+                            if (function.spk == SPK.LightRGBW || function.spk == SPK.LightRGB || function.spk == SPK.LightDimming)
+                            {
+                                var functionDiv = new FunctionControlZone(function)
+                                {
+                                    Gravity = Gravity.CenterHorizontal,
+                                    Width = Application.GetRealWidth(343),
+                                    Height = Application.GetRealHeight(116),
+                                    Radius = (uint)Application.GetMinRealAverage(12),
+                                    BorderColor = 0x00FFFFFF,
+                                    BorderWidth = 1,
+                                    BackgroundColor = CSS_Color.MainBackgroundColor,
+                                    Tag = function.spk + function.sid
+                                };
+                                functionDiv.LoadFunctionDiv();
+                                functionListView.AddChidren(functionDiv);
+                            }
+                            else if (function.spk == SPK.IpCam_Imou)
+                            {
+                                var functionDiv = new FunctionControlZone(function)
+                                {
+                                    Gravity = Gravity.CenterHorizontal,
+                                    Width = Application.GetRealWidth(343),
+                                    Height = Application.GetRealHeight(96),
+                                    Radius = (uint)Application.GetMinRealAverage(12),
+                                    BorderColor = 0x00FFFFFF,
+                                    BorderWidth = 1,
+                                    BackgroundColor = CSS_Color.MainBackgroundColor,
+                                    Tag = function.spk + function.sid
+                                };
+                                functionDiv.LoadFunctionDiv();
+                                functionListView.AddChidren(functionDiv);
+
+                            }
+                            else
+                            {
+                                var functionDiv = new FunctionControlZone(function)
+                                {
+                                    Gravity = Gravity.CenterHorizontal,
+                                    Width = Application.GetRealWidth(343),
+                                    Height = Application.GetRealHeight(96),
+                                    Radius = (uint)Application.GetMinRealAverage(12),
+                                    BorderColor = 0x00FFFFFF,
+                                    BorderWidth = 1,
+                                    BackgroundColor = CSS_Color.MainBackgroundColor,
+                                    Tag = function.spk + function.sid
+                                };
+                                functionDiv.LoadFunctionDiv();
+                                functionListView.AddChidren(functionDiv);
+                            }
+                            functionListView.AddChidren(new Button() { Height = Application.GetRealHeight(10) });
+                        }
+                        if (showList.Count > showCount)
+                        {
+                            var btnAppend = new Button()
+                            {
+                                Height = Application.GetRealHeight(60),
+                                TextAlignment = TextAlignment.Center,
+                                TextSize = CSS_FontSize.SubheadingFontSize,
+                                TextColor = CSS_Color.FirstLevelTitleColor,
+                                Text = "鍔犺浇鏇村",
+                            };
+                            if (Language.CurrentLanguage != "Chinese")
+                            {
+                                btnAppend.Text = "Load more";
+                            }
+                            functionListView.AddChidren(btnAppend);
+                            btnAppend.MouseUpEventHandler = (sender, e) =>
+                            {
+                                btnAppend.RemoveFromParent();
+                                ShowFunctionRow(showList, true);
+                            };
+                        }
+
+                    });
                 }
-                functionListView.AddChidren(new Button() { Height = Application.GetRealHeight(10) });
-            }
+                catch (Exception ex)
+                {
+                    MainPage.Log("ShowFunctionRowError : " + ex.Message);
+                }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        if (waitPage != null)
+                        {
+                            waitPage.RemoveFromParent();
+                            waitPage = null;
+                        }
+                    });
+                }
+            })
+            { IsBackground = true }.Start();
         }
 
 

--
Gitblit v1.8.0