Add AppControl handling for Home, Apps
authorcskim <charles0.kim@samsung.com>
Thu, 16 Mar 2017 08:42:40 +0000 (17:42 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:47 +0000 (18:34 +0900)
(TODO) need to provide selection app info to Home.

Change-Id: I7cd94a2f65310975320e3fcabf511bd7e777bb70

23 files changed:
LibTVRefCommonPortable/LibTVRefCommonPortable.csproj
LibTVRefCommonPortable/Models/AppShortcutController.cs
LibTVRefCommonPortable/Models/RecentShortcutController.cs
LibTVRefCommonPortable/Utils/AppControlUtils.cs
LibTVRefCommonPortable/Utils/AppShortcutStorage.cs
LibTVRefCommonPortable/Utils/IAppControl.cs
LibTVRefCommonPortable/Utils/IAppLifeControl.cs [new file with mode: 0644]
LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs
LibTVRefCommonPortable/Utils/IPlatformNotification.cs
LibTVRefCommonTizen/Ports/AppControlPort.cs
LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs
LibTVRefCommonTizen/Ports/FileSystemPort.cs
TVApps/TVApps.TizenTV/TVApps.TizenTV.cs
TVApps/TVApps/TVApps.cs
TVApps/TVApps/ViewModels/AppsHolder.cs
TVApps/TVApps/ViewModels/IAppsViewModel.cs
TVApps/TVApps/ViewModels/MainPageViewModel.cs
TVApps/TVApps/Views/MainPage.xaml.cs
TVHome/TVHome.TizenTV/TVHome.TizenTV.cs
TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk
TVHome/TVHome/TVHome.cs
TVHome/TVHome/ViewModels/MainPageViewModel.cs
TVHome/TVHome/Views/MainPage.xaml.cs

index bde6e163d5c5d443a06339dc7d4d5a77e1cacea7..3aa2f42690a3820070e61cb20c4affccced85012 100644 (file)
@@ -67,6 +67,7 @@
     <Compile Include="Utils\DebuggingUtils.cs" />
     <Compile Include="Utils\IAppControl.cs" />
     <Compile Include="Utils\IApplicationManagerAPIs.cs" />
+    <Compile Include="Utils\IAppLifeControl.cs" />
     <Compile Include="Utils\IPlatformNotification.cs" />
     <Compile Include="Utils\IBTAPIs.cs" />
     <Compile Include="Utils\IDBAPIs.cs" />
index de8edff876b9f5204cad8e3616c30598070ba4a3..cdf27ce4c1237f791336c8b6c5ce9665fa4744e2 100755 (executable)
@@ -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<IEnumerable<AppShortcutInfo>> GetInstalledApps()
         {
-            DebuggingUtils.Dbg(">AppShortcutController, GetInstalledApps - start");
             IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
             List<AppShortcutInfo> appShortcutInfoList = new List<AppShortcutInfo>();
 
@@ -64,11 +65,10 @@ namespace LibTVRefCommonPortable.Models
                 appShortcutInfoList.Add(appShortcutInfo);
             }
 
-            DebuggingUtils.Dbg("<AppShortcutController, GetInstalledApps - end");
             return appShortcutInfoList;
         }
 
-        private void AddAllAppsAndMediaHubShortcut(ref List<AppShortcutInfo> returnPinnedAppsInfo)
+        private void AddAllAppsAndMediaHubShortcut(ref List<ShortcutInfo> returnPinnedAppsInfo)
         {
             var allAppsStateDescription = new StateDescription()
             {
@@ -104,15 +104,20 @@ namespace LibTVRefCommonPortable.Models
             returnPinnedAppsInfo.Insert(1, mediaHubShortcutInfo);
         }
 
-        private void AppendAddPinShortcut(ref List<AppShortcutInfo> returnPinnedAppsInfo)
+        private void AppendAddPinShortcut(ref List<ShortcutInfo> 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<string>((key) =>
+                    {
+                        AppControlUtils.SendAddAppRequestToApps();
+                    }),
+                    CommandParameter = "",
                 }
             };
 
@@ -124,13 +129,12 @@ namespace LibTVRefCommonPortable.Models
             returnPinnedAppsInfo.Add(addPinShortcutInfo);
         }
 
-        private List<AppShortcutInfo> GetPinnedApps()
+        private async Task<List<ShortcutInfo>> GetPinnedApps()
         {
             IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
-            IEnumerable<AppShortcutInfo> 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<AppShortcutInfo> pinned_apps_info = await AppShortcutStorage.Read();
 
-            List<AppShortcutInfo> returnPinnedAppsInfo = new List<AppShortcutInfo>();
+            List<ShortcutInfo> returnPinnedAppsInfo = new List<ShortcutInfo>();
 
             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<AppShortcutInfo> GetPinnedAppsWithDefaultShortcuts()
+        public IEnumerable<ShortcutInfo> GetDefaultShortcuts()
         {
-            List<AppShortcutInfo> returnPinnedAppsInfo = GetPinnedApps();
+            List<ShortcutInfo> returnPinnedAppsInfo = new List<ShortcutInfo>();
 
             AddAllAppsAndMediaHubShortcut(ref returnPinnedAppsInfo);
             AppendAddPinShortcut(ref returnPinnedAppsInfo);
@@ -178,11 +181,20 @@ namespace LibTVRefCommonPortable.Models
             return returnPinnedAppsInfo;
         }
 
-        public Dictionary<string, string> GetPinnedAppsAppIDs()
+        public async Task<IEnumerable<ShortcutInfo>> GetPinnedAppsWithDefaultShortcuts()
+        {
+            List<ShortcutInfo> returnPinnedAppsInfo = await GetPinnedApps();
+
+            AddAllAppsAndMediaHubShortcut(ref returnPinnedAppsInfo);
+            AppendAddPinShortcut(ref returnPinnedAppsInfo);
+
+            return returnPinnedAppsInfo;
+        }
+
+        public async Task<Dictionary<string, string>> GetPinnedAppsAppIDs()
         {
             IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
-            IEnumerable<AppShortcutInfo> 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<AppShortcutInfo> pinned_apps_info = await AppShortcutStorage.Read();
 
             Dictionary<string, string> pinnedAppsDictionary = new Dictionary<string, string>();
 
@@ -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<EventArgs> eventListener)
         {
             if (AppShortcutStorage.Instance != null)
index 300ba08473c76e74f743ff51a26960f83cb53a4c..30d0ece50905702d2faa2a4bb12fa02239956ffa 100644 (file)
@@ -47,49 +47,7 @@ namespace LibTVRefCommonPortable.Models
             return false;
         }
 
-        public IEnumerable<RecentShortcutInfo> GetList()
-        {
-            // TODO : This is a clone of AppShorcutController.ReadFromFile(). Write new code by using RUA
-            IEnumerable<AppShortcutInfo> pinned_apps_info = AppShortcutStorage.Read();
-            IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
-            List<RecentShortcutInfo> recentShortcutInfoList = new List<RecentShortcutInfo>();
-            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<string, string> 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<IEnumerable<RecentShortcutInfo>> GetListAsync()
+        public async Task<IEnumerable<RecentShortcutInfo>> GetList()
         {
             IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
             List<RecentShortcutInfo> recentShortcutInfoList = new List<RecentShortcutInfo>();
@@ -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);
index 91952642937f3b2528b1fd929ca57e67558b44e5..f71bfdd9024673fe992bfb457e9f8e255650c401 100644 (file)
@@ -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<IAppControl>().SendLaunchRequest(PkgID);
         }
+
+        public static void SendAddAppRequestToApps()
+        {
+            if (DependencyService.Get<IAppControl>() == null)
+            {
+                return;
+            }
+
+            DependencyService.Get<IAppControl>().SendAddAppRequestToApps();
+        }
+
+        public static void SendAppAddedNotificationToHome(string addedAddID)
+        {
+            if (DependencyService.Get<IAppControl>() == null)
+            {
+                return;
+            }
+
+            DependencyService.Get<IAppControl>().SendAppAddedNotificationToHome(addedAddID);
+        }
+
+        public static void SelfTerminate()
+        {
+            if (DependencyService.Get<IAppLifeControl>() == null)
+            {
+                return;
+            }
+
+            DependencyService.Get<IAppLifeControl>().SelfTerminate();
+        }
     }
 }
index 87dbe5e948315c2470e4bea5e54b5d44c77dd2d1..643c6cf780dece65349ebcf1a5004d5d054feddd 100644 (file)
  */
 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<AppShortcutInfo> Read()
+        public static async Task<IEnumerable<AppShortcutInfo>> Read()
         {
             IFileSystemAPIs fileSystem = DependencyService.Get<IFileSystemAPIs>();
-            XmlSerializer serializer = new XmlSerializer(typeof(List<AppShortcutInfo>));
-            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<AppShortcutInfo> result = GetSampleList();
-                    Write(result);
-                    return result;
-                }
-
-                StreamReader streamReader = new StreamReader(fileStream);
-                List<AppShortcutInfo> list = (List<AppShortcutInfo>)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<AppShortcutInfo> 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<AppShortcutInfo>();
+                }
+                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<AppShortcutInfo>));
+                StreamReader streamReader = new StreamReader(fileStream);
+                List<AppShortcutInfo> list = (List<AppShortcutInfo>)serializer.Deserialize(streamReader);
+
+                return list;
             }
         }
 
         public static bool Write(IEnumerable<AppShortcutInfo> pinnedAppInfo)
         {
             IFileSystemAPIs fileSystem = DependencyService.Get<IFileSystemAPIs>();
-            XmlSerializer serializer = new XmlSerializer(typeof(List<AppShortcutInfo>));
-            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<AppShortcutInfo>));
                 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;
         }
index 127658f5b23d7b60e23362e075c032d37235b99f..e261a0e87c6e166fb11b5f76dfdbc6ed575e1bb5 100644 (file)
@@ -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 (file)
index 0000000..44b0f11
--- /dev/null
@@ -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();
+    }
+}
index 2555da1315923115099942c3c2a8424eb4ed39f9..63ec1328e97dfe6b8d516ade49c098b1d62a5a8d 100644 (file)
@@ -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);
     }
 }
index 19f1f5d0a94af9d62f6e5cfc9bfc1fc73dfae11f..c78426d035efcf5f42139bc0cbcc31557c2ac615 100644 (file)
@@ -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);
     }
 }
index f5022f04b30d4e8655e0d49aa669f857799b00ff..72fca7e32675fca4df4aebf6adfaf3185952631d 100644 (file)
@@ -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);
+        }
     }
 }
index b0ed1bf84e8332ab04fa6cc1deb3e0d2f7d7c408..68f9fbc3670995971ee9ef97fde46e688e34f6ba 100644 (file)
@@ -26,6 +26,8 @@ namespace LibTVRefCommonTizen.Ports
 {
     public class ApplicationManagerPort : IApplicationManagerAPIs
     {
+        private static String DefaultAppIcon = "AppIcon.png";
+
         public ApplicationManagerPort()
         {
             ApplicationManager.ApplicationLaunched += new EventHandler<ApplicationLaunchedEventArgs>(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<string, string> 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<string, string>();
                 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);
                 }
 
index 6c15e1b4813a8e346cb25daafd9f45539a35a4ee..283eda80e3f15962717e82568e2879690a4d5428 100644 (file)
@@ -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;
+            }
+        }
     }
 }
index 7304dd40988190a43c8298ac85fd4ea5602d4f0c..32824e57da66724e447c2be3d4d4fb3e3925dd82 100644 (file)
  * 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<DebuggingPort>();
             Xamarin.Forms.DependencyService.Register<DBPort>();
+            Xamarin.Forms.DependencyService.Register<IAppLifeControl>();
             Xamarin.Forms.DependencyService.Register<AppControlPort>();
             Xamarin.Forms.DependencyService.Register<PackageManagerPort>();
             Xamarin.Forms.DependencyService.Register<WifiModulePort>();
@@ -92,5 +93,9 @@ namespace TVApps.TizenTV
 
         }
 
+        public void SelfTerminate()
+        {
+            Exit();
+        }
     }
 }
index f8056fdd764257ac3a1d816d5630a1bf1fd3d056..e6f4aaae9025cd58fb91a2e0d13b09212db905cb 100644 (file)
@@ -28,9 +28,9 @@ namespace TVApps
 
     public class App : Application, IPlatformNotification
     {
-        private static EventHandler<TVAppsEventArgs> BackKeyListener;
         private static EventHandler<TVAppsEventArgs> AppInstalledListener;
         private static EventHandler<TVAppsEventArgs> AppUninstalledListener;
+        private static EventHandler<TVAppsEventArgs> PinAppRequestListener;
 
         public App()
         {
@@ -52,11 +52,6 @@ namespace TVApps
 
         }
 
-        public static void SetBackKeyListener(EventHandler<TVAppsEventArgs> listener)
-        {
-            BackKeyListener += listener;
-        }
-
         public static void SetAppInstalledListener(EventHandler<TVAppsEventArgs> listener)
         {
             AppInstalledListener += listener;
@@ -66,14 +61,9 @@ namespace TVApps
         {
             AppUninstalledListener += listener;
         }
-
-        public void OnBackKeyPressed()
+        public static void SetPinAppRequestListener(EventHandler<TVAppsEventArgs> 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)
+        {
+        }
     }
 }
index 29056bf56e97e29c2672a4fad9fd62d6eb5a8fb2..0705e0938919050e537ac1bde4e2e3b6966b61af 100644 (file)
@@ -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()
index 088ae898e9ef685ad9dbfe555f2d7ac94947be39..66cb8950f5e2baaba9ecd5f5a4782045163b7d73 100644 (file)
@@ -18,6 +18,8 @@ namespace TVApps.ViewModels
 {
     interface IAppsViewModel
     {
+        AppsStatus CurrentStatus { get; }
+
         void OnPropertyChanged(string name);
         void ChangeCurrentStatus(AppsStatus newStatus);
     }
index cf79e2979820a6e217242c40e9389d9e3fe14cc9..adf674816a1c0c992161eb81e1a52cac3c952f4d 100644 (file)
@@ -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("<MainPageViewModel - End");
index 8c26a327cf855954e8baae5c1c62681e6ff14ac7..3b24bf95d7bc40f6ddc121a9b93b6896e750f9d9 100644 (file)
@@ -85,16 +85,10 @@ namespace TVApps.Views
             }
         }
 
-        // TODO : Remove this if focus issue is solved!!!
-        static bool isBackKeyUsed = false;
-
         private async Task<bool> 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;
         }
+        */
     }
 }
index 27b03ff6fef36a4b0b2ffafb937a7594bb0e5783..33b3db35bd3182f32e0e726147a06094083c06a2 100644 (file)
@@ -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)
index fcf83341814666f153cbfe6378fa20fb2f980b40..8dedb0db61131d749672f2e8d4cdbe71231a5b8c 100644 (file)
Binary files a/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk and b/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk differ
index fedc5f821734db3f8063168bd56f034fff172d86..0b70745616e1b18f3f6608483461597f7335c9af 100644 (file)
@@ -28,9 +28,9 @@ namespace TVHome
 
     public class App : Application, IPlatformNotification
     {
-        private static EventHandler<TVHomeEventArgs> BackKeyListener;
         private static EventHandler<TVHomeEventArgs> AppInstalledListener;
         private static EventHandler<TVHomeEventArgs> AppUninstalledListener;
+        private static EventHandler<TVHomeEventArgs> AppPinnedNotificationListener;
 
         public App()
         {
@@ -52,11 +52,6 @@ namespace TVHome
 
         }
 
-        public static void SetBackKeyListener(EventHandler<TVHomeEventArgs> listener)
-        {
-            BackKeyListener += listener;
-        }
-
         public static void SetAppInstalledListener(EventHandler<TVHomeEventArgs> listener)
         {
             AppInstalledListener += listener;
@@ -66,14 +61,9 @@ namespace TVHome
         {
             AppUninstalledListener += listener;
         }
-
-        public void OnBackKeyPressed()
+        public static void SetAppPinnedNotificationListener(EventHandler<TVHomeEventArgs> 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,
+            });
+        }
     }
 }
index 1576ac7ff048544c1bfdf1080651bd63893f1037..6232ea53940ab98f610890e505a9c987e21297cd 100755 (executable)
@@ -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");
index e3db19bf7684f3ebe548afbb137c26084bc36aad..99416b69150917a12c22328e61d6a5b9b54d27e6 100755 (executable)
@@ -100,9 +100,9 @@ namespace TVHome.Views
             TVHomeImpl.GetInstance.AppShortcutControllerInstance.UpdatePinnedApps(pinnedAppList);
         }
 
-        public void RemovePinnedApp(string AppID)
+        public async void RemovePinnedApp(string AppID)
         {
-            Dictionary<string, string> PinnedApps = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs();
+            Dictionary<string, string> PinnedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs();
             if (PinnedApps.ContainsKey(AppID))
             {
                 PinnedApps.Remove(AppID);