From: Geunsun, Lee Date: Thu, 6 Apr 2017 10:59:42 +0000 (+0900) Subject: Implement ApplicationManagerUtils in PCL X-Git-Tag: submit/tizen/20170808.015446~119 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e335f3f8532efebe2f84186a15ee3659fa6e486c;p=profile%2Ftv%2Fapps%2Fdotnet%2Fhome.git Implement ApplicationManagerUtils in PCL Change-Id: If60a660d6a6257679110086ee25d7c365c5f99ca --- diff --git a/LibTVRefCommonPortable/DataModels/RecentShortcutInfo.cs b/LibTVRefCommonPortable/DataModels/RecentShortcutInfo.cs index 255d3f5..96b2750 100755 --- a/LibTVRefCommonPortable/DataModels/RecentShortcutInfo.cs +++ b/LibTVRefCommonPortable/DataModels/RecentShortcutInfo.cs @@ -24,7 +24,7 @@ namespace LibTVRefCommonPortable.DataModels public class RecentShortcutInfo : ShortcutInfo { /// - /// A application ID + /// An application ID /// public string AppID { get; set; } /// diff --git a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj index 1b1f96c..f682b4a 100755 --- a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj +++ b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj @@ -51,6 +51,7 @@ + diff --git a/LibTVRefCommonPortable/Models/AppShortcutController.cs b/LibTVRefCommonPortable/Models/AppShortcutController.cs index 2db6bae..e0a38ff 100755 --- a/LibTVRefCommonPortable/Models/AppShortcutController.cs +++ b/LibTVRefCommonPortable/Models/AppShortcutController.cs @@ -45,10 +45,9 @@ namespace LibTVRefCommonPortable.Models /// A installed app list. public async Task> GetInstalledApps() { - IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); List appShortcutInfoList = new List(); - var installedAppList = await applicationManagerPort.GetAllInstalledApplication(); + var installedAppList = await ApplicationManagerUtils.GetAllInstalledApplication(); foreach (KeyValuePair item in installedAppList) { @@ -64,6 +63,7 @@ namespace LibTVRefCommonPortable.Models var appShortcutInfo = new AppShortcutInfo() { + IsRemovable = ApplicationManagerUtils.GetAppInfoRemovable(item.Key), // TODO : Fill these correctly by using Tizen Device APIs Installed = DateUtils.GetRandomDate(), LastUsed = DateUtils.GetRandomDate(), @@ -160,14 +160,13 @@ namespace LibTVRefCommonPortable.Models /// A Pinned App Shortcut list. private async Task> GetPinnedApps() { - IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); IEnumerable pinned_apps_info = await AppShortcutStorage.Read(); List returnPinnedAppsInfo = new List(); foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info) { - Dictionary appInfo = applicationManagerPort.GetInstalledApplication(appShortcutInfo.AppID); + Dictionary appInfo = ApplicationManagerUtils.GetInstalledApplication(appShortcutInfo.AppID); if (appInfo == null) { diff --git a/LibTVRefCommonPortable/Models/RecentShortcutController.cs b/LibTVRefCommonPortable/Models/RecentShortcutController.cs index 6678270..a3a7ca0 100755 --- a/LibTVRefCommonPortable/Models/RecentShortcutController.cs +++ b/LibTVRefCommonPortable/Models/RecentShortcutController.cs @@ -70,10 +70,9 @@ namespace LibTVRefCommonPortable.Models /// A Recent Shortcut list. public IEnumerable GetList() { - IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); List recentShortcutInfoList = new List(); - var recentApps = applicationManagerPort.GetRecentApplications(); + var recentApps = ApplicationManagerUtils.GetRecentApplications(); foreach (var item in recentApps) { var defaultStateDescription = new StateDescription() diff --git a/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs b/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs new file mode 100644 index 0000000..a69a27b --- /dev/null +++ b/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs @@ -0,0 +1,75 @@ + +using System.Collections.Generic; +using System.Threading.Tasks; +using Xamarin.Forms; + +namespace LibTVRefCommonPortable.Utils +{ + public sealed class ApplicationManagerUtils + { + /// + /// A constructor + /// + public ApplicationManagerUtils() + { + } + + /// + /// Gets the information of the recent applications + /// + /// The list of the recent applications + public static IEnumerable GetRecentApplications() + { + if (DependencyService.Get() == null) + { + return null; + } + + return DependencyService.Get().GetRecentApplications(); + } + + /// + /// Gets the information of the specified application with the app ID + /// + /// The app Id to get + /// The information of the installed application + public static Dictionary GetInstalledApplication(string appID) + { + if (DependencyService.Get() == null) + { + return null; + } + + return DependencyService.Get().GetInstalledApplication(appID); + } + + /// + /// Gets the information of the installed applications asynchronously + /// + /// The list of the installed applications + public static Task> GetAllInstalledApplication() + { + if (DependencyService.Get() == null) + { + return null; + } + + return DependencyService.Get().GetAllInstalledApplication(); + } + + /// + /// Checks whether application is removable + /// + /// The app ID to get + /// If the application is removable, true; otherwise, false + public static bool GetAppInfoRemovable(string appID) + { + if (DependencyService.Get() == null) + { + return false; + } + + return DependencyService.Get().GetAppInfoRemovable(appID); + } + } +} diff --git a/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs b/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs index cf65a8e..39ac943 100755 --- a/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs +++ b/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs @@ -85,14 +85,21 @@ namespace LibTVRefCommonPortable.Utils /// A installed application information Dictionary GetInstalledApplication(string applicationId); - /// - /// A method for removing all recent applications - /// + /// + /// A method for removing all recent applications + /// void DeleteAllRecentApplication(); - /// - /// A method for removing the specified recent application - /// + /// + /// A method for removing the specified recent application + /// void DeleteRecentApplication(string appId); + + /// + /// Checks whether application is removable + /// + /// The app ID to get + /// If the application is removable, true; otherwise, false + bool GetAppInfoRemovable(string appID); } } diff --git a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs index 8182734..014050c 100755 --- a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs +++ b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs @@ -150,7 +150,7 @@ namespace LibTVRefCommonTizen.Ports } catch (Exception exception) { - DbgPort.E("Exception " + appID + " :" + exception.Message); + DbgPort.E("Failed to get the installed application(" + appID + ") :" + exception.Message); return null; } @@ -203,9 +203,36 @@ namespace LibTVRefCommonTizen.Ports } catch (Exception exception) { - DbgPort.E(exception.Message); + DbgPort.E("Failed to get the all installed applications : " + exception.Message); return null; } } + + /// + /// Checks whether application is removable + /// + /// The app ID to get + /// If the application is removable, true; otherwise, false + public bool GetAppInfoRemovable(string appID) + { + ApplicationInfo appInfo = null; + + try + { + appInfo = ApplicationManager.GetInstalledApplication(appID); + if (appInfo == null) + { + DbgPort.D("Failed to get the installed application(" + appID +")"); + return false; + } + + return !appInfo.IsPreload; + } + catch (Exception exception) + { + DbgPort.E("Failed to get the installed application(" + appID + ") :" + exception.Message); + return false; + } + } } } \ No newline at end of file diff --git a/TVApps/TVApps/ViewModels/AppsHolder.cs b/TVApps/TVApps/ViewModels/AppsHolder.cs index 88e9685..c9fb8c2 100644 --- a/TVApps/TVApps/ViewModels/AppsHolder.cs +++ b/TVApps/TVApps/ViewModels/AppsHolder.cs @@ -251,6 +251,12 @@ namespace TVApps.ViewModels { DebuggingUtils.Dbg("Delete, " + appID); + if (!ApplicationManagerUtils.GetAppInfoRemovable(appID)) + { + DebuggingUtils.Dbg("This app is not removable : " + appID); + return; + } + // TODO : popup // if the app to be deleted is pinned, remove the app in the pinned apps list @@ -262,8 +268,8 @@ namespace TVApps.ViewModels return; } - List removableAppsList = PackageManagerUtils.GetApplicationsByPkgID(pkgID); - if (removableAppsList == null || removableAppsList.Count == 0) + List appsList = PackageManagerUtils.GetApplicationsByPkgID(pkgID); + if (appsList == null || appsList.Count == 0) { DebuggingUtils.Err("Failed to get the apps list by package ID(" + pkgID + ")"); @@ -287,7 +293,7 @@ namespace TVApps.ViewModels DebuggingUtils.Dbg("- " + item.AppID); } - RemovePinnedApp(removableAppsList); + RemovePinnedApp(appsList); RefreshApps(); } } @@ -348,6 +354,11 @@ namespace TVApps.ViewModels break; case AppsStatus.Delete: + if (!item.IsRemovable) + { + item.IsDim = true; + } + item.IsChecked = false; break; }