From 3e21538dd7f44054120fec5c20c63cd1834e2259 Mon Sep 17 00:00:00 2001 From: Hyerim Kim Date: Wed, 29 Mar 2017 20:58:58 +0900 Subject: [PATCH] Add comments for TVHome.ViewModels, TVHome.Views and Main Change-Id: I1a1542c2e9e0ff14eb3167cf9c622c974ef8e17c Signed-off-by: Hyerim Kim (cherry picked from commit b39a3b334f32c982fe77b278dee39e11c7bfffd6) --- TVHome/TVHome.TizenTV/TVHome.TizenTV.cs | 39 +++++++++-- TVHome/TVHome/TVHome.cs | 93 +++++++++++++++++++++++++-- TVHome/TVHome/ViewModels/IHomeViewModel.cs | 33 ++++++++-- TVHome/TVHome/ViewModels/MainPageViewModel.cs | 87 +++++++++++++++++++++++++ TVHome/TVHome/Views/MainPage.xaml.cs | 68 ++++++++++++++++++-- TVHome/TVHome/Views/MainPanel.xaml.cs | 29 +++++++-- TVHome/TVHome/Views/Panel.cs | 43 ++++++++++++- TVHome/TVHome/Views/SubPanel.xaml.cs | 30 +++++++-- TVHome/TVHome/Views/SubThumbnailPanel.xaml.cs | 25 ++++++- 9 files changed, 415 insertions(+), 32 deletions(-) mode change 100644 => 100755 TVHome/TVHome/ViewModels/IHomeViewModel.cs diff --git a/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs b/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs index 04e4e55..86336ec 100755 --- a/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs +++ b/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs @@ -14,33 +14,48 @@ * limitations under the License. */ -using System; -using System.Threading; +using Tizen.Applications; using LibTVRefCommonPortable.Utils; using LibTVRefCommonTizen.Ports; -using Tizen.Applications; -using ElmSharp; namespace TVHome.TizenTV { + /// + /// TV Home application main entry point + /// class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication { + /// + /// A interface for the platform notification + /// IPlatformNotification notification; + /// + /// A port for handling Window APIs + /// WindowPort windowPort; + /// + /// Gets or set the application resource path + /// public static string AppResourcePath { get; private set; } + /// + /// Gets or set the application data path + /// public static string AppDataPath { get; private set; } + /// + /// A method will be called when application is created + /// protected override void OnCreate() { base.OnCreate(); @@ -69,6 +84,11 @@ namespace TVHome.TizenTV windowPort.SetKeyGrabExclusively(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName); } + /// + /// A method will be called when application receives KeyUp event + /// + /// The source of the event + /// A EvasKey event's argument private void KeyUpListener(object sender, ElmSharp.EvasKeyEventArgs e) { DbgPort.D("Key Pressed :" + e.KeyName); @@ -88,6 +108,9 @@ namespace TVHome.TizenTV } } + /// + /// A method will be called when application is terminated + /// protected override void OnTerminate() { base.OnTerminate(); @@ -98,6 +121,10 @@ namespace TVHome.TizenTV MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName); } + /// + /// A method will be called when application receives app control + /// + /// AppControl event argument protected override void OnAppControlReceived(AppControlReceivedEventArgs e) { if (AppControlPort.AppAddedNotifyOperation.CompareTo(e.ReceivedAppControl.Operation) == 0) @@ -115,6 +142,10 @@ namespace TVHome.TizenTV } } + /// + /// The entry point for the application + /// + /// A list of command line arguments static void Main(string[] args) { var app = new Program(); diff --git a/TVHome/TVHome/TVHome.cs b/TVHome/TVHome/TVHome.cs index a925b9b..0627e07 100755 --- a/TVHome/TVHome/TVHome.cs +++ b/TVHome/TVHome/TVHome.cs @@ -21,11 +21,17 @@ using Xamarin.Forms; namespace TVHome { + /// + /// A custom EventArgs with string field + /// public class TVHomeEventArgs : EventArgs { public string arg; } + /// + /// A TVHomeStatus type enumeration + /// public enum TVHomeStatus { OnStart, @@ -33,61 +39,122 @@ namespace TVHome OnResume, } + /// + /// A class that represents TV Home application + /// public class App : Application, IPlatformNotification { + /// + /// A keyword for checking app status + /// public static readonly string AppStatus = "appstatus"; + /// + /// A event handler for handling Home key pressed event + /// private static EventHandler HomeKeyListener; + + /// + /// A event handler for handling Menu key pressed event + /// private static EventHandler MenuKeyListener; + + /// + /// A event handler for handling application installed event + /// private static EventHandler AppInstalledListener; + + /// + /// A event handler for handling application uninstalled event + /// private static EventHandler AppUninstalledListener; + + /// + /// A event handler for handling application pinned event + /// private static EventHandler AppPinnedNotificationListener; + /// + /// A Constructor + /// Sets main page to MainPage instance + /// public App() { MainPage = new MainPage(); } + /// + /// A method is called when the application starts + /// protected override void OnStart() { MessagingCenter.Send(this, "appstatus", TVHomeStatus.OnStart); } + /// + /// A method is called when the application enters the sleeping state + /// protected override void OnSleep() { MessagingCenter.Send(this, "appstatus", TVHomeStatus.OnSleep); } + /// + /// A method is called when the application resumes from a sleeping state + /// protected override void OnResume() { MessagingCenter.Send(this, "appstatus", TVHomeStatus.OnResume); } + /// + /// A method adds EventHandler to HomeKeyListener + /// + /// The EventHandler for adding public static void SetHomeKeyListener(EventHandler listener) { HomeKeyListener += listener; } + /// + /// A method adds EventHandler to MenuKeyListener + /// + /// The EventHandler for adding public static void SetMenuKeyListener(EventHandler listener) { MenuKeyListener += listener; } + /// + /// A method adds EventHandler to AppInstalledListener + /// + /// The EventHandler for adding public static void SetAppInstalledListener(EventHandler listener) { AppInstalledListener += listener; } + /// + /// A method adds EventHandler to AppUninstalledListener + /// + /// The EventHandler for adding public static void SetAppUninstalledListener(EventHandler listener) { AppUninstalledListener += listener; } - + + /// + /// A method adds EventHandler to AppPinnedNotificationListener + /// + /// The EventHandler for adding public static void SetAppPinnedNotificationListener(EventHandler listener) { AppPinnedNotificationListener += listener; } + /// + /// A method for handling home key pressed event + /// public void OnHomeKeyPressed() { DebuggingUtils.Dbg("[[[ Home Key ]]] "); @@ -97,6 +164,9 @@ namespace TVHome }); } + /// + /// A method for handling menu key pressed event + /// public void OnMenuKeyPressed() { DebuggingUtils.Dbg("\" Menu Key \" "); @@ -106,6 +176,10 @@ namespace TVHome }); } + /// + /// A method for handling application installed event + /// + /// A installed package ID public void OnAppInstalled(string pkgID) { DebuggingUtils.Dbg("[[[ App Installed ]]] " + pkgID); @@ -115,6 +189,10 @@ namespace TVHome }); } + /// + /// A method for handling application uninstalled event + /// + /// A uninstalled package ID public void OnAppUninstalled(string pkgID) { DebuggingUtils.Dbg("[[[ App Uninstalled ]]] " + pkgID); @@ -124,17 +202,24 @@ namespace TVHome }); } + /// + /// A method for receiving a pin app App Control request + /// public void OnPinAppRequestReceived() { } - public void OnAppPinnedNotificationReceived(String AppID) + /// + /// A method for receiving application pinned noficiation and invoke pinned event + /// + /// A pinned app ID + public void OnAppPinnedNotificationReceived(String appID) { - DebuggingUtils.Dbg("[[[ App Pinned ]]] " + AppID); + DebuggingUtils.Dbg("[[[ App Pinned ]]] " + appID); AppPinnedNotificationListener.Invoke(this, new TVHomeEventArgs() { - arg = AppID, + arg = appID, }); } } diff --git a/TVHome/TVHome/ViewModels/IHomeViewModel.cs b/TVHome/TVHome/ViewModels/IHomeViewModel.cs old mode 100644 new mode 100755 index f3e6528..1aee6f4 --- a/TVHome/TVHome/ViewModels/IHomeViewModel.cs +++ b/TVHome/TVHome/ViewModels/IHomeViewModel.cs @@ -1,14 +1,37 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +/* + * 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 TVHome.ViewModels { + /// + /// A interface for TV Home MainPageViewModel + /// interface IHomeViewModel { + /// + /// A method for invoking PropertyChanged event + /// + /// The name of property void OnPropertyChanged(string name); + + /// + /// A method changes CurrentStatus according to parameter + /// + /// The next status name + /// A flag indicates whether CurrentStatus to be changed or not void ChangeCurrentStatus(HomeStatus newStatus, bool isForceUpdate); } } diff --git a/TVHome/TVHome/ViewModels/MainPageViewModel.cs b/TVHome/TVHome/ViewModels/MainPageViewModel.cs index e6a2cc1..5ee9ec1 100755 --- a/TVHome/TVHome/ViewModels/MainPageViewModel.cs +++ b/TVHome/TVHome/ViewModels/MainPageViewModel.cs @@ -24,6 +24,9 @@ using Xamarin.Forms; namespace TVHome.ViewModels { + /// + /// A HomeStatus type enumeration + /// public enum HomeStatus { Default = 0, @@ -32,6 +35,10 @@ namespace TVHome.ViewModels UnPin, Move, }; + + /// + /// A HomeMenuItem type enumeration + /// public enum HomeMenuItem { Recent = 0, @@ -40,25 +47,68 @@ namespace TVHome.ViewModels NotSelected, }; + /// + /// A class for ViewModel of TV Home + /// public class MainPageViewModel : INotifyPropertyChanged, IHomeViewModel { + /// + /// Gets or set MainList for MainPanel + /// public IEnumerable MainList { get; set; } + /// + /// Gets or set RecentList for Recent SubPanel + /// public IEnumerable RecentList { get; set; } + /// + /// Gets or set AppList for Apps SubPanel + /// public IEnumerable AppList { get; set; } + /// + /// Gets or set SettingsList for Settings SubPanel + /// public IEnumerable SettingsList { get; set; } + /// + /// A command for executing when MainPanel is focused. + /// public Command MainPanelFocusedCommand { get; set; } + /// + /// A command for executing when SubPanel is focused. + /// public Command SubPanelFocusedCommand { get; set; } + /// + /// A command for changing the status to Move status + /// public Command SetMoveStatusCommand { get; set; } + /// + /// A command for changing the status to Unpin status + /// public Command SetUnpinStatusCommand { get; set; } + /// + /// Gets or set CurrentStatus of HomeStatus + /// public HomeStatus CurrentStatus { get; private set; } + /// + /// Gets or set SelectedMenuName of HomeMenuItem + /// public HomeMenuItem SelectedMenuName { get; private set; } + /// + /// A flag indicates whether "No recent info" in Recent SubPanel to be displayed or not + /// public bool IsShowNoRecentContents { get; set; } + /// + /// A event that is occurred when property of MainPageViewModel is changed + /// public event PropertyChangedEventHandler PropertyChanged; + /// + /// Constructor + /// Initialize MainPanel, SubPanel, Command and EventListeners + /// public MainPageViewModel() { // Init sequence @@ -102,11 +152,17 @@ namespace TVHome.ViewModels }); } + /// + /// A method for initializing HomeStatus to Default + /// private void InitStatus() { ChangeCurrentStatus(HomeStatus.Default, true); } + /// + /// A method for initializing commands + /// private void InitCommands() { MainPanelFocusedCommand = new Command((key) => @@ -132,6 +188,9 @@ namespace TVHome.ViewModels }); } + /// + /// A method for makeing MainMenu items and display in MainPanel + /// private void MakeMainMenuItems() { string[] AppName = { "Recent", "Apps", "Settings" }; @@ -208,24 +267,38 @@ namespace TVHome.ViewModels OnPropertyChanged("MainList"); } + /// + /// Gets default AppList for displaying items and updates the list to Apps SubPanel + /// private void SetDefaultAppList() { AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetDefaultShortcuts(); OnPropertyChanged("AppList"); } + /// + /// Gets the AppList for displaying items and updates the list to Apps SubPanel + /// + /// The source of event + /// The event that is occurred pinned app file is changed private async void UpdateAppList(object sender, EventArgs e) { AppList = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsWithDefaultShortcuts(); OnPropertyChanged("AppList"); } + /// + /// Gets the SettingsList for displaying items and updates the list to Settings SubPanel + /// private void MakeSettingsButtons() { SettingsList = TVHomeImpl.GetInstance.SettingShortcutControllerInstance.GetList(); OnPropertyChanged("SettingsList"); } + /// + /// Gets the RecentList for displaying items and updates the list to Recent SubPanel + /// private void MakeRecentButtons() { RecentList = TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList(); @@ -242,6 +315,10 @@ namespace TVHome.ViewModels OnPropertyChanged("IsShowNoRecentContents"); } + /// + /// A method for invoking PropertyChanged event + /// + /// The name of property public void OnPropertyChanged(string name) { PropertyChangedEventHandler handler = PropertyChanged; @@ -251,6 +328,11 @@ namespace TVHome.ViewModels } } + /// + /// A method for changing CurrentStatus according to parameter + /// + /// The next status name + /// A flag indicates whether CurrentStatus to be changed or not public void ChangeCurrentStatus(HomeStatus newStatus, bool isForceUpdate = false) { if (isForceUpdate || @@ -318,6 +400,11 @@ namespace TVHome.ViewModels } } + /// + /// A method for changing selected HomeMenuItem according to parameter + /// + /// Selected menu name in MainPanel + /// A flag indicates whether selected menu name to be changed or not public void ChangeSelectedPanelName(HomeMenuItem panelName, bool isForceUpdate = false) { if (isForceUpdate || diff --git a/TVHome/TVHome/Views/MainPage.xaml.cs b/TVHome/TVHome/Views/MainPage.xaml.cs index 8c8887d..49eb657 100755 --- a/TVHome/TVHome/Views/MainPage.xaml.cs +++ b/TVHome/TVHome/Views/MainPage.xaml.cs @@ -14,40 +14,55 @@ * limitations under the License. */ -using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Windows.Input; using LibTVRefCommonPortable.DataModels; -using LibTVRefCommonPortable.Models; using LibTVRefCommonPortable.Utils; using Xamarin.Forms; using TVHome.ViewModels; -using System.Linq; namespace TVHome.Views { /// - /// Root Page of TV Home Application + /// A custom view for displaying main page of TV Home /// public partial class MainPage : ContentPage { + /// + /// Identifies the CurrentStatus bindable property + /// public static readonly BindableProperty CurrentStatusProperty = BindableProperty.Create("CurrentStatus", typeof(HomeStatus), typeof(MainPage), default(HomeStatus)); + + /// + /// Gets or sets current status of MainPage + /// public HomeStatus CurrentStatus { get { return (HomeStatus)GetValue(CurrentStatusProperty); } set { SetValue(CurrentStatusProperty, value); } } + /// + /// Identifies the SelectedMenuName bindable property + /// public static readonly BindableProperty SelectedMenuNameProperty = BindableProperty.Create("SelectedMenuName", typeof(HomeMenuItem), typeof(MainPage), default(HomeMenuItem)); + + /// + /// Gets or sets selected HomeMenuItem + /// public HomeMenuItem SelectedMenuName { get { return (HomeMenuItem)GetValue(SelectedMenuNameProperty); } set { SetValue(SelectedMenuNameProperty, value); } } + /// + /// A list of SubPanels + /// private Dictionary SubPanelDictionary; + /// + /// Iconifies the Home screen(Minimizes the Home screen) + /// private async void Iconified() { #pragma warning disable CS4014 @@ -58,6 +73,9 @@ namespace TVHome.Views DependencyService.Get().SetIconified(true); } + /// + /// Uniconifies the Home screen(Maximize the Home screen) + /// private async void Uniconified() { #pragma warning disable CS4014 @@ -68,6 +86,9 @@ namespace TVHome.Views DependencyService.Get().SetIconified(false); } + /// + /// Iconify/uniconify Home screen following current status + /// private void ToggleIconified() { if (DependencyService.Get().GetIconified() == true) @@ -81,6 +102,12 @@ namespace TVHome.Views } } + /// + /// A constructor + /// Makes SubPanel list + /// Adds PropertyChanged event handler + /// Adds HomeKey and MenuKey event listener + /// public MainPage() { InitializeComponent(); @@ -127,6 +154,11 @@ namespace TVHome.Views }); } + /// + /// This method is called when the properties of MainPage is changed + /// + /// The source of event + /// The event that is occurred when property is changed private void MainPage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName.CompareTo("CurrentStatus") == 0) @@ -139,6 +171,10 @@ namespace TVHome.Views } } + /// + /// A method sets current status according to parameter + /// + /// The next status name private void SetCurrentStatus(HomeStatus status) { switch (status) @@ -153,6 +189,10 @@ namespace TVHome.Views } } + /// + /// A method sets selected HomeMenuItem according to parameter + /// + /// Selected HomeMenuItem private void SelectMenu(HomeMenuItem panelName) { foreach (var panelItem in SubPanelDictionary) @@ -168,11 +208,19 @@ namespace TVHome.Views SubPanelDictionary[panelName].ShowPanel(); } + /// + /// A method unpins selected item according to parameter + /// + /// Selected item's app ID private void UnpinAppShortcutInfo(string appId) { RemovePinnedApp(appId); } + /// + /// A method updates the pinned app list according to parameter + /// + /// A new pinned apps list private void UpdatePinnedApps(Dictionary PinnedApps) { List pinnedAppList = new List(); @@ -187,6 +235,10 @@ namespace TVHome.Views TVHomeImpl.GetInstance.AppShortcutControllerInstance.UpdatePinnedApps(pinnedAppList); } + /// + /// A method removes specific pinned app according to parameter + /// + /// To be removed app's app ID private async void RemovePinnedApp(string AppID) { Dictionary PinnedApps = await TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPinnedAppsAppIDs(); @@ -197,6 +249,10 @@ namespace TVHome.Views } } + /// + /// A task for handling BackKey event + /// + /// Always returns true protected override bool OnBackButtonPressed() { ToggleIconified(); diff --git a/TVHome/TVHome/Views/MainPanel.xaml.cs b/TVHome/TVHome/Views/MainPanel.xaml.cs index 0619207..8ef8b4f 100755 --- a/TVHome/TVHome/Views/MainPanel.xaml.cs +++ b/TVHome/TVHome/Views/MainPanel.xaml.cs @@ -14,13 +14,9 @@ * limitations under the License. */ -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Windows.Input; using TVHome.Controls; using LibTVRefCommonPortable.DataModels; -using LibTVRefCommonPortable.Utils; using TVHome.ViewModels; using Xamarin.Forms; using System.Threading.Tasks; @@ -28,16 +24,24 @@ using System.Threading.Tasks; namespace TVHome.Views { /// - /// Main Panel in Main Page + /// A MainPanel view in Main Page /// public partial class MainPanel : Panel { + /// + /// Constructor + /// public MainPanel() { InitializeComponent(); PropertyChanged += OnItemsSourcePropertyChanged; } + /// + /// A event handler for handling property changed event + /// + /// The source of the event + /// The event that is occurred when property is changed private void OnItemsSourcePropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName != "ItemsSource") @@ -72,28 +76,43 @@ namespace TVHome.Views PanelButtonGrid.ForceLayout(); } + /// + /// A method for initializing focus of MainPanel item + /// public void InitialFocusing() { var button = PanelButtonGrid.Children[1]; button.FindByName