--- /dev/null
+/*
+ * 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.IO;
+using TVHome.Utils;
+using TVHome.DataModels;
+
+namespace TVHome.TizenTV.Ports
+{
+ public class FileSystemWatcherPort : IFileSystemWatcherAPIs
+ {
+ static FileSystemWatcher watcher;
+ public event EventHandler<EventArgs> CustomChanged;
+ private FileSystemEventCustomArgs args;
+
+ public void run()
+ {
+ watcher = new FileSystemWatcher();
+ watcher.Path = "/opt/usr/home/owner/share/";
+ watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.Size;
+ watcher.Filter = "apinnedapp.xml";
+
+ watcher.Created += new FileSystemEventHandler(WatcherChanged);
+ watcher.Changed += new FileSystemEventHandler(WatcherChanged);
+ watcher.Deleted += new FileSystemEventHandler(WatcherChanged);
+ watcher.IncludeSubdirectories = true;
+ watcher.EnableRaisingEvents = true;
+ }
+
+ private void WatcherChanged(object sender, FileSystemEventArgs e)
+ {
+ args = new FileSystemEventCustomArgs((WatcherType)e.ChangeType, e.FullPath, e.Name);
+ if (e.ChangeType.Equals(WatcherChangeTypes.Changed))
+ {
+ CustomChanged(this, args);
+ }
+ DebuggingPort.d(e.ChangeType + ", " + e.Name);
+ }
+ }
+}
global::Xamarin.Forms.DependencyService.Register<PackageManagerPort>();\r
global::Xamarin.Forms.DependencyService.Register<WifiModulePort>();\r
global::Xamarin.Forms.DependencyService.Register<BTModulePort>();\r
- global::Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();\r
+ global::Xamarin.Forms.DependencyService.Register<FileSystemWatcherPort>();\r
+ global::Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();\r
global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);\r
app.Run(args);\r
}\r
--- /dev/null
+/*
+ * 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;
+
+namespace TVHome.DataModels
+{
+ public class FileSystemEventCustomArgs : EventArgs
+ {
+ //
+ // Summary:
+ // Initializes a new instance of the System.IO.FileSystemEventArgs class.
+ //
+ // Parameters:
+ // changeType:
+ // One of the System.IO.WatcherChangeTypes values, which represents the kind of
+ // change detected in the file system.
+ //
+ // directory:
+ // The root directory of the affected file or directory.
+ //
+ // name:
+ // The name of the affected file or directory.
+ public FileSystemEventCustomArgs(WatcherType changeType, string directory, string name)
+ {
+ ChangeType = changeType;
+ FullPath = directory;
+ Name = name;
+ }
+
+ //
+ // Summary:
+ // Gets the type of directory event that occurred.
+ //
+ // Returns:
+ // One of the System.IO.WatcherChangeTypes values that represents the kind of change
+ // detected in the file system.
+ public WatcherType ChangeType { set; get; }
+ //
+ // Summary:
+ // Gets the fully qualifed path of the affected file or directory.
+ //
+ // Returns:
+ // The path of the affected file or directory.
+ public string FullPath { set; get; }
+ //
+ // Summary:
+ // Gets the name of the affected file or directory.
+ //
+ // Returns:
+ // The name of the affected file or directory.
+ public string Name { set; get; }
+ }
+}
+
--- /dev/null
+namespace TVHome.DataModels
+{
+ public enum WatcherType
+ {
+ //
+ // Summary:
+ // The creation of a file or folder.
+ Created = 1,
+ //
+ // Summary:
+ // The deletion of a file or folder.
+ Deleted = 2,
+ //
+ // Summary:
+ // The change of a file or folder. The types of changes include: changes to size,
+ // attributes, security settings, last write, and last access time.
+ Changed = 4,
+ //
+ // Summary:
+ // The renaming of a file or folder.
+ Renamed = 8,
+ //
+ // Summary:
+ // The creation, deletion, change, or renaming of a file or folder.
+ All = 15
+ }
+}
* limitations under the License.\r
*/\r
\r
+using System;\r
using System.Collections.Generic;\r
using TVHome.DataModels;\r
using TVHome.Utils;\r
\r
public IEnumerable<AppShortcutInfo> GetPackageList()\r
{\r
- IEnumerable<AppShortcutInfo> appList = AppShortcutStorage.Read();\r
+ IEnumerable<AppShortcutInfo> appList = AppShortcutStorage.Instance.Read();\r
return appList;\r
}\r
\r
// TODO : register to Tizen app framework to get notification of app list change.\r
return false;\r
}\r
+\r
+ public void AddFileSystemChangedListener(EventHandler<EventArgs> eventListener)\r
+ {\r
+ if (AppShortcutStorage.Instance != null)\r
+ {\r
+ AppShortcutStorage.Instance.AddFileSystemChangedListener(eventListener);\r
+ }\r
+ else\r
+ {\r
+ DebuggingUtils.Dbg("AppShortcutStorage Instance is NULL");\r
+ }\r
+ }\r
}\r
}\r
{\r
public class AppShortcutStorage\r
{\r
- private static AppShortcutStorage instance = new 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
\r
public static AppShortcutStorage Instance\r
{\r
- get;\r
+ get { return instance; }\r
}\r
\r
private AppShortcutStorage()\r
{\r
- DebuggingUtils.Err("AppShortcutStorage ------------------------------");\r
-\r
- DebuggingUtils.Err("Create Table");\r
- if (DependencyService.Get<IDBAPIs>().ExecSQL(DBName, CreateTableStatement) == false)\r
- {\r
- DebuggingUtils.Err("DB Creation Failed!!! " + CreateTableStatement);\r
- }\r
-\r
- DebuggingUtils.Err("Create Apps ------------------------------");\r
- AppShortcutInfo app1 = new AppShortcutInfo()\r
- {\r
- ID = "app1",\r
- AppName = "app1",\r
- PackageID = "org.tizen.settings",\r
- AppID = "org.tizen.settings",\r
- StateDescriptions =\r
- {\r
- {\r
- "default",\r
- new StateDescription\r
- {\r
- Label = "default",\r
- IconPath = "wifion.png", // result[2]\r
- Action = new AppControlAction()\r
- {\r
- PkgID = "org.tizen.settings" // result[1]\r
- }\r
- }\r
- },\r
- }\r
- };\r
- Create(app1);\r
- AppShortcutInfo app2 = new AppShortcutInfo()\r
- {\r
- ID = "app2",\r
- AppName = "app2",\r
- PackageID = "org.tizen.settings",\r
- AppID = "org.tizen.settings",\r
- StateDescriptions =\r
- {\r
- {\r
- "default",\r
- new StateDescription\r
- {\r
- Label = "default",\r
- IconPath = "wifion.png", // result[2]\r
- Action = new AppControlAction()\r
- {\r
- PkgID = "org.tizen.settings" // result[1]\r
- }\r
- }\r
- },\r
- }\r
- };\r
- Create(app2);\r
- AppShortcutInfo app3 = new AppShortcutInfo()\r
- {\r
- ID = "app3",\r
- AppName = "app3",\r
- PackageID = "org.tizen.settings",\r
- AppID = "org.tizen.settings",\r
- StateDescriptions =\r
- {\r
- {\r
- "default",\r
- new StateDescription\r
- {\r
- Label = "default",\r
- IconPath = "wifion.png", // result[2]\r
- Action = new AppControlAction()\r
- {\r
- PkgID = "org.tizen.settings" // result[1]\r
- }\r
- }\r
- },\r
- }\r
- };\r
- Create(app3);\r
-\r
- // DB Test code\r
- DebuggingUtils.Err("Read Apps ------------------------------");\r
- Read();\r
+ fileSystemWatcher.run();\r
}\r
-\r
public bool Create(AppShortcutInfo app)\r
{\r
string query = "INSERT INTO app_shortcut VALUES(";\r
\r
- foreach(var value in app.GetColumnValues())\r
+ foreach (var value in app.GetColumnValues())\r
{\r
query += "'";\r
query += value;\r
return null;\r
}\r
\r
- public static IEnumerable<AppShortcutInfo> Read()\r
+ public IEnumerable<AppShortcutInfo> Read()\r
{\r
// DB Test code\r
- /*\r
+ /*\r
{\r
DebuggingUtils.Dbg("Read test");\r
string query = "SELECT * FROM app_shortcut;";\r
return false;\r
}\r
}\r
+\r
+ public void AddFileSystemChangedListener(EventHandler<EventArgs> eventListener)\r
+ {\r
+ fileSystemWatcher.CustomChanged += eventListener;\r
+ }\r
}\r
}\r
--- /dev/null
+using System;
+using TVHome.DataModels;
+
+namespace TVHome.Utils
+{
+ public interface IFileSystemWatcherAPIs
+ {
+ event EventHandler<EventArgs> CustomChanged;
+ void run();
+ }
+}
MainList = TempList;\r
OnPropertyChanged("MainList");\r
\r
- MakeRecentButtons();\r
-\r
- AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList();\r
+ MakeRecentButtons();\r
\r
+ AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList();\r
OnPropertyChanged("AppList");\r
\r
//SettingsList = TVHomeImpl.GetInstance.AppShortcutControllerInstnace.GetPackageList();\r
SettingsList = TVHomeImpl.GetInstance.SettingShortcutControllerInstance.GetList();\r
OnPropertyChanged("SettingsList");\r
+\r
+ TVHomeImpl.GetInstance.AppShortcutControllerInstance.AddFileSystemChangedListener(TestFunction);\r
}\r
\r
- private async void MakeRecentButtons()\r
- {\r
- RecentList = await TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList();\r
- if (RecentList != null)\r
- {\r
- OnPropertyChanged("RecentList");\r
- }\r
- }\r
\r
- }\r
+ private void TestFunction(object sender, EventArgs e)\r
+ {\r
+ AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList();\r
+ OnPropertyChanged("AppList");\r
+ }\r
+\r
+ private async void MakeRecentButtons()\r
+ {\r
+ RecentList = await TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList();\r
+ if (RecentList != null)\r
+ {\r
+ OnPropertyChanged("RecentList");\r
+ }\r
+ }\r
+\r
+ }\r
}\r