From dc914421b09ac7e66db14d9e21ccf0b34fb0d7bf Mon Sep 17 00:00:00 2001 From: "Geunsun, Lee" Date: Thu, 30 Mar 2017 14:14:48 +0900 Subject: [PATCH] Remove the app in the pinned app list if the app to be deleted is pinned Change-Id: Ib5cfcddcc115fabc5f3d592a8fafd56794029982 (cherry picked from commit f6d7b37daeb5cc6539a17b465e874740ecca493b) --- LibTVRefCommonPortable/Utils/IPackageManager.cs | 18 +++++- .../Utils/PackageManagerUtils.cs | 36 +++++++++++- LibTVRefCommonTizen/Ports/PackageManagerPort.cs | 64 ++++++++++++++++++++- TVApps/TVApps/ViewModels/AppsHolder.cs | 66 ++++++++++++++-------- 4 files changed, 153 insertions(+), 31 deletions(-) diff --git a/LibTVRefCommonPortable/Utils/IPackageManager.cs b/LibTVRefCommonPortable/Utils/IPackageManager.cs index db05acc..894b76a 100644 --- a/LibTVRefCommonPortable/Utils/IPackageManager.cs +++ b/LibTVRefCommonPortable/Utils/IPackageManager.cs @@ -32,9 +32,16 @@ namespace LibTVRefCommonPortable.Utils /// /// A method provides a detail information (TBD) /// - /// A package ID + /// A package ID /// A package label - string GetPackage(string PkgID); + string GetPackageID(string pkgID); + + /// + /// Gets the pacakge ID by the app ID + /// + /// The app ID to get + /// The pacakge ID that contains given app ID + string GetPackageIDByAppID(string appID); /// /// A method removes the package. @@ -49,5 +56,12 @@ namespace LibTVRefCommonPortable.Utils /// A app ID /// A status of uninstall bool UninstallPackageByAppID(string appID); + + /// + /// Gets applications list by the package ID + /// + /// The package ID to get applications + /// The list of applications + List GetApplicationsByPkgID(string pkgID); } } diff --git a/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs b/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs index 790f7b1..d00040e 100644 --- a/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs +++ b/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs @@ -41,16 +41,31 @@ namespace LibTVRefCommonPortable.Utils /// /// A method provides a detail information (TBD) /// - /// A package ID + /// A package ID /// A package label - public static string GetPackage(string PkgID) + public static string GetPackageID(string pkgID) { if (DependencyService.Get() == null) { return ""; } - return DependencyService.Get().GetPackage(PkgID); + return DependencyService.Get().GetPackageID(pkgID); + } + + /// + /// Gets the pacakge ID by the app ID + /// + /// The app ID to get + /// The pacakge ID that contains given app ID + public static string GetPackageIDByAppID(string appID) + { + if (DependencyService.Get() == null) + { + return null; + } + + return DependencyService.Get().GetPackageIDByAppID(appID); } /// @@ -82,5 +97,20 @@ namespace LibTVRefCommonPortable.Utils return DependencyService.Get().UninstallPackageByAppID(appID); } + + /// + /// Gets applications list by the package ID + /// + /// The package ID to get applications + /// The list of applications + public static List GetApplicationsByPkgID(string pkgID) + { + if (DependencyService.Get() == null) + { + return null; + } + + return DependencyService.Get().GetApplicationsByPkgID(pkgID); + } } } diff --git a/LibTVRefCommonTizen/Ports/PackageManagerPort.cs b/LibTVRefCommonTizen/Ports/PackageManagerPort.cs index 66cb1aa..c414882 100644 --- a/LibTVRefCommonTizen/Ports/PackageManagerPort.cs +++ b/LibTVRefCommonTizen/Ports/PackageManagerPort.cs @@ -27,6 +27,9 @@ namespace LibTVRefCommonTizen.Ports /// public class PackageManagerPort : IPackageManager { + /// + /// A interface for platform notification + /// private static IPlatformNotification Notification { get; @@ -99,7 +102,7 @@ namespace LibTVRefCommonTizen.Ports /// /// Retrieves package information of all installed packages /// - /// The list of packages. + /// The list of packages public Dictionary GetPackageList() { Dictionary pkgList = new Dictionary(); @@ -130,7 +133,7 @@ namespace LibTVRefCommonTizen.Ports /// /// The ID of the package /// The package name for the given package ID - public string GetPackage(string pkgID) + public string GetPackageID(string pkgID) { try { @@ -147,6 +150,25 @@ namespace LibTVRefCommonTizen.Ports } /// + /// Gets the pacakge ID by the app ID + /// + /// The app ID to get + /// The pacakge ID that contains given app ID + public string GetPackageIDByAppID(string appID) + { + try + { + return PackageManager.GetPackageIdByApplicationId(appID); + } + catch (Exception e) + { + DebuggingUtils.Err("Failed to get the package ID by app ID(" + appID + ") : " + e.Message); + + return null; + } + } + + /// /// Uninstalls package with the given package /// /// The ID of the package to be uninstalled @@ -188,5 +210,43 @@ namespace LibTVRefCommonTizen.Ports return false; } } + + /// + /// Gets applications list by the package ID + /// + /// The package ID to get applications + /// The list of applications + public List GetApplicationsByPkgID(string pkgID) + { + try + { + int index = 0; + List apps = new List(); + Package pkg = PackageManager.GetPackage(pkgID); + IEnumerable appsList = pkg.GetApplications(); + if (appsList == null) + { + DebuggingUtils.Err("Failed to get apps list(" + pkgID + ")"); + + return null; + } + + foreach (var app in appsList) + { + apps.Add(app.ApplicationId); + DebuggingUtils.Dbg("[" + index + "] " + app.ApplicationId); + index++; + } + + return apps; + } + catch (Exception e) + { + DebuggingUtils.Err("Failed to get the package information(" + pkgID + ") : " + e.Message); + + return new List(); + } + + } } } \ No newline at end of file diff --git a/TVApps/TVApps/ViewModels/AppsHolder.cs b/TVApps/TVApps/ViewModels/AppsHolder.cs index 290c9d3..88e9685 100644 --- a/TVApps/TVApps/ViewModels/AppsHolder.cs +++ b/TVApps/TVApps/ViewModels/AppsHolder.cs @@ -70,9 +70,6 @@ namespace TVApps.ViewModels App.SetAppUninstalledListener((s, e) => { - // TODO : find apps by package id - // TODO : remove all apps from pinned app list - SetApps(); }); @@ -227,29 +224,62 @@ namespace TVApps.ViewModels } /// + /// Removes the pinned app by app ID + /// + /// The apps list to remove at the pinned app list + public void RemovePinnedApp(List removableAppsList) + { + foreach (string app in removableAppsList) + { + if (PinnedApps.ContainsKey(app)) + { + DebuggingUtils.Dbg("UnPin! : " + app); + + PinnedApps.Remove(app); + } + } + + UpdatePinnedApps(); + } + + /// /// A method sends application delete request /// If application is pinned, removes in PinnedApps /// - /// The ID of application for deleting - public void DeleteApp(string AppID) + /// The ID of application for deleting + public void DeleteApp(string appID) { - DebuggingUtils.Dbg("Delete, " + AppID); + DebuggingUtils.Dbg("Delete, " + appID); // TODO : popup - // TODO : remove all app of removed package!!! - RemovePinnedApp(AppID); + // if the app to be deleted is pinned, remove the app in the pinned apps list + string pkgID = PackageManagerUtils.GetPackageIDByAppID(appID); + if (pkgID == null) + { + DebuggingUtils.Err("Failed to get the package ID by app ID(" + appID + ")"); + + return; + } + + List removableAppsList = PackageManagerUtils.GetApplicationsByPkgID(pkgID); + if (removableAppsList == null || removableAppsList.Count == 0) + { + DebuggingUtils.Err("Failed to get the apps list by package ID(" + pkgID + ")"); + + return; + } ViewModel.ChangeCurrentStatus(AppsStatus.Default); - if (PackageManagerUtils.UninstallPackageByAppID(AppID) == false) + if (PackageManagerUtils.UninstallPackageByAppID(appID) == false) { - DebuggingUtils.Err("App uninstall is failed!!!, " + AppID); + DebuggingUtils.Err("App uninstall is failed!!!, " + appID); } else { var removed = from app in InstalledApps - where app.AppID == AppID + where app.AppID == appID select app; InstalledApps.Remove(removed.First()); foreach (var item in InstalledApps) @@ -257,6 +287,7 @@ namespace TVApps.ViewModels DebuggingUtils.Dbg("- " + item.AppID); } + RemovePinnedApp(removableAppsList); RefreshApps(); } } @@ -375,19 +406,6 @@ namespace TVApps.ViewModels } /// - /// A method removes a application in pinned list - /// - /// The ID of application for changing pin state to false - public void RemovePinnedApp(string AppID) - { - if (PinnedApps.ContainsKey(AppID)) - { - PinnedApps.Remove(AppID); - UpdatePinnedApps(); - } - } - - /// /// A method changes visible state of option menu to true /// /// The ID of application for showing option menu -- 2.7.4