From: Yurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics Date: Thu, 7 Sep 2023 14:56:29 +0000 (+0200) Subject: add app info gadget X-Git-Tag: accepted/tizen/unified/20230915.160537~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7a71a129b54a5bc99cdea2bc30f69be02dad605d;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsettings.git add app info gadget --- diff --git a/SettingMainGadget/SettingMainGadget/Apps/AppsAppInfoGadget.cs b/SettingMainGadget/SettingMainGadget/Apps/AppsAppInfoGadget.cs new file mode 100644 index 0000000..f37f465 --- /dev/null +++ b/SettingMainGadget/SettingMainGadget/Apps/AppsAppInfoGadget.cs @@ -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); + } + } +} diff --git a/SettingMainGadget/SettingMainGadget/Apps/AppsManagerGadget.cs b/SettingMainGadget/SettingMainGadget/Apps/AppsManagerGadget.cs index d8cda26..604bf7d 100644 --- a/SettingMainGadget/SettingMainGadget/Apps/AppsManagerGadget.cs +++ b/SettingMainGadget/SettingMainGadget/Apps/AppsManagerGadget.cs @@ -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); diff --git a/SettingMainGadget/SettingMainGadget/MainMenuProvider.cs b/SettingMainGadget/SettingMainGadget/MainMenuProvider.cs index a07efdd..a85cf6d 100644 --- a/SettingMainGadget/SettingMainGadget/MainMenuProvider.cs +++ b/SettingMainGadget/SettingMainGadget/MainMenuProvider.cs @@ -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)),