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 a69a27b..4904fa4 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 39ac943..28b8a25 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 894b76a..58a8548 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 d00040e..20b6c99 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 014050c..827f566 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 c414882..bf77e2d 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 c9fb8c2..c29deab 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 a9f622c..1c06dce 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 bb579df..c032da8 100644 (file)
@@ -79,6 +79,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>
         /// <see cref="FooterDeleteStatus"/>
@@ -115,6 +133,11 @@ namespace TVApps.ViewModels
         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>
         /// <see cref="AppsHolder"/>
@@ -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) =>
@@ -296,6 +369,19 @@ namespace TVApps.ViewModels
         }
 
         /// <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>
         /// <param name="name">The name of property</param>
index 96fcfaf..73800dc 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 84d7a86..972bed8 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>