Storing/Restoring AppShortcutInfo
authorKyuho Jo <kyuho.jo@samsung.com>
Tue, 28 Feb 2017 10:42:42 +0000 (19:42 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:44 +0000 (18:34 +0900)
Change-Id: I
Signed-off-by: Kyuho Jo <kyuho.jo@samsung.com>
14 files changed:
TVHome/TVHome.TizenTV/Ports/ApplicationManagerPort.cs
TVHome/TVHome.TizenTV/Ports/FileSystemPort.cs [new file with mode: 0644]
TVHome/TVHome.TizenTV/TVHome.TizenTV.cs
TVHome/TVHome.TizenTV/TVHome.TizenTV.csproj
TVHome/TVHome/DataModels/AppControlAction.cs
TVHome/TVHome/DataModels/AppShortcutInfo.cs
TVHome/TVHome/DataModels/ShortcutInfo.cs
TVHome/TVHome/Models/AppShortcutController.cs
TVHome/TVHome/Models/RecentShortcutController.cs
TVHome/TVHome/TVHome.csproj
TVHome/TVHome/Utils/AppShortcutStorage.cs
TVHome/TVHome/Utils/IApplicationManagerAPIs.cs
TVHome/TVHome/Utils/IFileSystemAPIs.cs [new file with mode: 0644]
TVHome/TVHome/ViewModels/MainPageViewModel.cs

index e2fb26434e7e746e2cdb9c66455b55ee54e656b7..ca109c19f4acdd0345011529afb5a542746ea953 100644 (file)
@@ -34,7 +34,6 @@ namespace TVHome.TizenTV.Ports
         void OnApplicationLaunched(object sender, EventArgs args)\r
         {\r
             ApplicationLaunchedEventArgs launchedEventArgs = args as ApplicationLaunchedEventArgs;\r
-\r
             DebuggingUtils.Dbg(launchedEventArgs.ApplicationInfo.Label.ToString() + " launched");\r
         }\r
 \r
@@ -53,11 +52,35 @@ namespace TVHome.TizenTV.Ports
                 result[0] = appInfo.Label != null ? appInfo.Label : null;\r
                 result[1] = appInfo.ApplicationId != null ? appInfo.ApplicationId : null;\r
                 result[2] = appInfo.IconPath != null ? appInfo.IconPath : "AppIcon.png";\r
-\r
                 resultList.Add(appInfo.ApplicationId, result);\r
             }\r
 \r
             return resultList;\r
         }\r
+\r
+        public Dictionary<string, string> GetInstalledApplication(string applicationId)\r
+        {\r
+            Dictionary<string, string> result = null;\r
+            ApplicationInfo appInfo = null;\r
+            try\r
+            {\r
+                appInfo = ApplicationManager.GetInstalledApplication(applicationId);\r
+                if (appInfo == null)\r
+                {\r
+                    DebuggingPort.D("GetInstalledApplication failed");\r
+                    return null;\r
+                }\r
+                result = new Dictionary<string, string>();\r
+                result.Add("Label", appInfo.Label);\r
+                result.Add("ApplicationId", appInfo.ApplicationId);\r
+                result.Add("IconPath", appInfo.IconPath);\r
+            }\r
+            catch(Exception exception)\r
+            {\r
+                DebuggingPort.E("Exception " + applicationId + " :" + exception.Message);\r
+                return null;\r
+            }\r
+            return result;\r
+        }\r
     }\r
 }
\ No newline at end of file
diff --git a/TVHome/TVHome.TizenTV/Ports/FileSystemPort.cs b/TVHome/TVHome.TizenTV/Ports/FileSystemPort.cs
new file mode 100644 (file)
index 0000000..585e211
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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 System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.IO;
+
+using Tizen;
+using Tizen.Applications;
+using TVHome.Utils;
+
+namespace TVHome.TizenTV.Ports 
+{
+    class FileSystemPort : IFileSystemAPIs
+    {
+        public Stream OpenFile(string filePath, UtilFileMode mode)
+        {
+            Stream fileStream = null;
+            DebuggingPort.D("Opening the file... " + filePath);
+            try
+            {
+                fileStream = new FileStream(filePath, (FileMode)mode);
+                DebuggingPort.D("Opened.");
+            }
+            catch (Exception exception)
+            {
+                DebuggingPort.E("Exception!! " + exception.Message);
+            }
+            return fileStream;
+        }
+
+        public void Flush(Stream stream)
+        {
+            var fileStream = stream as FileStream;
+            fileStream.Flush();
+        }
+
+        public void CloseFile(Stream stream)
+        {
+            var fileStream = stream as FileStream;
+            fileStream.Dispose();
+        }
+}
+}
index 0b516f1dc862a0672dc7471e500d67e3fdafe4ed..0ba37bda4b6e114c5437212a8cae0f6595b26ce1 100644 (file)
@@ -24,7 +24,7 @@ namespace TVHome.TizenTV
 \r
             AppResourcePath = DirectoryInfo.Resource;\r
             AppDataPath = DirectoryInfo.Data;\r
-            DebuggingPort.D("I'm here");\r
+            DebuggingPort.D("Home application is being loaded...");\r
             LoadApplication(new App());\r
         }\r
 \r
@@ -39,6 +39,7 @@ namespace TVHome.TizenTV
             global::Xamarin.Forms.DependencyService.Register<BTModulePort>();\r
             global::Xamarin.Forms.DependencyService.Register<FileSystemWatcherPort>();\r
             global::Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();\r
+            global::Xamarin.Forms.DependencyService.Register<FileSystemPort>();\r
             global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);\r
             app.Run(args);\r
         }\r
index 69739e4754f4c72ca35cc85a028e4c475f9e5fd4..bd75a010427742ac8b20046b04c2bf62cff14dba 100644 (file)
@@ -51,6 +51,7 @@
     <Compile Include="Ports\AppControlPort.cs" />\r
     <Compile Include="Ports\ApplicationManagerPort.cs" />\r
     <Compile Include="Ports\BTModulePort.cs" />\r
+    <Compile Include="Ports\FileSystemPort.cs" />\r
     <Compile Include="Ports\FileSystemWatcherPort.cs" />\r
     <Compile Include="Ports\PackageManagerPort.cs" />\r
     <Compile Include="Ports\WifiModulePort.cs" />\r
@@ -60,7 +61,6 @@
   </ItemGroup>\r
   <ItemGroup>\r
     <Folder Include="lib\" />\r
-    <Folder Include="res\" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ProjectReference Include="..\TVHome\TVHome.csproj">\r
@@ -68,6 +68,9 @@
       <Name>TVHome</Name>\r
     </ProjectReference>\r
   </ItemGroup>\r
+  <ItemGroup>\r
+    <None Include="res\pinned_apps_info.xml" />\r
+  </ItemGroup>\r
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r
                Other similar extension points exist, see Microsoft.Common.targets.\r
index 62ad2ae674465b141944f3a59e3b9954bb2805dc..3fb1d3cbbf01a8076297fbc7b6ca624ccddfcca8 100644 (file)
@@ -21,11 +21,11 @@ namespace TVHome.DataModels
 {\r
     class AppControlAction : IAction\r
     {\r
-        public string PkgID { get; set; }\r
+        public string AppID { get; set; }\r
         public string Execute()\r
         {\r
             string result = "default";\r
-            AppControlUtils.SendLaunchRequest(PkgID);\r
+            AppControlUtils.SendLaunchRequest(AppID);\r
 \r
             return result;\r
         }\r
index 0d8314e584529fd1e157588001bb522a95df4dd5..1e5cf0eb756f9c1cbad15921a8e824139bcdb84a 100644 (file)
 \r
 using System;\r
 using System.Collections.Generic;\r
+using System.Xml.Serialization;\r
+\r
 \r
 namespace TVHome.DataModels\r
 {\r
-    public class AppShortcutInfo : ShortcutInfo, IDBItem\r
+    public class AppShortcutInfo : ShortcutInfo\r
     {\r
-        public string ID\r
-        {\r
-            get;\r
-            set;\r
-        }\r
-\r
-        public string PackageID\r
-        {\r
-            get;\r
-            set;\r
-        }\r
-\r
-        public string AppID\r
-        {\r
-            get;\r
-            set;\r
-        }\r
-\r
-        public string AppName\r
-        {\r
-            get;\r
-            set;\r
-        }\r
-\r
+        public string AppID { get; set; }\r
+       \r
         public override void UpdateState()\r
         {\r
             SetCurrentState("default");\r
         }\r
-\r
-        public void SetDBItem(IDBItem item)\r
-        {\r
-            int idx = 0;\r
-            foreach (var column in item.GetColumnValues())\r
-            {\r
-                SetColumnValue(idx++, column);\r
-            }\r
-        }\r
-\r
-        public string GetColumnValue(int idx)\r
-        {\r
-            switch (idx)\r
-            {\r
-                case 0: return ID;\r
-                case 1: return PackageID;\r
-                case 2: return AppID;\r
-                case 3: return AppName;\r
-            }\r
-\r
-            return "";\r
-        }\r
-\r
-        public void SetColumnValue(int idx, string value)\r
-        {\r
-            switch (idx)\r
-            {\r
-                case 0:\r
-                    ID = value;\r
-                    break;\r
-                case 1:\r
-                    PackageID = value;\r
-                    break;\r
-                case 2:\r
-                    AppID = value;\r
-                    break;\r
-                case 3:\r
-                    AppName = value;\r
-                    break;\r
-            }\r
-        }\r
-\r
-        public IEnumerable<string> GetColumnValues()\r
-        {\r
-            return new List<string>()\r
-            {\r
-                ID,\r
-                PackageID,\r
-                AppID,\r
-                AppName,\r
-            };\r
-        }\r
     }\r
 }\r
index 37604c52467975cc9f4a43d72e2919838339ded8..48733733a4cc63ea01eaf8ec4f5e7cd736362304 100644 (file)
 using System;\r
 using System.Collections.Generic;\r
 using System.ComponentModel;\r
+using System.Xml.Serialization;\r
 using TVHome.Utils;\r
 \r
 namespace TVHome.DataModels\r
 {\r
     public abstract class ShortcutInfo : INotifyPropertyChanged\r
     {\r
+        [XmlIgnore]\r
         private Dictionary<String, StateDescription> stateDescriptions = new Dictionary<String, StateDescription>();\r
 \r
         public event PropertyChangedEventHandler PropertyChanged;\r
@@ -36,6 +38,7 @@ namespace TVHome.DataModels
             }\r
         }\r
 \r
+        [XmlIgnore]\r
         public Dictionary<String, StateDescription> StateDescriptions\r
         {\r
             get\r
@@ -44,6 +47,7 @@ namespace TVHome.DataModels
             }\r
         }\r
 \r
+        [XmlIgnore]\r
         public StateDescription CurrentStateDescription\r
         {\r
             get;\r
index 56b62a29586c09fa3049e60d88c85bd8cb2caa76..ce9d0f467a5f7d61de4edf642af62667d30070b3 100644 (file)
 \r
 using System;\r
 using System.Collections.Generic;\r
+using Xamarin.Forms;\r
+\r
 using TVHome.DataModels;\r
 using TVHome.Utils;\r
 \r
+\r
 namespace TVHome.Models\r
 {\r
     public class AppShortcutController\r
@@ -29,33 +32,59 @@ namespace TVHome.Models
 \r
         }\r
 \r
-        public bool Remove(AppShortcutInfo shortcut)\r
+        public IEnumerable<AppShortcutInfo> ReadFromFile()\r
         {\r
-            if (AppShortcutStorage.Instance.Delete(shortcut))\r
-            {\r
-                return true;\r
-            }\r
-            else\r
+            IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();\r
+            // Accessing below directory is not permitted.\r
+            // IEnumerable<AppShortcutInfo> pinned_apps_info = AppShortcutStorage.ReadFromFile("/home/owner/apps_rw/TVHome.TizenTV/res/pinned_apps_info.xml");\r
+            IEnumerable<AppShortcutInfo> pinned_apps_info = AppShortcutStorage.ReadFromFile("/opt/usr/home/owner/share/pinned_apps_info.xml");\r
+            string[] icons = { "ic_black.png", "ic_blue.png", "ic_green.png", "ic_red.png", "ic_yellow.png", "AppIcon.png" };\r
+\r
+            foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info)\r
             {\r
-                return false;\r
-            }\r
-        }\r
+                Dictionary<string, string> appInfo = applicationManagerPort.GetInstalledApplication(appShortcutInfo.AppID);\r
 \r
-        public bool ChangeOrder(AppShortcutInfo shortcut)\r
-        {\r
-            return false;\r
-        }\r
+                if (appInfo != null)\r
+                {\r
+                    string appLabel;\r
+                    string appIconPath;\r
 \r
-        public IEnumerable<AppShortcutInfo> GetPackageList()\r
-        {\r
-            IEnumerable<AppShortcutInfo> appList = AppShortcutStorage.Instance.Read();\r
-            return appList;\r
+                    appInfo.TryGetValue("Label",out appLabel);\r
+                    appInfo.TryGetValue("IconPath", out appIconPath);\r
+\r
+                    DebuggingUtils.Dbg("AppID: " + appShortcutInfo.AppID + ", Label : " + appLabel + " IconPath : " + appIconPath);\r
+                    var defaultStateDescription = new StateDescription()\r
+                    {\r
+                        Label = appLabel,\r
+                        IconPath = appIconPath,\r
+                        Action = new AppControlAction\r
+                        {\r
+                            AppID = appShortcutInfo.AppID,\r
+                        }\r
+                    };\r
+                    \r
+                    if (defaultStateDescription.IconPath == null || defaultStateDescription.IconPath.Length == 0)\r
+                    {\r
+                        Random random = new Random();\r
+                        defaultStateDescription.IconPath = icons[random.Next(0, 6)]; //IconPath = (resul5t[2] == null) ? "AppIcon.png" : result[2],\r
+                    }\r
+\r
+                    appShortcutInfo.StateDescriptions.Add("default", defaultStateDescription);\r
+                    appShortcutInfo.CurrentStateDescription = defaultStateDescription;\r
+                }\r
+                else\r
+                {\r
+                    // TODO : Remove the broken appInfo from pinned_apps_info\r
+                }\r
+            }\r
+            return pinned_apps_info;\r
         }\r
 \r
-        public AppShortcutInfo GetItem(string name)\r
+        public void WriteToFile(IEnumerable<AppShortcutInfo> pinnedAppsInfo)\r
         {\r
-            AppShortcutInfo shortcutInfo = AppShortcutStorage.Instance.Read(name);\r
-            return shortcutInfo;\r
+            // Accessing below directory is not permitted.\r
+            // AppShortcutStorage.WriteToFile(pinnedAppsInfo, "/home/owner/apps_rw/TVHome.TizenTV/res/pinned_apps_info.xml");\r
+            AppShortcutStorage.WriteToFile(pinnedAppsInfo, "/opt/usr/home/owner/share/pinned_apps_info.xml");\r
         }\r
 \r
         private bool AddAppShortcutChangedListener()\r
index a0d305f04d565ec47c66ca1b6655ca87ea09f78c..b81c4e986a5d3ea441d6976311fb3a569c1234c7 100644 (file)
@@ -62,7 +62,7 @@ namespace TVHome.Models
                     IconPath = item.Value[2],\r
                     Action = new AppControlAction()\r
                     {\r
-                        PkgID = item.Key\r
+                        AppID = item.Key\r
                     }\r
                 };\r
                 var recentShortcutInfo = new RecentShortcutInfo();\r
index 39da45025a6035db3c0150db74b90202faf965ba..d7d5f2af9f3e14fac3257657c6ed96e32f65f9db 100644 (file)
@@ -73,6 +73,7 @@
     <Compile Include="Utils\IApplicationManagerAPIs.cs" />\r
     <Compile Include="Utils\IBTAPIs.cs" />\r
     <Compile Include="Utils\IDBAPIs.cs" />\r
+    <Compile Include="Utils\IFileSystemAPIs.cs" />\r
     <Compile Include="Utils\IFileSystemWatcherAPIs.cs" />\r
     <Compile Include="Utils\IPackageManager.cs" />\r
     <Compile Include="Utils\IWifiAPIs.cs" />\r
index 6c349fb30a296a8e2ad6fdd62fa0a1ffeb16959e..8ebe08390f09da5fade6ee0c9e2f72682212307a 100644 (file)
@@ -18,8 +18,12 @@ using System.Collections.Generic;
 using System.Linq;\r
 using System.Text;\r
 using System.Threading.Tasks;\r
+using System.Xml;\r
+using System.Xml.Serialization;\r
+using System.IO;\r
 \r
 using TVHome.DataModels;\r
+using TVHome.Utils;\r
 \r
 using Xamarin.Forms;\r
 \r
@@ -27,17 +31,9 @@ namespace TVHome.Utils
 {\r
     public class AppShortcutStorage\r
     {\r
-        private static List<HomeMenuAppShortcutInfo> HomeMenuList = new List<HomeMenuAppShortcutInfo>();\r
-        private static List<AppShortcutInfo> list = new List<AppShortcutInfo>();\r
         private static IFileSystemWatcherAPIs fileSystemWatcher = DependencyService.Get<IFileSystemWatcherAPIs>();\r
-\r
         private static AppShortcutStorage instance = new AppShortcutStorage();\r
 \r
-        private string DBName = "tvhome.apps";\r
-        //private string CreateTableStatement = "CREATE TABLE IF NOT EXISTS app_shortcut(" +\r
-        //private string CreateTableStatement = "CREATE TABLE app_shortcut(" +\r
-        //    "id TEXT PRIMARY KEY, package_id TEXT, app_id TEXT, app_name TEXT);";\r
-\r
         public static AppShortcutStorage Instance\r
         {\r
             get { return instance; }\r
@@ -47,131 +43,87 @@ namespace TVHome.Utils
         {\r
             fileSystemWatcher.Run();\r
         }\r
-\r
-        public bool Create(AppShortcutInfo app)\r
+        \r
+        private static List<AppShortcutInfo> GetSampleList()\r
         {\r
-            string query = "INSERT INTO app_shortcut VALUES(";\r
+            var pinnedAppsInfo = new List<AppShortcutInfo>();\r
 \r
-            foreach (var value in app.GetColumnValues())\r
+            pinnedAppsInfo.Add(new AppShortcutInfo()\r
             {\r
-                query += "'";\r
-                query += value;\r
-                query += "', ";\r
-            }\r
+                AppID = "org.tizen.settings",\r
+            });\r
 \r
-            query = query.Remove(query.Length - 2);\r
-            query += ");";\r
-\r
-            DebuggingUtils.Dbg(DBName + ", " + query);\r
-\r
-            if (DependencyService.Get<IDBAPIs>().ExecSQL(DBName, query) == false)\r
+            pinnedAppsInfo.Add(new AppShortcutInfo()\r
             {\r
-                DebuggingUtils.Err("DB inserting Failed!!! " + query);\r
-            }\r
+                AppID = "org.tizen.chromium-efl.ubrowser",\r
+            });\r
 \r
-            return false;\r
-        }\r
-\r
-        public AppShortcutInfo Read(string key)\r
-        {\r
-            AppShortcutInfo appShortcutInfo = null;\r
+            pinnedAppsInfo.Add(new AppShortcutInfo()\r
+            {\r
+                AppID = "org.tizen.dpm-toolkit",\r
+            });\r
 \r
-            foreach (var item in list)\r
+            pinnedAppsInfo.Add(new AppShortcutInfo()\r
             {\r
-                if (item.StateDescriptions["default"].Label.Equals(key))\r
-                {\r
-                    appShortcutInfo = item;\r
-                    return appShortcutInfo;\r
-                }\r
-            }\r
+                AppID = "org.tizen.infosquare",\r
+            });\r
 \r
-            return null;\r
-        }\r
+            pinnedAppsInfo.Add(new AppShortcutInfo()\r
+            {\r
+                AppID = "org.tizen.mediahub",\r
+            });\r
 \r
-        public IEnumerable<AppShortcutInfo> Read()\r
-        {\r
-            // DB Test code\r
-            /*\r
+            pinnedAppsInfo.Add(new AppShortcutInfo()\r
             {\r
-                DebuggingUtils.Dbg("Read test");\r
-                string query = "SELECT * FROM app_shortcut;";\r
-                IEnumerable<DBItem> items;\r
-\r
-                if (DependencyService.Get<IDBAPIs>().ExecSQL(DBName, query, out items) == false)\r
-                {\r
-                    DebuggingUtils.Err("DB Read Failed!!! " + query);\r
-                }\r
-\r
-                List<AppShortcutInfo> shortcuts = new List<AppShortcutInfo>();\r
-                foreach(var item in items)\r
-                {\r
-                    AppShortcutInfo s = new AppShortcutInfo();\r
-                    s.SetDBItem(item);\r
-                    shortcuts.Add(s);\r
-                }\r
-\r
-                // Testing code, instead of this shortcuts should be returned.\r
-                DebuggingUtils.Dbg("-----------------------");\r
-                foreach (var s in shortcuts)\r
-                {\r
-                    DebuggingUtils.Dbg(String.Format("AppShortcut, {0}, {1}, {2}", s.AppName, s.PackageID, s.AppID));\r
-                }\r
-                DebuggingUtils.Dbg("-----------------------");\r
-            }\r
-                       */\r
+                AppID = "org.tizen.heremaps-uc",\r
+            });\r
 \r
-            // Actual Test code\r
-            List<AppShortcutInfo> list = new List<AppShortcutInfo>();\r
-            Dictionary<string, string[]> pkgList = PackageManagerUtils.Instance.GetPackageList();\r
-            string[] icons = { "ic_black.png", "ic_blue.png", "ic_green.png", "ic_red.png", "ic_yellow.png", "AppIcon.png" };\r
-            Random random = new Random();\r
+            pinnedAppsInfo.Add(new AppShortcutInfo()\r
+            {\r
+                AppID = "org.tizen.ode",\r
+            });\r
 \r
-            string[] result;\r
-            AppShortcutInfo shortcutInfo;\r
+            pinnedAppsInfo.Add(new AppShortcutInfo()\r
+            {\r
+                AppID = "org.tizen.apps",\r
+            });\r
 \r
-            foreach (KeyValuePair<string, string[]> item in pkgList)\r
+            pinnedAppsInfo.Add(new AppShortcutInfo()\r
             {\r
-                result = pkgList[item.Key];\r
-                shortcutInfo = new AppShortcutInfo()\r
-                {\r
-                    StateDescriptions =\r
-                    {\r
-                        {\r
-                            "default",\r
-                            new StateDescription\r
-                            {\r
-                                Label = result[0],\r
-                                IconPath = icons[random.Next(0, 6)],//IconPath = (resul5t[2] == null) ? "AppIcon.png" : result[2],\r
-                                Action = new AppControlAction()\r
-                                {\r
-                                    PkgID = "org.tizen.settings"    // result[1]\r
-                                }\r
-                            }\r
-                        },\r
-                    }\r
-                };\r
-                shortcutInfo.UpdateState();\r
-                list.Add(shortcutInfo);\r
-            }\r
+                AppID = "org.tizen.home",\r
+            });\r
 \r
-            return list;\r
+            return pinnedAppsInfo;\r
         }\r
-\r
-        public bool Update(AppShortcutInfo shortcut)\r
+        public static List<AppShortcutInfo> ReadFromFile(string filePath)\r
         {\r
-            return false;\r
+            IFileSystemAPIs fileSystem = DependencyService.Get<IFileSystemAPIs>();\r
+            XmlSerializer serializer = new XmlSerializer(typeof(List<AppShortcutInfo>));\r
+            Stream fileStream = fileSystem.OpenFile(filePath, UtilFileMode.Open);\r
+            if (fileStream == null)\r
+            {\r
+                DebuggingUtils.Dbg("OpenFile failed : " + filePath);\r
+                // Below lines are just for sample \r
+                List<AppShortcutInfo> result = GetSampleList();\r
+                WriteToFile(result, filePath);\r
+                return result;\r
+            }\r
+            StreamReader streamReader = new StreamReader(fileStream);\r
+            return (List<AppShortcutInfo>)serializer.Deserialize(streamReader);\r
         }\r
 \r
-        public bool Delete(AppShortcutInfo shortcut)\r
+        public static bool WriteToFile(IEnumerable<AppShortcutInfo> pinnedAppInfo, string filePath)\r
         {\r
-            if (list.Remove(shortcut))\r
-            {\r
-                return true;\r
-            }\r
-            else\r
-            {\r
+            IFileSystemAPIs fileSystem = DependencyService.Get<IFileSystemAPIs>();\r
+            XmlSerializer serializer = new XmlSerializer(typeof(List<AppShortcutInfo>));\r
+            Stream fileStream = fileSystem.OpenFile(filePath, UtilFileMode.OpenOrCreate);\r
+            if (fileStream == null)\r
                 return false;\r
-            }\r
+            StreamWriter streamWriter = new StreamWriter(fileStream);\r
+            serializer.Serialize(streamWriter, pinnedAppInfo);\r
+            streamWriter.Flush();\r
+            fileSystem.CloseFile(fileStream);\r
+            return true;\r
         }\r
 \r
         public void AddFileSystemChangedListener(EventHandler<EventArgs> eventListener)\r
index afd41d40646108b48e8a434493866052026d0962..4a01b73d069105cdeacaa3f3232dc828b15decdd 100644 (file)
@@ -25,5 +25,6 @@ namespace TVHome.Utils
     public interface IApplicationManagerAPIs\r
     {\r
         Task<Dictionary<string, string[]>> GetRecentApplications();\r
+        Dictionary<string, string> GetInstalledApplication(string applicationId);\r
     }\r
 }\r
diff --git a/TVHome/TVHome/Utils/IFileSystemAPIs.cs b/TVHome/TVHome/Utils/IFileSystemAPIs.cs
new file mode 100644 (file)
index 0000000..4deef2c
--- /dev/null
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.IO;
+
+namespace TVHome.Utils
+{
+    //
+    // 요약:
+    //     운영 체제에서 파일을 여는 방법을 지정합니다.
+    public enum UtilFileMode
+    {
+        CreateNew = 1,
+        Create = 2,
+        Open = 3,
+        OpenOrCreate = 4,
+        Truncate = 5,
+        Append = 6
+    }
+    public interface IFileSystemAPIs
+    {
+        Stream OpenFile(string filePath, UtilFileMode mode);
+        void Flush(Stream stream);
+        void CloseFile(Stream stream);
+
+    }
+}
index 2d4482dbdb94b8c67ceed2b451f993b66e2b5ae8..cd203bc9c72e53a55d06757b076bd4a7746c75aa 100644 (file)
@@ -64,7 +64,7 @@ namespace TVHome.ViewModels
                                 IconPath = AppIconPath[i],\r
                                 Action = new AppControlAction()\r
                                 {\r
-                                    PkgID = AppControlID[i]\r
+                                    AppID = AppControlID[i]\r
                                 }\r
                             }\r
                         },\r
@@ -79,10 +79,11 @@ namespace TVHome.ViewModels
 \r
             MakeRecentButtons();\r
 \r
-            AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList();\r
+            DebuggingUtils.Dbg("Reading Apps list");\r
+            AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.ReadFromFile();\r
             OnPropertyChanged("AppList");\r
 \r
-            //SettingsList = TVHomeImpl.GetInstance.AppShortcutControllerInstnace.GetPackageList();\r
+            //SettingsList = TVHomeImpl.GetInstance.AppShortcutControllerInstnace.ReadFromFile();\r
             SettingsList = TVHomeImpl.GetInstance.SettingShortcutControllerInstance.GetList();\r
             OnPropertyChanged("SettingsList");\r
 \r
@@ -92,7 +93,7 @@ namespace TVHome.ViewModels
 \r
         private void TestFunction(object sender, EventArgs e)\r
         {\r
-            AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList();\r
+            AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.ReadFromFile();\r
             OnPropertyChanged("AppList");\r
         }\r
 \r