From 9c34b786f0021eb0351d8fd062cad12db867765d Mon Sep 17 00:00:00 2001 From: cskim Date: Sat, 11 Mar 2017 16:41:49 +0900 Subject: [PATCH] - Add Pin/Unpin function - Add Sorting function(Asc,desc) - Fix AppShortcutStorage - Modify Util classes Change-Id: Ibefb5103c44c250a78dde174cf72dcadcec18068 --- .../DataModels/AppShortcutInfo.cs | 3 + .../DataModels/CommandAction.cs | 3 +- .../DataModels/ShortcutInfo.cs | 16 ++ .../DataModels/StateDescription.cs | 6 + .../LibTVRefCommonPortable.csproj | 1 + .../Models/AppShortcutController.cs | 90 ++++--- .../Utils/AppControlUtils.cs | 30 +-- .../Utils/AppShortcutStorage.cs | 68 +++-- .../Utils/IPackageManager.cs | 4 + .../Utils/IPlatformNotification.cs | 28 +++ .../Utils/PackageManagerUtils.cs | 47 ++-- LibTVRefCommonTizen/LibTVRefCommonTizen.cs | 12 - .../LibTVRefCommonTizen.csproj | 1 - .../Ports/ApplicationManagerPort.cs | 7 - .../Ports/PackageManagerPort.cs | 57 ++++- TVApps/TVApps.TizenTV/TVApps.TizenTV.cs | 74 +++++- TVApps/TVApps.TizenTV/TVApps.TizenTV.csproj | 3 + TVApps/TVApps/TVApps.cs | 55 +++- TVApps/TVApps/TVApps.csproj | 2 + TVApps/TVApps/ViewModels/AppsHolder.cs | 234 ++++++++++++++++++ TVApps/TVApps/ViewModels/AppsListSorter.cs | 11 +- TVApps/TVApps/ViewModels/IAppsViewModel.cs | 24 ++ TVApps/TVApps/ViewModels/MainPageViewModel.cs | 200 +++++---------- TVApps/TVApps/Views/FooterDeleteStatus.xaml | 5 +- TVApps/TVApps/Views/FooterNormalStatus.xaml | 10 +- TVApps/TVApps/Views/FooterPinStatus.xaml | 26 +- TVApps/TVApps/Views/FooterPinStatus.xaml.cs | 2 +- TVApps/TVApps/Views/MainPage.xaml | 226 ++++++++++------- TVApps/TVApps/Views/MainPage.xaml.cs | 48 ++-- .../bin/Debug/TVHome.TizenTV.tpk | Bin 1700422 -> 1564621 bytes TVHome/TVHome.TizenTV/tizen-manifest.xml | 1 + TVHome/TVHome/ViewModels/MainPageViewModel.cs | 4 +- 32 files changed, 885 insertions(+), 413 deletions(-) create mode 100644 LibTVRefCommonPortable/Utils/IPlatformNotification.cs delete mode 100644 LibTVRefCommonTizen/LibTVRefCommonTizen.cs create mode 100644 TVApps/TVApps/ViewModels/AppsHolder.cs create mode 100644 TVApps/TVApps/ViewModels/IAppsViewModel.cs diff --git a/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs b/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs index 3814d7e..a0dc7a1 100644 --- a/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs +++ b/LibTVRefCommonPortable/DataModels/AppShortcutInfo.cs @@ -33,8 +33,11 @@ namespace LibTVRefCommmonPortable.DataModels [XmlIgnore] public bool IsRemovable { get; set; } + + [XmlIgnore] public DateTime Installed { get; set; } + [XmlIgnore] public DateTime LastUsed { get; set; } public override void UpdateState() diff --git a/LibTVRefCommonPortable/DataModels/CommandAction.cs b/LibTVRefCommonPortable/DataModels/CommandAction.cs index d5dda84..a46e12a 100644 --- a/LibTVRefCommonPortable/DataModels/CommandAction.cs +++ b/LibTVRefCommonPortable/DataModels/CommandAction.cs @@ -21,12 +21,13 @@ namespace LibTVRefCommonPortable.DataModels { public class CommandAction : IAction { + public string NextStateDescription { get; set; } public ICommand Command { get; set; } public string CommandParameter { get; set; } public string Execute() { Command.Execute(CommandParameter); - return null; + return NextStateDescription; } } } diff --git a/LibTVRefCommonPortable/DataModels/ShortcutInfo.cs b/LibTVRefCommonPortable/DataModels/ShortcutInfo.cs index c14ccba..cfb1b11 100644 --- a/LibTVRefCommonPortable/DataModels/ShortcutInfo.cs +++ b/LibTVRefCommonPortable/DataModels/ShortcutInfo.cs @@ -62,6 +62,22 @@ namespace LibTVRefCommmonPortable.DataModels return false; } + if (CurrentStateDescription != null && + CurrentStateDescription == stateDescriptions[state]) + { + return true; + } + + // TODO : remove, for debugging purpose + foreach (var item in stateDescriptions) + { + if (item.Value.Equals(CurrentStateDescription)) + { + DebuggingUtils.Dbg("[" + item.Key + "] => [" + state + "]"); + break; + } + } + CurrentStateDescription = stateDescriptions[state]; OnPropertyChanged("CurrentStateDescription"); return true; diff --git a/LibTVRefCommonPortable/DataModels/StateDescription.cs b/LibTVRefCommonPortable/DataModels/StateDescription.cs index 0a68f3e..0ffc05c 100644 --- a/LibTVRefCommonPortable/DataModels/StateDescription.cs +++ b/LibTVRefCommonPortable/DataModels/StateDescription.cs @@ -18,6 +18,12 @@ namespace LibTVRefCommmonPortable.DataModels { public class StateDescription { + public StateDescription() + { + Label = ""; + IconPath = ""; + } + public string Label { get; diff --git a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj index 1744dc7..05c8a62 100644 --- a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj +++ b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj @@ -68,6 +68,7 @@ + diff --git a/LibTVRefCommonPortable/Models/AppShortcutController.cs b/LibTVRefCommonPortable/Models/AppShortcutController.cs index f975993..8de24f3 100755 --- a/LibTVRefCommonPortable/Models/AppShortcutController.cs +++ b/LibTVRefCommonPortable/Models/AppShortcutController.cs @@ -27,8 +27,6 @@ namespace LibTVRefCommmonPortable.Models { public class AppShortcutController { - private List returnPinnedAppsInfo = new List(); - public AppShortcutController() { @@ -36,6 +34,7 @@ namespace LibTVRefCommmonPortable.Models public async Task> GetInstalledApps() { + DebuggingUtils.Dbg(">AppShortcutController, GetInstalledApps - start"); IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); List appShortcutInfoList = new List(); @@ -66,10 +65,11 @@ namespace LibTVRefCommmonPortable.Models appShortcutInfoList.Add(appShortcutInfo); } + DebuggingUtils.Dbg(" returnPinnedAppsInfo) { var allAppsStateDescription = new StateDescription() { @@ -86,7 +86,7 @@ namespace LibTVRefCommmonPortable.Models allAppsShortcutInfo.StateDescriptions.Add("default", allAppsStateDescription); allAppsShortcutInfo.CurrentStateDescription = allAppsStateDescription; - returnPinnedAppsInfo.Add(allAppsShortcutInfo); + returnPinnedAppsInfo.Insert(0, allAppsShortcutInfo); var mediaHubStateDescription = new StateDescription() { @@ -102,10 +102,10 @@ namespace LibTVRefCommmonPortable.Models mediaHubShortcutInfo.StateDescriptions.Add("default", mediaHubStateDescription); mediaHubShortcutInfo.CurrentStateDescription = mediaHubStateDescription; - returnPinnedAppsInfo.Add(mediaHubShortcutInfo); + returnPinnedAppsInfo.Insert(1, mediaHubShortcutInfo); } - private void AppendAddPinShortcut() + private void AppendAddPinShortcut(ref List returnPinnedAppsInfo) { var addPinStateDescription = new StateDescription() { @@ -125,54 +125,76 @@ namespace LibTVRefCommmonPortable.Models returnPinnedAppsInfo.Add(addPinShortcutInfo); } - public IEnumerable GetPinnedApps() + private List GetPinnedApps() { IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); IEnumerable pinned_apps_info = AppShortcutStorage.Read(); string[] icons = { "ic_black.png", "ic_blue.png", "ic_green.png", "ic_red.png", "ic_yellow.png", "AppIcon.png" }; - AddAllAppsAndMediaHubShortcut(); + List returnPinnedAppsInfo = new List(); foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info) { Dictionary appInfo = applicationManagerPort.GetInstalledApplication(appShortcutInfo.AppID); - if (appInfo != null) + if (appInfo == null) { - string appLabel; - string appIconPath; + continue; + } - appInfo.TryGetValue("Label", out appLabel); - appInfo.TryGetValue("IconPath", out appIconPath); + string appLabel; + string appIconPath; - DebuggingUtils.Dbg("AppID: " + appShortcutInfo.AppID + ", Label : " + appLabel + " IconPath : " + appIconPath); - Random random = new Random(); - var defaultStateDescription = new StateDescription() - { - Label = appLabel, - IconPath = appIconPath ?? icons[random.Next(0, 6)], - Action = new AppControlAction - { - AppID = appShortcutInfo.AppID, - } - }; - - appShortcutInfo.StateDescriptions.Add("default", defaultStateDescription); - appShortcutInfo.CurrentStateDescription = defaultStateDescription; - appShortcutInfo.IsPinned = true; - returnPinnedAppsInfo.Add(appShortcutInfo); - } - else + appInfo.TryGetValue("Label", out appLabel); + appInfo.TryGetValue("IconPath", out appIconPath); + + DebuggingUtils.Dbg("AppID: " + appShortcutInfo.AppID + ", Label : " + appLabel + " IconPath : " + appIconPath); + Random random = new Random(); + var defaultStateDescription = new StateDescription() { - // TODO : Remove the broken appInfo from pinned_apps_info - } + Label = appLabel, + IconPath = appIconPath ?? icons[random.Next(0, 6)], + Action = new AppControlAction + { + AppID = appShortcutInfo.AppID, + } + }; + + appShortcutInfo.StateDescriptions.Add("default", defaultStateDescription); + appShortcutInfo.CurrentStateDescription = defaultStateDescription; + appShortcutInfo.IsPinned = true; + returnPinnedAppsInfo.Add(appShortcutInfo); } - AppendAddPinShortcut(); + return returnPinnedAppsInfo; + } + + public IEnumerable GetPinnedAppsWithDefaultShortcuts() + { + List returnPinnedAppsInfo = GetPinnedApps(); + + AddAllAppsAndMediaHubShortcut(ref returnPinnedAppsInfo); + AppendAddPinShortcut(ref returnPinnedAppsInfo); return returnPinnedAppsInfo; } + public Dictionary GetPinnedAppsAppIDs() + { + IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); + IEnumerable pinned_apps_info = AppShortcutStorage.Read(); + string[] icons = { "ic_black.png", "ic_blue.png", "ic_green.png", "ic_red.png", "ic_yellow.png", "AppIcon.png" }; + + Dictionary pinnedAppsDictionary = new Dictionary(); + + foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info) + { + pinnedAppsDictionary.Add(appShortcutInfo.AppID, appShortcutInfo.AppID); + } + + return pinnedAppsDictionary; + } + public void UpdatePinnedApps(IEnumerable pinnedAppsInfo) { AppShortcutStorage.Write(pinnedAppsInfo); diff --git a/LibTVRefCommonPortable/Utils/AppControlUtils.cs b/LibTVRefCommonPortable/Utils/AppControlUtils.cs index 7d4a467..304262f 100644 --- a/LibTVRefCommonPortable/Utils/AppControlUtils.cs +++ b/LibTVRefCommonPortable/Utils/AppControlUtils.cs @@ -26,36 +26,14 @@ namespace LibTVRefCommmonPortable.Utils { public sealed class AppControlUtils { - private static IAppControl iam; - private static readonly AppControlUtils instance = new AppControlUtils(); - - public static AppControlUtils Instance - { - get { return instance; } - } - - private class DefaultAM : IAppControl - { - public void SendLaunchRequest(string PkgID) - { - } - } - - private AppControlUtils() + public static void SendLaunchRequest(string PkgID) { - if (DependencyService.Get() != null) - { - iam = DependencyService.Get(); - } - else + if (DependencyService.Get() == null) { - iam = new DefaultAM(); + return; } - } - public static void SendLaunchRequest(string PkgID) - { - iam.SendLaunchRequest(PkgID); + DependencyService.Get().SendLaunchRequest(PkgID); } } } diff --git a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs index d691cf4..6ef851e 100644 --- a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs +++ b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs @@ -104,36 +104,74 @@ namespace LibTVRefCommmonPortable.Utils { IFileSystemAPIs fileSystem = DependencyService.Get(); XmlSerializer serializer = new XmlSerializer(typeof(List)); - Stream fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.Open); - if (fileStream == null) + Stream fileStream = null; + + try + { + fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.Open); + if (fileStream == null) + { + DebuggingUtils.Dbg("OpenFile failed : " + storagePath); + // TODO : Remove later, below lines are sample apps for demonstration. + List result = GetSampleList(); + Write(result); + return result; + } + + StreamReader streamReader = new StreamReader(fileStream); + List list = (List)serializer.Deserialize(streamReader); + + return list; + } + catch (Exception e) { - DebuggingUtils.Dbg("OpenFile failed : " + storagePath); - // TODO : Remove later, below lines are sample apps for demonstration. + // TODO : recover xml file here! + DebuggingUtils.Err("XML Desearialize is failed, " + storagePath + ", " + e.Message); List result = GetSampleList(); Write(result); return result; } - - StreamReader streamReader = new StreamReader(fileStream); - List list = (List)serializer.Deserialize(streamReader); - fileSystem.CloseFile(fileStream); - return list; + finally + { + if (fileStream != null) + { + fileSystem.CloseFile(fileStream); + } + } } public static bool Write(IEnumerable pinnedAppInfo) { IFileSystemAPIs fileSystem = DependencyService.Get(); XmlSerializer serializer = new XmlSerializer(typeof(List)); - Stream fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.OpenOrCreate); - if (fileStream == null) + Stream fileStream = null; + + try + { + fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.Create); + if (fileStream == null) + { + return false; + } + + StreamWriter streamWriter = new StreamWriter(fileStream); + serializer.Serialize(streamWriter, pinnedAppInfo); + streamWriter.Flush(); + } + catch (Exception e) { + DebuggingUtils.Err("XML Searialize is failed, " + storagePath + ", " + e.Message); return false; } + finally + { + if (fileStream != null) + { + fileSystem.CloseFile(fileStream); + } + + } - StreamWriter streamWriter = new StreamWriter(fileStream); - serializer.Serialize(streamWriter, pinnedAppInfo); - streamWriter.Flush(); - fileSystem.CloseFile(fileStream); return true; } diff --git a/LibTVRefCommonPortable/Utils/IPackageManager.cs b/LibTVRefCommonPortable/Utils/IPackageManager.cs index 073609a..a9bbff0 100644 --- a/LibTVRefCommonPortable/Utils/IPackageManager.cs +++ b/LibTVRefCommonPortable/Utils/IPackageManager.cs @@ -36,5 +36,9 @@ namespace LibTVRefCommmonPortable.Utils Dictionary GetPackageList(); string GetPackage(string PkgID); + + bool UninstallPackage(string pkgID); + + bool UninstallPackageByAppID(string appID); } } diff --git a/LibTVRefCommonPortable/Utils/IPlatformNotification.cs b/LibTVRefCommonPortable/Utils/IPlatformNotification.cs new file mode 100644 index 0000000..3a8c2e1 --- /dev/null +++ b/LibTVRefCommonPortable/Utils/IPlatformNotification.cs @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +namespace LibTVRefCommonPortable.Utils +{ + public interface IPlatformNotification + { + void OnBackKeyPressed(); + + void OnAppInstalled(string pkgID); + + void OnAppUninstalled(string pkgID); + } +} diff --git a/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs b/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs index 7ccaf4e..dd18a18 100644 --- a/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs +++ b/LibTVRefCommonPortable/Utils/PackageManagerUtils.cs @@ -27,47 +27,44 @@ namespace LibTVRefCommmonPortable.Utils { public sealed class PackageManagerUtils { - private static IPackageManager ipm; - private static readonly PackageManagerUtils instance = new PackageManagerUtils(); - - public static PackageManagerUtils Instance + public static Dictionary GetPackageList() { - get { return instance; } + if (DependencyService.Get() == null) + { + return new Dictionary(); + } + + return DependencyService.Get().GetPackageList(); } - private class DefaultPM : IPackageManager + public static string GetPackage(string PkgID) { - public Dictionary GetPackageList() + if (DependencyService.Get() == null) { - return null; + return ""; } - public string GetPackage(string PkgID) - { - return null; - } + return DependencyService.Get().GetPackage(PkgID); } - private PackageManagerUtils() + public static bool UninstallPackage(string pkgID) { - if (DependencyService.Get() != null) + if (DependencyService.Get() == null) { - ipm = DependencyService.Get(); + return false; } - else - { - ipm = new DefaultPM(); - } - } - public Dictionary GetPackageList() - { - return ipm.GetPackageList(); + return DependencyService.Get().UninstallPackage(pkgID); } - public string GetPackage(string PkgID) + public static bool UninstallPackageByAppID(string appID) { - return ipm.GetPackage(PkgID); + if (DependencyService.Get() == null) + { + return false; + } + + return DependencyService.Get().UninstallPackageByAppID(appID); } } } diff --git a/LibTVRefCommonTizen/LibTVRefCommonTizen.cs b/LibTVRefCommonTizen/LibTVRefCommonTizen.cs deleted file mode 100644 index d53b4eb..0000000 --- a/LibTVRefCommonTizen/LibTVRefCommonTizen.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace LibTVRefCommonTizen -{ - public class MyLibrary - { - public string MyMethod() - { - return "Hello Tizen Library!!!"; - } - } -} diff --git a/LibTVRefCommonTizen/LibTVRefCommonTizen.csproj b/LibTVRefCommonTizen/LibTVRefCommonTizen.csproj index 6df096f..565835c 100644 --- a/LibTVRefCommonTizen/LibTVRefCommonTizen.csproj +++ b/LibTVRefCommonTizen/LibTVRefCommonTizen.csproj @@ -45,7 +45,6 @@ - diff --git a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs index c2e8b42..1b8e49d 100644 --- a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs +++ b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs @@ -106,8 +106,6 @@ namespace LibTVRefCommonTizen.Ports foreach (var appInfo in installedList) { - DebuggingPort.D("-------------------------------------"); - DebuggingPort.D("TRY" + appInfo.ToString()); if (appInfo.IsNoDisplay) { continue; @@ -119,16 +117,11 @@ namespace LibTVRefCommonTizen.Ports continue; } - DebuggingPort.D("TRY" + pkgInfo.ToString()); - if (pkgInfo.IsSystemPackage) { continue; } - DebuggingPort.D("ADD" + appInfo.ToString()); - - result = new string[3]; result[0] = (appInfo.Label != null) ? appInfo.Label : null; diff --git a/LibTVRefCommonTizen/Ports/PackageManagerPort.cs b/LibTVRefCommonTizen/Ports/PackageManagerPort.cs index 99d99c3..b0f61b0 100644 --- a/LibTVRefCommonTizen/Ports/PackageManagerPort.cs +++ b/LibTVRefCommonTizen/Ports/PackageManagerPort.cs @@ -24,30 +24,56 @@ using Tizen; using Tizen.Applications; using LibTVRefCommmonPortable.Utils; +using LibTVRefCommonPortable.Utils; namespace LibTVRefCommonTizen.Ports { public class PackageManagerPort : IPackageManager { + private static IPlatformNotification Notification + { + get; + set; + } + public PackageManagerPort() { + + } + + public static void RegisterCallbacks(IPlatformNotification app) + { + Notification = app; PackageManager.InstallProgressChanged += PackageManager_InstallProgressChanged; PackageManager.UninstallProgressChanged += PackageManager_UninstallProgressChanged; } - private void PackageManager_UninstallProgressChanged(object sender, PackageManagerEventArgs e) + public static void DeregisterCallbacks() + { + Notification = null; + PackageManager.InstallProgressChanged -= PackageManager_InstallProgressChanged; + PackageManager.UninstallProgressChanged -= PackageManager_UninstallProgressChanged; + } + + private static void PackageManager_UninstallProgressChanged(object sender, PackageManagerEventArgs e) { if (e.State == PackageEventState.Completed) { - DebuggingUtils.Dbg("uninstall completed"); + if (Notification != null) + { + Notification.OnAppUninstalled(e.PackageId); + } } } - private void PackageManager_InstallProgressChanged(object sender, PackageManagerEventArgs e) + private static void PackageManager_InstallProgressChanged(object sender, PackageManagerEventArgs e) { if (e.State == PackageEventState.Completed) { - DebuggingUtils.Dbg("install completed"); + if (Notification != null) + { + Notification.OnAppInstalled(e.PackageId); + } } } @@ -78,5 +104,28 @@ namespace LibTVRefCommonTizen.Ports return (tempItem != null) ? tempItem.Label : null; } + + public bool UninstallPackage(string pkgID) + { + Package tempItem = PackageManager.GetPackage(pkgID); + if (tempItem == null) + { + return false; + } + + return PackageManager.Uninstall(tempItem.Id, tempItem.PackageType); + } + + public bool UninstallPackageByAppID(string appID) + { + string pkgID = PackageManager.GetPackageIdByApplicationId(appID); + if (pkgID == null || + pkgID.Length == 0) + { + return false; + } + + return UninstallPackage(pkgID); + } } } \ No newline at end of file diff --git a/TVApps/TVApps.TizenTV/TVApps.TizenTV.cs b/TVApps/TVApps.TizenTV/TVApps.TizenTV.cs index 44387bf..f34d510 100644 --- a/TVApps/TVApps.TizenTV/TVApps.TizenTV.cs +++ b/TVApps/TVApps.TizenTV/TVApps.TizenTV.cs @@ -1,29 +1,81 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using LibTVRefCommonPortable.Utils; using LibTVRefCommonTizen.Ports; +using LibTVRefCommonTizen; namespace TVApps.TizenTV { - class Program : Xamarin.Forms.Platform.Tizen.FormsApplication + public class Program : Xamarin.Forms.Platform.Tizen.FormsApplication { + IPlatformNotification notification; + protected override void OnCreate() { base.OnCreate(); - LoadApplication(new App()); + var app = new App(); + notification = app; + LoadApplication(app); + + PackageManagerPort.RegisterCallbacks(notification); + MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName, true); + MainWindow.KeyUp += BackkeyListener; + } + + private void BackkeyListener(object sender, ElmSharp.EvasKeyEventArgs e) + { + if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName) == 0) + { + if (notification != null) + { + notification.OnBackKeyPressed(); + } + } + } + + protected override void OnTerminate() + { + base.OnTerminate(); + + notification = null; + PackageManagerPort.DeregisterCallbacks(); + MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName); + MainWindow.KeyUp -= BackkeyListener; } static void Main(string[] args) { var app = new Program(); - global::Xamarin.Forms.DependencyService.Register(); - global::Xamarin.Forms.DependencyService.Register(); - global::Xamarin.Forms.DependencyService.Register(); - global::Xamarin.Forms.DependencyService.Register(); - global::Xamarin.Forms.DependencyService.Register(); - global::Xamarin.Forms.DependencyService.Register(); - global::Xamarin.Forms.DependencyService.Register(); - global::Xamarin.Forms.DependencyService.Register(); - global::Xamarin.Forms.DependencyService.Register(); + + Xamarin.Forms.DependencyService.Register(); + Xamarin.Forms.DependencyService.Register(); + Xamarin.Forms.DependencyService.Register(); + Xamarin.Forms.DependencyService.Register(); + Xamarin.Forms.DependencyService.Register(); + Xamarin.Forms.DependencyService.Register(); + Xamarin.Forms.DependencyService.Register(); + Xamarin.Forms.DependencyService.Register(); + Xamarin.Forms.DependencyService.Register(); Xamarin.Forms.Platform.Tizen.Forms.Init(app); + app.Run(args); + } + } } diff --git a/TVApps/TVApps.TizenTV/TVApps.TizenTV.csproj b/TVApps/TVApps.TizenTV/TVApps.TizenTV.csproj index 283d6ef..151e5a2 100644 --- a/TVApps/TVApps.TizenTV/TVApps.TizenTV.csproj +++ b/TVApps/TVApps.TizenTV/TVApps.TizenTV.csproj @@ -68,6 +68,9 @@ TVApps + + +