From 0c3d9e734856e0891000fea9501b335e736b0c3a Mon Sep 17 00:00:00 2001 From: "Geunsun, Lee" Date: Thu, 6 Apr 2017 21:50:48 +0900 Subject: [PATCH] Implement Delete Popup Change-Id: Ic398c065acd8f96d2caff846c6d88ceae174806a --- .../Utils/ApplicationManagerUtils.cs | 15 ++++ .../Utils/IApplicationManagerAPIs.cs | 7 ++ LibTVRefCommonPortable/Utils/IPackageManager.cs | 2 +- .../Utils/PackageManagerUtils.cs | 6 +- .../Ports/ApplicationManagerPort.cs | 20 +++++ LibTVRefCommonTizen/Ports/PackageManagerPort.cs | 6 +- TVApps/TVApps/ViewModels/AppsHolder.cs | 15 +++- TVApps/TVApps/ViewModels/IAppsViewModel.cs | 6 ++ TVApps/TVApps/ViewModels/MainPageViewModel.cs | 88 +++++++++++++++++++++- TVApps/TVApps/Views/MainPage.xaml | 5 +- TVApps/TVApps/Views/MainPage.xaml.cs | 59 ++++++++++++++- 11 files changed, 214 insertions(+), 15 deletions(-) diff --git a/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs b/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs index a69a27b..4904fa4 100644 --- a/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs +++ b/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs @@ -71,5 +71,20 @@ namespace LibTVRefCommonPortable.Utils return DependencyService.Get().GetAppInfoRemovable(appID); } + + /// + /// Gets the app ID by the app label + /// + /// the app label to get + /// the app ID of the app label + public static Task GetAppIDbyAppLabel(string appLabel) + { + if (DependencyService.Get() == null) + { + return null; + } + + return DependencyService.Get().GetAppIDbyAppLabel(appLabel); + } } } diff --git a/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs b/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs index 39ac943..28b8a25 100755 --- a/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs +++ b/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs @@ -101,5 +101,12 @@ namespace LibTVRefCommonPortable.Utils /// The app ID to get /// If the application is removable, true; otherwise, false bool GetAppInfoRemovable(string appID); + + /// + /// Gets the app ID by the app label + /// + /// the app label to get + /// the app ID of the app label + Task GetAppIDbyAppLabel(string appLabel); } } diff --git a/LibTVRefCommonPortable/Utils/IPackageManager.cs b/LibTVRefCommonPortable/Utils/IPackageManager.cs index 894b76a..58a8548 100644 --- a/LibTVRefCommonPortable/Utils/IPackageManager.cs +++ b/LibTVRefCommonPortable/Utils/IPackageManager.cs @@ -34,7 +34,7 @@ namespace LibTVRefCommonPortable.Utils /// /// A package ID /// A package label - string GetPackageID(string pkgID); + string GetPackageLabel(string pkgID); /// /// Gets the pacakge ID by the app ID diff --git a/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs b/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs index d00040e..20b6c99 100644 --- a/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs +++ b/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs @@ -43,14 +43,14 @@ namespace LibTVRefCommonPortable.Utils /// /// A package ID /// A package label - public static string GetPackageID(string pkgID) + public static string GetPackageLabel(string pkgID) { if (DependencyService.Get() == null) { - return ""; + return null; } - return DependencyService.Get().GetPackageID(pkgID); + return DependencyService.Get().GetPackageLabel(pkgID); } /// diff --git a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs index 014050c..827f566 100755 --- a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs +++ b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs @@ -234,5 +234,25 @@ namespace LibTVRefCommonTizen.Ports return false; } } + + /// + /// Gets the app ID by the app label + /// + /// the app label to get + /// the app ID of the app label + public async Task GetAppIDbyAppLabel(string appLabel) + { + IEnumerable 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 diff --git a/LibTVRefCommonTizen/Ports/PackageManagerPort.cs b/LibTVRefCommonTizen/Ports/PackageManagerPort.cs index c414882..bf77e2d 100644 --- a/LibTVRefCommonTizen/Ports/PackageManagerPort.cs +++ b/LibTVRefCommonTizen/Ports/PackageManagerPort.cs @@ -129,11 +129,11 @@ namespace LibTVRefCommonTizen.Ports } /// - /// Gets the package information for the given package + /// Gets the package label for the given package /// /// The ID of the package - /// The package name for the given package ID - public string GetPackageID(string pkgID) + /// The package label for the given package ID + public string GetPackageLabel(string pkgID) { try { diff --git a/TVApps/TVApps/ViewModels/AppsHolder.cs b/TVApps/TVApps/ViewModels/AppsHolder.cs index c9fb8c2..c29deab 100644 --- a/TVApps/TVApps/ViewModels/AppsHolder.cs +++ b/TVApps/TVApps/ViewModels/AppsHolder.cs @@ -128,7 +128,7 @@ namespace TVApps.ViewModels NextStateDescription = AppsStatus.Delete.ToString().ToLower(), Command = new Command((key) => { - DeleteApp(key); + CheckDeleteApp(key); }), CommandParameter = item.AppID } @@ -247,9 +247,9 @@ namespace TVApps.ViewModels /// If application is pinned, removes in PinnedApps /// /// The ID of application for deleting - 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) diff --git a/TVApps/TVApps/ViewModels/IAppsViewModel.cs b/TVApps/TVApps/ViewModels/IAppsViewModel.cs index a9f622c..1c06dce 100644 --- a/TVApps/TVApps/ViewModels/IAppsViewModel.cs +++ b/TVApps/TVApps/ViewModels/IAppsViewModel.cs @@ -37,5 +37,11 @@ namespace TVApps.ViewModels /// /// The next status name void ChangeCurrentStatus(AppsStatus newStatus); + + /// + /// Show delete popup + /// + /// The app label to display + void ShowDeletePopup(string appLabel); } } diff --git a/TVApps/TVApps/ViewModels/MainPageViewModel.cs b/TVApps/TVApps/ViewModels/MainPageViewModel.cs index bb579df..c032da8 100644 --- a/TVApps/TVApps/ViewModels/MainPageViewModel.cs +++ b/TVApps/TVApps/ViewModels/MainPageViewModel.cs @@ -79,6 +79,24 @@ namespace TVApps.ViewModels } /// + /// Gets or sets the app label to display at the delete popup + /// + public string DeletePopupAppLabel + { + get; + set; + } + + /// + /// Gets or sets whether delete popup is displayed + /// + public bool IsEnabledDeletePopup + { + get; + set; + } + + /// /// A command will be executed if the cancel button in FooterDeleteStatus is clicked /// /// @@ -115,6 +133,11 @@ namespace TVApps.ViewModels public AppsStatus CurrentStatus { get; private set; } /// + /// A command will be executed if the button of the delete popup is clicked + /// + public Command DeletePopupCommand { get; set; } + + /// /// Gets and Sets current sorting option of AppsHolder /// /// @@ -223,6 +246,56 @@ namespace TVApps.ViewModels } }); + DeletePopupCommand = new Command>(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(this, "OptionMenuDelete", (sender, arg) => { - appsHolder.DeleteApp(arg); + appsHolder.CheckDeleteApp(arg); }); TVHomeImpl.GetInstance.AppShortcutControllerInstance.AddFileSystemChangedListener((sender, arg) => @@ -296,6 +369,19 @@ namespace TVApps.ViewModels } /// + /// Show the delete popup + /// + /// The app label to display at the delete popup + public void ShowDeletePopup(string appLabel) + { + DeletePopupAppLabel = appLabel; + OnPropertyChanged("DeletePopupAppLabel"); + + IsEnabledDeletePopup = true; + OnPropertyChanged("IsEnabledDeletePopup"); + } + + /// /// A method for invoking PropertyChanged event /// /// The name of property diff --git a/TVApps/TVApps/Views/MainPage.xaml b/TVApps/TVApps/Views/MainPage.xaml index 96fcfaf..73800dc 100755 --- a/TVApps/TVApps/Views/MainPage.xaml +++ b/TVApps/TVApps/Views/MainPage.xaml @@ -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}"> diff --git a/TVApps/TVApps/Views/MainPage.xaml.cs b/TVApps/TVApps/Views/MainPage.xaml.cs index 84d7a86..972bed8 100644 --- a/TVApps/TVApps/Views/MainPage.xaml.cs +++ b/TVApps/TVApps/Views/MainPage.xaml.cs @@ -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); } } + /// + /// Identifies the app label bindable property + /// + public static readonly BindableProperty DeletePopupAppLabelProperty = BindableProperty.Create("DeletePopupAppLabel", typeof(string), typeof(MainPage), default(string)); + + /// + /// Gets or sets the app label to display at the delete popup + /// + public string DeletePopupAppLabel + { + get { return (string)GetValue(DeletePopupAppLabelProperty); } + set { SetValue(DeletePopupAppLabelProperty, value); } + } + + /// + /// Identifies the delete popup visibility bindable property + /// + public static readonly BindableProperty IsEnabledDeletePopupProperty = BindableProperty.Create("IsEnabledDeletePopup", typeof(bool), typeof(MainPage), default(bool)); + + /// + /// Gets or sets whether delete popup is displayed + /// + public bool IsEnabledDeletePopup + { + get { return (bool)GetValue(IsEnabledDeletePopupProperty); } + set { SetValue(IsEnabledDeletePopupProperty, value); } + } + + /// + /// Identifies the delete popup command bindable property + /// + public static readonly BindableProperty DeletePopupCommandProperty = BindableProperty.Create("DeletePopupCommand", typeof(Command), typeof(MainPage), default(Command)); + + /// + /// A command will be executed if the button of the delete popup is clicked + /// + public ICommand DeletePopupCommand + { + get { return (ICommand)GetValue(DeletePopupCommandProperty); } + set { SetValue(DeletePopupCommandProperty, value); } + } + /* private async void PlayHideAnimation() { @@ -131,12 +175,23 @@ namespace TVApps.Views /// /// The source of the event /// The event that is occurred when property of MainPage is changed - 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 ret = new Dictionary(); + ret.Add("AppLabel", DeletePopupAppLabel); + ret.Add("answer", answer ? "yes" : "no"); + DeletePopupCommand?.Execute(ret); + } + } } /// -- 2.7.4