(TODO) need to provide selection app info to Home.
Change-Id: I7cd94a2f65310975320e3fcabf511bd7e777bb70
<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" />
{
public class AppShortcutController
{
+ private static String DefaultAppIcon = "AppIcon.png";
+
public AppShortcutController()
{
public async Task<IEnumerable<AppShortcutInfo>> GetInstalledApps()
{
- DebuggingUtils.Dbg(">AppShortcutController, GetInstalledApps - start");
IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
List<AppShortcutInfo> appShortcutInfoList = new List<AppShortcutInfo>();
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()
{
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 = "",
}
};
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)
{
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,
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);
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>();
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)
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>();
}
};
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);
* limitations under the License.
*/
-using LibTVRefCommonPortable.Utils;
using Xamarin.Forms;
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();
+ }
}
}
*/
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
{
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;
}
public interface IAppControl
{
void SendLaunchRequest(string PkgID);
+
+ void SendAddAppRequestToApps();
+
+ void SendAppAddedNotificationToHome(string addedAddID);
}
}
--- /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.
+ */
+
+namespace LibTVRefCommonPortable.Utils
+{
+ public interface IAppLifeControl
+ {
+ void SelfTerminate();
+ }
+}
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);
}
}
{
public interface IPlatformNotification
{
- void OnBackKeyPressed();
-
void OnAppInstalled(string pkgID);
void OnAppUninstalled(string pkgID);
+
+ void OnPinAppRequestReceived();
+
+ void OnAppPinnedNotificationReceived(string appID);
}
}
-/*
+/*
* Copyright (c) 2017 Samsung Electronics Co., Ltd
*
* Licensed under the Flora License, Version 1.1 (the "License");
*/
+using System;
using LibTVRefCommonPortable.Utils;
using Tizen.Applications;
{
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();
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);
+ }
}
}
{
public class ApplicationManagerPort : IApplicationManagerAPIs
{
+ private static String DefaultAppIcon = "AppIcon.png";
+
public ApplicationManagerPort()
{
ApplicationManager.ApplicationLaunched += new EventHandler<ApplicationLaunchedEventArgs>(OnApplicationLaunched);
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);
}
{
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
{
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)
{
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);
}
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)
{
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;
+ }
+ }
}
}
* 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;
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()
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)
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>();
}
+ public void SelfTerminate()
+ {
+ Exit();
+ }
}
}
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()
{
}
- public static void SetBackKeyListener(EventHandler<TVAppsEventArgs> listener)
- {
- BackKeyListener += listener;
- }
-
public static void SetAppInstalledListener(EventHandler<TVAppsEventArgs> listener)
{
AppInstalledListener += listener;
{
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)
arg = pkgID,
});
}
+
+ public void OnPinAppRequestReceived()
+ {
+ DebuggingUtils.Dbg("[[[ Pin Add Request ]]] ");
+ PinAppRequestListener.Invoke(this, new TVAppsEventArgs());
+ }
+
+ public void OnAppPinnedNotificationReceived(string appID)
+ {
+ }
}
}
using LibTVRefCommonPortable.Utils;
using System.Collections.Generic;
using System.Linq;
+using System.Threading.Tasks;
using Xamarin.Forms;
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)
{
InstalledApps = installedApps.ToList();
SortApps(SortingOption);
+ UpdateStateDescription(ViewModel.CurrentStatus);
}
private void PinToggle(string key)
RefreshApps();
}
- public void ResetPinnedApps()
+ public async void ResetPinnedApps()
{
- PinnedApps = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs();
+ PinnedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs();
}
public void UpdatePinnedApps()
{
interface IAppsViewModel
{
+ AppsStatus CurrentStatus { get; }
+
void OnPropertyChanged(string name);
void ChangeCurrentStatus(AppsStatus newStatus);
}
public event PropertyChangedEventHandler PropertyChanged;
+ private bool IsPinAppRequested;
+
public MainPageViewModel()
{
DebuggingUtils.Dbg(">MainPageViewModel - Start");
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) =>
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");
}
}
- // 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;
}
return true;
}
-
+ /*
protected override bool OnBackButtonPressed()
{
DebuggingUtils.Dbg("OnBackButtonPressed");
}, "");
return true;
}
+ */
}
}
using LibTVRefCommonPortable.Utils;
using LibTVRefCommonTizen.Ports;
+using Tizen.Applications;
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()
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)
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()
{
}
- public static void SetBackKeyListener(EventHandler<TVHomeEventArgs> listener)
- {
- BackKeyListener += listener;
- }
-
public static void SetAppInstalledListener(EventHandler<TVHomeEventArgs> listener)
{
AppInstalledListener += listener;
{
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)
arg = pkgID,
});
}
+
+ public void OnPinAppRequestReceived()
+ {
+
+ }
+
+ public void OnAppPinnedNotificationReceived(String AppID)
+ {
+ DebuggingUtils.Dbg("[[[ App Pinned ]]] " + AppID);
+ AppPinnedNotificationListener.Invoke(this, new TVHomeEventArgs()
+ {
+ arg = AppID,
+ });
+ }
}
}
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");
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);