add app manager
authorYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Thu, 7 Sep 2023 09:08:21 +0000 (11:08 +0200)
committerPiotr Czaja/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <p.czaja@samsung.com>
Wed, 13 Sep 2023 15:42:52 +0000 (17:42 +0200)
SettingMainGadget/SettingMainGadget/Apps/AppManager.cs [new file with mode: 0644]

diff --git a/SettingMainGadget/SettingMainGadget/Apps/AppManager.cs b/SettingMainGadget/SettingMainGadget/Apps/AppManager.cs
new file mode 100644 (file)
index 0000000..c0fd2f2
--- /dev/null
@@ -0,0 +1,54 @@
+using SettingCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Tizen.Applications;
+
+namespace SettingMainGadget.Apps
+{
+    public static class AppManager
+    {
+        public static Package CurrentApp { get; set; }
+
+        public static ApplicationRunningContext GetRunningContext()
+        {
+            try
+            {
+                var appContext = new ApplicationRunningContext(CurrentApp.Id);
+                return appContext;
+            }
+            catch (Exception ex)
+            {
+                Logger.Warn($"Cann't get application running context: {ex.Message}");
+                return null;
+            }
+        }
+
+        public static string GetSizeString(double size)
+        {
+            string[] suffixes = { "Bytes", "KB", "MB", "GB" };
+            int counter = 0;
+
+            while (Math.Round(size / 1024, 2) >= 1)
+            {
+                size = size / 1024;
+                counter++;
+            }
+
+            return string.Format("{0:0.##} {1}", size, suffixes[counter]);
+        }
+
+        public static List<ApplicationInfo> GetApplicationsInfoByCategory(string category)
+        {
+            var allPackages = PackageManager.GetPackages().ToList();
+            var listInfo = new List<ApplicationInfo>();
+
+            foreach (var package in allPackages)
+            {
+                listInfo.Add(new ApplicationInfo(package.Id));
+            }
+
+            return listInfo.Where(a => a.Categories.Contains(category)).ToList();
+        }
+    }
+}