using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace LibTVRefCommonPortable.Utils
{
///
/// A class provides application controlling functions
///
public sealed class ApplicationManagerUtils
{
///
/// A instance of platform specific application manager port.
///
private static IApplicationManagerAPIs applicationManagerAPIs;
///
/// A instance of ApplicationManagerUtils
///
private static readonly ApplicationManagerUtils instance = new ApplicationManagerUtils();
///
/// A getter of ApplicationManagerUtils instance
///
public static ApplicationManagerUtils Instance
{
get
{
return instance;
}
}
///
/// A unit testing stub of IApplicationManagerAPIs.
///
private class TestingStub : IApplicationManagerAPIs
{
public void DeleteAllRecentApplication()
{
throw new NotImplementedException();
}
public void DeleteRecentApplication(string appId)
{
throw new NotImplementedException();
}
public Task> GetAllInstalledApplication()
{
throw new NotImplementedException();
}
public Task GetAppIDbyAppLabel(string appLabel)
{
throw new NotImplementedException();
}
public bool GetAppInfoRemovable(string appID)
{
throw new NotImplementedException();
}
public Dictionary GetInstalledApplication(string applicationId)
{
throw new NotImplementedException();
}
public IEnumerable GetRecentApplications()
{
IList testData = new List();
testData.Add(new RecentApp
{
InstanceID = "recentapp1",
InstanceLabel = "recentapp1",
AppID = "org.tizen.recentapp1",
Applabel = "recentapp1",
IconPath = "/test/recentapp1",
LaunchedTime = new DateTime(2014, 11, 12),
Uri = "uri/recentapp1",
ScreenShot = "screenshot/recentapp1",
});
testData.Add(new RecentApp
{
InstanceID = "recentapp2.noscreenshot",
InstanceLabel = "recentapp2.noscreenshot",
AppID = "org.tizen.recentapp2.noscreenshot",
Applabel = "recentapp2.noscreenshot",
IconPath = "/test/recentapp2",
LaunchedTime = new DateTime(2014, 11, 12),
Uri = "uri/recentapp2",
});
testData.Add(new RecentApp
{
InstanceID = "invalid.recentapp3.nolabel",
AppID = "invalid.org.tizen.recentapp3.nolabel",
IconPath = "/test/recentapp3",
LaunchedTime = new DateTime(2014, 11, 12),
Uri = "uri/recentapp3",
ScreenShot = "screenshot/recentapp3",
});
testData.Add(new RecentApp
{
InstanceID = "invalid.recentapp4.notime",
AppID = "invalid.org.tizen.recentapp4.notime",
Applabel = "recentapp4.notime",
IconPath = "/test/recentapp4",
Uri = "uri/recentapp4",
ScreenShot = "screenshot/recentapp4",
});
testData.Add(new RecentApp
{
InstanceID = "recentapp5",
InstanceLabel = "recentapp5",
AppID = "org.tizen.recentapp5",
Applabel = "recentapp5",
IconPath = "/test/recentapp5",
LaunchedTime = new DateTime(2017, 05, 02),
Uri = "uri/recentapp5",
ScreenShot = "screenshot/recentapp5",
});
testData.Add(new RecentApp
{
InstanceID = "recentapp6",
InstanceLabel = "recentapp6",
AppID = "org.tizen.recentapp6",
Applabel = "recentapp6",
IconPath = "/test/recentapp6",
LaunchedTime = new DateTime(2017, 02, 26),
Uri = "uri/recentapp6",
ScreenShot = "screenshot/recentapp6",
});
testData.Add(new RecentApp
{
InstanceID = "recentapp7",
InstanceLabel = "recentapp7",
AppID = "org.tizen.recentapp7",
Applabel = "recentapp7",
IconPath = "/test/recentapp7",
LaunchedTime = new DateTime(2016, 04, 25),
Uri = "uri/recentapp7",
ScreenShot = "screenshot/recentapp7",
});
return testData;
}
}
///
/// A constructor
///
private ApplicationManagerUtils()
{
applicationManagerAPIs = new TestingStub();
try
{
if (DependencyService.Get() != null)
{
applicationManagerAPIs = DependencyService.Get();
}
}
catch (InvalidOperationException e)
{
DebuggingUtils.Err(e.Message);
}
}
///
/// A method for removing all recent applications
///
public void DeleteAllRecentApplication()
{
applicationManagerAPIs.DeleteAllRecentApplication();
}
///
/// A method for removing the specified recent application
///
/// An application ID
public void DeleteRecentApplication(string appId)
{
applicationManagerAPIs.DeleteRecentApplication(appId);
}
///
/// Gets the information of the recent applications
///
/// The list of the recent applications
public IEnumerable GetRecentApplications()
{
return applicationManagerAPIs.GetRecentApplications();
}
///
/// Gets the information of the specified application with the app ID
///
/// The app Id to get
/// The information of the installed application
public Dictionary GetInstalledApplication(string appID)
{
return applicationManagerAPIs.GetInstalledApplication(appID);
}
///
/// Gets the information of the installed applications asynchronously
///
/// The list of the installed applications
public Task> GetAllInstalledApplication()
{
return applicationManagerAPIs.GetAllInstalledApplication();
}
///
/// Checks whether application is removable
///
/// The app ID to get
/// If the application is removable, true; otherwise, false
public bool GetAppInfoRemovable(string appID)
{
return applicationManagerAPIs.GetAppInfoRemovable(appID);
}
///
/// Gets the app ID by the app label
///
/// the app label to get
/// the app ID of the app label
public Task GetAppIDbyAppLabel(string appLabel)
{
return applicationManagerAPIs.GetAppIDbyAppLabel(appLabel);
}
}
}