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);
+ }
}
}
/// <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);
}
}
/// </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
/// </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>
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
}
/// <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
{
NextStateDescription = AppsStatus.Delete.ToString().ToLower(),
Command = new Command<string>((key) =>
{
- DeleteApp(key);
+ CheckDeleteApp(key);
}),
CommandParameter = item.AppID
}
/// 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))
{
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)
/// </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);
}
}
}
/// <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"/>
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"/>
}
});
+ 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
MessagingCenter.Subscribe<AppShortcutInfo, string>(this, "OptionMenuDelete", (sender, arg) =>
{
- appsHolder.DeleteApp(arg);
+ appsHolder.CheckDeleteApp(arg);
});
TVHomeImpl.GetInstance.AppShortcutControllerInstance.AddFileSystemChangedListener((sender, arg) =>
}
/// <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>
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>
using LibTVRefCommonPortable.Utils;
using System.Threading;
using System.Threading.Tasks;
+using System.Windows.Input;
+using System.Collections.Generic;
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()
{
/// </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>