Remove the app in the pinned app list if the app to be deleted is pinned
authorGeunsun, Lee <gs86.lee@samsung.com>
Thu, 30 Mar 2017 05:14:48 +0000 (14:14 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:52 +0000 (18:34 +0900)
Change-Id: Ib5cfcddcc115fabc5f3d592a8fafd56794029982
(cherry picked from commit f6d7b37daeb5cc6539a17b465e874740ecca493b)

LibTVRefCommonPortable/Utils/IPackageManager.cs
LibTVRefCommonPortable/Utils/PackageManagerUtils.cs
LibTVRefCommonTizen/Ports/PackageManagerPort.cs
TVApps/TVApps/ViewModels/AppsHolder.cs

index db05acc..894b76a 100644 (file)
@@ -32,9 +32,16 @@ namespace LibTVRefCommonPortable.Utils
         /// <summary>
         /// A method provides a detail information (TBD)
         /// </summary>
-        /// <param name="PkgID">A package ID</param>
+        /// <param name="pkgID">A package ID</param>
         /// <returns>A package label</returns>
-        string GetPackage(string PkgID);
+        string GetPackageID(string pkgID);
+
+        /// <summary>
+        /// Gets the pacakge ID by the app ID
+        /// </summary>
+        /// <param name="appID">The app ID to get</param>
+        /// <returns>The pacakge ID that contains given app ID</returns>
+        string GetPackageIDByAppID(string appID);
 
         /// <summary>
         /// A method removes the package.
@@ -49,5 +56,12 @@ namespace LibTVRefCommonPortable.Utils
         /// <param name="appID">A app ID</param>
         /// <returns>A status of uninstall</returns>
         bool UninstallPackageByAppID(string appID);
+
+        /// <summary>
+        /// Gets applications list by the package ID
+        /// </summary>
+        /// <param name="pkgID">The package ID to get applications</param>
+        /// <returns>The list of applications</returns>
+        List<string> GetApplicationsByPkgID(string pkgID);
     }
 }
index 790f7b1..d00040e 100644 (file)
@@ -41,16 +41,31 @@ namespace LibTVRefCommonPortable.Utils
         /// <summary>
         /// A method provides a detail information (TBD)
         /// </summary>
-        /// <param name="PkgID">A package ID</param>
+        /// <param name="pkgID">A package ID</param>
         /// <returns>A package label</returns>
-        public static string GetPackage(string PkgID)
+        public static string GetPackageID(string pkgID)
         {
             if (DependencyService.Get<IPackageManager>() == null)
             {
                 return "";
             }
 
-            return DependencyService.Get<IPackageManager>().GetPackage(PkgID);
+            return DependencyService.Get<IPackageManager>().GetPackageID(pkgID);
+        }
+
+        /// <summary>
+        /// Gets the pacakge ID by the app ID
+        /// </summary>
+        /// <param name="appID">The app ID to get</param>
+        /// <returns>The pacakge ID that contains given app ID</returns>
+        public static string GetPackageIDByAppID(string appID)
+        {
+            if (DependencyService.Get<IPackageManager>() == null)
+            {
+                return null;
+            }
+
+            return DependencyService.Get<IPackageManager>().GetPackageIDByAppID(appID);
         }
 
         /// <summary>
@@ -82,5 +97,20 @@ namespace LibTVRefCommonPortable.Utils
 
             return DependencyService.Get<IPackageManager>().UninstallPackageByAppID(appID);
         }
+
+        /// <summary>
+        /// Gets applications list by the package ID
+        /// </summary>
+        /// <param name="pkgID">The package ID to get applications</param>
+        /// <returns>The list of applications</returns>
+        public static List<string> GetApplicationsByPkgID(string pkgID)
+        {
+            if (DependencyService.Get<IPackageManager>() == null)
+            {
+                return null;
+            }
+
+            return DependencyService.Get<IPackageManager>().GetApplicationsByPkgID(pkgID);
+        }
     }
 }
index 66cb1aa..c414882 100644 (file)
@@ -27,6 +27,9 @@ namespace LibTVRefCommonTizen.Ports
     /// </summary>
     public class PackageManagerPort : IPackageManager
     {
+        /// <summary>
+        /// A interface for platform notification
+        /// </summary>
         private static IPlatformNotification Notification
         {
             get;
@@ -99,7 +102,7 @@ namespace LibTVRefCommonTizen.Ports
         /// <summary>
         /// Retrieves package information of all installed packages
         /// </summary>
-        /// <returns>The list of packages.</returns>
+        /// <returns>The list of packages</returns>
         public Dictionary<string, string[]> GetPackageList()
         {
             Dictionary<string, string[]> pkgList = new Dictionary<string, string[]>();
@@ -130,7 +133,7 @@ namespace LibTVRefCommonTizen.Ports
         /// </summary>
         /// <param name="pkgID">The ID of the package</param>
         /// <returns>The package name for the given package ID</returns>
-        public string GetPackage(string pkgID)
+        public string GetPackageID(string pkgID)
         {
             try
             {
@@ -147,6 +150,25 @@ namespace LibTVRefCommonTizen.Ports
         }
 
         /// <summary>
+        /// Gets the pacakge ID by the app ID
+        /// </summary>
+        /// <param name="appID">The app ID to get</param>
+        /// <returns>The pacakge ID that contains given app ID</returns>
+        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;
+            }
+        }
+
+        /// <summary>
         /// Uninstalls package with the given package
         /// </summary>
         /// <param name="pkgID">The ID of the package to be uninstalled</param>
@@ -188,5 +210,43 @@ namespace LibTVRefCommonTizen.Ports
                 return false;
             }
         }
+
+        /// <summary>
+        /// Gets applications list by the package ID
+        /// </summary>
+        /// <param name="pkgID">The package ID to get applications</param>
+        /// <returns>The list of applications</returns>
+        public List<string> GetApplicationsByPkgID(string pkgID)
+        {
+            try
+            {
+                int index = 0;
+                List<string> apps = new List<string>();
+                Package pkg = PackageManager.GetPackage(pkgID);
+                IEnumerable<ApplicationInfo> 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<string>();
+            }
+
+        }
     }
 }
\ No newline at end of file
index 290c9d3..88e9685 100644 (file)
@@ -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
         }
 
         /// <summary>
+        /// Removes the pinned app by app ID
+        /// </summary>
+        /// <param name="removableAppsList">The apps list to remove at the pinned app list</param>
+        public void RemovePinnedApp(List<string> removableAppsList)
+        {
+            foreach (string app in removableAppsList)
+            {
+                if (PinnedApps.ContainsKey(app))
+                {
+                    DebuggingUtils.Dbg("UnPin! : " + app);
+
+                    PinnedApps.Remove(app);
+                }
+            }
+
+            UpdatePinnedApps();
+        }
+
+        /// <summary>
         /// A method sends application delete request
         /// If application is pinned, removes in PinnedApps
         /// </summary>
-        /// <param name="AppID">The ID of application for deleting</param>
-        public void DeleteApp(string AppID)
+        /// <param name="appID">The ID of application for deleting</param>
+        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<string> 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
         }
 
         /// <summary>
-        /// A method removes a application in pinned list
-        /// </summary>
-        /// <param name="AppID">The ID of application for changing pin state to false</param>
-        public void RemovePinnedApp(string AppID)
-        {
-            if (PinnedApps.ContainsKey(AppID))
-            {
-                PinnedApps.Remove(AppID);
-                UpdatePinnedApps();
-            }
-        }
-
-        /// <summary>
         /// A method changes visible state of option menu to true
         /// </summary>
         /// <param name="appId">The ID of application for showing option menu</param>