add app info gadget
authorYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Thu, 7 Sep 2023 14:56:29 +0000 (16:56 +0200)
committerYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Thu, 14 Sep 2023 12:19:58 +0000 (14:19 +0200)
SettingMainGadget/SettingMainGadget/Apps/AppsAppInfoGadget.cs [new file with mode: 0644]
SettingMainGadget/SettingMainGadget/Apps/AppsManagerGadget.cs
SettingMainGadget/SettingMainGadget/MainMenuProvider.cs

diff --git a/SettingMainGadget/SettingMainGadget/Apps/AppsAppInfoGadget.cs b/SettingMainGadget/SettingMainGadget/Apps/AppsAppInfoGadget.cs
new file mode 100644 (file)
index 0000000..f37f465
--- /dev/null
@@ -0,0 +1,305 @@
+using SettingCore;
+using SettingCore.Views;
+using SettingMainGadget.Apps;
+using SettingMainGadget.TextResources;
+using System.Linq;
+using System.Threading.Tasks;
+using Tizen.Applications;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+using Tizen.Security;
+
+namespace Setting.Menu.Apps
+{
+    public class AppsAppInfoGadget : MenuGadget
+    {
+        // update the resources according to the GUI, application info -> app info
+        public override string ProvideTitle() => NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BODY_APPLICATION_INFO));
+
+        private ScrollableBase content;
+
+        protected override View OnCreate()
+        {
+            base.OnCreate();
+
+            content = new ScrollableBase
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = LayoutParamPolicies.MatchParent,
+                ScrollingDirection = ScrollableBase.Direction.Vertical,
+                HideScrollbar = false,
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Vertical,
+                },
+            };
+
+            _ = CreateContent();
+
+            return content;
+        }
+
+        private async Task CreateContent()
+        {
+            var app = AppManager.CurrentApp;
+            var appInfo = ApplicationManager.GetInstalledApplication(app.Id);
+            var appContext = AppManager.GetRunningContext();
+
+            var appInfoView = new View()
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = LayoutParamPolicies.WrapContent,
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Vertical,
+                },
+            };
+
+            // TODO : add version to the resources
+
+            var appVersion = new TextWithIconListItem(app.Label, Color.Transparent, iconPath: app.IconPath, subText: $"Version {app.Version}");
+
+            var close = new Button("Tizen.NUI.Components.Button.Outlined")
+            {
+                Text = NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BUTTON_FORCE_STOP)), // TODO : add force close to the resources
+                Size = new Size(252, 48).SpToPx(),
+                WidthResizePolicy = ResizePolicyType.FitToChildren,
+                HeightResizePolicy = ResizePolicyType.FitToChildren,
+                IsEnabled = appContext != null && appContext.State == ApplicationRunningContext.AppState.Background,
+            };
+
+            close.Clicked += (s, e) =>
+            {
+                try
+                {
+                    if (!appContext.IsTerminated)
+                    {
+                        ApplicationManager.TerminateBackgroundApplication(appContext);
+                    }
+                }
+                catch (System.Exception ex)
+                {
+                    Logger.Warn($"Couldn't close the application {app.Id}, {ex.Message}");
+                }
+            };
+
+            var uninstall = new Button("Tizen.NUI.Components.Button.Outlined")
+            {
+                Text = NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BUTTON_UNINSTALL)),
+                Size = new Size(252, 48).SpToPx(),
+                WidthResizePolicy = ResizePolicyType.FitToChildren,
+                HeightResizePolicy = ResizePolicyType.FitToChildren,
+                IsEnabled = app.IsRemovable
+            };
+
+            uninstall.Clicked += (s, e) =>
+            {
+                ShowUninstallPopup(app.Id);
+            };
+
+            var buttonsView = new View()
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = LayoutParamPolicies.WrapContent,
+                Layout = new FlexLayout()
+                {
+                    Alignment = FlexLayout.AlignmentType.Center,
+                    Justification = FlexLayout.FlexJustification.SpaceEvenly,
+                    Direction = FlexLayout.FlexDirection.Row,
+                },
+                Margin = new Extents(0, 0, 16, 24).SpToPx(),
+            };
+
+            buttonsView.Add(close);
+            buttonsView.Add(uninstall);
+
+            var infoView = new View()
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = LayoutParamPolicies.WrapContent,
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Vertical,
+                },
+            };
+
+            var packageSizeInfo = await app.GetSizeInformationAsync();
+
+            var appSize = packageSizeInfo.AppSize + packageSizeInfo.ExternalAppSize;
+            var userDataSize = packageSizeInfo.DataSize + packageSizeInfo.ExternalDataSize;
+            var cachedSize = packageSizeInfo.CacheSize + packageSizeInfo.ExternalCacheSize;
+            var totalSize = appSize + userDataSize + cachedSize;
+
+            infoView.Add(new TextHeaderListItem("Storage")); // TODO : add to the resources
+            infoView.Add(TextListItem.CreatePrimaryTextItemWithSubText("Total size", AppManager.GetSizeString(totalSize))); // TODO : add to the resources
+            infoView.Add(TextListItem.CreatePrimaryTextItemWithSubText(NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BODY_APPLICATION)), AppManager.GetSizeString(appSize)));
+            infoView.Add(TextListItem.CreatePrimaryTextItemWithSubText("User data", AppManager.GetSizeString(userDataSize))); // TODO : add to the resources
+
+            infoView.Add(new TextHeaderListItem("Cache")); // TODO : add to the resources
+            infoView.Add(TextListItem.CreatePrimaryTextItemWithSubText("Cache", AppManager.GetSizeString(cachedSize))); // TODO : add to the resources
+            var clearCache = TextListItem.CreatePrimaryTextItem(NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_HEADER_CLEAR_CACHE_ABB)));
+
+            if (cachedSize > 0)
+            {
+                clearCache.Clicked += (s, e) =>
+                {
+                    PackageManager.ClearCacheDirectory(app.Id);
+                };
+            }
+            else
+            {
+                clearCache.IsEnabled = false;
+            }
+
+            infoView.Add(clearCache);
+
+            var defaultApps = AppControl.GetDefaultApplicationIds();
+
+            if (defaultApps != null && defaultApps.Contains(app.Id))
+            {
+                infoView.Add(new TextHeaderListItem("Default app settings")); // TODO : add to the resources
+                var defaultApp = TextListItem.CreatePrimaryTextItemWithSubText("Clear default app settings", "This app is set to open by default for some actions."); // TODO : add to the resources
+                clearCache.Clicked += (s, e) =>
+                {
+                    // TODO : clear defaults
+                };
+            }
+
+            if (app.PackageType == PackageType.WGT)
+            {
+                infoView.Add(new TextHeaderListItem("Web app")); // TODO : add to the resources
+                var webSettings = TextListItem.CreatePrimaryTextItem("Website settings"); // TODO : add to the resources
+                webSettings.Clicked += (s, e) =>
+                {
+                    // TODO : web settings
+                };
+            }
+
+            if (app.Privileges.Count() > 0)
+            {
+                infoView.Add(new TextHeaderListItem(NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_HEADER_PRIVILEGES))));
+
+                foreach (var privilege in app.Privileges)
+                {
+                    try
+                    {
+                        // TODO : how to get api version
+                        var privilegeItem = TextListItem.CreatePrimaryTextItemWithSubText(Privilege.GetDisplayName("9", privilege), Privilege.GetDescription("9", privilege));
+                        infoView.Add(privilegeItem);
+                    }
+                    catch (System.Exception ex)
+                    {
+                        Logger.Warn($"{ex.Message}");
+                    }
+                }
+            }
+
+            appInfoView.Add(appVersion);
+            content.Add(appInfoView);
+            content.Add(buttonsView);
+            content.Add(infoView);
+        }
+
+        private void ShowUninstallPopup(string appid)
+        {
+            var content = new View()
+            {
+                BackgroundColor = ThemeManager.PlatformThemeId == "org.tizen.default-light-theme" ? new Color("#FAFAFA") : new Color("#16131A"),
+                WidthSpecification = LayoutParamPolicies.WrapContent,
+                HeightSpecification = LayoutParamPolicies.WrapContent,
+                Layout = new LinearLayout()
+                {
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    LinearOrientation = LinearLayout.Orientation.Vertical,
+                },
+            };
+
+            // title text
+            var textTitle = new TextLabel(NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BUTTON_UNINSTALL)))
+            {
+                FontFamily = "BreezeSans",
+                PixelSize = 24.SpToPx(),
+                Margin = new Extents(0, 0, 24, 16).SpToPx(),
+            };
+
+            content.Add(textTitle);
+
+            // main text
+            var textSubTitle = new TextLabel("This app will be uninstalled.") // TODO : add to the resources
+            {
+                FontFamily = "BreezeSans",
+                PixelSize = 24.SpToPx(),
+                SizeWidth = 618.SpToPx(),
+                MultiLine = true,
+                LineWrapMode = LineWrapMode.Word,
+                Margin = new Extents(24, 24, 0, 24).SpToPx(),
+            };
+            content.Add(textSubTitle);
+
+            // buttons
+            View buttons = new View()
+            {
+                HeightSpecification = LayoutParamPolicies.WrapContent,
+                Layout = new FlexLayout()
+                {
+                    Alignment = FlexLayout.AlignmentType.Center,
+                    Justification = FlexLayout.FlexJustification.SpaceBetween,
+                    Direction = FlexLayout.FlexDirection.Row,
+                },
+                Size2D = new Size2D(658, 80).SpToPx(),
+                Padding = new Extents(16, 16, 16, 16).SpToPx(),
+                Margin = new Extents(16, 16, 0, 16).SpToPx(),
+            };
+
+            var uninstallButton = new Button()
+            {
+                WidthResizePolicy = ResizePolicyType.FitToChildren,
+                HeightResizePolicy = ResizePolicyType.FitToChildren,
+                Text = NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BUTTON_UNINSTALL)),
+                Size = new Size(252, 48).SpToPx(),
+            };
+
+            uninstallButton.Clicked += (o, e) =>
+            {
+                var appInfoLabel = ApplicationManager.GetInstalledApplication(appid).Label;
+                NUIApplication.GetDefaultWindow().GetDefaultNavigator().Pop();
+
+                try
+                {
+                    if (PackageManager.Uninstall(appid))
+                    {
+                        Notification.MakeToast($"{appInfoLabel} uninstalled.", Notification.ToastBottom).Post(Notification.ToastShort);
+                        GadgetNavigation.NavigateBack();
+                    }
+                    else
+                    {
+                        Notification.MakeToast($"Failed to uninstall {appInfoLabel}.", Notification.ToastBottom).Post(Notification.ToastShort);
+                    }
+                }
+                catch (System.Exception ex)
+                {
+                    Logger.Warn($"Couldn't uninstall the application {appid}, {ex.Message}");
+                    Notification.MakeToast($"Failed to uninstall {appInfoLabel}.", Notification.ToastBottom).Post(Notification.ToastShort);
+                }
+            };
+
+            var cancelButton = new Button("Tizen.NUI.Components.Button.Outlined")
+            {
+                WidthResizePolicy = ResizePolicyType.FitToChildren,
+                HeightResizePolicy = ResizePolicyType.FitToChildren,
+                Text = NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BUTTON_CANCEL)),
+                Size = new Size(252, 48).SpToPx(),
+            };
+
+            cancelButton.Clicked += (o, e) => { NUIApplication.GetDefaultWindow().GetDefaultNavigator().Pop(); };
+
+            buttons.Add(cancelButton);
+            buttons.Add(uninstallButton);
+
+            content.Add(buttons);
+
+            RoundedDialogPage.ShowDialog(content);
+        }
+    }
+}
index d8cda264a3f7873cb9a5bc04b6a9a395623a533d..604bf7d11a664009d0678120899e7e2dfeda6150 100644 (file)
@@ -216,6 +216,9 @@ namespace Setting.Menu.Apps
                     var appItem = new TextWithIconListItem(package.Label, Color.Transparent, iconPath: iconPath, subText: NUIGadgetResourceManager.GetString(nameof(Resources.IDS_SM_SBODY_CALCULATING_ING)));
                     appItem.Clicked += (s, e) =>
                     {
+                        Logger.Debug($"Set current package id: {package.Id}");
+                        AppManager.CurrentApp = package;
+                        NavigateTo(MainMenuProvider.Apps_AppInfo);
                     };
 
                     installedApps.Add(package, appItem);
@@ -259,6 +262,8 @@ namespace Setting.Menu.Apps
                 var appItem = new TextWithIconListItem(applicationInfo.Label, Color.Transparent, iconPath: iconPath, subText: NUIGadgetResourceManager.GetString(nameof(Resources.IDS_SM_SBODY_CALCULATING_ING)));
                 appItem.Clicked += (s, e) =>
                 {
+                    AppManager.CurrentApp = PackageManager.GetPackage(applicationInfo.PackageId);
+                    NavigateTo(MainMenuProvider.Apps_AppInfo);
                 };
 
                 runningApps.Add(applicationInfo, appItem);
@@ -283,6 +288,8 @@ namespace Setting.Menu.Apps
                 var appItem = new TextWithIconListItem(package.Label, Color.Transparent, iconPath: iconPath, subText: NUIGadgetResourceManager.GetString(nameof(Resources.IDS_SM_SBODY_CALCULATING_ING)));
                 appItem.Clicked += (s, e) =>
                 {
+                    AppManager.CurrentApp = package;
+                    NavigateTo(MainMenuProvider.Apps_AppInfo);
                 };
 
                 allApps.Add(package, appItem);
index a07efdd0f12e4669bee93283d54ac366eb74c671..a85cf6d0dc723a02e610684cb86c7e79d81d74c1 100644 (file)
@@ -53,6 +53,7 @@ namespace SettingMainGadget
         public static string Apps_AppsManager = "Apps.AppsManager";
         public static string Apps_DefaultApps = "Apps.DefaultApps";
         public static string Apps_DefaultHome = "Apps.DefaultHome";
+        public static string Apps_AppInfo = "Apps.AppsInfo";
 
         //storage
         public static string Storage = "Storage";
@@ -131,6 +132,7 @@ namespace SettingMainGadget
                 new SettingMenu(path: Apps_AppsManager, defaultOrder: 10, typeof(Setting.Menu.Apps.AppsManagerGadget)),
                 new SettingMenu(path: Apps_DefaultApps, defaultOrder: 20, typeof(Setting.Menu.Apps.AppsDefaultGadget)),
                 new SettingMenu(path: Apps_DefaultHome, defaultOrder: 40, typeof(Setting.Menu.Apps.AppsDefaultHomeGadget)),
+                new SettingMenu(path: Apps_AppInfo, defaultOrder: 50, typeof(Setting.Menu.Apps.AppsAppInfoGadget)),
 
                 //storage
                 new SettingMenu(path: Storage, defaultOrder: 120, type: typeof(Setting.Menu.StorageGadget)),