From: cskim Date: Mon, 27 Mar 2017 05:50:10 +0000 (+0900) Subject: Make the TVHome uses application api for Recent apps X-Git-Tag: submit/tizen/20170808.015446~153 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff50ba37d065465a28a175fcd41a17f1e045a603;p=profile%2Ftv%2Fapps%2Fdotnet%2Fhome.git Make the TVHome uses application api for Recent apps Change-Id: I250d28f60537a52d29a15d215bd97b74b154d92b --- diff --git a/LibTVRefCommonPortable/Models/AppShortcutController.cs b/LibTVRefCommonPortable/Models/AppShortcutController.cs index cdf27ce..e432e4f 100755 --- a/LibTVRefCommonPortable/Models/AppShortcutController.cs +++ b/LibTVRefCommonPortable/Models/AppShortcutController.cs @@ -148,10 +148,13 @@ namespace LibTVRefCommonPortable.Models string appLabel; string appIconPath; - appInfo.TryGetValue("Label", out appLabel); + if (appInfo.TryGetValue("Label", out appLabel) == false) + { + appLabel = "No Name"; + } + appInfo.TryGetValue("IconPath", out appIconPath); - DebuggingUtils.Dbg("AppID: " + appShortcutInfo.AppID + ", Label : " + appLabel); var defaultStateDescription = new StateDescription() { Label = appLabel, diff --git a/LibTVRefCommonPortable/Models/RecentShortcutController.cs b/LibTVRefCommonPortable/Models/RecentShortcutController.cs index 30d0ece..0de468b 100644 --- a/LibTVRefCommonPortable/Models/RecentShortcutController.cs +++ b/LibTVRefCommonPortable/Models/RecentShortcutController.cs @@ -47,21 +47,21 @@ namespace LibTVRefCommonPortable.Models return false; } - public async Task> GetList() + public IEnumerable GetList() { IApplicationManagerAPIs applicationManagerPort = DependencyService.Get(); List recentShortcutInfoList = new List(); - var applicationList = await applicationManagerPort.GetRecentApplications(); - foreach (KeyValuePair item in applicationList) + var recentApps = applicationManagerPort.GetRecentApplications(); + foreach (var item in recentApps) { var defaultStateDescription = new StateDescription() { - Label = item.Value[0], - IconPath = item.Value[2], + Label = item.instanceLabel, + IconPath = item.iconPath, Action = new AppControlAction() { - AppID = item.Key + AppID = item.appID, } }; var recentShortcutInfo = new RecentShortcutInfo(); diff --git a/LibTVRefCommonPortable/Models/SettingShortcutController.cs b/LibTVRefCommonPortable/Models/SettingShortcutController.cs index 3f35578..448dfd9 100755 --- a/LibTVRefCommonPortable/Models/SettingShortcutController.cs +++ b/LibTVRefCommonPortable/Models/SettingShortcutController.cs @@ -27,6 +27,7 @@ namespace LibTVRefCommonPortable.Models public SettingShortcutController() { + // TODO : read from file!!! ShortcutInfo settings = SettingShortcutFactory.Get(SettingID.SETTINGS); settingShortcutList.Add(settings); @@ -41,7 +42,7 @@ namespace LibTVRefCommonPortable.Models public IEnumerable GetList() { - return settingShortcutList ?? null; + return new List(settingShortcutList); } } diff --git a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs index a5865eb..acc4777 100644 --- a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs +++ b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs @@ -54,36 +54,16 @@ namespace LibTVRefCommonPortable.Utils AppID = "org.tizen.settings", }); - pinnedAppsInfo.Add(new AppShortcutInfo() - { - AppID = "org.tizen.chromium-efl.ubrowser", - }); - pinnedAppsInfo.Add(new AppShortcutInfo() { AppID = "org.tizen.dpm-toolkit", }); - pinnedAppsInfo.Add(new AppShortcutInfo() - { - AppID = "org.tizen.infosquare", - }); - pinnedAppsInfo.Add(new AppShortcutInfo() { AppID = "org.tizen.mediahub", }); - pinnedAppsInfo.Add(new AppShortcutInfo() - { - AppID = "org.tizen.heremaps-uc", - }); - - pinnedAppsInfo.Add(new AppShortcutInfo() - { - AppID = "org.tizen.ode", - }); - pinnedAppsInfo.Add(new AppShortcutInfo() { AppID = "org.tizen.apps", diff --git a/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs b/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs index df1c369..7a8f693 100644 --- a/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs +++ b/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs @@ -22,10 +22,21 @@ using System.Threading.Tasks; namespace LibTVRefCommonPortable.Utils { + public class RecentApp + { + public String instanceID; + public String instanceLabel; + public String appID; + public String applabel; + public String iconPath; + public DateTime launchedTime; + public String uri; + } + public interface IApplicationManagerAPIs { Task> GetAllInstalledApplication(); - Task> GetRecentApplications(); + IEnumerable GetRecentApplications(); Dictionary GetInstalledApplication(string applicationId); } } diff --git a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs index bb98cb7..2995618 100644 --- a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs +++ b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs @@ -39,27 +39,30 @@ namespace LibTVRefCommonTizen.Ports DebuggingUtils.Dbg(launchedEventArgs.ApplicationRunningContext.ApplicationId + " launched"); } - public async Task> GetRecentApplications() + public IEnumerable GetRecentApplications() { - // RUA가 지원되지 않으므로 일단 설치된 app들을 가져와 본다 - // TODO: RUA로 대체한다 - Dictionary resultList = new Dictionary(); - var applicationList = await ApplicationManager.GetInstalledApplicationsAsync(); - string[] result; + List resultList = new List(); + IEnumerable recentApps = ApplicationManager.GetRecentApplications(); - foreach (ApplicationInfo appInfo in applicationList) + foreach (var app in recentApps) { - if (appInfo.Label == null || - appInfo.ApplicationId == null) + if (app.IsNoDisplay || + app.ApplicationId == null || + app.ApplicationId.Length < 1) { continue; } - result = new string[3]; - result[0] = appInfo.Label; - result[1] = appInfo.ApplicationId; - result[2] = (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : DefaultAppIcon; - resultList.Add(appInfo.ApplicationId, result); + resultList.Add(new RecentApp() + { + instanceID = app.InstanceId, + instanceLabel = app.InstanceName, + appID = app.ApplicationId, + applabel = (app.Label == null || app.Label.Length < 1) ? "No Name" : app.Label, + iconPath = app.IconPath, + launchedTime = app.LaunchTime, + uri = app.Uri, + }); } return resultList; diff --git a/TVApps/TVApps.TizenTV/Renderer/NinePatchImageRenderer.cs b/TVApps/TVApps.TizenTV/Renderer/NinePatchImageRenderer.cs index f9b18f9..a83f448 100644 --- a/TVApps/TVApps.TizenTV/Renderer/NinePatchImageRenderer.cs +++ b/TVApps/TVApps.TizenTV/Renderer/NinePatchImageRenderer.cs @@ -42,6 +42,7 @@ namespace TVApps.TizenTV.Renderer { UpdateBorder(); } + base.OnElementPropertyChanged(sender, e); } diff --git a/TVApps/TVApps/Views/MainPage.xaml.cs b/TVApps/TVApps/Views/MainPage.xaml.cs index 50f6409..83b5481 100644 --- a/TVApps/TVApps/Views/MainPage.xaml.cs +++ b/TVApps/TVApps/Views/MainPage.xaml.cs @@ -35,12 +35,14 @@ namespace TVApps.Views get { return (AppsStatus)GetValue(CurrentStatusProperty); } set { SetValue(CurrentStatusProperty, value); } } + /* private async void PlayHideAnimation() { // TODO : Apps Out Animation. } */ + private async void PlayShowAnimation() { await AppList.TranslateTo(0, 12, 0); @@ -114,8 +116,6 @@ namespace TVApps.Views private async Task OnBackKeyPressedAtMain() { - DebuggingUtils.Dbg("OnBackKeyPressedAtMain - first item focused? " + AppList.IsFirstItemFocused); - if (CurrentStatus != AppsStatus.Default) { MessagingCenter.Send(this, "ChangeCurrentStatus", AppsStatus.Default.ToString()); @@ -124,7 +124,6 @@ namespace TVApps.Views if (!AppList.IsFirstItemFocused) { - DebuggingUtils.Dbg("OnBackKeyPressedAtMain - focus move"); AppList.InitializeFocus(); return true; } @@ -132,7 +131,6 @@ namespace TVApps.Views var answer = await DisplayAlert("QUIT", "Do you want to quit?", "YES", "NO"); if (answer) { - DebuggingUtils.Dbg("OnBackKeyPressedAtMain - Yes"); AppControlUtils.SelfTerminate(); return true; } @@ -142,7 +140,6 @@ namespace TVApps.Views protected override bool OnBackButtonPressed() { - DebuggingUtils.Dbg("OnBackButtonPressed"); SynchronizationContext.Current.Post(async (o) => { await OnBackKeyPressedAtMain(); diff --git a/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs b/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs index 8adcef5..b88fe17 100755 --- a/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs +++ b/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs @@ -50,7 +50,9 @@ namespace TVHome.TizenTV AppResourcePath = DirectoryInfo.Resource; AppDataPath = DirectoryInfo.Data; + DbgPort.D("-----------------------------------"); DbgPort.D("Home application is being loaded..."); + DbgPort.D("-----------------------------------"); LoadApplication(app); PackageManagerPort.RegisterCallbacks(notification); @@ -98,10 +100,6 @@ namespace TVHome.TizenTV protected override void OnAppControlReceived(AppControlReceivedEventArgs e) { - DbgPort.D("OnAppControlReceived, " + e.ReceivedAppControl.Operation); - DbgPort.D("ApplicationId = " + e.ReceivedAppControl.ApplicationId); - DbgPort.D("CallerApplicationId = " + e.ReceivedAppControl.CallerApplicationId); - if (AppControlPort.AppAddedNotifyOperation.CompareTo(e.ReceivedAppControl.Operation) == 0) { DbgPort.D("App Added Notification"); diff --git a/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk b/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk index 8b7cce5..67c65aa 100644 Binary files a/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk and b/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk differ diff --git a/TVHome/TVHome/TVHome.cs b/TVHome/TVHome/TVHome.cs index 59102ce..a925b9b 100755 --- a/TVHome/TVHome/TVHome.cs +++ b/TVHome/TVHome/TVHome.cs @@ -26,8 +26,17 @@ namespace TVHome public string arg; } + public enum TVHomeStatus + { + OnStart, + OnSleep, + OnResume, + } + public class App : Application, IPlatformNotification { + public static readonly string AppStatus = "appstatus"; + private static EventHandler HomeKeyListener; private static EventHandler MenuKeyListener; private static EventHandler AppInstalledListener; @@ -41,17 +50,17 @@ namespace TVHome protected override void OnStart() { - + MessagingCenter.Send(this, "appstatus", TVHomeStatus.OnStart); } protected override void OnSleep() { - + MessagingCenter.Send(this, "appstatus", TVHomeStatus.OnSleep); } protected override void OnResume() { - + MessagingCenter.Send(this, "appstatus", TVHomeStatus.OnResume); } public static void SetHomeKeyListener(EventHandler listener) diff --git a/TVHome/TVHome/ViewModels/IHomeViewModel.cs b/TVHome/TVHome/ViewModels/IHomeViewModel.cs index 31963b3..f3e6528 100644 --- a/TVHome/TVHome/ViewModels/IHomeViewModel.cs +++ b/TVHome/TVHome/ViewModels/IHomeViewModel.cs @@ -9,6 +9,6 @@ namespace TVHome.ViewModels interface IHomeViewModel { void OnPropertyChanged(string name); - void ChangeCurrentStatus(HomeStatus newStatus); + void ChangeCurrentStatus(HomeStatus newStatus, bool isForceUpdate); } } diff --git a/TVHome/TVHome/ViewModels/MainPageViewModel.cs b/TVHome/TVHome/ViewModels/MainPageViewModel.cs index 5221cdc..e6a2cc1 100755 --- a/TVHome/TVHome/ViewModels/MainPageViewModel.cs +++ b/TVHome/TVHome/ViewModels/MainPageViewModel.cs @@ -15,11 +15,8 @@ */ using System; -using System.Collections; using System.Collections.Generic; using System.ComponentModel; -using System.Windows.Input; -using System.Threading.Tasks; using System.Linq; using LibTVRefCommonPortable.DataModels; using LibTVRefCommonPortable.Utils; @@ -64,25 +61,23 @@ namespace TVHome.ViewModels public MainPageViewModel() { - Init(); - InitCommands(); + // Init sequence + // MainPage ( MainPageViewModel -> MainPanel -> SubPanel ) MakeMainMenuItems(); - MakeRecentButtons(); + InitStatus(); + InitCommands(); + SetDefaultAppList(); + MakeSettingsButtons(); - DebuggingUtils.Dbg("Reading Apps list"); - 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(UpdateAppList); App.SetAppPinnedNotificationListener((s, e) => { // TODO : Make this for Move a pinned app/Show pinned apps(scroll to last) + ChangeCurrentStatus(HomeStatus.SubPanelFocused); + ChangeSelectedPanelName(HomeMenuItem.Apps); if (e.arg.Length > 0) { DebuggingUtils.Dbg("Move, AppID : " + e.arg); @@ -92,12 +87,24 @@ namespace TVHome.ViewModels DebuggingUtils.Dbg("Show, Pinned Apps"); } }); + + MessagingCenter.Subscribe(this, App.AppStatus, (sender, arg) => + { + switch (arg) + { + case TVHomeStatus.OnResume: + MakeRecentButtons(); + break; + case TVHomeStatus.OnSleep: + ChangeCurrentStatus(HomeStatus.Default, true); + break; + } + }); } - private void Init() + private void InitStatus() { - CurrentStatus = HomeStatus.Default; - SelectedMenuName = HomeMenuItem.NotSelected; + ChangeCurrentStatus(HomeStatus.Default, true); } private void InitCommands() @@ -137,7 +144,7 @@ namespace TVHome.ViewModels string[] AppUnselectIconPath = { "ic_tizen_home_menu_recent_unselect.png", "ic_tizen_home_menu_apps_unselect.png", "ic_tizen_home_menu_settings_unselect.png" }; List TempList = new List(); - for (int i = 0; i < 3; i++) + for (int i = 0; i < AppName.Length; i++) { ShortcutInfo shortcutInfo = new HomeMenuAppShortcutInfo() { @@ -201,15 +208,27 @@ namespace TVHome.ViewModels OnPropertyChanged("MainList"); } + private void SetDefaultAppList() + { + AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetDefaultShortcuts(); + OnPropertyChanged("AppList"); + } + private async void UpdateAppList(object sender, EventArgs e) { AppList = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsWithDefaultShortcuts(); OnPropertyChanged("AppList"); } - private async void MakeRecentButtons() + private void MakeSettingsButtons() + { + SettingsList = TVHomeImpl.GetInstance.SettingShortcutControllerInstance.GetList(); + OnPropertyChanged("SettingsList"); + } + + private void MakeRecentButtons() { - RecentList = await TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList(); + RecentList = TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList(); if (RecentList.Count() > 0) { IsShowNoRecentContents = false; @@ -232,25 +251,43 @@ namespace TVHome.ViewModels } } - public void ChangeCurrentStatus(HomeStatus newStatus) + public void ChangeCurrentStatus(HomeStatus newStatus, bool isForceUpdate = false) { - if (CurrentStatus.CompareTo(newStatus) != 0) + if (isForceUpdate || + CurrentStatus.CompareTo(newStatus) != 0) { CurrentStatus = newStatus; - if (CurrentStatus.CompareTo(HomeStatus.MainPanelFocused) == 0) + if (CurrentStatus.CompareTo(HomeStatus.Default) == 0) + { + foreach (HomeMenuAppShortcutInfo item in MainList) + { + if (item.CurrentStateDescription.Label.CompareTo("Apps") == 0) + { + DebuggingUtils.Dbg(item.CurrentStateDescription.Label + " To Focused"); + item.ChangeStatus("focused"); + } + else + { + DebuggingUtils.Dbg(item.CurrentStateDescription.Label + " To Default"); + item.ChangeStatus("default"); + } + } + + ChangeSelectedPanelName(HomeMenuItem.Apps, isForceUpdate); + } + else if (CurrentStatus.CompareTo(HomeStatus.MainPanelFocused) == 0) { HomeMenuItem index = HomeMenuItem.Recent; foreach (HomeMenuAppShortcutInfo item in MainList) { - DebuggingUtils.Dbg(index.ToString()); if (index == SelectedMenuName) { - DebuggingUtils.Dbg("To Focused"); + DebuggingUtils.Dbg(index.ToString() + " To Focused"); item.ChangeStatus("focused"); } else { - DebuggingUtils.Dbg("To Default"); + DebuggingUtils.Dbg(index.ToString() + " To Default"); item.ChangeStatus("default"); } @@ -262,15 +299,14 @@ namespace TVHome.ViewModels HomeMenuItem index = HomeMenuItem.Recent; foreach (HomeMenuAppShortcutInfo item in MainList) { - DebuggingUtils.Dbg(index.ToString()); if (index == SelectedMenuName) { - DebuggingUtils.Dbg("To be selected"); + DebuggingUtils.Dbg(index.ToString() + " To be selected"); item.ChangeStatus("selected"); } else { - DebuggingUtils.Dbg("To be unselect"); + DebuggingUtils.Dbg(index.ToString() + " To be unselect"); item.ChangeStatus("unselect"); } @@ -282,23 +318,23 @@ namespace TVHome.ViewModels } } - public void ChangeSelectedPanelName(HomeMenuItem panelName) + public void ChangeSelectedPanelName(HomeMenuItem panelName, bool isForceUpdate = false) { - if (SelectedMenuName.CompareTo(panelName) != 0) + if (isForceUpdate || + SelectedMenuName.CompareTo(panelName) != 0) { SelectedMenuName = panelName; HomeMenuItem index = HomeMenuItem.Recent; foreach (HomeMenuAppShortcutInfo item in MainList) { - DebuggingUtils.Dbg(index.ToString()); if (index == panelName) { - DebuggingUtils.Dbg("To Focused"); + DebuggingUtils.Dbg(index.ToString() + " To Focused"); item.ChangeStatus("focused"); } else { - DebuggingUtils.Dbg("To Default"); + DebuggingUtils.Dbg(index.ToString() + " To Default"); item.ChangeStatus("default"); } diff --git a/TVHome/TVHome/Views/MainPage.xaml b/TVHome/TVHome/Views/MainPage.xaml index 4cba2b0..fe668c9 100755 --- a/TVHome/TVHome/Views/MainPage.xaml +++ b/TVHome/TVHome/Views/MainPage.xaml @@ -5,7 +5,6 @@ xmlns:Views="clr-namespace:TVHome.Views" xmlns:ViewModels="clr-namespace:TVHome.ViewModels" xmlns:Controls="clr-namespace:TVHome.Controls" - Appearing="OnAppearing" CurrentStatus="{Binding CurrentStatus}" SelectedMenuName="{Binding SelectedMenuName}"> diff --git a/TVHome/TVHome/Views/MainPage.xaml.cs b/TVHome/TVHome/Views/MainPage.xaml.cs index a344fcf..8c8887d 100755 --- a/TVHome/TVHome/Views/MainPage.xaml.cs +++ b/TVHome/TVHome/Views/MainPage.xaml.cs @@ -88,6 +88,11 @@ namespace TVHome.Views SubPanelDictionary.Add(HomeMenuItem.Recent, RecentSubPanel); SubPanelDictionary.Add(HomeMenuItem.Apps, AppsSubPanel); SubPanelDictionary.Add(HomeMenuItem.Settings, SettingsSubPanel); + + RecentSubPanel.HidePanel(); + AppsSubPanel.ShowPanel(); + SettingsSubPanel.HidePanel(); + PropertyChanged += MainPage_PropertyChanged; App.SetHomeKeyListener((e, arg) => @@ -112,11 +117,18 @@ namespace TVHome.Views { //UnpinAppShortcutInfo(appId); }); + + MessagingCenter.Subscribe(this, App.AppStatus, (sender, arg) => + { + if (arg == TVHomeStatus.OnSleep) + { + PageMainPanel.InitialFocusing(); + } + }); } private void MainPage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { - DebuggingUtils.Dbg(e.PropertyName); if (e.PropertyName.CompareTo("CurrentStatus") == 0) { SetCurrentStatus(CurrentStatus); @@ -143,28 +155,19 @@ namespace TVHome.Views private void SelectMenu(HomeMenuItem panelName) { - if (panelName == HomeMenuItem.NotSelected) + foreach (var panelItem in SubPanelDictionary) { - return; + panelItem.Value.HidePanel(); } - IEnumerable panels = from pair in SubPanelDictionary - where pair.Key != panelName - select pair.Value; - - foreach (Panel panel in panels) + if (panelName == HomeMenuItem.NotSelected) { - panel.HidePanel(); + return; } SubPanelDictionary[panelName].ShowPanel(); } - private void OnAppearing(object sender, EventArgs e) - { - PageMainPanel.InitialFocusing(); - } - private void UnpinAppShortcutInfo(string appId) { RemovePinnedApp(appId); diff --git a/TVHome/TVHome/Views/SubThumbnailPanel.xaml b/TVHome/TVHome/Views/SubThumbnailPanel.xaml index a11e9e0..d60d64b 100755 --- a/TVHome/TVHome/Views/SubThumbnailPanel.xaml +++ b/TVHome/TVHome/Views/SubThumbnailPanel.xaml @@ -41,7 +41,7 @@ RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=BackgroundBox ,Property=Width, Factor=0.28858}" Text="No Content to display" HorizontalTextAlignment="Center" - FontSize="56" + FontSize="40" TextColor="White" />