From: cskim Date: Thu, 16 Mar 2017 08:42:40 +0000 (+0900) Subject: Add AppControl handling for Home, Apps X-Git-Tag: submit/tizen/20170808.015446~190 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3987116395779f485df3eea669f105c57e517e24;p=profile%2Ftv%2Fapps%2Fdotnet%2Fhome.git Add AppControl handling for Home, Apps (TODO) need to provide selection app info to Home. Change-Id: I7cd94a2f65310975320e3fcabf511bd7e777bb70 --- diff --git a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj index bde6e16..3aa2f42 100644 --- a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj +++ b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj @@ -67,6 +67,7 @@ + diff --git a/LibTVRefCommonPortable/Models/AppShortcutController.cs b/LibTVRefCommonPortable/Models/AppShortcutController.cs index de8edff..cdf27ce 100755 --- a/LibTVRefCommonPortable/Models/AppShortcutController.cs +++ b/LibTVRefCommonPortable/Models/AppShortcutController.cs @@ -26,6 +26,8 @@ namespace LibTVRefCommonPortable.Models { public class AppShortcutController { + private static String DefaultAppIcon = "AppIcon.png"; + public AppShortcutController() { @@ -33,7 +35,6 @@ namespace LibTVRefCommonPortable.Models public async Task> GetInstalledApps() { - DebuggingUtils.Dbg(">AppShortcutController, GetInstalledApps - start"); IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); List appShortcutInfoList = new List(); @@ -64,11 +65,10 @@ namespace LibTVRefCommonPortable.Models appShortcutInfoList.Add(appShortcutInfo); } - DebuggingUtils.Dbg(" returnPinnedAppsInfo) + private void AddAllAppsAndMediaHubShortcut(ref List returnPinnedAppsInfo) { var allAppsStateDescription = new StateDescription() { @@ -104,15 +104,20 @@ namespace LibTVRefCommonPortable.Models returnPinnedAppsInfo.Insert(1, mediaHubShortcutInfo); } - private void AppendAddPinShortcut(ref List returnPinnedAppsInfo) + private void AppendAddPinShortcut(ref List returnPinnedAppsInfo) { var addPinStateDescription = new StateDescription() { Label = "Add pin", IconPath = "ic_tizen_home_list_addpin_normal.png", - Action = new AppControlAction + Action = new CommandAction() { - AppID = "org.tizen.example.TVApps.TizenTV", + NextStateDescription = "default", + Command = new Command((key) => + { + AppControlUtils.SendAddAppRequestToApps(); + }), + CommandParameter = "", } }; @@ -124,13 +129,12 @@ namespace LibTVRefCommonPortable.Models returnPinnedAppsInfo.Add(addPinShortcutInfo); } - private List GetPinnedApps() + private async Task> 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" }; + IEnumerable pinned_apps_info = await AppShortcutStorage.Read(); - List returnPinnedAppsInfo = new List(); + List returnPinnedAppsInfo = new List(); foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info) { @@ -147,12 +151,11 @@ namespace LibTVRefCommonPortable.Models appInfo.TryGetValue("Label", out appLabel); appInfo.TryGetValue("IconPath", out appIconPath); - DebuggingUtils.Dbg("AppID: " + appShortcutInfo.AppID + ", Label : " + appLabel + " IconPath : " + appIconPath); - Random random = new Random(); + DebuggingUtils.Dbg("AppID: " + appShortcutInfo.AppID + ", Label : " + appLabel); var defaultStateDescription = new StateDescription() { Label = appLabel, - IconPath = appIconPath ?? icons[random.Next(0, 6)], + IconPath = appIconPath ?? DefaultAppIcon, Action = new AppControlAction { AppID = appShortcutInfo.AppID, @@ -168,9 +171,9 @@ namespace LibTVRefCommonPortable.Models return returnPinnedAppsInfo; } - public IEnumerable GetPinnedAppsWithDefaultShortcuts() + public IEnumerable GetDefaultShortcuts() { - List returnPinnedAppsInfo = GetPinnedApps(); + List returnPinnedAppsInfo = new List(); AddAllAppsAndMediaHubShortcut(ref returnPinnedAppsInfo); AppendAddPinShortcut(ref returnPinnedAppsInfo); @@ -178,11 +181,20 @@ namespace LibTVRefCommonPortable.Models return returnPinnedAppsInfo; } - public Dictionary GetPinnedAppsAppIDs() + public async Task> GetPinnedAppsWithDefaultShortcuts() + { + List returnPinnedAppsInfo = await GetPinnedApps(); + + AddAllAppsAndMediaHubShortcut(ref returnPinnedAppsInfo); + AppendAddPinShortcut(ref returnPinnedAppsInfo); + + return returnPinnedAppsInfo; + } + + public async Task> 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" }; + IEnumerable pinned_apps_info = await AppShortcutStorage.Read(); Dictionary pinnedAppsDictionary = new Dictionary(); @@ -199,12 +211,6 @@ namespace LibTVRefCommonPortable.Models AppShortcutStorage.Write(pinnedAppsInfo); } - private bool AddAppShortcutChangedListener() - { - // TODO : register to Tizen app framework to get notification of app list change. - return false; - } - public void AddFileSystemChangedListener(EventHandler eventListener) { if (AppShortcutStorage.Instance != null) diff --git a/LibTVRefCommonPortable/Models/RecentShortcutController.cs b/LibTVRefCommonPortable/Models/RecentShortcutController.cs index 300ba08..30d0ece 100644 --- a/LibTVRefCommonPortable/Models/RecentShortcutController.cs +++ b/LibTVRefCommonPortable/Models/RecentShortcutController.cs @@ -47,49 +47,7 @@ namespace LibTVRefCommonPortable.Models return false; } - public IEnumerable GetList() - { - // TODO : This is a clone of AppShorcutController.ReadFromFile(). Write new code by using RUA - IEnumerable pinned_apps_info = AppShortcutStorage.Read(); - IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); - List recentShortcutInfoList = new List(); - string[] icons = { "ic_black.png", "ic_blue.png", "ic_green.png", "ic_red.png", "ic_yellow.png", "AppIcon.png" }; - - foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info) - { - Dictionary appInfo = applicationManagerPort.GetInstalledApplication(appShortcutInfo.AppID); - - if (appInfo != null) - { - string appLabel; - string appIconPath; - - appInfo.TryGetValue("Label", out appLabel); - appInfo.TryGetValue("IconPath", out appIconPath); - - Random random = new Random(); - var defaultStateDescription = new StateDescription() - { - Label = appLabel, - IconPath = appIconPath ?? icons[random.Next(0, 6)], - Action = new AppControlAction - { - AppID = appShortcutInfo.AppID, - } - }; - var newRecentShortcutInfo = new RecentShortcutInfo(); - newRecentShortcutInfo.ScreenshotPath = "screenshot.png"; - // newRecentShortcutInfo.ScreenshotPath = "screenshot_" + appShortcutInfo.AppID + ".png"; - newRecentShortcutInfo.StateDescriptions.Add("default", defaultStateDescription); - newRecentShortcutInfo.CurrentStateDescription = defaultStateDescription; - recentShortcutInfoList.Add(newRecentShortcutInfo); - } - } - - return recentShortcutInfoList; - } - - public async Task> GetListAsync() + public async Task> GetList() { IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); List recentShortcutInfoList = new List(); @@ -107,7 +65,9 @@ namespace LibTVRefCommonPortable.Models } }; var recentShortcutInfo = new RecentShortcutInfo(); - recentShortcutInfo.ScreenshotPath = "screenshot_" + item.Value[0] + ".png"; + // TODO : Revert this after getting a API from app framework team. + //recentShortcutInfo.ScreenshotPath = "screenshot_" + item.Value[0] + ".png"; + recentShortcutInfo.ScreenshotPath = "screenshot.png"; recentShortcutInfo.StateDescriptions.Add("default", defaultStateDescription); recentShortcutInfo.CurrentStateDescription = defaultStateDescription; recentShortcutInfoList.Add(recentShortcutInfo); diff --git a/LibTVRefCommonPortable/Utils/AppControlUtils.cs b/LibTVRefCommonPortable/Utils/AppControlUtils.cs index 9195264..f71bfdd 100644 --- a/LibTVRefCommonPortable/Utils/AppControlUtils.cs +++ b/LibTVRefCommonPortable/Utils/AppControlUtils.cs @@ -14,7 +14,6 @@ * limitations under the License. */ -using LibTVRefCommonPortable.Utils; using Xamarin.Forms; namespace LibTVRefCommonPortable.Utils @@ -30,5 +29,35 @@ namespace LibTVRefCommonPortable.Utils DependencyService.Get().SendLaunchRequest(PkgID); } + + public static void SendAddAppRequestToApps() + { + if (DependencyService.Get() == null) + { + return; + } + + DependencyService.Get().SendAddAppRequestToApps(); + } + + public static void SendAppAddedNotificationToHome(string addedAddID) + { + if (DependencyService.Get() == null) + { + return; + } + + DependencyService.Get().SendAppAddedNotificationToHome(addedAddID); + } + + public static void SelfTerminate() + { + if (DependencyService.Get() == null) + { + return; + } + + DependencyService.Get().SelfTerminate(); + } } } diff --git a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs index 87dbe5e..643c6cf 100644 --- a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs +++ b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs @@ -15,17 +15,14 @@ */ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml; using System.Xml.Serialization; using System.IO; using LibTVRefCommonPortable.DataModels; -using LibTVRefCommonPortable.Utils; using Xamarin.Forms; +using System.Threading.Tasks; +using System.Diagnostics; namespace LibTVRefCommonPortable.Utils { @@ -100,77 +97,59 @@ namespace LibTVRefCommonPortable.Utils return pinnedAppsInfo; } - public static List Read() + public static async Task> Read() { IFileSystemAPIs fileSystem = DependencyService.Get(); - XmlSerializer serializer = new XmlSerializer(typeof(List)); - 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) + if (fileSystem.IsFileExist(storagePath) == false) { - // TODO : recover xml file here! - DebuggingUtils.Err("XML Desearialize is failed, " + storagePath + ", " + e.Message); + // TODO : Modify default pinned Apps + DebuggingUtils.Err("Set Default Pinned Apps" + storagePath); List result = GetSampleList(); Write(result); return result; } - finally + + for (int i = 0; i < 5; i++) { - if (fileStream != null) + if (fileSystem.IsFileReady(storagePath)) { - fileSystem.CloseFile(fileStream); + break; } + if (i >= 4) + { + DebuggingUtils.Err("Can't open storage" + storagePath); + return new List(); + } + await Task.Delay(100); + DebuggingUtils.Dbg("[" + i + "/5] Waiting for Writting" + storagePath); + } + + using (Stream fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.Open)) + { + Debug.Assert(fileStream != null); + + XmlSerializer serializer = new XmlSerializer(typeof(List)); + StreamReader streamReader = new StreamReader(fileStream); + List list = (List)serializer.Deserialize(streamReader); + + return list; } } public static bool Write(IEnumerable pinnedAppInfo) { IFileSystemAPIs fileSystem = DependencyService.Get(); - XmlSerializer serializer = new XmlSerializer(typeof(List)); - Stream fileStream = null; - try + using (Stream fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.Create)) { - fileStream = fileSystem.OpenFile(storagePath, UtilFileMode.Create); - if (fileStream == null) - { - return false; - } + Debug.Assert(fileStream != null); + XmlSerializer serializer = new XmlSerializer(typeof(List)); 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); - } - - } return true; } diff --git a/LibTVRefCommonPortable/Utils/IAppControl.cs b/LibTVRefCommonPortable/Utils/IAppControl.cs index 127658f..e261a0e 100644 --- a/LibTVRefCommonPortable/Utils/IAppControl.cs +++ b/LibTVRefCommonPortable/Utils/IAppControl.cs @@ -20,5 +20,9 @@ namespace LibTVRefCommonPortable.Utils public interface IAppControl { void SendLaunchRequest(string PkgID); + + void SendAddAppRequestToApps(); + + void SendAppAddedNotificationToHome(string addedAddID); } } diff --git a/LibTVRefCommonPortable/Utils/IAppLifeControl.cs b/LibTVRefCommonPortable/Utils/IAppLifeControl.cs new file mode 100644 index 0000000..44b0f11 --- /dev/null +++ b/LibTVRefCommonPortable/Utils/IAppLifeControl.cs @@ -0,0 +1,23 @@ +/* + * 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 IAppLifeControl + { + void SelfTerminate(); + } +} diff --git a/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs b/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs index 2555da1..63ec132 100644 --- a/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs +++ b/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs @@ -39,8 +39,13 @@ namespace LibTVRefCommonPortable.Utils public interface IFileSystemAPIs { Stream OpenFile(string filePath, UtilFileMode mode); + void Flush(Stream stream); + void CloseFile(Stream stream); + bool IsFileExist(String fileName); + + bool IsFileReady(String fileName); } } diff --git a/LibTVRefCommonPortable/Utils/IPlatformNotification.cs b/LibTVRefCommonPortable/Utils/IPlatformNotification.cs index 19f1f5d..c78426d 100644 --- a/LibTVRefCommonPortable/Utils/IPlatformNotification.cs +++ b/LibTVRefCommonPortable/Utils/IPlatformNotification.cs @@ -19,10 +19,12 @@ namespace LibTVRefCommonPortable.Utils { public interface IPlatformNotification { - void OnBackKeyPressed(); - void OnAppInstalled(string pkgID); void OnAppUninstalled(string pkgID); + + void OnPinAppRequestReceived(); + + void OnAppPinnedNotificationReceived(string appID); } } diff --git a/LibTVRefCommonTizen/Ports/AppControlPort.cs b/LibTVRefCommonTizen/Ports/AppControlPort.cs index f5022f0..72fca7e 100644 --- a/LibTVRefCommonTizen/Ports/AppControlPort.cs +++ b/LibTVRefCommonTizen/Ports/AppControlPort.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2017 Samsung Electronics Co., Ltd * * Licensed under the Flora License, Version 1.1 (the "License"); @@ -15,6 +15,7 @@ */ +using System; using LibTVRefCommonPortable.Utils; using Tizen.Applications; @@ -22,6 +23,15 @@ namespace LibTVRefCommonTizen.Ports { public class AppControlPort : IAppControl { + // TODO : change application later + public static string TVHomeAppID = "org.tizen.example.TVHome.TizenTV"; + public static string TVAppsAppID = "org.tizen.example.TVApps.TizenTV"; + + public static string AddAppOperation = "http://xahome.tizen.org/appcontrol/operation/add_app"; + public static string AppAddedNotifyOperation = "http://xahome.tizen.org/appcontrol/operation/app_added"; + + public static string KeyAddedAppID = "AddedAppID"; + public void SendLaunchRequest(string PkgID) { AppControl appControl = new AppControl(); @@ -37,5 +47,26 @@ namespace LibTVRefCommonTizen.Ports AppControl.SendLaunchRequest(appControl); } + + public void SendAddAppRequestToApps() + { + AppControl appControl = new AppControl() + { + ApplicationId = TVAppsAppID, + Operation = AddAppOperation, + }; + AppControl.SendLaunchRequest(appControl); + } + + public void SendAppAddedNotificationToHome(string addedAddID) + { + AppControl appControl = new AppControl() + { + ApplicationId = TVHomeAppID, + Operation = AppAddedNotifyOperation, + }; + appControl.ExtraData.Add(KeyAddedAppID, addedAddID); + AppControl.SendLaunchRequest(appControl); + } } } diff --git a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs index b0ed1bf..68f9fbc 100644 --- a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs +++ b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs @@ -26,6 +26,8 @@ namespace LibTVRefCommonTizen.Ports { public class ApplicationManagerPort : IApplicationManagerAPIs { + private static String DefaultAppIcon = "AppIcon.png"; + public ApplicationManagerPort() { ApplicationManager.ApplicationLaunched += new EventHandler(OnApplicationLaunched); @@ -51,7 +53,7 @@ namespace LibTVRefCommonTizen.Ports result[0] = (appInfo.Label != null) ? appInfo.Label : null; result[1] = (appInfo.ApplicationId != null) ? appInfo.ApplicationId : null; - result[2] = (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : "AppIcon.png"; + result[2] = (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : DefaultAppIcon; resultList.Add(appInfo.ApplicationId, result); } @@ -62,8 +64,6 @@ namespace LibTVRefCommonTizen.Ports { Dictionary result = null; ApplicationInfo appInfo = null; - string[] icons = { "ic_black.png", "ic_blue.png", "ic_green.png", "ic_red.png", "ic_yellow.png", "AppIcon.png" }; - Random random = new Random(); try { @@ -77,7 +77,7 @@ namespace LibTVRefCommonTizen.Ports result = new Dictionary(); result.Add("Label", appInfo.Label); result.Add("ApplicationId", appInfo.ApplicationId); - result.Add("IconPath", (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : icons[random.Next(0, 6)]); + result.Add("IconPath", (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : DefaultAppIcon); } catch (Exception exception) { @@ -126,7 +126,7 @@ namespace LibTVRefCommonTizen.Ports result[0] = (appInfo.Label != null) ? appInfo.Label : null; result[1] = (appInfo.ApplicationId != null) ? appInfo.ApplicationId : null; - result[2] = (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : "AppIcon.png"; + result[2] = (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : DefaultAppIcon; resultList.Add(appInfo.ApplicationId, result); } diff --git a/LibTVRefCommonTizen/Ports/FileSystemPort.cs b/LibTVRefCommonTizen/Ports/FileSystemPort.cs index 6c15e1b..283eda8 100644 --- a/LibTVRefCommonTizen/Ports/FileSystemPort.cs +++ b/LibTVRefCommonTizen/Ports/FileSystemPort.cs @@ -32,11 +32,10 @@ namespace LibTVRefCommonTizen.Ports public Stream OpenFile(string filePath, UtilFileMode mode) { Stream fileStream = null; - DebuggingPort.D("Opening the file... " + filePath); + DebuggingPort.D("[" + mode.ToString() + "] Opening the file, " + filePath); try { fileStream = new FileStream(filePath, (FileMode)mode); - DebuggingPort.D("Opened."); } catch (Exception exception) { @@ -57,5 +56,32 @@ namespace LibTVRefCommonTizen.Ports var fileStream = stream as FileStream; fileStream.Dispose(); } + + public bool IsFileExist(String fileName) + { + return File.Exists(fileName); + } + + public bool IsFileReady(String fileName) + { + try + { + using (FileStream inputStream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.None)) + { + if (inputStream.Length > 0) + { + return true; + } + else + { + return false; + } + } + } + catch (Exception) + { + return false; + } + } } } diff --git a/TVApps/TVApps.TizenTV/TVApps.TizenTV.cs b/TVApps/TVApps.TizenTV/TVApps.TizenTV.cs index 7304dd4..32824e5 100644 --- a/TVApps/TVApps.TizenTV/TVApps.TizenTV.cs +++ b/TVApps/TVApps.TizenTV/TVApps.TizenTV.cs @@ -14,12 +14,14 @@ * limitations under the License. */ +using System; using LibTVRefCommonPortable.Utils; using LibTVRefCommonTizen.Ports; +using Tizen.Applications; namespace TVApps.TizenTV { - public class Program : Xamarin.Forms.Platform.Tizen.FormsApplication + public class Program : Xamarin.Forms.Platform.Tizen.FormsApplication, IAppLifeControl { IPlatformNotification notification; @@ -48,18 +50,6 @@ namespace TVApps.TizenTV LoadApplication(app); PackageManagerPort.RegisterCallbacks(notification); - MainWindow.KeyUp += KeyUpListener; - } - - private void KeyUpListener(object sender, ElmSharp.EvasKeyEventArgs e) - { - if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName) == 0) - { - if (notification != null) - { - notification.OnBackKeyPressed(); - } - } } protected override void OnTerminate() @@ -69,7 +59,17 @@ namespace TVApps.TizenTV notification = null; PackageManagerPort.DeregisterCallbacks(); MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName); - MainWindow.KeyUp -= KeyUpListener; + } + + protected override void OnAppControlReceived(AppControlReceivedEventArgs e) + { + DebuggingPort.D("OnAppControlReceived, " + e.ReceivedAppControl.Operation); + + if (AppControlPort.AddAppOperation.CompareTo(e.ReceivedAppControl.Operation) == 0) + { + DebuggingPort.D("Add App Request"); + notification.OnPinAppRequestReceived(); + } } static void Main(string[] args) @@ -78,6 +78,7 @@ namespace TVApps.TizenTV Xamarin.Forms.DependencyService.Register(); Xamarin.Forms.DependencyService.Register(); + Xamarin.Forms.DependencyService.Register(); Xamarin.Forms.DependencyService.Register(); Xamarin.Forms.DependencyService.Register(); Xamarin.Forms.DependencyService.Register(); @@ -92,5 +93,9 @@ namespace TVApps.TizenTV } + public void SelfTerminate() + { + Exit(); + } } } diff --git a/TVApps/TVApps/TVApps.cs b/TVApps/TVApps/TVApps.cs index f8056fd..e6f4aaa 100644 --- a/TVApps/TVApps/TVApps.cs +++ b/TVApps/TVApps/TVApps.cs @@ -28,9 +28,9 @@ namespace TVApps public class App : Application, IPlatformNotification { - private static EventHandler BackKeyListener; private static EventHandler AppInstalledListener; private static EventHandler AppUninstalledListener; + private static EventHandler PinAppRequestListener; public App() { @@ -52,11 +52,6 @@ namespace TVApps } - public static void SetBackKeyListener(EventHandler listener) - { - BackKeyListener += listener; - } - public static void SetAppInstalledListener(EventHandler listener) { AppInstalledListener += listener; @@ -66,14 +61,9 @@ namespace TVApps { AppUninstalledListener += listener; } - - public void OnBackKeyPressed() + public static void SetPinAppRequestListener(EventHandler listener) { - DebuggingUtils.Dbg("[[[ Back Key ]]] "); - BackKeyListener.Invoke(this, new TVAppsEventArgs() - { - arg = "", - }); + PinAppRequestListener += listener; } public void OnAppInstalled(string pkgID) @@ -93,5 +83,15 @@ namespace TVApps arg = pkgID, }); } + + public void OnPinAppRequestReceived() + { + DebuggingUtils.Dbg("[[[ Pin Add Request ]]] "); + PinAppRequestListener.Invoke(this, new TVAppsEventArgs()); + } + + public void OnAppPinnedNotificationReceived(string appID) + { + } } } diff --git a/TVApps/TVApps/ViewModels/AppsHolder.cs b/TVApps/TVApps/ViewModels/AppsHolder.cs index 29056bf..0705e09 100644 --- a/TVApps/TVApps/ViewModels/AppsHolder.cs +++ b/TVApps/TVApps/ViewModels/AppsHolder.cs @@ -18,6 +18,7 @@ using LibTVRefCommonPortable.DataModels; using LibTVRefCommonPortable.Utils; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Xamarin.Forms; namespace TVApps.ViewModels @@ -58,8 +59,13 @@ namespace TVApps.ViewModels private async void SetApps() { - PinnedApps = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs(); - var installedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetInstalledApps(); + var pinnedAppsGettingTask = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs(); + var installedAppsGettingTask = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetInstalledApps(); + + await Task.WhenAll(pinnedAppsGettingTask, installedAppsGettingTask); + + PinnedApps = pinnedAppsGettingTask.Result; + var installedApps = installedAppsGettingTask.Result; foreach (AppShortcutInfo item in installedApps) { @@ -124,6 +130,7 @@ namespace TVApps.ViewModels InstalledApps = installedApps.ToList(); SortApps(SortingOption); + UpdateStateDescription(ViewModel.CurrentStatus); } private void PinToggle(string key) @@ -218,9 +225,9 @@ namespace TVApps.ViewModels RefreshApps(); } - public void ResetPinnedApps() + public async void ResetPinnedApps() { - PinnedApps = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs(); + PinnedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs(); } public void UpdatePinnedApps() diff --git a/TVApps/TVApps/ViewModels/IAppsViewModel.cs b/TVApps/TVApps/ViewModels/IAppsViewModel.cs index 088ae89..66cb895 100644 --- a/TVApps/TVApps/ViewModels/IAppsViewModel.cs +++ b/TVApps/TVApps/ViewModels/IAppsViewModel.cs @@ -18,6 +18,8 @@ namespace TVApps.ViewModels { interface IAppsViewModel { + AppsStatus CurrentStatus { get; } + void OnPropertyChanged(string name); void ChangeCurrentStatus(AppsStatus newStatus); } diff --git a/TVApps/TVApps/ViewModels/MainPageViewModel.cs b/TVApps/TVApps/ViewModels/MainPageViewModel.cs index cf79e29..adf6748 100644 --- a/TVApps/TVApps/ViewModels/MainPageViewModel.cs +++ b/TVApps/TVApps/ViewModels/MainPageViewModel.cs @@ -103,6 +103,8 @@ namespace TVApps.ViewModels public event PropertyChangedEventHandler PropertyChanged; + private bool IsPinAppRequested; + public MainPageViewModel() { DebuggingUtils.Dbg(">MainPageViewModel - Start"); @@ -127,14 +129,25 @@ namespace TVApps.ViewModels ButtonPinOkCommand = new Command(() => { appsHolder.UpdatePinnedApps(); - ChangeCurrentStatus(AppsStatus.Default); + + if(IsPinAppRequested) + { + // TODO : check pinneed apps and a number of pinned apps + AppControlUtils.SendAppAddedNotificationToHome("org.tizen.settings"); + AppControlUtils.SelfTerminate(); + } }); ButtonPinCancelCommand = new Command(() => { appsHolder.ResetPinnedApps(); ChangeCurrentStatus(AppsStatus.Default); + + if (IsPinAppRequested) + { + AppControlUtils.SelfTerminate(); + } }); SetLongPressCommand = new Command((appId) => @@ -162,10 +175,12 @@ namespace TVApps.ViewModels appsHolder.UnsetAppItemDim((string) appId); }); - App.SetBackKeyListener((s, e) => + + App.SetPinAppRequestListener((s, e) => { // TODO : check concurrency - ChangeCurrentStatus(AppsStatus.Default); + IsPinAppRequested = true; + ChangeCurrentStatus(AppsStatus.Pin); }); DebuggingUtils.Dbg(" OnBackKeyPressedAtMain() { - // TODO : Remove isBackKeyUsed if focus issue is solved!!! - if (!AppList.IsFirstItemFocused && - isBackKeyUsed == false) + if (!AppList.IsFirstItemFocused) { - isBackKeyUsed = true; DebuggingUtils.Dbg("OnBackKeyPressedAtMain - focus move"); AppList.InitializeFocus(); return true; @@ -110,7 +104,7 @@ namespace TVApps.Views } return true; } - + /* protected override bool OnBackButtonPressed() { DebuggingUtils.Dbg("OnBackButtonPressed"); @@ -120,5 +114,6 @@ namespace TVApps.Views }, ""); return true; } + */ } } diff --git a/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs b/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs index 27b03ff..33b3db3 100644 --- a/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs +++ b/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs @@ -16,6 +16,7 @@ using LibTVRefCommonPortable.Utils; using LibTVRefCommonTizen.Ports; +using Tizen.Applications; namespace TVHome.TizenTV { @@ -49,18 +50,6 @@ namespace TVHome.TizenTV PackageManagerPort.RegisterCallbacks(notification); MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName, true); - MainWindow.KeyUp += KeyUpListener; - } - - private void KeyUpListener(object sender, ElmSharp.EvasKeyEventArgs e) - { - if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName) == 0) - { - if (notification != null) - { - notification.OnBackKeyPressed(); - } - } } protected override void OnTerminate() @@ -70,7 +59,27 @@ namespace TVHome.TizenTV notification = null; PackageManagerPort.DeregisterCallbacks(); MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName); - MainWindow.KeyUp -= KeyUpListener; + } + + protected override void OnAppControlReceived(AppControlReceivedEventArgs e) + { + DebuggingPort.D("OnAppControlReceived, " + e.ReceivedAppControl.Operation); + DebuggingPort.D("ApplicationId = " + e.ReceivedAppControl.ApplicationId); + DebuggingPort.D("CallerApplicationId = " + e.ReceivedAppControl.CallerApplicationId); + + if (AppControlPort.AppAddedNotifyOperation.CompareTo(e.ReceivedAppControl.Operation) == 0) + { + DebuggingPort.D("App Added Notification"); + string pinnedApp; + if (e.ReceivedAppControl.ExtraData.TryGet(AppControlPort.KeyAddedAppID, out pinnedApp)) + { + notification.OnAppPinnedNotificationReceived(pinnedApp); + } + else + { + notification.OnAppPinnedNotificationReceived(""); + } + } } static void Main(string[] args) diff --git a/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk b/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk index fcf8334..8dedb0d 100644 Binary files a/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk and b/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk differ diff --git a/TVHome/TVHome/TVHome.cs b/TVHome/TVHome/TVHome.cs index fedc5f8..0b70745 100644 --- a/TVHome/TVHome/TVHome.cs +++ b/TVHome/TVHome/TVHome.cs @@ -28,9 +28,9 @@ namespace TVHome public class App : Application, IPlatformNotification { - private static EventHandler BackKeyListener; private static EventHandler AppInstalledListener; private static EventHandler AppUninstalledListener; + private static EventHandler AppPinnedNotificationListener; public App() { @@ -52,11 +52,6 @@ namespace TVHome } - public static void SetBackKeyListener(EventHandler listener) - { - BackKeyListener += listener; - } - public static void SetAppInstalledListener(EventHandler listener) { AppInstalledListener += listener; @@ -66,14 +61,9 @@ namespace TVHome { AppUninstalledListener += listener; } - - public void OnBackKeyPressed() + public static void SetAppPinnedNotificationListener(EventHandler listener) { - DebuggingUtils.Dbg("[[[ Back Key ]]] "); - BackKeyListener.Invoke(this, new TVHomeEventArgs() - { - arg = "", - }); + AppPinnedNotificationListener += listener; } public void OnAppInstalled(string pkgID) @@ -93,5 +83,19 @@ namespace TVHome arg = pkgID, }); } + + public void OnPinAppRequestReceived() + { + + } + + public void OnAppPinnedNotificationReceived(String AppID) + { + DebuggingUtils.Dbg("[[[ App Pinned ]]] " + AppID); + AppPinnedNotificationListener.Invoke(this, new TVHomeEventArgs() + { + arg = AppID, + }); + } } } diff --git a/TVHome/TVHome/ViewModels/MainPageViewModel.cs b/TVHome/TVHome/ViewModels/MainPageViewModel.cs index 1576ac7..6232ea5 100755 --- a/TVHome/TVHome/ViewModels/MainPageViewModel.cs +++ b/TVHome/TVHome/ViewModels/MainPageViewModel.cs @@ -82,26 +82,40 @@ namespace TVHome.ViewModels MakeRecentButtons(); DebuggingUtils.Dbg("Reading Apps list"); - AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsWithDefaultShortcuts(); + AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetDefaultShortcuts(); OnPropertyChanged("AppList"); + UpdateAppList(null, null); //SettingsList = TVHomeImpl.GetInstance.AppShortcutControllerInstnace.ReadFromFile(); SettingsList = TVHomeImpl.GetInstance.SettingShortcutControllerInstance.GetList(); OnPropertyChanged("SettingsList"); - TVHomeImpl.GetInstance.AppShortcutControllerInstance.AddFileSystemChangedListener(TestFunction); + TVHomeImpl.GetInstance.AppShortcutControllerInstance.AddFileSystemChangedListener(UpdateAppList); + + App.SetAppPinnedNotificationListener((s, e) => + { + // TODO : Make this for Move a pinned app/Show pinned apps(scroll to last) + if (e.arg.Length > 0) + { + DebuggingUtils.Dbg("Move, AppID : " + e.arg); + } + else + { + DebuggingUtils.Dbg("Show, Pinned Apps"); + } + }); } - private void TestFunction(object sender, EventArgs e) + private async void UpdateAppList(object sender, EventArgs e) { - AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsWithDefaultShortcuts(); + AppList = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsWithDefaultShortcuts(); OnPropertyChanged("AppList"); } - private void MakeRecentButtons() + private async void MakeRecentButtons() { - RecentList = TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList(); + RecentList = await TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList(); if (RecentList != null) { OnPropertyChanged("RecentList"); diff --git a/TVHome/TVHome/Views/MainPage.xaml.cs b/TVHome/TVHome/Views/MainPage.xaml.cs index e3db19b..99416b6 100755 --- a/TVHome/TVHome/Views/MainPage.xaml.cs +++ b/TVHome/TVHome/Views/MainPage.xaml.cs @@ -100,9 +100,9 @@ namespace TVHome.Views TVHomeImpl.GetInstance.AppShortcutControllerInstance.UpdatePinnedApps(pinnedAppList); } - public void RemovePinnedApp(string AppID) + public async void RemovePinnedApp(string AppID) { - Dictionary PinnedApps = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs(); + Dictionary PinnedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs(); if (PinnedApps.ContainsKey(AppID)) { PinnedApps.Remove(AppID);