Implement Delete Popup
authorGeunsun, Lee <gs86.lee@samsung.com>
Thu, 6 Apr 2017 12:50:48 +0000 (21:50 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:52 +0000 (18:34 +0900)
Change-Id: Ic398c065acd8f96d2caff846c6d88ceae174806a

LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs
LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs
LibTVRefCommonPortable/Utils/IPackageManager.cs
LibTVRefCommonPortable/Utils/PackageManagerUtils.cs
LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs
LibTVRefCommonTizen/Ports/PackageManagerPort.cs
TVApps/TVApps/ViewModels/AppsHolder.cs
TVApps/TVApps/ViewModels/IAppsViewModel.cs
TVApps/TVApps/ViewModels/MainPageViewModel.cs
TVApps/TVApps/Views/MainPage.xaml
TVApps/TVApps/Views/MainPage.xaml.cs

index a69a27bf44a8ad7432dd9dd5ffa416002979a9a7..4904fa43036f1124ee7ad76eef8bf18a699f3c13 100644 (file)
@@ -71,5 +71,20 @@ namespace LibTVRefCommonPortable.Utils
 
             return DependencyService.Get<IApplicationManagerAPIs>().GetAppInfoRemovable(appID);
         }
+
+        /// <summary>
+        /// Gets the app ID by the app label
+        /// </summary>
+        /// <param name="appLabel">the app label to get</param>
+        /// <returns>the app ID of the app label</returns>
+        public static Task<string> GetAppIDbyAppLabel(string appLabel)
+        {
+            if (DependencyService.Get<IApplicationManagerAPIs>() == null)
+            {
+                return null;
+            }
+
+            return DependencyService.Get<IApplicationManagerAPIs>().GetAppIDbyAppLabel(appLabel);
+        }
     }
 }
index 39ac9434bbc152aa839c4ffde70e23fb29b53a5f..28b8a25f6eda9b815a5410201bd88075137da655 100755 (executable)
@@ -101,5 +101,12 @@ namespace LibTVRefCommonPortable.Utils
         /// <param name="appID">The app ID to get</param>
         /// <returns>If the application is removable, true; otherwise, false</returns>
         bool GetAppInfoRemovable(string appID);
+
+        /// <summary>
+        /// Gets the app ID by the app label
+        /// </summary>
+        /// <param name="appLabel">the app label to get</param>
+        /// <returns>the app ID of the app label</returns>
+        Task<string> GetAppIDbyAppLabel(string appLabel);
     }
 }
index 894b76ac3463acdbf45409e7324c9d0eb24a3f1e..58a8548941f293e34e3f909dd57f64bfd7a251b8 100644 (file)
@@ -34,7 +34,7 @@ namespace LibTVRefCommonPortable.Utils
         /// </summary>
         /// <param name="pkgID">A package ID</param>
         /// <returns>A package label</returns>
-        string GetPackageID(string pkgID);
+        string GetPackageLabel(string pkgID);
 
         /// <summary>
         /// Gets the pacakge ID by the app ID
index d00040ed16d0389e0f8b068b6bee2ee969abb692..20b6c992fa299c35ab0d8f402833e28beb50b134 100644 (file)
@@ -43,14 +43,14 @@ namespace LibTVRefCommonPortable.Utils
         /// </summary>
         /// <param name="pkgID">A package ID</param>
         /// <returns>A package label</returns>
-        public static string GetPackageID(string pkgID)
+        public static string GetPackageLabel(string pkgID)
         {
             if (DependencyService.Get<IPackageManager>() == null)
             {
-                return "";
+                return null;
             }
 
-            return DependencyService.Get<IPackageManager>().GetPackageID(pkgID);
+            return DependencyService.Get<IPackageManager>().GetPackageLabel(pkgID);
         }
 
         /// <summary>
index 014050c0b425116f5ae3d57d88372563502363d5..827f5665757bcc3e890701d6155a9510ee69e714 100755 (executable)
@@ -234,5 +234,25 @@ namespace LibTVRefCommonTizen.Ports
                 return false;
             }
         }
+
+        /// <summary>
+        /// Gets the app ID by the app label
+        /// </summary>
+        /// <param name="appLabel">the app label to get</param>
+        /// <returns>the app ID of the app label</returns>
+        public async Task<string> GetAppIDbyAppLabel(string appLabel)
+        {
+            IEnumerable<ApplicationInfo> installedList = await ApplicationManager.GetInstalledApplicationsAsync();
+
+            foreach(var app in installedList)
+            {
+                if (app.Label.Equals(appLabel))
+                {
+                    return app.ApplicationId;
+                }
+            }
+
+            return null;
+        }
     }
 }
\ No newline at end of file
index c414882944815d2ffc19db82863803cefcec0209..bf77e2d4bc4d51841eb3d0f60ed8ceec5912c460 100644 (file)
@@ -129,11 +129,11 @@ namespace LibTVRefCommonTizen.Ports
         }
 
         /// <summary>
-        /// Gets the package information for the given package
+        /// Gets the package label for the given package
         /// </summary>
         /// <param name="pkgID">The ID of the package</param>
-        /// <returns>The package name for the given package ID</returns>
-        public string GetPackageID(string pkgID)
+        /// <returns>The package label for the given package ID</returns>
+        public string GetPackageLabel(string pkgID)
         {
             try
             {
index c9fb8c27876009b9476a722d333764854a7c5776..c29deabacb4fa53dc4842fb40d9348bbef7684b5 100644 (file)
@@ -128,7 +128,7 @@ namespace TVApps.ViewModels
                         NextStateDescription = AppsStatus.Delete.ToString().ToLower(),
                         Command = new Command<string>((key) =>
                         {
-                            DeleteApp(key);
+                            CheckDeleteApp(key);
                         }),
                         CommandParameter = item.AppID
                     }
@@ -247,9 +247,9 @@ namespace TVApps.ViewModels
         /// If application is pinned, removes in PinnedApps
         /// </summary>
         /// <param name="appID">The ID of application for deleting</param>
-        public void DeleteApp(string appID)
+        public void CheckDeleteApp(string appID)
         {
-            DebuggingUtils.Dbg("Delete, " + appID);
+            DebuggingUtils.Dbg("check that the app( " + appID + ") can be deleted");
 
             if (!ApplicationManagerUtils.GetAppInfoRemovable(appID))
             {
@@ -257,8 +257,15 @@ namespace TVApps.ViewModels
                 return;
             }
 
-            // TODO : popup
+            string appLabel = null;
+            if (ApplicationManagerUtils.GetInstalledApplication(appID).TryGetValue("Label", out appLabel))
+            {
+                ViewModel.ShowDeletePopup(appLabel);
+            }
+        }
 
+        public void DeleteApp(string 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)
index a9f622c7513853099629a9f69d6c5bdc544230fe..1c06dcec6f502cbf799da503994638f6e35ed363 100644 (file)
@@ -37,5 +37,11 @@ namespace TVApps.ViewModels
         /// </summary>
         /// <param name="newStatus">The next status name</param>
         void ChangeCurrentStatus(AppsStatus newStatus);
+
+        /// <summary>
+        /// Show delete popup
+        /// </summary>
+        /// <param name="appLabel">The app label to display</param>
+        void ShowDeletePopup(string appLabel);
     }
 }
index bb579dfc53a64379c3ef94242322efcf870e65d7..c032da826e7e3a5eb95eb4923c6401cba219aec0 100644 (file)
@@ -78,6 +78,24 @@ namespace TVApps.ViewModels
             }
         }
 
+        /// <summary>
+        /// Gets or sets the app label to display at the delete popup
+        /// </summary>
+        public string DeletePopupAppLabel
+        {
+            get;
+            set;
+        }
+
+        /// <summary>
+        /// Gets or sets whether delete popup is displayed
+        /// </summary>
+        public bool IsEnabledDeletePopup
+        {
+            get;
+            set;
+        }
+
         /// <summary>
         /// A command will be executed if the cancel button in FooterDeleteStatus is clicked
         /// </summary>
@@ -114,6 +132,11 @@ namespace TVApps.ViewModels
         /// <see cref="AppsStatus"/>
         public AppsStatus CurrentStatus { get; private set; }
 
+        /// <summary>
+        /// A command will be executed if the button of the delete popup is clicked
+        /// </summary>
+        public Command DeletePopupCommand { get; set; }
+
         /// <summary>
         /// Gets and Sets current sorting option of AppsHolder
         /// </summary>
@@ -223,6 +246,56 @@ namespace TVApps.ViewModels
                 }
             });
 
+            DeletePopupCommand = new Command<Dictionary<string, string>>(async (arg) =>
+            {
+                string answer;
+                if (!arg.TryGetValue("answer", out answer))
+                {
+                    DebuggingUtils.Err("Failed to get delete popup answer");
+
+                    IsEnabledDeletePopup = false;
+                    OnPropertyChanged("IsEnabledDeletePopup");
+
+                    return;
+                }
+
+                DebuggingUtils.Dbg("DeletePopup answer : " + answer);
+                if (answer.Equals("no"))
+                {
+                    IsEnabledDeletePopup = false;
+                    OnPropertyChanged("IsEnabledDeletePopup");
+
+                    return;
+                }
+
+                string appLabel;
+                if (!arg.TryGetValue("AppLabel", out appLabel))
+                {
+                    DebuggingUtils.Err("Failed to get the app label to delete");
+
+                    IsEnabledDeletePopup = false;
+                    OnPropertyChanged("IsEnabledDeletePopup");
+
+                    return;
+                }
+
+                string appId = await ApplicationManagerUtils.GetAppIDbyAppLabel(appLabel);
+                if (appId == null)
+                {
+                    DebuggingUtils.Err("Failed to get the app ID by app label : " + appLabel);
+
+                    IsEnabledDeletePopup = false;
+                    OnPropertyChanged("IsEnabledDeletePopup");
+
+                    return;
+                }
+
+                appsHolder.DeleteApp(appId);
+
+                IsEnabledDeletePopup = false;
+                OnPropertyChanged("IsEnabledDeletePopup");
+            });
+
             App.SetPinAppRequestListener((s, e) =>
             {
                 // TODO : check concurrency
@@ -252,7 +325,7 @@ namespace TVApps.ViewModels
 
             MessagingCenter.Subscribe<AppShortcutInfo, string>(this, "OptionMenuDelete", (sender, arg) =>
             {
-                appsHolder.DeleteApp(arg);
+                appsHolder.CheckDeleteApp(arg);
             });
 
             TVHomeImpl.GetInstance.AppShortcutControllerInstance.AddFileSystemChangedListener((sender, arg) =>
@@ -295,6 +368,19 @@ namespace TVApps.ViewModels
             OnPropertyChanged("CurrentStatus");
         }
 
+        /// <summary>
+        /// Show the delete popup
+        /// </summary>
+        /// <param name="appLabel">The app label to display at the delete popup</param>
+        public void ShowDeletePopup(string appLabel)
+        {
+            DeletePopupAppLabel = appLabel;
+            OnPropertyChanged("DeletePopupAppLabel");
+
+            IsEnabledDeletePopup = true;
+            OnPropertyChanged("IsEnabledDeletePopup");
+        }
+
         /// <summary>
         /// A method for invoking PropertyChanged event
         /// </summary>
index 96fcfaff293bb638b90251deaf79730b3755e784..73800dcd2afa2cde51f61aa643cb77c583e4bc39 100755 (executable)
@@ -6,7 +6,10 @@
              xmlns:Views="clr-namespace:TVApps.Views"
              x:Class="TVApps.Views.MainPage"
              BackgroundColor="#000000"
-             CurrentStatus="{Binding CurrentStatus}">
+             CurrentStatus="{Binding CurrentStatus}"
+             IsEnabledDeletePopup="{Binding IsEnabledDeletePopup}"
+             DeletePopupAppLabel="{Binding DeletePopupAppLabel}"
+             DeletePopupCommand="{Binding DeletePopupCommand}">
   <ContentPage.BindingContext>
     <ViewModels:MainPageViewModel />
   </ContentPage.BindingContext>
index 84d7a8677b7aaa7e4f2b836003736fce434b7f2a..972bed8b9c46d14d982889e9ac8c67027aa898a0 100644 (file)
@@ -21,6 +21,8 @@ using System.ComponentModel;
 using LibTVRefCommonPortable.Utils;
 using System.Threading;
 using System.Threading.Tasks;
+using System.Windows.Input;
+using System.Collections.Generic;
 
 namespace TVApps.Views
 {
@@ -43,6 +45,48 @@ namespace TVApps.Views
             set { SetValue(CurrentStatusProperty, value); }
         }
 
+        /// <summary>
+        /// Identifies the app label bindable property
+        /// </summary>
+        public static readonly BindableProperty DeletePopupAppLabelProperty = BindableProperty.Create("DeletePopupAppLabel", typeof(string), typeof(MainPage), default(string));
+
+        /// <summary>
+        /// Gets or sets the app label to display at the delete popup
+        /// </summary>
+        public string DeletePopupAppLabel
+        {
+            get { return (string)GetValue(DeletePopupAppLabelProperty); }
+            set { SetValue(DeletePopupAppLabelProperty, value); }
+        }
+
+        /// <summary>
+        /// Identifies the delete popup visibility bindable property
+        /// </summary>
+        public static readonly BindableProperty IsEnabledDeletePopupProperty = BindableProperty.Create("IsEnabledDeletePopup", typeof(bool), typeof(MainPage), default(bool));
+
+        /// <summary>
+        /// Gets or sets whether delete popup is displayed
+        /// </summary>
+        public bool IsEnabledDeletePopup
+        {
+            get { return (bool)GetValue(IsEnabledDeletePopupProperty); }
+            set { SetValue(IsEnabledDeletePopupProperty, value); }
+        }
+
+        /// <summary>
+        /// Identifies the delete popup command bindable property
+        /// </summary>
+        public static readonly BindableProperty DeletePopupCommandProperty = BindableProperty.Create("DeletePopupCommand", typeof(Command), typeof(MainPage), default(Command));
+
+        /// <summary>
+        /// A command will be executed if the button of the delete popup is clicked
+        /// </summary>
+        public ICommand DeletePopupCommand
+        {
+            get { return (ICommand)GetValue(DeletePopupCommandProperty); }
+            set { SetValue(DeletePopupCommandProperty, value); }
+        }
+
         /*
         private async void PlayHideAnimation()
         {
@@ -131,12 +175,23 @@ namespace TVApps.Views
         /// </summary>
         /// <param name="sender">The source of the event</param>
         /// <param name="e">The event that is occurred when property of MainPage is changed</param>
-        private void MainPagePropertyChanged(object sender, PropertyChangedEventArgs e)
+        private async void MainPagePropertyChanged(object sender, PropertyChangedEventArgs e)
         {
-            if (e.PropertyName.CompareTo("CurrentStatus") == 0)
+            if (e.PropertyName.Equals("CurrentStatus"))
             {
                 SetCurrentStatus(CurrentStatus);
             }
+            else if (e.PropertyName.Equals("IsEnabledDeletePopup"))
+            {
+                if (IsEnabledDeletePopup)
+                {
+                    bool answer = await DisplayAlert(DeletePopupAppLabel, "Do you want to delete?", "YES", "NO");
+                    Dictionary<string, string> ret = new Dictionary<string, string>();
+                    ret.Add("AppLabel", DeletePopupAppLabel);
+                    ret.Add("answer", answer ? "yes" : "no");
+                    DeletePopupCommand?.Execute(ret);
+                }
+            }
         }
 
         /// <summary>