fix after review
authorYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Thu, 20 Apr 2023 10:34:24 +0000 (12:34 +0200)
committerYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Mon, 24 Apr 2023 12:50:02 +0000 (14:50 +0200)
SettingCore/Views/StorageIndicator.cs
SettingMainGadget/SettingMainGadget/StorageGadget.cs

index fc199059d76466e3e548358a38130ee3f5fa9c5b..f5999d948e9330f360cd8d3a7078bc41e059265c 100644 (file)
@@ -9,10 +9,10 @@ namespace SettingCore.Views
     {
         public class IndicatorItem
         {
-            public string Name { get; private set; }
-            public Color Color { get; private set; }
-            public double SizeInfo { get; private set; }
-            public float Width { get; private set; }
+            public string Name { get; set; }
+            public Color Color { get; set; }
+            public double SizeInfo { get; set; }
+            public float Width { get; set; }
 
             public IndicatorItem(string name, Color color, double sizeInfo)
             {
@@ -20,35 +20,13 @@ namespace SettingCore.Views
                 Color = color;
                 SizeInfo = sizeInfo;
             }
-
-            public void SetWidth(float width)
-            {
-                Width = width;
-            }
-
-            public void SetSize(double sizeInfo)
-            {
-                SizeInfo = sizeInfo;
-            }
         }
 
-        private const int duration = 1000;
+        private const int duration = 500;
         private double totalSize;
-
         private Animation animation;      
-        private List<IndicatorItem> sizeInfoList = new List<IndicatorItem>();
 
-        public List<IndicatorItem> SizeInfoList
-        {
-            get => sizeInfoList; 
-            set 
-            { 
-                if(sizeInfoList != value) 
-                {
-                    sizeInfoList = value;
-                }
-            }
-        }
+        public List<IndicatorItem> SizeInfoList = new List<IndicatorItem>();
 
         public StorageIndicator(double totalSize)
         {
@@ -69,7 +47,7 @@ namespace SettingCore.Views
 
         public void AddItem(string name, Color color, double size)
         {
-            sizeInfoList.Add(new IndicatorItem(name, color, size));
+            SizeInfoList.Add(new IndicatorItem(name, color, size));
         }
 
         public void Update()
@@ -79,10 +57,14 @@ namespace SettingCore.Views
                 return;
             }
 
-            sizeInfoList = new List<IndicatorItem>(sizeInfoList.OrderByDescending(a => a.SizeInfo).ToList());
+            SizeInfoList = new List<IndicatorItem>(SizeInfoList.OrderByDescending(a => a.SizeInfo).ToList());
+
+            foreach (var item in SizeInfoList)
+            {
+                item.Width = (float)(item.SizeInfo / totalSize * SizeWidth);
+            }
 
-            Calculation();
-            RemoveChildren(this);
+            RemoveChildren();
             AddItems();
         }
 
@@ -90,16 +72,16 @@ namespace SettingCore.Views
         {
             animation = new Animation(duration);
 
-            for (int i = sizeInfoList.Count - 1; i >= 0; i--)
+            for (int i = SizeInfoList.Count - 1; i >= 0; i--)
             {
-                var coloredView = CreateColoredView(sizeInfoList[i].Color, sizeInfoList[i].Equals(sizeInfoList.First()));
+                var coloredView = CreateColoredView(SizeInfoList[i].Color, i == 0);
                 Add(coloredView);
 
-                animation.AnimateTo(coloredView, "SizeWidth", sizeInfoList[i].Width, 0, duration, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut));
+                animation.AnimateTo(coloredView, "SizeWidth", SizeInfoList[i].Width, 0, duration, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut));
 
                 if (i > 0)
                 {
-                    animation.AnimateTo(coloredView, "PositionX", sizeInfoList.GetRange(0, i).Select(x => x.Width).Sum(), 0, duration, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut));
+                    animation.AnimateTo(coloredView, "PositionX", SizeInfoList.GetRange(0, i).Select(x => x.Width).Sum(), 0, duration, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut));
                 }
             }
 
@@ -122,35 +104,20 @@ namespace SettingCore.Views
             return view;
         }
 
-        private void RemoveChildren(View parent)
+        private void RemoveChildren()
         {
-            if (parent == null)
+            for (int i = (int)ChildCount - 1; i >= 0; --i)
             {
-                return;
-            }
-
-            int maxChild = (int)parent.ChildCount;
-            for (int i = maxChild - 1; i >= 0; --i)
-            {
-                View child = parent.GetChildAt((uint)i);
+                View child = GetChildAt((uint)i);
 
                 if (child == null)
                 {
                     continue;
                 }
 
-                RemoveChildren(child);
-                parent.Remove(child);
+                Remove(child);
                 child.Dispose();
             }
         }
-
-        private void Calculation()
-        {
-            foreach (var item in sizeInfoList)
-            {
-                item.SetWidth((float)(item.SizeInfo / totalSize * SizeWidth));
-            }
-        }
     }
 }
index f5154cda317d63791a1e069fc1ae0d32fa055246..304ad718b3f6b3b87fd79ca5945d513fd56d2621 100644 (file)
@@ -123,7 +123,6 @@ namespace Setting.Menu
             appsItem = new TextWithIconListItem(Resources.IDS_SM_TMBODY_APPS_ABB, new Color("#FFC700"), subText: Resources.IDS_SM_SBODY_CALCULATING_ING);
             appsItem.Clicked += (s, e) =>
             {
-                // TODO : add apps info gadget 
             };
             usageSummary.Add(appsItem);
 
@@ -315,19 +314,33 @@ namespace Setting.Menu
             if (appsItem != null)
             {
                 appsItem.SubText = GetMediaSizeString(sizeApp);
+
+                var apps = storageIndicator.SizeInfoList.FirstOrDefault(x => x.Name == "apps");
+                if (apps != null)
+                {
+                    apps.SizeInfo = sizeApp;
+                }
             }
             if (cacheItem != null)
             {
                 cacheItem.SubText = GetMediaSizeString(sizeCache);
+
+                var cache = storageIndicator.SizeInfoList.FirstOrDefault(x => x.Name == "cache");
+                if (cache != null)
+                {
+                    cache.SizeInfo = sizeCache;
+                }
             }
             if (systemItem != null)
             {
                 systemItem.SubText = GetMediaSizeString(nonSystemSpace - sizeApp - sizeCache);
-            }
 
-            storageIndicator.SizeInfoList.Where(x => x.Name == "apps").FirstOrDefault()?.SetSize(sizeApp);
-            storageIndicator.SizeInfoList.Where(x => x.Name == "cache").FirstOrDefault()?.SetSize(sizeCache);
-            storageIndicator.SizeInfoList.Where(x => x.Name == "system").FirstOrDefault()?.SetSize(nonSystemSpace - sizeApp - sizeCache);
+                var system = storageIndicator.SizeInfoList.FirstOrDefault(x => x.Name == "system");
+                if (system != null)
+                {
+                    system.SizeInfo = (float)(nonSystemSpace - sizeApp - sizeCache);
+                }
+            }
 
             storageIndicator.Update();
         }