update sections
authorYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Wed, 13 Dec 2023 15:21:08 +0000 (16:21 +0100)
committerYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Fri, 22 Dec 2023 11:23:51 +0000 (12:23 +0100)
SettingCore/Sections.cs

index 4dc379e05004e965d34c77d3d3112ce5e478b99e..5cf5ff6a335b3e160fd9479b6b1df5420cbb484a 100644 (file)
@@ -1,5 +1,7 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
 using Tizen.NUI.BaseComponents;
 
 namespace SettingCore
@@ -7,6 +9,7 @@ namespace SettingCore
     public class Sections
     {
         private Dictionary<string, View> sections = new Dictionary<string, View>();
+        private List<Section> sectionList = new List<Section>();
 
         public IEnumerable<View> Views => sections.Values;
 
@@ -29,6 +32,36 @@ namespace SettingCore
             return false;
         }
 
+        public void Add(string menuPath, Action action, Action init = null)
+        {
+            menuPath = menuPath.ToLowerInvariant();
+            sectionList.Add(new Section
+            {
+                MenuPath = menuPath,
+                CreateItem = action,
+                Init = init
+            });
+        }
+
+        public Section GetSection(string menuPath)
+        {
+            return sectionList.Where(a => a.MenuPath == menuPath).FirstOrDefault();
+        }
+
+        public void InitSections()
+        {
+            var initList = sectionList.Where(a => a.Init != null).ToList();
+            foreach (var section in initList) 
+            {
+                section.InitComplete = Task.Run(() => section.Init);
+            }
+        }
+
+        public void Clear()
+        {
+            sectionList.Clear();
+        }
+
         public bool TryGetValue(string menuPath, out View view)
         {
             try
@@ -58,5 +91,13 @@ namespace SettingCore
             }
             sections.Clear();
         }
+
+        public class Section
+        {
+            public string MenuPath { get; set; }
+            public Action CreateItem { get; set; } 
+            public Action Init { get; set; } 
+            public Task InitComplete { get; set; }
+        }
     }
 }