fix after review
authorYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Fri, 15 Dec 2023 15:50:00 +0000 (16:50 +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/MenuGadget.cs
SettingCore/Sections.cs

index 6076f9a9623fb895a04c17b9d00518ef8b3a6a94..6068a1458958bb0d8e4f3cbdcc3f55b24825ddd2 100644 (file)
@@ -63,7 +63,6 @@ namespace SettingCore
 
         protected async void CreateItems()
         {
-            sections.InitSections();
             // add only visible sections to content view in required order
             var customization = GetCustomization().OrderBy(c => c.Order);
             foreach (var cust in customization)
@@ -74,10 +73,7 @@ namespace SettingCore
 
                 if (cust.IsVisible && section != null)
                 {
-                    if (section.Init != null)
-                    { 
-                        await section.InitComplete;
-                    }     
+                    await section.Init;
 
                     await CoreApplication.Post(() =>
                     {
index 5cf5ff6a335b3e160fd9479b6b1df5420cbb484a..83c190b1bd24ee366a013a40a761731479d4a3ea 100644 (file)
@@ -1,4 +1,5 @@
-using System;
+using SettingCore.TextResources;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
@@ -8,6 +9,7 @@ namespace SettingCore
 {
     public class Sections
     {
+        // TODO : remove dictionary after all gadget sections have been changed
         private Dictionary<string, View> sections = new Dictionary<string, View>();
         private List<Section> sectionList = new List<Section>();
 
@@ -32,29 +34,29 @@ namespace SettingCore
             return false;
         }
 
-        public void Add(string menuPath, Action action, Action init = null)
+        public void Add(string menuPath, Action action, Task task = null)
         {
             menuPath = menuPath.ToLowerInvariant();
             sectionList.Add(new Section
             {
                 MenuPath = menuPath,
                 CreateItem = action,
-                Init = init
+                Init = task is null ? Task.CompletedTask : InitAsync(task),
             });
         }
 
-        public Section GetSection(string menuPath)
+        private Task InitAsync(Task task)
         {
-            return sectionList.Where(a => a.MenuPath == menuPath).FirstOrDefault();
+            return Task.Run(async () =>
+            {
+                await task;
+                return true;
+            });
         }
 
-        public void InitSections()
+        public Section GetSection(string menuPath)
         {
-            var initList = sectionList.Where(a => a.Init != null).ToList();
-            foreach (var section in initList) 
-            {
-                section.InitComplete = Task.Run(() => section.Init);
-            }
+            return sectionList.Where(a => a.MenuPath == menuPath).FirstOrDefault();
         }
 
         public void Clear()
@@ -96,8 +98,7 @@ namespace SettingCore
         {
             public string MenuPath { get; set; }
             public Action CreateItem { get; set; } 
-            public Action Init { get; set; } 
-            public Task InitComplete { get; set; }
+            public Task Init { get; set; }
         }
     }
 }